1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Support Call to function Enables Locking of Mutex Object |
---|
5 | * @ingroup POSIXAPI |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2014. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <errno.h> |
---|
22 | #include <pthread.h> |
---|
23 | |
---|
24 | #include <rtems/system.h> |
---|
25 | #include <rtems/score/coremuteximpl.h> |
---|
26 | #include <rtems/score/watchdog.h> |
---|
27 | #include <rtems/score/threadimpl.h> |
---|
28 | #include <rtems/posix/muteximpl.h> |
---|
29 | #include <rtems/posix/priorityimpl.h> |
---|
30 | |
---|
31 | THREAD_WAIT_QUEUE_OBJECT_ASSERT( POSIX_Mutex_Control, Mutex.Wait_queue ); |
---|
32 | |
---|
33 | /* |
---|
34 | * _POSIX_Mutex_Lock_support |
---|
35 | * |
---|
36 | * A support routine which implements guts of the blocking, non-blocking, and |
---|
37 | * timed wait version of mutex lock. |
---|
38 | */ |
---|
39 | |
---|
40 | int _POSIX_Mutex_Lock_support( |
---|
41 | pthread_mutex_t *mutex, |
---|
42 | bool blocking, |
---|
43 | Watchdog_Interval timeout |
---|
44 | ) |
---|
45 | { |
---|
46 | POSIX_Mutex_Control *the_mutex; |
---|
47 | Objects_Locations location; |
---|
48 | ISR_lock_Context lock_context; |
---|
49 | Thread_Control *executing; |
---|
50 | |
---|
51 | the_mutex = _POSIX_Mutex_Get_interrupt_disable( |
---|
52 | mutex, |
---|
53 | &location, |
---|
54 | &lock_context |
---|
55 | ); |
---|
56 | switch ( location ) { |
---|
57 | |
---|
58 | case OBJECTS_LOCAL: |
---|
59 | executing = _Thread_Executing; |
---|
60 | _CORE_mutex_Seize( |
---|
61 | &the_mutex->Mutex, |
---|
62 | executing, |
---|
63 | the_mutex->Object.id, |
---|
64 | blocking, |
---|
65 | timeout, |
---|
66 | &lock_context |
---|
67 | ); |
---|
68 | return _POSIX_Mutex_Translate_core_mutex_return_code( |
---|
69 | (CORE_mutex_Status) executing->Wait.return_code |
---|
70 | ); |
---|
71 | |
---|
72 | #if defined(RTEMS_MULTIPROCESSING) |
---|
73 | case OBJECTS_REMOTE: |
---|
74 | #endif |
---|
75 | case OBJECTS_ERROR: |
---|
76 | break; |
---|
77 | } |
---|
78 | |
---|
79 | return EINVAL; |
---|
80 | } |
---|