From fb27af7637ca2d4844c67c20fbe026af6af8152c Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Mon, 15 Nov 1999 16:39:01 +0000 Subject: Split ITRON semaphore manager into multiple files. --- c/src/exec/itron/src/Makefile.in | 3 +- c/src/exec/itron/src/cre_sem.c | 93 +++++++++++++ c/src/exec/itron/src/del_sem.c | 61 +++++++++ c/src/exec/itron/src/itronsem.c | 284 --------------------------------------- c/src/exec/itron/src/preq_sem.c | 26 ++++ c/src/exec/itron/src/ref_sem.c | 59 ++++++++ c/src/exec/itron/src/sig_sem.c | 49 +++++++ c/src/exec/itron/src/twai_sem.c | 62 +++++++++ c/src/exec/itron/src/wai_sem.c | 26 ++++ 9 files changed, 378 insertions(+), 285 deletions(-) create mode 100644 c/src/exec/itron/src/cre_sem.c create mode 100644 c/src/exec/itron/src/del_sem.c create mode 100644 c/src/exec/itron/src/preq_sem.c create mode 100644 c/src/exec/itron/src/ref_sem.c create mode 100644 c/src/exec/itron/src/sig_sem.c create mode 100644 c/src/exec/itron/src/twai_sem.c create mode 100644 c/src/exec/itron/src/wai_sem.c (limited to 'c') diff --git a/c/src/exec/itron/src/Makefile.in b/c/src/exec/itron/src/Makefile.in index 9cd743e34a..52f3f8bfe7 100644 --- a/c/src/exec/itron/src/Makefile.in +++ b/c/src/exec/itron/src/Makefile.in @@ -19,7 +19,8 @@ TASK_C_PIECES = task cre_tsk del_tsk sta_tsk ext_tsk exd_tsk ter_tsk \ TASKSYNC_C_PIECES = sus_tsk rsm_tsk frsm_tsk slp_tsk tslp_tsk wup_tsk \ can_wup -SEMAPHORE_C_PIECES = itronsem +SEMAPHORE_C_PIECES = itronsem cre_sem del_sem preq_sem ref_sem sig_sem \ + twai_sem wai_sem EVENTFLAGS_C_PIECES = eventflags diff --git a/c/src/exec/itron/src/cre_sem.c b/c/src/exec/itron/src/cre_sem.c new file mode 100644 index 0000000000..6b5bd6c82b --- /dev/null +++ b/c/src/exec/itron/src/cre_sem.c @@ -0,0 +1,93 @@ +/* + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include + +#include +#include +#include + +/* + * cre_sem - Create Semaphore + * + * This function implements the ITRON 3.0 cre_sem() service. + */ + +ER cre_sem( + ID semid, + T_CSEM *pk_csem +) +{ + CORE_semaphore_Attributes the_semaphore_attributes; + ITRON_Semaphore_Control *the_semaphore; + + /* + * Bad pointer to the attributes structure + */ + + if ( !pk_csem ) + return E_PAR; + + /* + * Bits were set that were note defined. + */ + + if ( pk_csem->sematr & _ITRON_SEMAPHORE_UNUSED_ATTRIBUTES ) + return E_RSATR; + + /* + * Initial semaphore count exceeds the maximum. + */ + + if ( pk_csem->isemcnt > pk_csem->maxsem ) + return E_PAR; + + /* + * This error is not in the specification but this condition + * does not make sense. + */ + + if ( pk_csem->maxsem == 0 ) + return E_PAR; + + _Thread_Disable_dispatch(); /* prevents deletion */ + + the_semaphore = _ITRON_Semaphore_Allocate( semid ); + if ( !the_semaphore ) { + _Thread_Enable_dispatch(); + return _ITRON_Semaphore_Clarify_allocation_id_error( semid ); + } + + if ( pk_csem->sematr & TA_TPRI ) + the_semaphore_attributes.discipline = CORE_SEMAPHORE_DISCIPLINES_PRIORITY; + else + the_semaphore_attributes.discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO; + + the_semaphore_attributes.maximum_count = pk_csem->maxsem; + + _CORE_semaphore_Initialize( + &the_semaphore->semaphore, + OBJECTS_ITRON_SEMAPHORES, + &the_semaphore_attributes, + pk_csem->isemcnt, + NULL /* Multiprocessing not supported */ + ); + + _ITRON_Objects_Open( &_ITRON_Semaphore_Information, &the_semaphore->Object ); + + /* + * If multiprocessing were supported, this is where we would announce + * the existence of the semaphore to the rest of the system. + */ + +#if defined(RTEMS_MULTIPROCESSING) +#endif + + _Thread_Enable_dispatch(); + return E_OK; +} diff --git a/c/src/exec/itron/src/del_sem.c b/c/src/exec/itron/src/del_sem.c new file mode 100644 index 0000000000..5e205e3782 --- /dev/null +++ b/c/src/exec/itron/src/del_sem.c @@ -0,0 +1,61 @@ +/* + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include + +#include +#include +#include + +/* + * del_sem - Delete Semaphore + * + * This function implements the ITRON 3.0 del_sem() service. + */ + +ER del_sem( + ID semid +) +{ + ITRON_Semaphore_Control *the_semaphore; + Objects_Locations location; + + the_semaphore = _ITRON_Semaphore_Get( semid, &location ); + switch ( location ) { + case OBJECTS_REMOTE: /* Multiprocessing not supported */ + case OBJECTS_ERROR: + return _ITRON_Semaphore_Clarify_get_id_error( semid ); + + case OBJECTS_LOCAL: + _CORE_semaphore_Flush( + &the_semaphore->semaphore, + NULL, /* Multiprocessing not supported */ + CORE_SEMAPHORE_WAS_DELETED + ); + + _ITRON_Objects_Close( + &_ITRON_Semaphore_Information, + &the_semaphore->Object + ); + + _ITRON_Semaphore_Free( the_semaphore ); + + /* + * If multiprocessing were supported, this is where we would announce + * the destruction of the semaphore to the rest of the system. + */ + +#if defined(RTEMS_MULTIPROCESSING) +#endif + + _Thread_Enable_dispatch(); + return E_OK; + + } + return E_OK; +} diff --git a/c/src/exec/itron/src/itronsem.c b/c/src/exec/itron/src/itronsem.c index a41775f0f6..b7f93c3a55 100644 --- a/c/src/exec/itron/src/itronsem.c +++ b/c/src/exec/itron/src/itronsem.c @@ -51,287 +51,3 @@ void _ITRON_Semaphore_Manager_initialization( } -/* - * cre_sem - Create Semaphore - * - * This function implements the ITRON 3.0 cre_sem() service. - */ - -ER cre_sem( - ID semid, - T_CSEM *pk_csem -) -{ - CORE_semaphore_Attributes the_semaphore_attributes; - ITRON_Semaphore_Control *the_semaphore; - - /* - * Bad pointer to the attributes structure - */ - - if ( !pk_csem ) - return E_PAR; - - /* - * Bits were set that were note defined. - */ - - if ( pk_csem->sematr & _ITRON_SEMAPHORE_UNUSED_ATTRIBUTES ) - return E_RSATR; - - /* - * Initial semaphore count exceeds the maximum. - */ - - if ( pk_csem->isemcnt > pk_csem->maxsem ) - return E_PAR; - - /* - * This error is not in the specification but this condition - * does not make sense. - */ - - if ( pk_csem->maxsem == 0 ) - return E_PAR; - - _Thread_Disable_dispatch(); /* prevents deletion */ - - the_semaphore = _ITRON_Semaphore_Allocate( semid ); - if ( !the_semaphore ) { - _Thread_Enable_dispatch(); - return _ITRON_Semaphore_Clarify_allocation_id_error( semid ); - } - - if ( pk_csem->sematr & TA_TPRI ) - the_semaphore_attributes.discipline = CORE_SEMAPHORE_DISCIPLINES_PRIORITY; - else - the_semaphore_attributes.discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO; - - the_semaphore_attributes.maximum_count = pk_csem->maxsem; - - _CORE_semaphore_Initialize( - &the_semaphore->semaphore, - OBJECTS_ITRON_SEMAPHORES, - &the_semaphore_attributes, - pk_csem->isemcnt, - NULL /* Multiprocessing not supported */ - ); - - _ITRON_Objects_Open( &_ITRON_Semaphore_Information, &the_semaphore->Object ); - - /* - * If multiprocessing were supported, this is where we would announce - * the existence of the semaphore to the rest of the system. - */ - -#if defined(RTEMS_MULTIPROCESSING) -#endif - - _Thread_Enable_dispatch(); - return E_OK; -} - -/* - * del_sem - Delete Semaphore - * - * This function implements the ITRON 3.0 del_sem() service. - */ - -ER del_sem( - ID semid -) -{ - ITRON_Semaphore_Control *the_semaphore; - Objects_Locations location; - - the_semaphore = _ITRON_Semaphore_Get( semid, &location ); - switch ( location ) { - case OBJECTS_REMOTE: /* Multiprocessing not supported */ - case OBJECTS_ERROR: - return _ITRON_Semaphore_Clarify_get_id_error( semid ); - - case OBJECTS_LOCAL: - _CORE_semaphore_Flush( - &the_semaphore->semaphore, - NULL, /* Multiprocessing not supported */ - CORE_SEMAPHORE_WAS_DELETED - ); - - _ITRON_Objects_Close( - &_ITRON_Semaphore_Information, - &the_semaphore->Object - ); - - _ITRON_Semaphore_Free( the_semaphore ); - - /* - * If multiprocessing were supported, this is where we would announce - * the destruction of the semaphore to the rest of the system. - */ - -#if defined(RTEMS_MULTIPROCESSING) -#endif - - _Thread_Enable_dispatch(); - return E_OK; - - } - return E_OK; -} - -/* - * sig_sem - Signal Semaphore - * - * This function implements the ITRON 3.0 sig_sem() service. - */ - -ER sig_sem( - ID semid -) -{ - ITRON_Semaphore_Control *the_semaphore; - Objects_Locations location; - CORE_semaphore_Status status; - - the_semaphore = _ITRON_Semaphore_Get( semid, &location ); - switch ( location ) { - case OBJECTS_REMOTE: /* Multiprocessing not supported */ - case OBJECTS_ERROR: - return _ITRON_Semaphore_Clarify_get_id_error( semid ); - - case OBJECTS_LOCAL: - /* - * XXX maxsemcnt - */ - - status = _CORE_semaphore_Surrender( - &the_semaphore->semaphore, - the_semaphore->Object.id, - NULL /* Multiprocessing not supported */ - ); - _Thread_Enable_dispatch(); - return _ITRON_Semaphore_Translate_core_semaphore_return_code( status ); - } - return E_OK; -} - -/* - * wai_sem - Wait on Semaphore - * - * This function implements the ITRON 3.0 wai_sem() service. - */ - -ER wai_sem( - ID semid -) -{ - return twai_sem( semid, TMO_FEVR ); -} - -/* - * preq_sem - Poll and Request Semaphore - * - * This function implements the ITRON 3.0 preq_sem() service. - */ - -ER preq_sem( - ID semid -) -{ - return twai_sem( semid, TMO_POL ); -} - -/* - * twai_sem - Wait on Semaphore with Timeout - * - * This function implements the ITRON 3.0 twai_sem() service. - */ - -ER twai_sem( - ID semid, - TMO tmout -) -{ - ITRON_Semaphore_Control *the_semaphore; - Objects_Locations location; - Watchdog_Interval interval; - boolean wait; - CORE_semaphore_Status status; - - interval = 0; - if ( tmout == TMO_POL ) { - wait = FALSE; - } else { - wait = TRUE; - if ( tmout != TMO_FEVR ) - interval = TOD_MILLISECONDS_TO_TICKS(tmout); - } - - if ( wait && _ITRON_Is_in_non_task_state() ) - return E_CTX; - - the_semaphore = _ITRON_Semaphore_Get( semid, &location ); - switch ( location ) { - case OBJECTS_REMOTE: /* Multiprocessing not supported */ - case OBJECTS_ERROR: - return _ITRON_Semaphore_Clarify_get_id_error( semid ); - - case OBJECTS_LOCAL: - _CORE_semaphore_Seize( - &the_semaphore->semaphore, - the_semaphore->Object.id, - wait, /* wait for a timeout */ - interval /* timeout value */ - ); - _Thread_Enable_dispatch(); - status = (CORE_semaphore_Status) _Thread_Executing->Wait.return_code; - return _ITRON_Semaphore_Translate_core_semaphore_return_code( status ); - } - return E_OK; -} - -/* - * ref_sem - Reference Semaphore Status - * - * This function implements the ITRON 3.0 ref_sem() service. - */ - -ER ref_sem( - ID semid, - T_RSEM *pk_rsem -) -{ - ITRON_Semaphore_Control *the_semaphore; - Objects_Locations location; - - if ( !pk_rsem ) - return E_PAR; /* XXX check this error code */ - - the_semaphore = _ITRON_Semaphore_Get( semid, &location ); - switch ( location ) { - case OBJECTS_REMOTE: /* Multiprocessing not supported */ - case OBJECTS_ERROR: - return _ITRON_Semaphore_Clarify_get_id_error( semid ); - - case OBJECTS_LOCAL: - /* - * Fill in the current semaphore count - */ - - pk_rsem->semcnt = _CORE_semaphore_Get_count( &the_semaphore->semaphore ); - - /* - * Fill in whether or not there is a waiting task - */ - - if ( !_Thread_queue_First( &the_semaphore->semaphore.Wait_queue ) ) - pk_rsem->wtsk = FALSE; - else - pk_rsem->wtsk = TRUE; - - _Thread_Enable_dispatch(); - return E_OK; - } - return E_OK; -} - diff --git a/c/src/exec/itron/src/preq_sem.c b/c/src/exec/itron/src/preq_sem.c new file mode 100644 index 0000000000..a20cca00a0 --- /dev/null +++ b/c/src/exec/itron/src/preq_sem.c @@ -0,0 +1,26 @@ +/* + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include + +#include +#include +#include + +/* + * preq_sem - Poll and Request Semaphore + * + * This function implements the ITRON 3.0 preq_sem() service. + */ + +ER preq_sem( + ID semid +) +{ + return twai_sem( semid, TMO_POL ); +} diff --git a/c/src/exec/itron/src/ref_sem.c b/c/src/exec/itron/src/ref_sem.c new file mode 100644 index 0000000000..08bb5adff0 --- /dev/null +++ b/c/src/exec/itron/src/ref_sem.c @@ -0,0 +1,59 @@ +/* + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include + +#include +#include +#include + +/* + * ref_sem - Reference Semaphore Status + * + * This function implements the ITRON 3.0 ref_sem() service. + */ + +ER ref_sem( + ID semid, + T_RSEM *pk_rsem +) +{ + ITRON_Semaphore_Control *the_semaphore; + Objects_Locations location; + + if ( !pk_rsem ) + return E_PAR; /* XXX check this error code */ + + the_semaphore = _ITRON_Semaphore_Get( semid, &location ); + switch ( location ) { + case OBJECTS_REMOTE: /* Multiprocessing not supported */ + case OBJECTS_ERROR: + return _ITRON_Semaphore_Clarify_get_id_error( semid ); + + case OBJECTS_LOCAL: + /* + * Fill in the current semaphore count + */ + + pk_rsem->semcnt = _CORE_semaphore_Get_count( &the_semaphore->semaphore ); + + /* + * Fill in whether or not there is a waiting task + */ + + if ( !_Thread_queue_First( &the_semaphore->semaphore.Wait_queue ) ) + pk_rsem->wtsk = FALSE; + else + pk_rsem->wtsk = TRUE; + + _Thread_Enable_dispatch(); + return E_OK; + } + return E_OK; +} + diff --git a/c/src/exec/itron/src/sig_sem.c b/c/src/exec/itron/src/sig_sem.c new file mode 100644 index 0000000000..bde5d9b89f --- /dev/null +++ b/c/src/exec/itron/src/sig_sem.c @@ -0,0 +1,49 @@ +/* + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include + +#include +#include +#include + +/* + * sig_sem - Signal Semaphore + * + * This function implements the ITRON 3.0 sig_sem() service. + */ + +ER sig_sem( + ID semid +) +{ + ITRON_Semaphore_Control *the_semaphore; + Objects_Locations location; + CORE_semaphore_Status status; + + the_semaphore = _ITRON_Semaphore_Get( semid, &location ); + switch ( location ) { + case OBJECTS_REMOTE: /* Multiprocessing not supported */ + case OBJECTS_ERROR: + return _ITRON_Semaphore_Clarify_get_id_error( semid ); + + case OBJECTS_LOCAL: + /* + * XXX maxsemcnt + */ + + status = _CORE_semaphore_Surrender( + &the_semaphore->semaphore, + the_semaphore->Object.id, + NULL /* Multiprocessing not supported */ + ); + _Thread_Enable_dispatch(); + return _ITRON_Semaphore_Translate_core_semaphore_return_code( status ); + } + return E_OK; +} diff --git a/c/src/exec/itron/src/twai_sem.c b/c/src/exec/itron/src/twai_sem.c new file mode 100644 index 0000000000..4354c7cff3 --- /dev/null +++ b/c/src/exec/itron/src/twai_sem.c @@ -0,0 +1,62 @@ +/* + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include + +#include +#include +#include + +/* + * twai_sem - Wait on Semaphore with Timeout + * + * This function implements the ITRON 3.0 twai_sem() service. + */ + +ER twai_sem( + ID semid, + TMO tmout +) +{ + ITRON_Semaphore_Control *the_semaphore; + Objects_Locations location; + Watchdog_Interval interval; + boolean wait; + CORE_semaphore_Status status; + + interval = 0; + if ( tmout == TMO_POL ) { + wait = FALSE; + } else { + wait = TRUE; + if ( tmout != TMO_FEVR ) + interval = TOD_MILLISECONDS_TO_TICKS(tmout); + } + + if ( wait && _ITRON_Is_in_non_task_state() ) + return E_CTX; + + the_semaphore = _ITRON_Semaphore_Get( semid, &location ); + switch ( location ) { + case OBJECTS_REMOTE: /* Multiprocessing not supported */ + case OBJECTS_ERROR: + return _ITRON_Semaphore_Clarify_get_id_error( semid ); + + case OBJECTS_LOCAL: + _CORE_semaphore_Seize( + &the_semaphore->semaphore, + the_semaphore->Object.id, + wait, /* wait for a timeout */ + interval /* timeout value */ + ); + _Thread_Enable_dispatch(); + status = (CORE_semaphore_Status) _Thread_Executing->Wait.return_code; + return _ITRON_Semaphore_Translate_core_semaphore_return_code( status ); + } + return E_OK; +} diff --git a/c/src/exec/itron/src/wai_sem.c b/c/src/exec/itron/src/wai_sem.c new file mode 100644 index 0000000000..f9e0c4d712 --- /dev/null +++ b/c/src/exec/itron/src/wai_sem.c @@ -0,0 +1,26 @@ +/* + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include + +#include +#include +#include + +/* + * wai_sem - Wait on Semaphore + * + * This function implements the ITRON 3.0 wai_sem() service. + */ + +ER wai_sem( + ID semid +) +{ + return twai_sem( semid, TMO_FEVR ); +} -- cgit v1.2.3