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