1 | /* |
---|
2 | * SuperCore Spinlock Handler -- Release a Spinlock |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-2006. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.rtems.com/license/LICENSE. |
---|
10 | */ |
---|
11 | |
---|
12 | #if HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <rtems/system.h> |
---|
17 | #include <rtems/score/corespinlock.h> |
---|
18 | #include <rtems/score/states.h> |
---|
19 | #include <rtems/score/thread.h> |
---|
20 | #include <rtems/score/watchdog.h> |
---|
21 | |
---|
22 | /* |
---|
23 | * _CORE_spinlock_Release |
---|
24 | * |
---|
25 | * This function releases the spinlock. |
---|
26 | * |
---|
27 | * Input parameters: |
---|
28 | * the_spinlock - the spinlock control block to initialize |
---|
29 | * |
---|
30 | * Output parameters: |
---|
31 | * CORE_SPINLOCK_SUCCESSFUL - if successful |
---|
32 | * error code - if unsuccessful |
---|
33 | * |
---|
34 | */ |
---|
35 | |
---|
36 | CORE_spinlock_Status _CORE_spinlock_Release( |
---|
37 | CORE_spinlock_Control *the_spinlock |
---|
38 | ) |
---|
39 | { |
---|
40 | ISR_Level level; |
---|
41 | |
---|
42 | _ISR_Disable( level ); |
---|
43 | |
---|
44 | /* |
---|
45 | * It must locked before it can be unlocked. |
---|
46 | */ |
---|
47 | if ( the_spinlock->lock == CORE_SPINLOCK_UNLOCKED ) { |
---|
48 | _ISR_Enable( level ); |
---|
49 | return CORE_SPINLOCK_NOT_LOCKED; |
---|
50 | } |
---|
51 | |
---|
52 | /* |
---|
53 | * It must locked by the current thread before it can be unlocked. |
---|
54 | */ |
---|
55 | if ( the_spinlock->holder != _Thread_Executing->Object.id ) { |
---|
56 | _ISR_Enable( level ); |
---|
57 | return CORE_SPINLOCK_NOT_HOLDER; |
---|
58 | } |
---|
59 | |
---|
60 | /* |
---|
61 | * Let it be unlocked. |
---|
62 | */ |
---|
63 | the_spinlock->users -= 1; |
---|
64 | the_spinlock->lock = CORE_SPINLOCK_UNLOCKED; |
---|
65 | the_spinlock->holder = 0; |
---|
66 | |
---|
67 | _ISR_Enable( level ); |
---|
68 | return CORE_SPINLOCK_SUCCESSFUL; |
---|
69 | } |
---|