- struct freeable_stack *new_freeable_stack = 0;
- if (thread_to_be_cleaned_up) {
- /* FIXME: os_validate is mmap -- for small things like these
- * malloc would probably perform better. */
- new_freeable_stack = (struct freeable_stack *)
- os_validate(0, sizeof(struct freeable_stack));
- new_freeable_stack->next = NULL;
- new_freeable_stack->os_thread = thread_to_be_cleaned_up->os_thread;
- new_freeable_stack->os_address = thread_to_be_cleaned_up->os_address;
- pthread_mutex_lock(&freeable_stack_lock);
- if (freeable_stack_queue) {
- struct freeable_stack *next;
- next = freeable_stack_queue;
- while (next->next) {
- next = next->next;
- }
- next->next = new_freeable_stack;
- } else {
- freeable_stack_queue = new_freeable_stack;
- }
- freeable_stack_count++;
- pthread_mutex_unlock(&freeable_stack_lock);
- }
-}
-
-#define FREEABLE_STACK_QUEUE_SIZE 4
-
-static void
-free_freeable_stacks() {
- if (freeable_stack_queue && (freeable_stack_count > FREEABLE_STACK_QUEUE_SIZE)) {
- struct freeable_stack* old;
- pthread_mutex_lock(&freeable_stack_lock);
- old = freeable_stack_queue;
- freeable_stack_queue = old->next;
- freeable_stack_count--;
- gc_assert(pthread_join(old->os_thread, NULL) == 0);
- FSHOW((stderr, "freeing thread %x stack\n", old->os_thread));
- os_invalidate(old->os_address, THREAD_STRUCT_SIZE);
- os_invalidate((os_vm_address_t)old, sizeof(struct freeable_stack));
- pthread_mutex_unlock(&freeable_stack_lock);
+ if (corpse) {
+ struct thread_post_mortem *post_mortem = malloc(sizeof(struct thread_post_mortem));
+ gc_assert(post_mortem);
+ post_mortem->os_thread = corpse->os_thread;
+ post_mortem->os_attr = corpse->os_attr;
+ post_mortem->os_address = corpse->os_address;
+#ifdef DELAY_THREAD_POST_MORTEM
+ post_mortem->next = NULL;
+#endif
+ return post_mortem;
+ } else {
+ /* FIXME: When does this happen? */
+ return NULL;