/[cvs]/joko/Uni/BSArch/04/bmp_fractal.c
ViewVC logotype

Diff of /joko/Uni/BSArch/04/bmp_fractal.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.14 by joko, Sun Jul 2 11:44:57 2006 UTC revision 1.15 by joko, Sun Jul 2 12:08:10 2006 UTC
# Line 49  void printErrorAndExit(const char *msg, Line 49  void printErrorAndExit(const char *msg,
49                                            0,                                            0,
50                                            NULL ))                                            NULL ))
51          {          {
52                  fprintf(stdout, "%s: %s\n", msg, lpMsgBuf);                  fprintf(stderr, "%s: %s\n", msg, lpMsgBuf);
53                  LocalFree(lpMsgBuf);                  LocalFree(lpMsgBuf);
54          }          }
55          else          else
56          {          {
57                  fprintf(stdout, "Error at FormatMesage: %d\n",err=GetLastError());                  fprintf(stderr, "Error at FormatMesage: %d\n",err=GetLastError());
58          }          }
59          exit(err);          exit(err);
60  }  }
# Line 68  void write_blank_file(char *filename) { Line 68  void write_blank_file(char *filename) {
68    // open file handle    // open file handle
69    fd = fopen(filename, "wb+");    fd = fopen(filename, "wb+");
70    if (NULL == fd) {    if (NULL == fd) {
71      perror("open");      perror("Error while opening file for writing");
72      exit(1);      exit(1);
73    }    }
74    
# Line 77  void write_blank_file(char *filename) { Line 77  void write_blank_file(char *filename) {
77        
78    // error checking    // error checking
79    if (-1 == len || len != sizeof(header)) {    if (-1 == len || len != sizeof(header)) {
80      perror("write");      perror("Error while writing header to file");
81      exit(2);      exit(2);
82    }    }
83        
# Line 86  void write_blank_file(char *filename) { Line 86  void write_blank_file(char *filename) {
86    for (i = 0; i < img_size; i++) {    for (i = 0; i < img_size; i++) {
87      len = fwrite("\0\0\0", 1, 3, fd);      len = fwrite("\0\0\0", 1, 3, fd);
88      if (-1 == len || len != 3) {      if (-1 == len || len != 3) {
89        perror("write");        perror("Error while writing data to file");
90        exit(4);        exit(4);
91      }      }
92    }    }
# Line 315  int main(int argc, char *argv[]) { Line 315  int main(int argc, char *argv[]) {
315            
316      // allocate memory for one worker's arguments      // allocate memory for one worker's arguments
317      if ((worker_args = malloc(sizeof(worker_args[0]))) == NULL)      if ((worker_args = malloc(sizeof(worker_args[0]))) == NULL)
318        perror("malloc"), exit(1);        perror("Error while allocating memory for worker arguments via malloc"), exit(1);
319            
320      // assign worker's arguments      // assign worker's arguments
321      worker_args[0].start_row = worker_startrow;      worker_args[0].start_row = worker_startrow;
# Line 348  int main(int argc, char *argv[]) { Line 348  int main(int argc, char *argv[]) {
348        
349    // allocate memory for table of all worker handles    // allocate memory for table of all worker handles
350    if ((worker_handles = malloc(workers * sizeof(worker_handles[0]))) == NULL)    if ((worker_handles = malloc(workers * sizeof(worker_handles[0]))) == NULL)
351      perror("malloc"), exit(1);      perror("Error while allocating memory for worker handles via malloc"), exit(1);
352    
353    // allocate memory for table of all worker arguments    // allocate memory for table of all worker arguments
354    if ((worker_args = malloc(workers * sizeof(worker_args[0]))) == NULL)    if ((worker_args = malloc(workers * sizeof(worker_args[0]))) == NULL)
355      perror("malloc"), exit(1);      perror("Error while allocating memory for worker arguments via malloc"), exit(1);
356        
357        
358    // calculate bitmap segment length for workers    // calculate bitmap segment length for workers
# Line 431  int main(int argc, char *argv[]) { Line 431  int main(int argc, char *argv[]) {
431    if (VERBOSE)    if (VERBOSE)
432      fprintf(stdout, "waiting for workers to finish...\n");      fprintf(stdout, "waiting for workers to finish...\n");
433    if (WaitForMultipleObjects(workers, worker_handles, TRUE, INFINITE) == WAIT_FAILED)    if (WaitForMultipleObjects(workers, worker_handles, TRUE, INFINITE) == WAIT_FAILED)
434      perror("WaitForMultipleObjects");      printErrorAndExit("Error at WaitForMultipleObjects", GetLastError());
435    
436    // debugging: just run single thread    // debugging: just run single thread
437    //if (WaitForSingleObject(worker_handles[0], INFINITE) == WAIT_FAILED)    //if (WaitForSingleObject(worker_handles[0], INFINITE) == WAIT_FAILED)

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed