source: rtems/cpukit/posix/src/psignalunblockthread.c @ 4b48ece0

4.115
Last change on this file since 4b48ece0 was 4b48ece0, checked in by Sebastian Huber <sebastian.huber@…>, on 07/22/13 at 08:21:03

score: Create watchdog implementation header

Move implementation specific parts of watchdog.h and watchdog.inl into
new header file watchdogimpl.h. The watchdog.h contains now only the
application visible API.

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/**
2 * @file
3 *
4 * @brief POSIX Signals Thread Unlock
5 * @ingroup POSIX_SIGNALS
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2007.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <errno.h>
22#include <pthread.h>
23#include <signal.h>
24
25#include <rtems/system.h>
26#include <rtems/score/isr.h>
27#include <rtems/score/thread.h>
28#include <rtems/score/threadq.h>
29#include <rtems/score/watchdogimpl.h>
30#include <rtems/score/wkspace.h>
31#include <rtems/seterr.h>
32#include <rtems/posix/threadsup.h>
33#include <rtems/posix/psignalimpl.h>
34#include <rtems/posix/pthreadimpl.h>
35#include <rtems/posix/time.h>
36#include <stdio.h>
37
38bool _POSIX_signals_Unblock_thread(
39  Thread_Control  *the_thread,
40  int              signo,
41  siginfo_t       *info
42)
43{
44  POSIX_API_Control  *api;
45  sigset_t            mask;
46  siginfo_t          *the_info = NULL;
47
48  api = the_thread->API_Extensions[ THREAD_API_POSIX ];
49
50  mask = signo_to_mask( signo );
51
52  /*
53   *  Is the thread is specifically waiting for a signal?
54   */
55
56  if ( _States_Is_interruptible_signal( the_thread->current_state ) ) {
57
58    if ( (the_thread->Wait.option & mask) || (~api->signals_blocked & mask) ) {
59      the_thread->Wait.return_code = EINTR;
60
61      the_info = (siginfo_t *) the_thread->Wait.return_argument;
62
63      if ( !info ) {
64        the_info->si_signo = signo;
65        the_info->si_code = SI_USER;
66        the_info->si_value.sival_int = 0;
67      } else {
68        *the_info = *info;
69      }
70
71      _Thread_queue_Extract_with_proxy( the_thread );
72      return true;
73    }
74
75    /*
76     *  This should only be reached via pthread_kill().
77     */
78
79    return false;
80  }
81
82  /*
83   *  Thread is not waiting due to a sigwait.
84   */
85  if ( ~api->signals_blocked & mask ) {
86
87    /*
88     *  The thread is interested in this signal.  We are going
89     *  to post it.  We have a few broad cases:
90     *    + If it is blocked on an interruptible signal, THEN
91     *        we unblock the thread.
92     *    + If it is in the ready state AND
93     *      we are sending from an ISR AND
94     *      it is the interrupted thread AND
95     *      it is not blocked, THEN
96     *        we need to dispatch at the end of this ISR.
97     *    + Any other combination, do nothing.
98     */
99
100    if ( _States_Is_interruptible_by_signal( the_thread->current_state ) ) {
101      the_thread->Wait.return_code = EINTR;
102      /*
103       *  In pthread_cond_wait, a thread will be blocking on a thread
104       *  queue, but is also interruptible by a POSIX signal.
105       */
106       if ( _States_Is_waiting_on_thread_queue(the_thread->current_state) )
107         _Thread_queue_Extract_with_proxy( the_thread );
108       else if ( _States_Is_delaying(the_thread->current_state) ) {
109          (void) _Watchdog_Remove( &the_thread->Timer );
110          _Thread_Unblock( the_thread );
111       }
112
113    } else if ( the_thread->current_state == STATES_READY ) {
114      if ( _ISR_Is_in_progress() && _Thread_Is_executing( the_thread ) )
115        _Thread_Dispatch_necessary = true;
116    }
117  }
118  return false;
119}
Note: See TracBrowser for help on using the repository browser.