1 | /* |
---|
2 | * $Id$ |
---|
3 | */ |
---|
4 | |
---|
5 | #if HAVE_CONFIG_H |
---|
6 | #include "config.h" |
---|
7 | #endif |
---|
8 | |
---|
9 | #include <assert.h> |
---|
10 | #include <errno.h> |
---|
11 | #include <pthread.h> |
---|
12 | |
---|
13 | #include <rtems/system.h> |
---|
14 | #include <rtems/score/coremutex.h> |
---|
15 | #include <rtems/score/watchdog.h> |
---|
16 | #if defined(RTEMS_MULTIPROCESSING) |
---|
17 | #include <rtems/score/mpci.h> |
---|
18 | #endif |
---|
19 | #include <rtems/posix/mutex.h> |
---|
20 | #include <rtems/posix/priority.h> |
---|
21 | #include <rtems/posix/time.h> |
---|
22 | |
---|
23 | /*PAGE |
---|
24 | * |
---|
25 | * 13.6.2 Change the Priority Ceiling of a Mutex, P1003.1c/Draft 10, p. 131 |
---|
26 | */ |
---|
27 | |
---|
28 | int pthread_mutex_setprioceiling( |
---|
29 | pthread_mutex_t *mutex, |
---|
30 | int prioceiling, |
---|
31 | int *old_ceiling |
---|
32 | ) |
---|
33 | { |
---|
34 | register POSIX_Mutex_Control *the_mutex; |
---|
35 | Objects_Locations location; |
---|
36 | Priority_Control the_priority; |
---|
37 | int status; |
---|
38 | |
---|
39 | if ( !old_ceiling ) |
---|
40 | return EINVAL; |
---|
41 | |
---|
42 | if ( !_POSIX_Priority_Is_valid( prioceiling ) ) |
---|
43 | return EINVAL; |
---|
44 | |
---|
45 | the_priority = _POSIX_Priority_To_core( prioceiling ); |
---|
46 | |
---|
47 | /* |
---|
48 | * Must acquire the mutex before we can change it's ceiling |
---|
49 | */ |
---|
50 | |
---|
51 | status = pthread_mutex_lock( mutex ); |
---|
52 | if ( status ) |
---|
53 | return status; |
---|
54 | |
---|
55 | the_mutex = _POSIX_Mutex_Get( mutex, &location ); |
---|
56 | switch ( location ) { |
---|
57 | case OBJECTS_REMOTE: |
---|
58 | #if defined(RTEMS_MULTIPROCESSING) |
---|
59 | /* XXX It feels questionable to set the ceiling on a remote mutex. */ |
---|
60 | return EINVAL; |
---|
61 | #endif |
---|
62 | case OBJECTS_ERROR: |
---|
63 | return EINVAL; /* impossible to get here */ |
---|
64 | case OBJECTS_LOCAL: |
---|
65 | *old_ceiling = _POSIX_Priority_From_core( |
---|
66 | the_mutex->Mutex.Attributes.priority_ceiling |
---|
67 | ); |
---|
68 | the_mutex->Mutex.Attributes.priority_ceiling = the_priority; |
---|
69 | _CORE_mutex_Surrender( |
---|
70 | &the_mutex->Mutex, |
---|
71 | the_mutex->Object.id, |
---|
72 | #if defined(RTEMS_MULTIPROCESSING) |
---|
73 | _POSIX_Threads_mutex_MP_support |
---|
74 | #else |
---|
75 | NULL |
---|
76 | #endif |
---|
77 | ); |
---|
78 | _Thread_Enable_dispatch(); |
---|
79 | return 0; |
---|
80 | } |
---|
81 | return POSIX_BOTTOM_REACHED(); |
---|
82 | } |
---|