/*
|
/*
|
* Semaphore Manager
|
* Semaphore Manager
|
*
|
*
|
* DESCRIPTION:
|
* DESCRIPTION:
|
*
|
*
|
* This package is the implementation of the Semaphore Manager.
|
* This package is the implementation of the Semaphore Manager.
|
* This manager utilizes standard Dijkstra counting semaphores to provide
|
* This manager utilizes standard Dijkstra counting semaphores to provide
|
* synchronization and mutual exclusion capabilities.
|
* synchronization and mutual exclusion capabilities.
|
*
|
*
|
* Directives provided are:
|
* Directives provided are:
|
*
|
*
|
* + create a semaphore
|
* + create a semaphore
|
* + get an ID of a semaphore
|
* + get an ID of a semaphore
|
* + delete a semaphore
|
* + delete a semaphore
|
* + acquire a semaphore
|
* + acquire a semaphore
|
* + release a semaphore
|
* + release a semaphore
|
*
|
*
|
* COPYRIGHT (c) 1989-1999.
|
* COPYRIGHT (c) 1989-1999.
|
* On-Line Applications Research Corporation (OAR).
|
* On-Line Applications Research Corporation (OAR).
|
*
|
*
|
* The license and distribution terms for this file may be
|
* The license and distribution terms for this file may be
|
* found in the file LICENSE in this distribution or at
|
* found in the file LICENSE in this distribution or at
|
* http://www.OARcorp.com/rtems/license.html.
|
* http://www.OARcorp.com/rtems/license.html.
|
*
|
*
|
* semrelease.c,v 1.4 2000/07/06 19:35:44 joel Exp
|
* semrelease.c,v 1.4 2000/07/06 19:35:44 joel Exp
|
*/
|
*/
|
|
|
#include <rtems/system.h>
|
#include <rtems/system.h>
|
#include <rtems/rtems/status.h>
|
#include <rtems/rtems/status.h>
|
#include <rtems/rtems/support.h>
|
#include <rtems/rtems/support.h>
|
#include <rtems/rtems/attr.h>
|
#include <rtems/rtems/attr.h>
|
#include <rtems/score/isr.h>
|
#include <rtems/score/isr.h>
|
#include <rtems/score/object.h>
|
#include <rtems/score/object.h>
|
#include <rtems/rtems/options.h>
|
#include <rtems/rtems/options.h>
|
#include <rtems/rtems/sem.h>
|
#include <rtems/rtems/sem.h>
|
#include <rtems/score/coremutex.h>
|
#include <rtems/score/coremutex.h>
|
#include <rtems/score/coresem.h>
|
#include <rtems/score/coresem.h>
|
#include <rtems/score/states.h>
|
#include <rtems/score/states.h>
|
#include <rtems/score/thread.h>
|
#include <rtems/score/thread.h>
|
#include <rtems/score/threadq.h>
|
#include <rtems/score/threadq.h>
|
#if defined(RTEMS_MULTIPROCESSING)
|
#if defined(RTEMS_MULTIPROCESSING)
|
#include <rtems/score/mpci.h>
|
#include <rtems/score/mpci.h>
|
#endif
|
#endif
|
#include <rtems/score/sysstate.h>
|
#include <rtems/score/sysstate.h>
|
|
|
#include <rtems/score/interr.h>
|
#include <rtems/score/interr.h>
|
|
|
/*PAGE
|
/*PAGE
|
*
|
*
|
* rtems_semaphore_release
|
* rtems_semaphore_release
|
*
|
*
|
* This directive allows a thread to release a semaphore.
|
* This directive allows a thread to release a semaphore.
|
*
|
*
|
* Input parameters:
|
* Input parameters:
|
* id - semaphore id
|
* id - semaphore id
|
*
|
*
|
* Output parameters:
|
* Output parameters:
|
* RTEMS_SUCCESSFUL - if successful
|
* RTEMS_SUCCESSFUL - if successful
|
* error code - if unsuccessful
|
* error code - if unsuccessful
|
*/
|
*/
|
|
|
#if defined(RTEMS_MULTIPROCESSING)
|
#if defined(RTEMS_MULTIPROCESSING)
|
#define MUTEX_MP_SUPPORT _Semaphore_Core_mutex_mp_support
|
#define MUTEX_MP_SUPPORT _Semaphore_Core_mutex_mp_support
|
#else
|
#else
|
#define MUTEX_MP_SUPPORT NULL
|
#define MUTEX_MP_SUPPORT NULL
|
#endif
|
#endif
|
|
|
rtems_status_code rtems_semaphore_release(
|
rtems_status_code rtems_semaphore_release(
|
Objects_Id id
|
Objects_Id id
|
)
|
)
|
{
|
{
|
register Semaphore_Control *the_semaphore;
|
register Semaphore_Control *the_semaphore;
|
Objects_Locations location;
|
Objects_Locations location;
|
CORE_mutex_Status mutex_status;
|
CORE_mutex_Status mutex_status;
|
CORE_semaphore_Status semaphore_status;
|
CORE_semaphore_Status semaphore_status;
|
|
|
the_semaphore = _Semaphore_Get( id, &location );
|
the_semaphore = _Semaphore_Get( id, &location );
|
switch ( location ) {
|
switch ( location ) {
|
|
|
case OBJECTS_REMOTE:
|
case OBJECTS_REMOTE:
|
#if defined(RTEMS_MULTIPROCESSING)
|
#if defined(RTEMS_MULTIPROCESSING)
|
return _Semaphore_MP_Send_request_packet(
|
return _Semaphore_MP_Send_request_packet(
|
SEMAPHORE_MP_RELEASE_REQUEST,
|
SEMAPHORE_MP_RELEASE_REQUEST,
|
id,
|
id,
|
0, /* Not used */
|
0, /* Not used */
|
MPCI_DEFAULT_TIMEOUT
|
MPCI_DEFAULT_TIMEOUT
|
);
|
);
|
#endif
|
#endif
|
|
|
case OBJECTS_ERROR:
|
case OBJECTS_ERROR:
|
return RTEMS_INVALID_ID;
|
return RTEMS_INVALID_ID;
|
|
|
case OBJECTS_LOCAL:
|
case OBJECTS_LOCAL:
|
if ( !_Attributes_Is_counting_semaphore(the_semaphore->attribute_set) ) {
|
if ( !_Attributes_Is_counting_semaphore(the_semaphore->attribute_set) ) {
|
mutex_status = _CORE_mutex_Surrender(
|
mutex_status = _CORE_mutex_Surrender(
|
&the_semaphore->Core_control.mutex,
|
&the_semaphore->Core_control.mutex,
|
id,
|
id,
|
MUTEX_MP_SUPPORT
|
MUTEX_MP_SUPPORT
|
);
|
);
|
_Thread_Enable_dispatch();
|
_Thread_Enable_dispatch();
|
return _Semaphore_Translate_core_mutex_return_code( mutex_status );
|
return _Semaphore_Translate_core_mutex_return_code( mutex_status );
|
} else {
|
} else {
|
semaphore_status = _CORE_semaphore_Surrender(
|
semaphore_status = _CORE_semaphore_Surrender(
|
&the_semaphore->Core_control.semaphore,
|
&the_semaphore->Core_control.semaphore,
|
id,
|
id,
|
MUTEX_MP_SUPPORT
|
MUTEX_MP_SUPPORT
|
);
|
);
|
_Thread_Enable_dispatch();
|
_Thread_Enable_dispatch();
|
return
|
return
|
_Semaphore_Translate_core_semaphore_return_code( semaphore_status );
|
_Semaphore_Translate_core_semaphore_return_code( semaphore_status );
|
}
|
}
|
}
|
}
|
|
|
return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */
|
return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */
|
}
|
}
|
|
|