1 | /* |
---|
2 | * POSIX Spinlock Manager -- Initialize a Spinlock Instance |
---|
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 <pthread.h> |
---|
19 | #include <errno.h> |
---|
20 | |
---|
21 | #include <rtems/system.h> |
---|
22 | #include <rtems/posix/spinlock.h> |
---|
23 | |
---|
24 | /* |
---|
25 | * pthread_spinlock_init |
---|
26 | * |
---|
27 | * This directive creates a spinlock. A spinlock id is returned. |
---|
28 | * |
---|
29 | * Input parameters: |
---|
30 | * spinlock - pointer to spinlock id |
---|
31 | * pshared - is this spinlock shared between processes |
---|
32 | * |
---|
33 | * Output parameters: |
---|
34 | * spinlock - spinlock id |
---|
35 | * 0 - if successful |
---|
36 | * error code - if unsuccessful |
---|
37 | */ |
---|
38 | |
---|
39 | int pthread_spin_init( |
---|
40 | pthread_spinlock_t *spinlock, |
---|
41 | int pshared |
---|
42 | ) |
---|
43 | { |
---|
44 | POSIX_Spinlock_Control *the_spinlock; |
---|
45 | CORE_spinlock_Attributes attributes; |
---|
46 | |
---|
47 | |
---|
48 | if ( !spinlock ) |
---|
49 | return EINVAL; |
---|
50 | |
---|
51 | switch ( pshared ) { |
---|
52 | case PTHREAD_PROCESS_PRIVATE: /* only supported values */ |
---|
53 | break; |
---|
54 | case PTHREAD_PROCESS_SHARED: |
---|
55 | default: |
---|
56 | return EINVAL; |
---|
57 | } |
---|
58 | |
---|
59 | _Thread_Disable_dispatch(); /* prevents deletion */ |
---|
60 | |
---|
61 | the_spinlock = _POSIX_Spinlock_Allocate(); |
---|
62 | |
---|
63 | if ( !the_spinlock ) { |
---|
64 | _Thread_Enable_dispatch(); |
---|
65 | return EAGAIN; |
---|
66 | } |
---|
67 | |
---|
68 | _CORE_spinlock_Initialize( &the_spinlock->Spinlock, &attributes ); |
---|
69 | |
---|
70 | _Objects_Open_u32( &_POSIX_Spinlock_Information, &the_spinlock->Object, 0 ); |
---|
71 | |
---|
72 | *spinlock = the_spinlock->Object.id; |
---|
73 | |
---|
74 | _Thread_Enable_dispatch(); |
---|
75 | return 0; |
---|
76 | } |
---|