1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Obtain a Write Lock on a RWlock Instance |
---|
5 | * @ingroup POSIXAPI |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * POSIX RWLock Manager -- Obtain a Write Lock on a RWLock Instance |
---|
10 | * |
---|
11 | * COPYRIGHT (c) 1989-2007. |
---|
12 | * On-Line Applications Research Corporation (OAR). |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.org/license/LICENSE. |
---|
17 | */ |
---|
18 | |
---|
19 | #if HAVE_CONFIG_H |
---|
20 | #include "config.h" |
---|
21 | #endif |
---|
22 | |
---|
23 | #include <pthread.h> |
---|
24 | #include <errno.h> |
---|
25 | |
---|
26 | #include <rtems/posix/rwlockimpl.h> |
---|
27 | #include <rtems/score/threadimpl.h> |
---|
28 | |
---|
29 | THREAD_WAIT_QUEUE_OBJECT_ASSERT( POSIX_RWLock_Control, RWLock.Wait_queue ); |
---|
30 | |
---|
31 | /* |
---|
32 | * pthread_rwlock_wrlock |
---|
33 | * |
---|
34 | * This directive attempts to obtain a write only lock on an rwlock instance. |
---|
35 | * |
---|
36 | * Input parameters: |
---|
37 | * rwlock - pointer to rwlock id |
---|
38 | * |
---|
39 | * Output parameters: |
---|
40 | * 0 - if successful |
---|
41 | * error code - if unsuccessful |
---|
42 | */ |
---|
43 | |
---|
44 | int pthread_rwlock_wrlock( |
---|
45 | pthread_rwlock_t *rwlock |
---|
46 | ) |
---|
47 | { |
---|
48 | POSIX_RWLock_Control *the_rwlock; |
---|
49 | Objects_Locations location; |
---|
50 | Thread_Control *executing; |
---|
51 | |
---|
52 | the_rwlock = _POSIX_RWLock_Get( rwlock, &location ); |
---|
53 | switch ( location ) { |
---|
54 | |
---|
55 | case OBJECTS_LOCAL: |
---|
56 | |
---|
57 | executing = _Thread_Executing; |
---|
58 | _CORE_RWLock_Obtain_for_writing( |
---|
59 | &the_rwlock->RWLock, |
---|
60 | executing, |
---|
61 | true, /* do not timeout -- wait forever */ |
---|
62 | 0 |
---|
63 | ); |
---|
64 | |
---|
65 | _Objects_Put( &the_rwlock->Object ); |
---|
66 | return _POSIX_RWLock_Translate_core_RWLock_return_code( |
---|
67 | (CORE_RWLock_Status) executing->Wait.return_code |
---|
68 | ); |
---|
69 | |
---|
70 | #if defined(RTEMS_MULTIPROCESSING) |
---|
71 | case OBJECTS_REMOTE: |
---|
72 | #endif |
---|
73 | case OBJECTS_ERROR: |
---|
74 | break; |
---|
75 | } |
---|
76 | |
---|
77 | return EINVAL; |
---|
78 | } |
---|