From 98dca75bf3c7cd6692349b6a9e4f66430d90e779 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Tue, 2 Nov 1999 18:25:26 +0000 Subject: Split condition variables into multiple files. --- c/src/exec/posix/include/rtems/posix/cond.h | 36 ++ c/src/exec/posix/src/Makefile.in | 9 +- c/src/exec/posix/src/cond.c | 482 --------------------------- c/src/exec/posix/src/condattrdestroy.c | 31 ++ c/src/exec/posix/src/condattrgetpshared.c | 32 ++ c/src/exec/posix/src/condattrinit.c | 31 ++ c/src/exec/posix/src/condattrsetpshared.c | 39 +++ c/src/exec/posix/src/condbroadcast.c | 26 ++ c/src/exec/posix/src/conddefaultattributes.c | 24 ++ c/src/exec/posix/src/condmp.c | 42 +++ c/src/exec/posix/src/condsignal.c | 26 ++ c/src/exec/posix/src/condsignalsupp.c | 57 ++++ c/src/exec/posix/src/condtimedwait.c | 57 ++++ c/src/exec/posix/src/condwait.c | 32 ++ c/src/exec/posix/src/condwaitsupp.c | 104 ++++++ 15 files changed, 544 insertions(+), 484 deletions(-) create mode 100644 c/src/exec/posix/src/condattrdestroy.c create mode 100644 c/src/exec/posix/src/condattrgetpshared.c create mode 100644 c/src/exec/posix/src/condattrinit.c create mode 100644 c/src/exec/posix/src/condattrsetpshared.c create mode 100644 c/src/exec/posix/src/condbroadcast.c create mode 100644 c/src/exec/posix/src/conddefaultattributes.c create mode 100644 c/src/exec/posix/src/condmp.c create mode 100644 c/src/exec/posix/src/condsignal.c create mode 100644 c/src/exec/posix/src/condsignalsupp.c create mode 100644 c/src/exec/posix/src/condtimedwait.c create mode 100644 c/src/exec/posix/src/condwait.c create mode 100644 c/src/exec/posix/src/condwaitsupp.c (limited to 'c/src/exec/posix') diff --git a/c/src/exec/posix/include/rtems/posix/cond.h b/c/src/exec/posix/include/rtems/posix/cond.h index 0fb44d8042..ba6063f207 100644 --- a/c/src/exec/posix/include/rtems/posix/cond.h +++ b/c/src/exec/posix/include/rtems/posix/cond.h @@ -48,6 +48,12 @@ typedef struct { */ POSIX_EXTERN Objects_Information _POSIX_Condition_variables_Information; + +/* + * The default condition variable attributes structure. + */ + +extern const pthread_condattr_t _POSIX_Condition_variables_Default_attributes; /* * _POSIX_Condition_variables_Manager_initialization @@ -118,6 +124,36 @@ RTEMS_INLINE_ROUTINE boolean _POSIX_Condition_variables_Is_null ( POSIX_Condition_variables_Control *the_condition_variable ); +/* + * _POSIX_Condition_variables_Signal_support + * + * DESCRIPTION: + * + * A support routine which implements guts of the broadcast and single task + * wake up version of the "signal" operation. + */ + +int _POSIX_Condition_variables_Signal_support( + pthread_cond_t *cond, + boolean is_broadcast +); + +/* + * _POSIX_Condition_variables_Wait_support + * + * DESCRIPTION: + * + * A support routine which implements guts of the blocking, non-blocking, and + * timed wait version of condition variable wait routines. + */ + +int _POSIX_Condition_variables_Wait_support( + pthread_cond_t *cond, + pthread_mutex_t *mutex, + Watchdog_Interval timeout, + boolean already_timedout +); + #include #if defined(RTEMS_MULTIPROCESSING) #include diff --git a/c/src/exec/posix/src/Makefile.in b/c/src/exec/posix/src/Makefile.in index a27b1416e6..55c1283afa 100644 --- a/c/src/exec/posix/src/Makefile.in +++ b/c/src/exec/posix/src/Makefile.in @@ -22,7 +22,11 @@ BUILD_FOR_NOW_C_PIECES = aio cancel utsname ENOSYS_C_PIECES = execl execle execlp execv execve execvp fork pthreadatfork \ wait waitpid -MESSAGE_QUEUE_PIECES= mqueue mqueueclose mqueuecreatesupp mqueuedeletesupp \ +CONDITION_VARIABLE_C_PIECES= cond condattrdestroy condattrgetpshared \ + condattrinit condattrsetpshared condbroadcast conddefaultattributes \ + condmp condsignal condsignalsupp condtimedwait condwait condwaitsupp + +MESSAGE_QUEUE_C_PIECES= mqueue mqueueclose mqueuecreatesupp mqueuedeletesupp \ mqueuegetattr mqueuenametoid mqueuenotify mqueueopen mqueuereceive \ mqueuerecvsupp mqueuesend mqueuesendsupp mqueuesetattr \ mqueuetimedreceive mqueuetimedsend mqueueunlink \ @@ -58,7 +62,8 @@ SEMAPHORE_C_PIECES= semaphore semaphorecreatesupp semaphoredeletesupp \ semgetvalue seminit semopen sempost semtimedwait semtrywait \ semunlink semwait -C_PIECES = adasupp cond getpid key $(MESSAGE_QUEUE_PIECES) \ +C_PIECES = adasupp $(CONDITION_VARIABLE_C_PIECES) \ + getpid key $(MESSAGE_QUEUE_C_PIECES) \ $(MUTEX_C_PIECES) $(PTHREAD_C_PIECES) \ $(PSIGNAL_C_PIECES) ptimer sched $(SEMAPHORE_C_PIECES) \ time types unistd $(ENOSYS_C_PIECES) \ diff --git a/c/src/exec/posix/src/cond.c b/c/src/exec/posix/src/cond.c index 0cb06ec192..32a1fea3f5 100644 --- a/c/src/exec/posix/src/cond.c +++ b/c/src/exec/posix/src/cond.c @@ -13,44 +13,6 @@ #include #include -/* - * TEMPORARY - */ - - -#if defined(RTEMS_MULTIPROCESSING) -void _POSIX_Condition_variables_MP_Send_process_packet ( - POSIX_Condition_variables_MP_Remote_operations operation, - Objects_Id condition_variables_id, - Objects_Name name, - Objects_Id proxy_id -) -{ - (void) POSIX_MP_NOT_IMPLEMENTED(); -} - -void _POSIX_Condition_variables_MP_Send_extract_proxy( - Thread_Control *the_thread -) -{ - (void) POSIX_MP_NOT_IMPLEMENTED(); -} -#endif - -/* - * END OF TEMPORARY - */ - -/*PAGE - * - * The default condition variable attributes structure. - */ - -const pthread_condattr_t _POSIX_Condition_variables_Default_attributes = { - TRUE, /* is_initialized */ - PTHREAD_PROCESS_PRIVATE /* process_shared */ -}; - /*PAGE * * _POSIX_Condition_variables_Manager_initialization @@ -79,447 +41,3 @@ void _POSIX_Condition_variables_Manager_initialization( FALSE ); } - -/*PAGE - * - * 11.4.1 Condition Variable Initialization Attributes, - * P1003.1c/Draft 10, p. 96 - */ - -int pthread_condattr_init( - pthread_condattr_t *attr -) -{ - if ( !attr ) - return EINVAL; - - *attr = _POSIX_Condition_variables_Default_attributes; - return 0; -} - -/*PAGE - * - * 11.4.1 Condition Variable Initialization Attributes, - * P1003.1c/Draft 10, p. 96 - */ - -int pthread_condattr_destroy( - pthread_condattr_t *attr -) -{ - if ( !attr || attr->is_initialized == FALSE ) - return EINVAL; - - attr->is_initialized = FALSE; - return 0; -} - -/*PAGE - * - * 11.4.1 Condition Variable Initialization Attributes, - * P1003.1c/Draft 10, p. 96 - */ - -int pthread_condattr_getpshared( - const pthread_condattr_t *attr, - int *pshared -) -{ - if ( !attr ) - return EINVAL; - - *pshared = attr->process_shared; - return 0; -} - -/*PAGE - * - * 11.4.1 Condition Variable Initialization Attributes, - * P1003.1c/Draft 10, p. 96 - */ - -int pthread_condattr_setpshared( - pthread_condattr_t *attr, - int pshared -) -{ - if ( !attr ) - return EINVAL; - - switch ( pshared ) { - case PTHREAD_PROCESS_SHARED: - case PTHREAD_PROCESS_PRIVATE: - attr->process_shared = pshared; - return 0; - - default: - return EINVAL; - } -} - -/*PAGE - * - * 11.4.2 Initializing and Destroying a Condition Variable, - * P1003.1c/Draft 10, p. 87 - */ - -int pthread_cond_init( - pthread_cond_t *cond, - const pthread_condattr_t *attr -) -{ - POSIX_Condition_variables_Control *the_cond; - const pthread_condattr_t *the_attr; - - if ( attr ) the_attr = attr; - else the_attr = &_POSIX_Condition_variables_Default_attributes; - - /* - * XXX: Be careful about attributes when global!!! - */ - - if ( the_attr->process_shared == PTHREAD_PROCESS_SHARED ) - return POSIX_MP_NOT_IMPLEMENTED(); - - if ( !the_attr->is_initialized ) - return EINVAL; - - _Thread_Disable_dispatch(); - - the_cond = _POSIX_Condition_variables_Allocate(); - - if ( !the_cond ) { - _Thread_Enable_dispatch(); - return ENOMEM; - } - -#if defined(RTEMS_MULTIPROCESSING) - if ( the_attr->process_shared == PTHREAD_PROCESS_SHARED && - !( _Objects_MP_Allocate_and_open( &_POSIX_Condition_variables_Information, - 0, the_cond->Object.id, FALSE ) ) ) { - _POSIX_Condition_variables_Free( the_cond ); - _Thread_Enable_dispatch(); - return EAGAIN; - } -#endif - - the_cond->process_shared = the_attr->process_shared; - - the_cond->Mutex = POSIX_CONDITION_VARIABLES_NO_MUTEX; - -/* XXX some more initialization might need to go here */ - _Thread_queue_Initialize( - &the_cond->Wait_queue, - OBJECTS_POSIX_CONDITION_VARIABLES, - THREAD_QUEUE_DISCIPLINE_FIFO, - STATES_WAITING_FOR_CONDITION_VARIABLE, -#if defined(RTEMS_MULTIPROCESSING) - _POSIX_Condition_variables_MP_Send_extract_proxy, -#else - NULL, -#endif - ETIMEDOUT - ); - - _Objects_Open( - &_POSIX_Condition_variables_Information, - &the_cond->Object, - 0 - ); - - *cond = the_cond->Object.id; - -#if defined(RTEMS_MULTIPROCESSING) - if ( the_attr->process_shared == PTHREAD_PROCESS_SHARED ) - _POSIX_Condition_variables_MP_Send_process_packet( - POSIX_CONDITION_VARIABLES_MP_ANNOUNCE_CREATE, - the_cond->Object.id, - 0, /* Name not used */ - 0 /* Not used */ - ); -#endif - - _Thread_Enable_dispatch(); - - return 0; -} - -/*PAGE - * - * 11.4.2 Initializing and Destroying a Condition Variable, - * P1003.1c/Draft 10, p. 87 - */ - -int pthread_cond_destroy( - pthread_cond_t *cond -) -{ - register POSIX_Condition_variables_Control *the_cond; - Objects_Locations location; - - the_cond = _POSIX_Condition_variables_Get( cond, &location ); - switch ( location ) { - case OBJECTS_REMOTE: -#if defined(RTEMS_MULTIPROCESSING) - _Thread_Dispatch(); - return POSIX_MP_NOT_IMPLEMENTED(); - return EINVAL; -#endif - - case OBJECTS_ERROR: - return EINVAL; - - - case OBJECTS_LOCAL: - - if ( _Thread_queue_First( &the_cond->Wait_queue ) ) { - _Thread_Enable_dispatch(); - return EBUSY; - } - - _Objects_Close( - &_POSIX_Condition_variables_Information, - &the_cond->Object - ); - - _POSIX_Condition_variables_Free( the_cond ); - -#if defined(RTEMS_MULTIPROCESSING) - if ( the_cond->process_shared == PTHREAD_PROCESS_SHARED ) { - - _Objects_MP_Close( - &_POSIX_Condition_variables_Information, - the_cond->Object.id - ); - - _POSIX_Condition_variables_MP_Send_process_packet( - POSIX_CONDITION_VARIABLES_MP_ANNOUNCE_DELETE, - the_cond->Object.id, - 0, /* Not used */ - 0 /* Not used */ - ); - } -#endif - _Thread_Enable_dispatch(); - return 0; - } - return POSIX_BOTTOM_REACHED(); -} - -/*PAGE - * - * _POSIX_Condition_variables_Signal_support - * - * A support routine which implements guts of the broadcast and single task - * wake up version of the "signal" operation. - */ - -int _POSIX_Condition_variables_Signal_support( - pthread_cond_t *cond, - boolean is_broadcast -) -{ - register POSIX_Condition_variables_Control *the_cond; - Objects_Locations location; - Thread_Control *the_thread; - - the_cond = _POSIX_Condition_variables_Get( cond, &location ); - switch ( location ) { - case OBJECTS_REMOTE: -#if defined(RTEMS_MULTIPROCESSING) - _Thread_Dispatch(); - return POSIX_MP_NOT_IMPLEMENTED(); - return EINVAL; -#endif - - case OBJECTS_ERROR: - return EINVAL; - case OBJECTS_LOCAL: - - do { - the_thread = _Thread_queue_Dequeue( &the_cond->Wait_queue ); - if ( !the_thread ) - the_cond->Mutex = POSIX_CONDITION_VARIABLES_NO_MUTEX; - } while ( is_broadcast && the_thread ); - - _Thread_Enable_dispatch(); - - return 0; - } - return POSIX_BOTTOM_REACHED(); -} - -/*PAGE - * - * 11.4.3 Broadcasting and Signaling a Condition, P1003.1c/Draft 10, p. 101 - */ - -int pthread_cond_signal( - pthread_cond_t *cond -) -{ - return _POSIX_Condition_variables_Signal_support( cond, FALSE ); -} - -/*PAGE - * - * 11.4.3 Broadcasting and Signaling a Condition, P1003.1c/Draft 10, p. 101 - */ - -int pthread_cond_broadcast( - pthread_cond_t *cond -) -{ - return _POSIX_Condition_variables_Signal_support( cond, TRUE ); -} - -/*PAGE - * - * _POSIX_Condition_variables_Wait_support - * - * A support routine which implements guts of the blocking, non-blocking, and - * timed wait version of condition variable wait routines. - */ - -int _POSIX_Condition_variables_Wait_support( - pthread_cond_t *cond, - pthread_mutex_t *mutex, - Watchdog_Interval timeout, - boolean already_timedout -) -{ - register POSIX_Condition_variables_Control *the_cond; - Objects_Locations location; - int status; - int mutex_status; - - if ( !_POSIX_Mutex_Get( mutex, &location ) ) { - return EINVAL; - } - - _Thread_Unnest_dispatch(); - - the_cond = _POSIX_Condition_variables_Get( cond, &location ); - switch ( location ) { - case OBJECTS_REMOTE: -#if defined(RTEMS_MULTIPROCESSING) - _Thread_Dispatch(); - return POSIX_MP_NOT_IMPLEMENTED(); - return EINVAL; -#endif - case OBJECTS_ERROR: - return EINVAL; - case OBJECTS_LOCAL: - - if ( the_cond->Mutex && ( the_cond->Mutex != *mutex ) ) { - _Thread_Enable_dispatch(); - return EINVAL; - } - - (void) pthread_mutex_unlock( mutex ); -/* XXX ignore this for now since behavior is undefined - if ( mutex_status ) { - _Thread_Enable_dispatch(); - return EINVAL; - } -*/ - - if ( !already_timedout ) { - the_cond->Mutex = *mutex; - - _Thread_queue_Enter_critical_section( &the_cond->Wait_queue ); - _Thread_Executing->Wait.return_code = 0; - _Thread_Executing->Wait.queue = &the_cond->Wait_queue; - _Thread_Executing->Wait.id = *cond; - - _Thread_queue_Enqueue( &the_cond->Wait_queue, timeout ); - - _Thread_Enable_dispatch(); - - /* - * Switch ourself out because we blocked as a result of the - * _Thread_queue_Enqueue. - */ - - status = _Thread_Executing->Wait.return_code; - if ( status && status != ETIMEDOUT ) - return status; - - } else { - _Thread_Enable_dispatch(); - status = ETIMEDOUT; - } - - /* - * When we get here the dispatch disable level is 0. - */ - - mutex_status = pthread_mutex_lock( mutex ); - if ( mutex_status ) - return EINVAL; - - return status; - } - return POSIX_BOTTOM_REACHED(); -} - -/*PAGE - * - * 11.4.4 Waiting on a Condition, P1003.1c/Draft 10, p. 105 - */ - -int pthread_cond_wait( - pthread_cond_t *cond, - pthread_mutex_t *mutex -) -{ - return _POSIX_Condition_variables_Wait_support( - cond, - mutex, - THREAD_QUEUE_WAIT_FOREVER, - FALSE - ); -} - -/*PAGE - * - * 11.4.4 Waiting on a Condition, P1003.1c/Draft 10, p. 105 - */ - -int pthread_cond_timedwait( - pthread_cond_t *cond, - pthread_mutex_t *mutex, - const struct timespec *abstime -) -{ - Watchdog_Interval timeout; - struct timespec current_time; - struct timespec difference; - boolean already_timedout = FALSE; - - if ( !abstime ) - return EINVAL; - - /* - * The abstime is a walltime. We turn it into an interval. - */ - - (void) clock_gettime( CLOCK_REALTIME, ¤t_time ); - - /* XXX probably some error checking should go here */ - - _POSIX_Timespec_subtract( ¤t_time, abstime, &difference ); - - if ( ( difference.tv_sec < 0 ) || ( ( difference.tv_sec == 0 ) && - ( difference.tv_nsec < 0 ) ) ) - already_timedout = TRUE; - - timeout = _POSIX_Timespec_to_interval( &difference ); - - return _POSIX_Condition_variables_Wait_support( - cond, - mutex, - timeout, - already_timedout - ); -} diff --git a/c/src/exec/posix/src/condattrdestroy.c b/c/src/exec/posix/src/condattrdestroy.c new file mode 100644 index 0000000000..f0e58eda06 --- /dev/null +++ b/c/src/exec/posix/src/condattrdestroy.c @@ -0,0 +1,31 @@ +/* + * $Id$ + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +/*PAGE + * + * 11.4.1 Condition Variable Initialization Attributes, + * P1003.1c/Draft 10, p. 96 + */ + +int pthread_condattr_destroy( + pthread_condattr_t *attr +) +{ + if ( !attr || attr->is_initialized == FALSE ) + return EINVAL; + + attr->is_initialized = FALSE; + return 0; +} diff --git a/c/src/exec/posix/src/condattrgetpshared.c b/c/src/exec/posix/src/condattrgetpshared.c new file mode 100644 index 0000000000..7e2e7944a3 --- /dev/null +++ b/c/src/exec/posix/src/condattrgetpshared.c @@ -0,0 +1,32 @@ +/* + * $Id$ + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +/*PAGE + * + * 11.4.1 Condition Variable Initialization Attributes, + * P1003.1c/Draft 10, p. 96 + */ + +int pthread_condattr_getpshared( + const pthread_condattr_t *attr, + int *pshared +) +{ + if ( !attr ) + return EINVAL; + + *pshared = attr->process_shared; + return 0; +} diff --git a/c/src/exec/posix/src/condattrinit.c b/c/src/exec/posix/src/condattrinit.c new file mode 100644 index 0000000000..891540227f --- /dev/null +++ b/c/src/exec/posix/src/condattrinit.c @@ -0,0 +1,31 @@ +/* + * $Id$ + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +/*PAGE + * + * 11.4.1 Condition Variable Initialization Attributes, + * P1003.1c/Draft 10, p. 96 + */ + +int pthread_condattr_init( + pthread_condattr_t *attr +) +{ + if ( !attr ) + return EINVAL; + + *attr = _POSIX_Condition_variables_Default_attributes; + return 0; +} diff --git a/c/src/exec/posix/src/condattrsetpshared.c b/c/src/exec/posix/src/condattrsetpshared.c new file mode 100644 index 0000000000..6c5b0e5301 --- /dev/null +++ b/c/src/exec/posix/src/condattrsetpshared.c @@ -0,0 +1,39 @@ +/* + * $Id$ + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +/*PAGE + * + * 11.4.1 Condition Variable Initialization Attributes, + * P1003.1c/Draft 10, p. 96 + */ + +int pthread_condattr_setpshared( + pthread_condattr_t *attr, + int pshared +) +{ + if ( !attr ) + return EINVAL; + + switch ( pshared ) { + case PTHREAD_PROCESS_SHARED: + case PTHREAD_PROCESS_PRIVATE: + attr->process_shared = pshared; + return 0; + + default: + return EINVAL; + } +} diff --git a/c/src/exec/posix/src/condbroadcast.c b/c/src/exec/posix/src/condbroadcast.c new file mode 100644 index 0000000000..5a55e75b23 --- /dev/null +++ b/c/src/exec/posix/src/condbroadcast.c @@ -0,0 +1,26 @@ +/* + * $Id$ + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +/*PAGE + * + * 11.4.3 Broadcasting and Signaling a Condition, P1003.1c/Draft 10, p. 101 + */ + +int pthread_cond_broadcast( + pthread_cond_t *cond +) +{ + return _POSIX_Condition_variables_Signal_support( cond, TRUE ); +} diff --git a/c/src/exec/posix/src/conddefaultattributes.c b/c/src/exec/posix/src/conddefaultattributes.c new file mode 100644 index 0000000000..a45b96f3c8 --- /dev/null +++ b/c/src/exec/posix/src/conddefaultattributes.c @@ -0,0 +1,24 @@ +/* + * $Id$ + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +/*PAGE + * + * The default condition variable attributes structure. + */ + +const pthread_condattr_t _POSIX_Condition_variables_Default_attributes = { + TRUE, /* is_initialized */ + PTHREAD_PROCESS_PRIVATE /* process_shared */ +}; diff --git a/c/src/exec/posix/src/condmp.c b/c/src/exec/posix/src/condmp.c new file mode 100644 index 0000000000..c085ab4976 --- /dev/null +++ b/c/src/exec/posix/src/condmp.c @@ -0,0 +1,42 @@ +/* + * $Id$ + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +/* + * TEMPORARY + */ + +#if defined(RTEMS_MULTIPROCESSING) +void _POSIX_Condition_variables_MP_Send_process_packet ( + POSIX_Condition_variables_MP_Remote_operations operation, + Objects_Id condition_variables_id, + Objects_Name name, + Objects_Id proxy_id +) +{ + (void) POSIX_MP_NOT_IMPLEMENTED(); +} + +void _POSIX_Condition_variables_MP_Send_extract_proxy( + Thread_Control *the_thread +) +{ + (void) POSIX_MP_NOT_IMPLEMENTED(); +} +#endif + +/* + * END OF TEMPORARY + */ + diff --git a/c/src/exec/posix/src/condsignal.c b/c/src/exec/posix/src/condsignal.c new file mode 100644 index 0000000000..52fb89e91e --- /dev/null +++ b/c/src/exec/posix/src/condsignal.c @@ -0,0 +1,26 @@ +/* + * $Id$ + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +/*PAGE + * + * 11.4.3 Broadcasting and Signaling a Condition, P1003.1c/Draft 10, p. 101 + */ + +int pthread_cond_signal( + pthread_cond_t *cond +) +{ + return _POSIX_Condition_variables_Signal_support( cond, FALSE ); +} diff --git a/c/src/exec/posix/src/condsignalsupp.c b/c/src/exec/posix/src/condsignalsupp.c new file mode 100644 index 0000000000..e6b4d6a1a3 --- /dev/null +++ b/c/src/exec/posix/src/condsignalsupp.c @@ -0,0 +1,57 @@ +/* + * $Id$ + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +/*PAGE + * + * _POSIX_Condition_variables_Signal_support + * + * A support routine which implements guts of the broadcast and single task + * wake up version of the "signal" operation. + */ + +int _POSIX_Condition_variables_Signal_support( + pthread_cond_t *cond, + boolean is_broadcast +) +{ + register POSIX_Condition_variables_Control *the_cond; + Objects_Locations location; + Thread_Control *the_thread; + + the_cond = _POSIX_Condition_variables_Get( cond, &location ); + switch ( location ) { + case OBJECTS_REMOTE: +#if defined(RTEMS_MULTIPROCESSING) + _Thread_Dispatch(); + return POSIX_MP_NOT_IMPLEMENTED(); + return EINVAL; +#endif + + case OBJECTS_ERROR: + return EINVAL; + case OBJECTS_LOCAL: + + do { + the_thread = _Thread_queue_Dequeue( &the_cond->Wait_queue ); + if ( !the_thread ) + the_cond->Mutex = POSIX_CONDITION_VARIABLES_NO_MUTEX; + } while ( is_broadcast && the_thread ); + + _Thread_Enable_dispatch(); + + return 0; + } + return POSIX_BOTTOM_REACHED(); +} diff --git a/c/src/exec/posix/src/condtimedwait.c b/c/src/exec/posix/src/condtimedwait.c new file mode 100644 index 0000000000..ed6d676293 --- /dev/null +++ b/c/src/exec/posix/src/condtimedwait.c @@ -0,0 +1,57 @@ +/* + * $Id$ + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +/*PAGE + * + * 11.4.4 Waiting on a Condition, P1003.1c/Draft 10, p. 105 + */ + +int pthread_cond_timedwait( + pthread_cond_t *cond, + pthread_mutex_t *mutex, + const struct timespec *abstime +) +{ + Watchdog_Interval timeout; + struct timespec current_time; + struct timespec difference; + boolean already_timedout = FALSE; + + if ( !abstime ) + return EINVAL; + + /* + * The abstime is a walltime. We turn it into an interval. + */ + + (void) clock_gettime( CLOCK_REALTIME, ¤t_time ); + + /* XXX probably some error checking should go here */ + + _POSIX_Timespec_subtract( ¤t_time, abstime, &difference ); + + if ( ( difference.tv_sec < 0 ) || ( ( difference.tv_sec == 0 ) && + ( difference.tv_nsec < 0 ) ) ) + already_timedout = TRUE; + + timeout = _POSIX_Timespec_to_interval( &difference ); + + return _POSIX_Condition_variables_Wait_support( + cond, + mutex, + timeout, + already_timedout + ); +} diff --git a/c/src/exec/posix/src/condwait.c b/c/src/exec/posix/src/condwait.c new file mode 100644 index 0000000000..74bc0fba0f --- /dev/null +++ b/c/src/exec/posix/src/condwait.c @@ -0,0 +1,32 @@ +/* + * $Id$ + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +/*PAGE + * + * 11.4.4 Waiting on a Condition, P1003.1c/Draft 10, p. 105 + */ + +int pthread_cond_wait( + pthread_cond_t *cond, + pthread_mutex_t *mutex +) +{ + return _POSIX_Condition_variables_Wait_support( + cond, + mutex, + THREAD_QUEUE_WAIT_FOREVER, + FALSE + ); +} diff --git a/c/src/exec/posix/src/condwaitsupp.c b/c/src/exec/posix/src/condwaitsupp.c new file mode 100644 index 0000000000..13827aa725 --- /dev/null +++ b/c/src/exec/posix/src/condwaitsupp.c @@ -0,0 +1,104 @@ +/* + * $Id$ + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +/*PAGE + * + * _POSIX_Condition_variables_Wait_support + * + * A support routine which implements guts of the blocking, non-blocking, and + * timed wait version of condition variable wait routines. + */ + +int _POSIX_Condition_variables_Wait_support( + pthread_cond_t *cond, + pthread_mutex_t *mutex, + Watchdog_Interval timeout, + boolean already_timedout +) +{ + register POSIX_Condition_variables_Control *the_cond; + Objects_Locations location; + int status; + int mutex_status; + + if ( !_POSIX_Mutex_Get( mutex, &location ) ) { + return EINVAL; + } + + _Thread_Unnest_dispatch(); + + the_cond = _POSIX_Condition_variables_Get( cond, &location ); + switch ( location ) { + case OBJECTS_REMOTE: +#if defined(RTEMS_MULTIPROCESSING) + _Thread_Dispatch(); + return POSIX_MP_NOT_IMPLEMENTED(); + return EINVAL; +#endif + case OBJECTS_ERROR: + return EINVAL; + case OBJECTS_LOCAL: + + if ( the_cond->Mutex && ( the_cond->Mutex != *mutex ) ) { + _Thread_Enable_dispatch(); + return EINVAL; + } + + (void) pthread_mutex_unlock( mutex ); +/* XXX ignore this for now since behavior is undefined + if ( mutex_status ) { + _Thread_Enable_dispatch(); + return EINVAL; + } +*/ + + if ( !already_timedout ) { + the_cond->Mutex = *mutex; + + _Thread_queue_Enter_critical_section( &the_cond->Wait_queue ); + _Thread_Executing->Wait.return_code = 0; + _Thread_Executing->Wait.queue = &the_cond->Wait_queue; + _Thread_Executing->Wait.id = *cond; + + _Thread_queue_Enqueue( &the_cond->Wait_queue, timeout ); + + _Thread_Enable_dispatch(); + + /* + * Switch ourself out because we blocked as a result of the + * _Thread_queue_Enqueue. + */ + + status = _Thread_Executing->Wait.return_code; + if ( status && status != ETIMEDOUT ) + return status; + + } else { + _Thread_Enable_dispatch(); + status = ETIMEDOUT; + } + + /* + * When we get here the dispatch disable level is 0. + */ + + mutex_status = pthread_mutex_lock( mutex ); + if ( mutex_status ) + return EINVAL; + + return status; + } + return POSIX_BOTTOM_REACHED(); +} -- cgit v1.2.3