diff options
author | Neal H. Walfield <neal@gnu.org> | 2009-03-17 20:35:46 +0100 |
---|---|---|
committer | Neal H. Walfield <neal@gnu.org> | 2009-03-17 20:35:46 +0100 |
commit | 85532309547c936947da9e27e328f0e4f29df323 (patch) | |
tree | 891786adce339419cc200d0112b79d802203dce2 /hieronymus | |
parent | d6cdbfd09d2ce8ed04298acbb91206c7f10bb053 (diff) |
Change Hieronymus to destroy activities when the corresponding thread exits.
Diffstat (limited to 'hieronymus')
-rw-r--r-- | hieronymus/hieronymus.c | 59 |
1 files changed, 42 insertions, 17 deletions
diff --git a/hieronymus/hieronymus.c b/hieronymus/hieronymus.c index 24cc86e..ce05b79 100644 --- a/hieronymus/hieronymus.c +++ b/hieronymus/hieronymus.c @@ -343,24 +343,49 @@ main (int argc, char *argv[]) /* Wait for all activities to die. */ - for (i = 0; i < module_count; i ++) + void *waiter (void *arg) + { + int i = (uintptr_t) arg; + + uintptr_t rt = -1; + vg_object_reply_on_destruction (root_activity, + thread[i], &rt); + + vg_addr_t folio = vg_addr_chop (activities[i], VG_FOLIO_OBJECTS_LOG2); + int index = vg_addr_extract (activities[i], VG_FOLIO_OBJECTS_LOG2); + + error_t err; + err = vg_folio_object_alloc (VG_ADDR_VOID, folio, index, + vg_cap_void, VG_OBJECT_POLICY_VOID, + (uintptr_t) rt, + NULL, NULL); + if (err) + debug (0, "deallocating object: %d", err); + + debug (0, "%s exited with %d", modules[i].name, (int) rt); + + return 0; + } + + if (module_count == 1) + waiter ((void *) 0); + else { - uintptr_t rt = -1; - vg_object_reply_on_destruction (root_activity, - thread[i], &rt); - - vg_addr_t folio = vg_addr_chop (activities[i], VG_FOLIO_OBJECTS_LOG2); - int index = vg_addr_extract (activities[i], VG_FOLIO_OBJECTS_LOG2); - - error_t err; - err = vg_folio_object_alloc (VG_ADDR_VOID, folio, index, - vg_cap_void, VG_OBJECT_POLICY_VOID, - (uintptr_t) rt, - NULL, NULL); - if (err) - debug (0, "deallocating object: %d", err); - - debug (0, "%s exited with %d", modules[i].name, (int) rt); + pthread_t tids[module_count]; + int i; + for (i = 0; i < module_count; i ++) + { + error_t err; + err = pthread_create (&tids[i], NULL, waiter, (void *) (uintptr_t) i); + if (err) + panic ("Creating thread: %d", err); + } + + for (i = 0; i < module_count; i ++) + { + void *ret; + pthread_join (tids[i], &ret); + } } if (gather_stats) |