1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Changes the Priority Ceiling of a Mutex and Releases it |
---|
5 | * @ingroup POSIXAPI |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2009. |
---|
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.com/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/posix/muteximpl.h> |
---|
28 | #include <rtems/posix/priorityimpl.h> |
---|
29 | #include <rtems/posix/time.h> |
---|
30 | |
---|
31 | /* |
---|
32 | * 13.6.2 Change the Priority Ceiling of a Mutex, P1003.1c/Draft 10, p. 131 |
---|
33 | */ |
---|
34 | |
---|
35 | int pthread_mutex_setprioceiling( |
---|
36 | pthread_mutex_t *mutex, |
---|
37 | int prioceiling, |
---|
38 | int *old_ceiling |
---|
39 | ) |
---|
40 | { |
---|
41 | register POSIX_Mutex_Control *the_mutex; |
---|
42 | Objects_Locations location; |
---|
43 | Priority_Control the_priority; |
---|
44 | |
---|
45 | if ( !old_ceiling ) |
---|
46 | return EINVAL; |
---|
47 | |
---|
48 | if ( !_POSIX_Priority_Is_valid( prioceiling ) ) |
---|
49 | return EINVAL; |
---|
50 | |
---|
51 | the_priority = _POSIX_Priority_To_core( prioceiling ); |
---|
52 | |
---|
53 | /* |
---|
54 | * Must acquire the mutex before we can change it's ceiling. |
---|
55 | * POSIX says block until we acquire it. |
---|
56 | */ |
---|
57 | (void) pthread_mutex_lock( mutex ); |
---|
58 | |
---|
59 | /* |
---|
60 | * Do not worry about the return code from this. The Get operation |
---|
61 | * will also fail if it is a bad id or was deleted between the two |
---|
62 | * operations. |
---|
63 | * |
---|
64 | * NOTE: This makes it easier to get 100% binary coverage since the |
---|
65 | * bad Id case is handled by the switch. |
---|
66 | */ |
---|
67 | the_mutex = _POSIX_Mutex_Get( mutex, &location ); |
---|
68 | switch ( location ) { |
---|
69 | |
---|
70 | case OBJECTS_LOCAL: |
---|
71 | *old_ceiling = _POSIX_Priority_From_core( |
---|
72 | the_mutex->Mutex.Attributes.priority_ceiling |
---|
73 | ); |
---|
74 | the_mutex->Mutex.Attributes.priority_ceiling = the_priority; |
---|
75 | /* |
---|
76 | * We are required to unlock the mutex before we return. |
---|
77 | */ |
---|
78 | _CORE_mutex_Surrender( |
---|
79 | &the_mutex->Mutex, |
---|
80 | the_mutex->Object.id, |
---|
81 | NULL |
---|
82 | ); |
---|
83 | _Objects_Put( &the_mutex->Object ); |
---|
84 | |
---|
85 | return 0; |
---|
86 | |
---|
87 | #if defined(RTEMS_MULTIPROCESSING) |
---|
88 | case OBJECTS_REMOTE: /* impossible to get here */ |
---|
89 | #endif |
---|
90 | case OBJECTS_ERROR: |
---|
91 | break; |
---|
92 | } |
---|
93 | |
---|
94 | return EINVAL; |
---|
95 | } |
---|