1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Inlined Routines Associated with the SuperCore Semaphore |
---|
5 | * |
---|
6 | * This include file contains all of the inlined routines associated |
---|
7 | * with the SuperCore semaphore. |
---|
8 | */ |
---|
9 | |
---|
10 | /* |
---|
11 | * COPYRIGHT (c) 1989-2006. |
---|
12 | * On-Line Applications Research Corporation (OAR). |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.com/license/LICENSE. |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef _RTEMS_SCORE_CORESEM_H |
---|
20 | # error "Never use <rtems/score/coresem.inl> directly; include <rtems/score/coresem.h> instead." |
---|
21 | #endif |
---|
22 | |
---|
23 | #ifndef _RTEMS_SCORE_CORESEM_INL |
---|
24 | #define _RTEMS_SCORE_CORESEM_INL |
---|
25 | |
---|
26 | /** |
---|
27 | * @addtogroup ScoreSemaphore |
---|
28 | */ |
---|
29 | /**@{**/ |
---|
30 | |
---|
31 | #include <rtems/score/thread.h> |
---|
32 | #include <rtems/score/threaddispatch.h> |
---|
33 | #include <rtems/score/threadq.h> |
---|
34 | |
---|
35 | /** |
---|
36 | * This function returns true if the priority attribute is |
---|
37 | * enabled in the @a attribute_set and false otherwise. |
---|
38 | * |
---|
39 | * @param[in] the_attribute is the attribute set to test |
---|
40 | * |
---|
41 | * @return true if the priority attribute is enabled |
---|
42 | */ |
---|
43 | RTEMS_INLINE_ROUTINE bool _CORE_semaphore_Is_priority( |
---|
44 | CORE_semaphore_Attributes *the_attribute |
---|
45 | ) |
---|
46 | { |
---|
47 | return ( the_attribute->discipline == CORE_SEMAPHORE_DISCIPLINES_PRIORITY ); |
---|
48 | } |
---|
49 | |
---|
50 | /** |
---|
51 | * This routine returns the current count associated with the semaphore. |
---|
52 | * |
---|
53 | * @param[in] the_semaphore is the semaphore to obtain the count of |
---|
54 | * |
---|
55 | * @return the current count of this semaphore |
---|
56 | */ |
---|
57 | RTEMS_INLINE_ROUTINE uint32_t _CORE_semaphore_Get_count( |
---|
58 | CORE_semaphore_Control *the_semaphore |
---|
59 | ) |
---|
60 | { |
---|
61 | return the_semaphore->count; |
---|
62 | } |
---|
63 | |
---|
64 | /** |
---|
65 | * This routine attempts to receive a unit from the_semaphore. |
---|
66 | * If a unit is available or if the wait flag is false, then the routine |
---|
67 | * returns. Otherwise, the calling task is blocked until a unit becomes |
---|
68 | * available. |
---|
69 | * |
---|
70 | * @param[in] the_semaphore is the semaphore to obtain |
---|
71 | * @param[in] id is the Id of the owning API level Semaphore object |
---|
72 | * @param[in] wait is true if the thread is willing to wait |
---|
73 | * @param[in] timeout is the maximum number of ticks to block |
---|
74 | * @param[in] level is a temporary variable used to contain the ISR |
---|
75 | * disable level cookie |
---|
76 | * |
---|
77 | * @note There is currently no MACRO version of this routine. |
---|
78 | */ |
---|
79 | RTEMS_INLINE_ROUTINE void _CORE_semaphore_Seize_isr_disable( |
---|
80 | CORE_semaphore_Control *the_semaphore, |
---|
81 | Objects_Id id, |
---|
82 | bool wait, |
---|
83 | Watchdog_Interval timeout, |
---|
84 | ISR_Level level |
---|
85 | ) |
---|
86 | { |
---|
87 | Thread_Control *executing; |
---|
88 | |
---|
89 | /* disabled when you get here */ |
---|
90 | |
---|
91 | executing = _Thread_Executing; |
---|
92 | executing->Wait.return_code = CORE_SEMAPHORE_STATUS_SUCCESSFUL; |
---|
93 | if ( the_semaphore->count != 0 ) { |
---|
94 | the_semaphore->count -= 1; |
---|
95 | _ISR_Enable( level ); |
---|
96 | return; |
---|
97 | } |
---|
98 | |
---|
99 | if ( !wait ) { |
---|
100 | _ISR_Enable( level ); |
---|
101 | executing->Wait.return_code = CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT; |
---|
102 | return; |
---|
103 | } |
---|
104 | |
---|
105 | _Thread_Disable_dispatch(); |
---|
106 | _Thread_queue_Enter_critical_section( &the_semaphore->Wait_queue ); |
---|
107 | executing->Wait.queue = &the_semaphore->Wait_queue; |
---|
108 | executing->Wait.id = id; |
---|
109 | _ISR_Enable( level ); |
---|
110 | |
---|
111 | _Thread_queue_Enqueue( &the_semaphore->Wait_queue, timeout ); |
---|
112 | _Thread_Enable_dispatch(); |
---|
113 | } |
---|
114 | |
---|
115 | /** @} */ |
---|
116 | |
---|
117 | #endif |
---|
118 | /* end of include file */ |
---|