forked from Imagelibrary/rtems
posix: Simplify _POSIX_Mutex_Get_interrupt_disable
Remove superfluous location parameter.
This commit is contained in:
@@ -15,13 +15,14 @@
|
|||||||
* http://www.rtems.org/license/LICENSE.
|
* http://www.rtems.org/license/LICENSE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef _RTEMS_POSIX_MUTEXIMPL_H
|
||||||
|
#define _RTEMS_POSIX_MUTEXIMPL_H
|
||||||
|
|
||||||
#include <rtems/posix/mutex.h>
|
#include <rtems/posix/mutex.h>
|
||||||
#include <rtems/score/coremuteximpl.h>
|
#include <rtems/score/coremuteximpl.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <pthread.h>
|
||||||
#ifndef _RTEMS_POSIX_MUTEXIMPL_H
|
|
||||||
#define _RTEMS_POSIX_MUTEXIMPL_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -139,10 +140,9 @@ POSIX_Mutex_Control *_POSIX_Mutex_Get (
|
|||||||
*
|
*
|
||||||
* @note: This version of the method uses an interrupt critical section.
|
* @note: This version of the method uses an interrupt critical section.
|
||||||
*/
|
*/
|
||||||
POSIX_Mutex_Control *_POSIX_Mutex_Get_interrupt_disable (
|
POSIX_Mutex_Control *_POSIX_Mutex_Get_interrupt_disable(
|
||||||
pthread_mutex_t *mutex,
|
pthread_mutex_t *mutex,
|
||||||
Objects_Locations *location,
|
ISR_lock_Context *lock_context
|
||||||
ISR_lock_Context *lock_context
|
|
||||||
);
|
);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -68,20 +68,21 @@ POSIX_Mutex_Control *_POSIX_Mutex_Get (
|
|||||||
_Objects_Get( &_POSIX_Mutex_Information, (Objects_Id) *mutex, location );
|
_Objects_Get( &_POSIX_Mutex_Information, (Objects_Id) *mutex, location );
|
||||||
}
|
}
|
||||||
|
|
||||||
POSIX_Mutex_Control *_POSIX_Mutex_Get_interrupt_disable (
|
POSIX_Mutex_Control *_POSIX_Mutex_Get_interrupt_disable(
|
||||||
pthread_mutex_t *mutex,
|
pthread_mutex_t *mutex,
|
||||||
Objects_Locations *location,
|
ISR_lock_Context *lock_context
|
||||||
ISR_lock_Context *lock_context
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if ( !_POSIX_Mutex_Check_id_and_auto_init( mutex, location ) ) {
|
Objects_Locations location;
|
||||||
|
|
||||||
|
if ( !_POSIX_Mutex_Check_id_and_auto_init( mutex, &location ) ) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (POSIX_Mutex_Control *) _Objects_Get_isr_disable(
|
return (POSIX_Mutex_Control *) _Objects_Get_isr_disable(
|
||||||
&_POSIX_Mutex_Information,
|
&_POSIX_Mutex_Information,
|
||||||
(Objects_Id) *mutex,
|
(Objects_Id) *mutex,
|
||||||
location,
|
&location,
|
||||||
lock_context
|
lock_context
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,62 +18,35 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
#include <rtems/system.h>
|
|
||||||
#include <rtems/score/coremuteximpl.h>
|
|
||||||
#include <rtems/score/watchdog.h>
|
|
||||||
#include <rtems/score/threadimpl.h>
|
|
||||||
#include <rtems/posix/muteximpl.h>
|
#include <rtems/posix/muteximpl.h>
|
||||||
#include <rtems/posix/priorityimpl.h>
|
|
||||||
|
|
||||||
THREAD_WAIT_QUEUE_OBJECT_ASSERT( POSIX_Mutex_Control, Mutex.Wait_queue );
|
THREAD_WAIT_QUEUE_OBJECT_ASSERT( POSIX_Mutex_Control, Mutex.Wait_queue );
|
||||||
|
|
||||||
/*
|
|
||||||
* _POSIX_Mutex_Lock_support
|
|
||||||
*
|
|
||||||
* A support routine which implements guts of the blocking, non-blocking, and
|
|
||||||
* timed wait version of mutex lock.
|
|
||||||
*/
|
|
||||||
|
|
||||||
int _POSIX_Mutex_Lock_support(
|
int _POSIX_Mutex_Lock_support(
|
||||||
pthread_mutex_t *mutex,
|
pthread_mutex_t *mutex,
|
||||||
bool blocking,
|
bool blocking,
|
||||||
Watchdog_Interval timeout
|
Watchdog_Interval timeout
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
POSIX_Mutex_Control *the_mutex;
|
POSIX_Mutex_Control *the_mutex;
|
||||||
Objects_Locations location;
|
ISR_lock_Context lock_context;
|
||||||
ISR_lock_Context lock_context;
|
Thread_Control *executing;
|
||||||
Thread_Control *executing;
|
|
||||||
|
|
||||||
the_mutex = _POSIX_Mutex_Get_interrupt_disable(
|
the_mutex = _POSIX_Mutex_Get_interrupt_disable( mutex, &lock_context );
|
||||||
mutex,
|
|
||||||
&location,
|
|
||||||
&lock_context
|
|
||||||
);
|
|
||||||
switch ( location ) {
|
|
||||||
|
|
||||||
case OBJECTS_LOCAL:
|
if ( the_mutex == NULL ) {
|
||||||
executing = _Thread_Executing;
|
return EINVAL;
|
||||||
_CORE_mutex_Seize(
|
|
||||||
&the_mutex->Mutex,
|
|
||||||
executing,
|
|
||||||
blocking,
|
|
||||||
timeout,
|
|
||||||
&lock_context
|
|
||||||
);
|
|
||||||
return _POSIX_Mutex_Translate_core_mutex_return_code(
|
|
||||||
(CORE_mutex_Status) executing->Wait.return_code
|
|
||||||
);
|
|
||||||
|
|
||||||
#if defined(RTEMS_MULTIPROCESSING)
|
|
||||||
case OBJECTS_REMOTE:
|
|
||||||
#endif
|
|
||||||
case OBJECTS_ERROR:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return EINVAL;
|
executing = _Thread_Executing;
|
||||||
|
_CORE_mutex_Seize(
|
||||||
|
&the_mutex->Mutex,
|
||||||
|
executing,
|
||||||
|
blocking,
|
||||||
|
timeout,
|
||||||
|
&lock_context
|
||||||
|
);
|
||||||
|
return _POSIX_Mutex_Translate_core_mutex_return_code(
|
||||||
|
(CORE_mutex_Status) executing->Wait.return_code
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,14 +18,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
#include <rtems/system.h>
|
|
||||||
#include <rtems/score/coremuteximpl.h>
|
|
||||||
#include <rtems/score/watchdog.h>
|
|
||||||
#include <rtems/posix/muteximpl.h>
|
#include <rtems/posix/muteximpl.h>
|
||||||
#include <rtems/posix/priorityimpl.h>
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 13.6.2 Change the Priority Ceiling of a Mutex, P1003.1c/Draft 10, p. 131
|
* 13.6.2 Change the Priority Ceiling of a Mutex, P1003.1c/Draft 10, p. 131
|
||||||
@@ -38,7 +31,6 @@ int pthread_mutex_setprioceiling(
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
register POSIX_Mutex_Control *the_mutex;
|
register POSIX_Mutex_Control *the_mutex;
|
||||||
Objects_Locations location;
|
|
||||||
Priority_Control the_priority;
|
Priority_Control the_priority;
|
||||||
ISR_lock_Context lock_context;
|
ISR_lock_Context lock_context;
|
||||||
|
|
||||||
@@ -64,36 +56,25 @@ int pthread_mutex_setprioceiling(
|
|||||||
* NOTE: This makes it easier to get 100% binary coverage since the
|
* NOTE: This makes it easier to get 100% binary coverage since the
|
||||||
* bad Id case is handled by the switch.
|
* bad Id case is handled by the switch.
|
||||||
*/
|
*/
|
||||||
the_mutex = _POSIX_Mutex_Get_interrupt_disable(
|
the_mutex = _POSIX_Mutex_Get_interrupt_disable( mutex, &lock_context );
|
||||||
mutex,
|
|
||||||
&location,
|
|
||||||
&lock_context
|
|
||||||
);
|
|
||||||
switch ( location ) {
|
|
||||||
|
|
||||||
case OBJECTS_LOCAL:
|
if ( the_mutex == NULL ) {
|
||||||
*old_ceiling = _POSIX_Priority_From_core(
|
return EINVAL;
|
||||||
the_mutex->Mutex.Attributes.priority_ceiling
|
|
||||||
);
|
|
||||||
the_mutex->Mutex.Attributes.priority_ceiling = the_priority;
|
|
||||||
/*
|
|
||||||
* We are required to unlock the mutex before we return.
|
|
||||||
*/
|
|
||||||
_CORE_mutex_Surrender(
|
|
||||||
&the_mutex->Mutex,
|
|
||||||
NULL,
|
|
||||||
0,
|
|
||||||
&lock_context
|
|
||||||
);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
#if defined(RTEMS_MULTIPROCESSING)
|
|
||||||
case OBJECTS_REMOTE: /* impossible to get here */
|
|
||||||
#endif
|
|
||||||
case OBJECTS_ERROR:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return EINVAL;
|
*old_ceiling = _POSIX_Priority_From_core(
|
||||||
|
the_mutex->Mutex.Attributes.priority_ceiling
|
||||||
|
);
|
||||||
|
the_mutex->Mutex.Attributes.priority_ceiling = the_priority;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We are required to unlock the mutex before we return.
|
||||||
|
*/
|
||||||
|
_CORE_mutex_Surrender(
|
||||||
|
&the_mutex->Mutex,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
&lock_context
|
||||||
|
);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,14 +18,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
#include <rtems/system.h>
|
|
||||||
#include <rtems/score/coremuteximpl.h>
|
|
||||||
#include <rtems/score/watchdog.h>
|
|
||||||
#include <rtems/posix/muteximpl.h>
|
#include <rtems/posix/muteximpl.h>
|
||||||
#include <rtems/posix/priorityimpl.h>
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 11.3.3 Locking and Unlocking a Mutex, P1003.1c/Draft 10, p. 93
|
* 11.3.3 Locking and Unlocking a Mutex, P1003.1c/Draft 10, p. 93
|
||||||
@@ -37,33 +30,21 @@ int pthread_mutex_unlock(
|
|||||||
pthread_mutex_t *mutex
|
pthread_mutex_t *mutex
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
register POSIX_Mutex_Control *the_mutex;
|
POSIX_Mutex_Control *the_mutex;
|
||||||
Objects_Locations location;
|
CORE_mutex_Status status;
|
||||||
CORE_mutex_Status status;
|
ISR_lock_Context lock_context;
|
||||||
ISR_lock_Context lock_context;
|
|
||||||
|
|
||||||
the_mutex = _POSIX_Mutex_Get_interrupt_disable(
|
the_mutex = _POSIX_Mutex_Get_interrupt_disable( mutex, &lock_context );
|
||||||
mutex,
|
|
||||||
&location,
|
|
||||||
&lock_context
|
|
||||||
);
|
|
||||||
switch ( location ) {
|
|
||||||
|
|
||||||
case OBJECTS_LOCAL:
|
if ( the_mutex == NULL ) {
|
||||||
status = _CORE_mutex_Surrender(
|
return EINVAL;
|
||||||
&the_mutex->Mutex,
|
|
||||||
NULL,
|
|
||||||
0,
|
|
||||||
&lock_context
|
|
||||||
);
|
|
||||||
return _POSIX_Mutex_Translate_core_mutex_return_code( status );
|
|
||||||
|
|
||||||
#if defined(RTEMS_MULTIPROCESSING)
|
|
||||||
case OBJECTS_REMOTE:
|
|
||||||
#endif
|
|
||||||
case OBJECTS_ERROR:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return EINVAL;
|
status = _CORE_mutex_Surrender(
|
||||||
|
&the_mutex->Mutex,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
&lock_context
|
||||||
|
);
|
||||||
|
return _POSIX_Mutex_Translate_core_mutex_return_code( status );
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user