1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Surrenders a Unit to a Semaphore |
---|
5 | * |
---|
6 | * @ingroup ScoreSemaphore |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * COPYRIGHT (c) 1989-1999. |
---|
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.com/license/LICENSE. |
---|
16 | */ |
---|
17 | |
---|
18 | #if HAVE_CONFIG_H |
---|
19 | #include "config.h" |
---|
20 | #endif |
---|
21 | |
---|
22 | #include <rtems/system.h> |
---|
23 | #include <rtems/score/isr.h> |
---|
24 | #include <rtems/score/coresemimpl.h> |
---|
25 | #include <rtems/score/states.h> |
---|
26 | #include <rtems/score/thread.h> |
---|
27 | #include <rtems/score/threadq.h> |
---|
28 | |
---|
29 | CORE_semaphore_Status _CORE_semaphore_Surrender( |
---|
30 | CORE_semaphore_Control *the_semaphore, |
---|
31 | Objects_Id id, |
---|
32 | CORE_semaphore_API_mp_support_callout api_semaphore_mp_support |
---|
33 | ) |
---|
34 | { |
---|
35 | Thread_Control *the_thread; |
---|
36 | ISR_Level level; |
---|
37 | CORE_semaphore_Status status; |
---|
38 | |
---|
39 | status = CORE_SEMAPHORE_STATUS_SUCCESSFUL; |
---|
40 | |
---|
41 | if ( (the_thread = _Thread_queue_Dequeue(&the_semaphore->Wait_queue)) ) { |
---|
42 | |
---|
43 | #if defined(RTEMS_MULTIPROCESSING) |
---|
44 | if ( !_Objects_Is_local_id( the_thread->Object.id ) ) |
---|
45 | (*api_semaphore_mp_support) ( the_thread, id ); |
---|
46 | #endif |
---|
47 | |
---|
48 | } else { |
---|
49 | _ISR_Disable( level ); |
---|
50 | if ( the_semaphore->count < the_semaphore->Attributes.maximum_count ) |
---|
51 | the_semaphore->count += 1; |
---|
52 | else |
---|
53 | status = CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED; |
---|
54 | _ISR_Enable( level ); |
---|
55 | } |
---|
56 | |
---|
57 | return status; |
---|
58 | } |
---|