RTEMS
threadtimeout.c
Go to the documentation of this file.
1 
9 /*
10  * COPYRIGHT (c) 1989-2008.
11  * On-Line Applications Research Corporation (OAR).
12  *
13  * The license and distribution terms for this file may be
14  * found in the file LICENSE in this distribution or at
15  * http://www.rtems.org/license/LICENSE.
16  */
17 
18 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
21 
22 #include <rtems/score/threadimpl.h>
23 #include <rtems/score/status.h>
24 
25 void _Thread_Continue( Thread_Control *the_thread, Status_Control status )
26 {
27  Thread_queue_Context queue_context;
28  Thread_Wait_flags wait_flags;
29  bool unblock;
30 
31  _Thread_queue_Context_initialize( &queue_context );
33  _Thread_Wait_acquire( the_thread, &queue_context );
34 
35  wait_flags = _Thread_Wait_flags_get( the_thread );
36 
37  if ( ( wait_flags & THREAD_WAIT_STATE_READY_AGAIN ) == 0 ) {
38  Thread_Wait_flags wait_class;
39  Thread_Wait_flags ready_again;
40  bool success;
41 
42  _Thread_Wait_cancel( the_thread, &queue_context );
43 
44  the_thread->Wait.return_code = status;
45 
46  wait_class = wait_flags & THREAD_WAIT_CLASS_MASK;
47  ready_again = wait_class | THREAD_WAIT_STATE_READY_AGAIN;
49  the_thread,
51  ready_again
52  );
53 
54  if ( success ) {
55  unblock = false;
56  } else {
57  _Assert(
58  _Thread_Wait_flags_get( the_thread )
59  == ( wait_class | THREAD_WAIT_STATE_BLOCKED )
60  );
61  _Thread_Wait_flags_set( the_thread, ready_again );
62  unblock = true;
63  }
64  } else {
65  unblock = false;
66  }
67 
68  _Thread_Wait_release( the_thread, &queue_context );
69  _Thread_Priority_update( &queue_context );
70 
71  if ( unblock ) {
72  _Thread_Wait_tranquilize( the_thread );
73  _Thread_Unblock( the_thread );
74 
75 #if defined(RTEMS_MULTIPROCESSING)
76  if ( !_Objects_Is_local_id( the_thread->Object.id ) ) {
77  _Thread_MP_Free_proxy( the_thread );
78  }
79 #endif
80  }
81 }
82 
83 void _Thread_Timeout( Watchdog_Control *the_watchdog )
84 {
85  Thread_Control *the_thread;
86 
87  the_thread = RTEMS_CONTAINER_OF(
88  the_watchdog,
90  Timer.Watchdog
91  );
92  _Thread_Continue( the_thread, STATUS_TIMEOUT );
93 }
static __inline__ void _Thread_Unblock(Thread_Control *the_thread)
Unblocks the thread.
Definition: threadimpl.h:965
static __inline__ bool _Objects_Is_local_id(Objects_Id id RTEMS_UNUSED)
Checks if the id is of a local object.
Definition: objectimpl.h:587
Thread_Wait_information Wait
Definition: thread.h:767
Thread queue context for the thread queue methods.
Definition: threadq.h:198
static __inline__ void _Thread_queue_Context_initialize(Thread_queue_Context *queue_context)
Initializes a thread queue context.
Definition: threadqimpl.h:152
The control block used to manage each watchdog timer.
Definition: watchdog.h:90
uint32_t return_code
Definition: thread.h:413
void _Thread_Continue(Thread_Control *the_thread, Status_Control status)
Cancels a blocking operation so that the thread can continue its execution.
Definition: threadtimeout.c:25
static __inline__ Thread_Wait_flags _Thread_Wait_flags_get(const Thread_Control *the_thread)
Gets the thread&#39;s wait flags according to the ATOMIC_ORDER_RELAXED.
Definition: threadimpl.h:2215
#define RTEMS_CONTAINER_OF(_m, _type, _member_name)
Returns the pointer to the container of a specified member pointer.
Definition: basedefs.h:550
void _Thread_Timeout(Watchdog_Control *the_watchdog)
General purpose thread wait timeout.
Definition: threadtimeout.c:83
#define THREAD_WAIT_STATE_READY_AGAIN
Indicates that a condition to end the thread wait occurred.
Definition: threadimpl.h:2163
static __inline__ void _Thread_Wait_flags_set(Thread_Control *the_thread, Thread_Wait_flags flags)
Sets the thread&#39;s wait flags.
Definition: threadimpl.h:2196
unsigned int Thread_Wait_flags
This type is able to contain several flags used to control the wait class and state of a thread...
Definition: thread.h:383
static __inline__ void _Thread_Wait_acquire(Thread_Control *the_thread, Thread_queue_Context *queue_context)
Acquires the thread wait default lock and disables interrupts.
Definition: threadimpl.h:1868
Objects_Control Object
Definition: thread.h:727
static __inline__ bool _Thread_Wait_flags_try_change_release(Thread_Control *the_thread, Thread_Wait_flags expected_flags, Thread_Wait_flags desired_flags)
Tries to change the thread wait flags with release semantics in case of success.
Definition: threadimpl.h:2260
#define THREAD_WAIT_STATE_BLOCKED
Indicates that the thread completed the blocking operation.
Definition: threadimpl.h:2156
void _Thread_Priority_update(Thread_queue_Context *queue_context)
Updates the priority of all threads in the set.
static __inline__ void _Thread_queue_Context_clear_priority_updates(Thread_queue_Context *queue_context)
Clears the priority update count of the thread queue context.
Definition: threadqimpl.h:338
#define THREAD_WAIT_CLASS_MASK
Mask to get the thread wait class flags.
Definition: threadimpl.h:2168
static __inline__ void _Thread_Wait_tranquilize(Thread_Control *the_thread)
Tranquilizes the thread after a wait on a thread queue.
Definition: threadimpl.h:2088
Inlined Routines from the Thread Handler.
static __inline__ void _Thread_Wait_release(Thread_Control *the_thread, Thread_queue_Context *queue_context)
Releases the thread wait lock and restores the previous interrupt status.
Definition: threadimpl.h:1929
static __inline__ void _Thread_Wait_cancel(Thread_Control *the_thread, Thread_queue_Context *queue_context)
Cancels a thread wait on a thread queue.
Definition: threadimpl.h:2106
#define THREAD_WAIT_STATE_INTEND_TO_BLOCK
Indicates that the thread begins with the blocking operation.
Definition: threadimpl.h:2151
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
Definition: assert.h:100
Objects_Id id
Definition: objectdata.h:43