Ticket #1628: pthreadcondwait.patch

File pthreadcondwait.patch, 2.8 KB (added by Vinu Rajashekhar, on 07/26/10 at 06:12:08)

patch which allows pthread_cond_wait to be interrupted by a POSIX signal

  • cpukit/posix/src/condinit.c

    diff --git a/cpukit/posix/src/condinit.c b/cpukit/posix/src/condinit.c
    index 1b69cfa..d4bdd50 100644
    a b int pthread_cond_init( 
    6868  _Thread_queue_Initialize(
    6969    &the_cond->Wait_queue,
    7070    THREAD_QUEUE_DISCIPLINE_FIFO,
    71     STATES_WAITING_FOR_CONDITION_VARIABLE,
     71    STATES_WAITING_FOR_CONDITION_VARIABLE
     72    | STATES_INTERRUPTIBLE_BY_SIGNAL,
    7273    ETIMEDOUT
    7374  );
    7475
  • cpukit/posix/src/condwaitsupp.c

    diff --git a/cpukit/posix/src/condwaitsupp.c b/cpukit/posix/src/condwaitsupp.c
    index 45dfb77..032eafb 100644
    a b int _POSIX_Condition_variables_Wait_support( 
    8585         *  _Thread_queue_Enqueue.
    8686         */
    8787
     88        /*
     89         *  If the thread is interrupted, while in the thread queue, by
     90         *  a POSIX signal, then pthread_cond_wait returns spuriously,
     91         *  according to the POSIX standard. It means that pthread_cond_wait
     92         *  returns a success status, except for the fact that it was not
     93         *  woken up a pthread_cond_signal or a pthread_cond_broadcast.
     94         */
    8895        status = _Thread_Executing->Wait.return_code;
    89         if ( status && status != ETIMEDOUT )
     96        if ( status && status != ETIMEDOUT && status != EINTR )
    9097          return status;
     98        else if ( status == EINTR )
     99          status = 0;
    91100
    92101      } else {
    93102        _Thread_Enable_dispatch();
  • cpukit/posix/src/psignalunblockthread.c

    diff --git a/cpukit/posix/src/psignalunblockthread.c b/cpukit/posix/src/psignalunblockthread.c
    index 551f5eb..c35dd1d 100644
    a b bool _POSIX_signals_Unblock_thread( 
    101101    if ( the_thread->current_state & STATES_INTERRUPTIBLE_BY_SIGNAL ) {
    102102      the_thread->Wait.return_code = EINTR;
    103103      /*
    104        *  At this time, there is no RTEMS API object which lets a task
    105        *  block on a thread queue and be interruptible by a POSIX signal.
    106        *  If an object class with that requirement is ever added, enable
    107        *  this code.
     104       *  In pthread_cond_wait, a thread will be blocking on a thread
     105       *  queue, but is also interruptible by a POSIX signal.
    108106       */
    109       #if 0
    110107        if ( _States_Is_waiting_on_thread_queue(the_thread->current_state) )
    111108          _Thread_queue_Extract_with_proxy( the_thread );
    112         else
    113       #endif
    114           if ( _States_Is_delaying(the_thread->current_state) ){
     109        else if ( _States_Is_delaying(the_thread->current_state) ){
    115110            if ( _Watchdog_Is_active( &the_thread->Timer ) )
    116111              (void) _Watchdog_Remove( &the_thread->Timer );
    117112            _Thread_Unblock( the_thread );
    118113          }
     114
    119115    } else if ( the_thread->current_state == STATES_READY ) {
    120116      if ( _ISR_Is_in_progress() && _Thread_Is_executing( the_thread ) )
    121117        _Context_Switch_necessary = true;