1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup ClassicSem |
---|
5 | * |
---|
6 | * @brief Classic Semaphores Implementation |
---|
7 | */ |
---|
8 | |
---|
9 | /* COPYRIGHT (c) 1989-2008. |
---|
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.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #ifndef _RTEMS_RTEMS_SEMIMPL_H |
---|
18 | #define _RTEMS_RTEMS_SEMIMPL_H |
---|
19 | |
---|
20 | #include <rtems/rtems/sem.h> |
---|
21 | #include <rtems/score/coremuteximpl.h> |
---|
22 | #include <rtems/score/coresemimpl.h> |
---|
23 | #include <rtems/score/mrspimpl.h> |
---|
24 | |
---|
25 | #ifdef __cplusplus |
---|
26 | extern "C" { |
---|
27 | #endif |
---|
28 | |
---|
29 | typedef enum { |
---|
30 | SEMAPHORE_VARIANT_MUTEX, |
---|
31 | SEMAPHORE_VARIANT_COUNTING |
---|
32 | #if defined(RTEMS_SMP) |
---|
33 | , |
---|
34 | SEMAPHORE_VARIANT_MRSP |
---|
35 | #endif |
---|
36 | } Semaphore_Variant; |
---|
37 | |
---|
38 | typedef enum { |
---|
39 | SEMAPHORE_DISCIPLINE_PRIORITY, |
---|
40 | SEMAPHORE_DISCIPLINE_FIFO |
---|
41 | } Semaphore_Discipline; |
---|
42 | |
---|
43 | /** |
---|
44 | * The following defines the information control block used to manage |
---|
45 | * this class of objects. |
---|
46 | */ |
---|
47 | extern Objects_Information _Semaphore_Information; |
---|
48 | |
---|
49 | RTEMS_INLINE_ROUTINE const Thread_queue_Operations *_Semaphore_Get_operations( |
---|
50 | const Semaphore_Control *the_semaphore |
---|
51 | ) |
---|
52 | { |
---|
53 | if ( the_semaphore->discipline == SEMAPHORE_DISCIPLINE_PRIORITY ) { |
---|
54 | return &_Thread_queue_Operations_priority; |
---|
55 | } else { |
---|
56 | return &_Thread_queue_Operations_FIFO; |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | /** |
---|
61 | * @brief Allocates a semaphore control block from |
---|
62 | * the inactive chain of free semaphore control blocks. |
---|
63 | * |
---|
64 | * This function allocates a semaphore control block from |
---|
65 | * the inactive chain of free semaphore control blocks. |
---|
66 | */ |
---|
67 | RTEMS_INLINE_ROUTINE Semaphore_Control *_Semaphore_Allocate( void ) |
---|
68 | { |
---|
69 | return (Semaphore_Control *) _Objects_Allocate( &_Semaphore_Information ); |
---|
70 | } |
---|
71 | |
---|
72 | /** |
---|
73 | * @brief Frees a semaphore control block to the |
---|
74 | * inactive chain of free semaphore control blocks. |
---|
75 | * |
---|
76 | * This routine frees a semaphore control block to the |
---|
77 | * inactive chain of free semaphore control blocks. |
---|
78 | */ |
---|
79 | RTEMS_INLINE_ROUTINE void _Semaphore_Free ( |
---|
80 | Semaphore_Control *the_semaphore |
---|
81 | ) |
---|
82 | { |
---|
83 | _Objects_Free( &_Semaphore_Information, &the_semaphore->Object ); |
---|
84 | } |
---|
85 | |
---|
86 | RTEMS_INLINE_ROUTINE Semaphore_Control *_Semaphore_Get( |
---|
87 | Objects_Id id, |
---|
88 | Thread_queue_Context *queue_context |
---|
89 | ) |
---|
90 | { |
---|
91 | _Thread_queue_Context_initialize( queue_context ); |
---|
92 | return (Semaphore_Control *) _Objects_Get( |
---|
93 | id, |
---|
94 | &queue_context->Lock_context, |
---|
95 | &_Semaphore_Information |
---|
96 | ); |
---|
97 | } |
---|
98 | |
---|
99 | #ifdef __cplusplus |
---|
100 | } |
---|
101 | #endif |
---|
102 | |
---|
103 | #ifdef RTEMS_MULTIPROCESSING |
---|
104 | #include <rtems/rtems/semmp.h> |
---|
105 | #endif |
---|
106 | |
---|
107 | #endif |
---|
108 | /* end of include file */ |
---|