#define MALLOC_SEM 1 /* Semaphore No. for malloc */
#define STRTOK_SEM 2 /* Semaphore No. for strtok */
#define FILE_TBL_SEM 3 /* Semaphore No. for fopen */
#define MBRLEN_SEM 4 /* Semaphore No. for mbrlen */
#define FPSWREG_SEM 5 /* Semaphore No. for FPSW register */
#define FILES_SEM 6 /* Semaphore No. for _Files */
#define SEMSIZE 26 /* FILES_SEM + _nfiles (assumed _nfiles=20) */
#define TRUE 1
#define FALSE 0
#define OK 1
#define NG 0
extern long *errno_addr(void);
extern long wait_sem(long);
extern long signal_sem(long);
static long sem_errno;
static int force_fail_signal_sem = FALSE;
static int semaphore[SEMSIZE];
/******************************************************************************/
/* errno_addr: Acquisition of errno address */
/* Return value: errno address */
/******************************************************************************/
long *errno_addr(void)
{
/* Return the errno address of the current task */
return (&sem_errno);
}
/******************************************************************************/
/* wait_sem: Defines the specified numbers of semaphores */
/* Return value: OK(=1) (Normal) */
/* NG(=0) (Error) */
/******************************************************************************/
long wait_sem(long semnum) /* Semaphore ID */
{
if((0 < semnum) && (semnum < SEMSIZE)) {
if(semaphore[semnum] == FALSE) {
semaphore[semnum] = TRUE;
return(OK);
}
}
return(NG);
}
/******************************************************************************/
/* signal_sem: Releases the specified numbers of semaphores */
/* Return value: OK(=1) (Normal) */
/* NG(=0) (Error) */
/******************************************************************************/
long signal_sem(long semnum) /* Semaphore ID */
{
if(!force_fail_signal_sem) {
if((0 <= semnum) && (semnum < SEMSIZE)) {
if( semaphore[semnum] == TRUE ) {
semaphore[semnum] = FALSE;
return(OK);
}
}
}
return(NG);
}
|