From 260b0c2155d809beb550b13fa4fcb08408af5d3f Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Mon, 30 Aug 1999 18:05:48 +0000 Subject: Patch from Charles-Antoine Gauthier to add support for return codes from POSIX threads that do an implicit exit by returning from the bottom of the main function. --- c/src/exec/posix/src/pthread.c | 14 +++++++++- c/src/exec/score/include/rtems/score/thread.h | 7 ++++- c/src/exec/score/src/threadhandler.c | 37 +++++++++++++++++---------- 3 files changed, 43 insertions(+), 15 deletions(-) (limited to 'c/src') diff --git a/c/src/exec/posix/src/pthread.c b/c/src/exec/posix/src/pthread.c index 1a238b006a..2a529ba49a 100644 --- a/c/src/exec/posix/src/pthread.c +++ b/c/src/exec/posix/src/pthread.c @@ -219,6 +219,18 @@ User_extensions_routine _POSIX_Threads_Delete_extension( (void) _Workspace_Free( api ); } +/* + * + * _POSIX_Threads_Exitted_extension + */ + +User_extensions_routine _POSIX_Threads_Exitted_extension( + Thread_Control *executing +) +{ + pthread_exit( executing->Wait.return_argument ); +} + /*PAGE * * _POSIX_Threads_Initialize_user_threads @@ -293,7 +305,7 @@ User_extensions_Control _POSIX_Threads_User_extensions = { _POSIX_Threads_Delete_extension, /* delete */ NULL, /* switch */ NULL, /* begin */ - NULL, /* exitted */ + _POSIX_Threads_Exitted_extension, /* exitted */ NULL /* fatal */ } }; diff --git a/c/src/exec/score/include/rtems/score/thread.h b/c/src/exec/score/include/rtems/score/thread.h index 57acb755fd..1ca0005490 100644 --- a/c/src/exec/score/include/rtems/score/thread.h +++ b/c/src/exec/score/include/rtems/score/thread.h @@ -36,9 +36,14 @@ extern "C" { /* * The following defines the "return type" of a thread. + * + * NOTE: This cannot always be right. Some APIs have void + * tasks/threads, others return pointers, others may + * return a numeric value. Hopefully a pointer is + * always at least as big as an unsigned32. :) */ -typedef void Thread; +typedef void *Thread; /* * The following defines the ways in which the entry point for a diff --git a/c/src/exec/score/src/threadhandler.c b/c/src/exec/score/src/threadhandler.c index bd4e4d319f..6b1d2dc5e2 100644 --- a/c/src/exec/score/src/threadhandler.c +++ b/c/src/exec/score/src/threadhandler.c @@ -86,29 +86,40 @@ void _Thread_Handler( void ) switch ( executing->Start.prototype ) { case THREAD_START_NUMERIC: - (*(Thread_Entry_numeric) executing->Start.entry_point)( - executing->Start.numeric_argument + executing->Wait.return_argument = + (*(Thread_Entry_numeric) executing->Start.entry_point)( + executing->Start.numeric_argument ); break; case THREAD_START_POINTER: - (*(Thread_Entry_pointer) executing->Start.entry_point)( - executing->Start.pointer_argument - ); + executing->Wait.return_argument = + (*(Thread_Entry_pointer) executing->Start.entry_point)( + executing->Start.pointer_argument + ); break; case THREAD_START_BOTH_POINTER_FIRST: - (*(Thread_Entry_both_pointer_first) executing->Start.entry_point)( - executing->Start.pointer_argument, - executing->Start.numeric_argument - ); + executing->Wait.return_argument = + (*(Thread_Entry_both_pointer_first) executing->Start.entry_point)( + executing->Start.pointer_argument, + executing->Start.numeric_argument + ); break; case THREAD_START_BOTH_NUMERIC_FIRST: - (*(Thread_Entry_both_numeric_first) executing->Start.entry_point)( - executing->Start.numeric_argument, - executing->Start.pointer_argument - ); + executing->Wait.return_argument = + (*(Thread_Entry_both_numeric_first) executing->Start.entry_point)( + executing->Start.numeric_argument, + executing->Start.pointer_argument + ); break; } + /* + * In the switch above, the return code from the user thread body + * was placed in return_argument. This assumed that if it returned + * anything (which is not supporting in all APIs), then it would be + * able to fit in a (void *). + */ + _User_extensions_Thread_exitted( executing ); _Internal_error_Occurred( -- cgit v1.2.3