Mercurial > libpst
comparison src/readpst.c @ 288:fa7fc1ac6385
add gprof profiling option; allow fork for parallel processing of individual email folders in separate mode
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 27 May 2011 09:50:24 -0700 |
parents | 898118c3675e |
children | cc8ee701f190 |
comparison
equal
deleted
inserted
replaced
287:0f0ccd29b0d7 | 288:fa7fc1ac6385 |
---|---|
150 { | 150 { |
151 int available = 0; | 151 int available = 0; |
152 #ifdef HAVE_FORK | 152 #ifdef HAVE_FORK |
153 #ifdef HAVE_SEMAPHORE_H | 153 #ifdef HAVE_SEMAPHORE_H |
154 if (global_children) { | 154 if (global_children) { |
155 sem_getvalue(global_children, &available); | 155 //sem_getvalue(global_children, &available); |
156 //printf("grim reaper %s for pid %d (parent %d) with %d children, %d available\n", (waitall) ? "all" : "", getpid(), getppid(), active_children, available); | 156 //printf("grim reaper %s for pid %d (parent %d) with %d children, %d available\n", (waitall) ? "all" : "", getpid(), getppid(), active_children, available); |
157 //fflush(stdout); | 157 //fflush(stdout); |
158 int i,j; | 158 int i,j; |
159 for (i=0; i<active_children; i++) { | 159 for (i=0; i<active_children; i++) { |
160 int status; | 160 int status; |
328 if ((ff.type != PST_TYPE_NOTE) && (ff.type != PST_TYPE_SCHEDULE) && (ff.type != PST_TYPE_REPORT) && (mode != MODE_SEPARATE)) { | 328 if ((ff.type != PST_TYPE_NOTE) && (ff.type != PST_TYPE_SCHEDULE) && (ff.type != PST_TYPE_REPORT) && (mode != MODE_SEPARATE)) { |
329 ff.skip_count++; | 329 ff.skip_count++; |
330 DEBUG_INFO(("I have an email type %"PRIi32", but the folder type %"PRIi32" isn't an email folder. Skipping it\n", item->type, ff.type)); | 330 DEBUG_INFO(("I have an email type %"PRIi32", but the folder type %"PRIi32" isn't an email folder. Skipping it\n", item->type, ff.type)); |
331 } | 331 } |
332 else { | 332 else { |
333 ff.item_count++; | |
333 char *extra_mime_headers = NULL; | 334 char *extra_mime_headers = NULL; |
334 ff.item_count++; | 335 if (mode == MODE_SEPARATE) { |
335 if (mode == MODE_SEPARATE) mk_separate_file(&ff, (mode_EX) ? ".eml" : ""); | 336 // process this single email message, possibly forking |
336 write_normal_email(ff.output, ff.name, item, mode, mode_MH, &pstfile, save_rtf_body, &extra_mime_headers); | 337 pid_t parent = getpid(); |
338 pid_t child = try_fork(item->file_as.str); | |
339 if (child == 0) { | |
340 // we are the child process, or the original parent if no children were available | |
341 pid_t me = getpid(); | |
342 mk_separate_file(&ff, (mode_EX) ? ".eml" : ""); | |
343 write_normal_email(ff.output, ff.name, item, mode, mode_MH, &pstfile, save_rtf_body, &extra_mime_headers); | |
344 #ifdef HAVE_FORK | |
345 #ifdef HAVE_SEMAPHORE_H | |
346 if (me != parent) { | |
347 // we really were a child, forked for the sole purpose of processing this message | |
348 // free my child count slot before really exiting, since | |
349 // all I am doing here is waiting for my children to exit | |
350 sem_post(global_children); | |
351 grim_reaper(1); // wait for all my child processes to exit - there should not be any | |
352 exit(0); // really exit | |
353 } | |
354 #endif | |
355 #endif | |
356 } | |
357 } | |
358 else { | |
359 // process this single email message, cannot fork since not separate mode | |
360 write_normal_email(ff.output, ff.name, item, mode, mode_MH, &pstfile, save_rtf_body, &extra_mime_headers); | |
361 } | |
337 } | 362 } |
338 } | 363 } |
339 | 364 |
340 } else if (item->journal && (item->type == PST_TYPE_JOURNAL)) { | 365 } else if (item->journal && (item->type == PST_TYPE_JOURNAL)) { |
341 DEBUG_INFO(("Processing Journal Entry\n")); | 366 DEBUG_INFO(("Processing Journal Entry\n")); |