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 | * $Id$ |
---|
12 | */ |
---|
13 | |
---|
14 | #if HAVE_CONFIG_H |
---|
15 | #include "config.h" |
---|
16 | #endif |
---|
17 | |
---|
18 | #include <rtems/system.h> |
---|
19 | #include <rtems/score/corespinlock.h> |
---|
20 | #include <rtems/score/states.h> |
---|
21 | #include <rtems/score/thread.h> |
---|
22 | #include <rtems/score/watchdog.h> |
---|
23 | |
---|
24 | /*PAGE |
---|
25 | * |
---|
26 | * _CORE_spinlock_Release |
---|
27 | * |
---|
28 | * This function releases the spinlock. |
---|
29 | * |
---|
30 | * Input parameters: |
---|
31 | * the_spinlock - the spinlock control block to initialize |
---|
32 | * |
---|
33 | * Output parameters: |
---|
34 | * CORE_SPINLOCK_SUCCESSFUL - if successful |
---|
35 | * error code - if unsuccessful |
---|
36 | * |
---|
37 | */ |
---|
38 | |
---|
39 | CORE_spinlock_Status _CORE_spinlock_Release( |
---|
40 | CORE_spinlock_Control *the_spinlock |
---|
41 | ) |
---|
42 | { |
---|
43 | ISR_Level level; |
---|
44 | |
---|
45 | _ISR_Disable( level ); |
---|
46 | |
---|
47 | /* |
---|
48 | * It must locked before it can be unlocked. |
---|
49 | */ |
---|
50 | if ( the_spinlock->lock == CORE_SPINLOCK_UNLOCKED ) { |
---|
51 | _ISR_Enable( level ); |
---|
52 | return CORE_SPINLOCK_NOT_LOCKED; |
---|
53 | } |
---|
54 | |
---|
55 | /* |
---|
56 | * It must locked by the current thread before it can be unlocked. |
---|
57 | */ |
---|
58 | if ( the_spinlock->holder != _Thread_Executing->Object.id ) { |
---|
59 | _ISR_Enable( level ); |
---|
60 | return CORE_SPINLOCK_NOT_HOLDER; |
---|
61 | } |
---|
62 | |
---|
63 | /* |
---|
64 | * Let it be unlocked. |
---|
65 | */ |
---|
66 | the_spinlock->users -= 1; |
---|
67 | the_spinlock->lock = CORE_SPINLOCK_UNLOCKED; |
---|
68 | the_spinlock->holder = 0; |
---|
69 | |
---|
70 | _ISR_Enable( level ); |
---|
71 | return CORE_SPINLOCK_SUCCESSFUL; |
---|
72 | } |
---|