From 1b1be254e7a3e3d6fe6d55d62010a81a7ef35411 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 25 Mar 2014 10:54:49 +0100 Subject: score: Thread life cycle re-implementation The thread deletion is now supported on SMP. This change fixes the following PRs: PR1814: SMP race condition between stack free and dispatch PR2035: psxcancel reveals NULL pointer access in _Thread_queue_Extract() The POSIX cleanup handler are now called in the right context (should be called in the context of the terminating thread). http://pubs.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_09.html Add a user extension the reflects a thread termination event. This is used to reclaim the Newlib reentrancy structure (may use file operations), the POSIX cleanup handlers and the POSIX key destructors. --- cpukit/score/src/heapfree.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'cpukit/score/src/heapfree.c') diff --git a/cpukit/score/src/heapfree.c b/cpukit/score/src/heapfree.c index c45c294f3f..4e69146232 100644 --- a/cpukit/score/src/heapfree.c +++ b/cpukit/score/src/heapfree.c @@ -83,26 +83,13 @@ bool do_free = true; Heap_Block *const next = block->Protection_begin.next_delayed_free_block; - /* - * Sometimes after a free the allocated area is still in use. An example - * is the task stack of a thread that deletes itself. The thread dispatch - * disable level is a way to detect this use case. - */ - if ( _Thread_Dispatch_is_enabled() ) { - if ( next == NULL ) { - _Heap_Protection_delay_block_free( heap, block ); - do_free = false; - } else if ( next == HEAP_PROTECTION_OBOLUS ) { - _Heap_Protection_check_free_block( heap, block ); - } else { - _Heap_Protection_block_error( heap, block ); - } - } else if ( next == NULL ) { - /* - * This is a hack to prevent heavy workspace fragmentation which would - * lead to test suite failures. - */ - _Heap_Protection_free_all_delayed_blocks( heap ); + if ( next == NULL ) { + _Heap_Protection_delay_block_free( heap, block ); + do_free = false; + } else if ( next == HEAP_PROTECTION_OBOLUS ) { + _Heap_Protection_check_free_block( heap, block ); + } else { + _Heap_Protection_block_error( heap, block ); } return do_free; -- cgit v1.2.3