예제 #1
0
static struct event_info * event_info_alloc(int event) {
    int nxt;
    struct event_info * info;
    SPIN_LOCK_ISR_TAKE(&events_lock);
    if (events_buf_overflow) {
        SPIN_LOCK_ISR_GIVE(&events_lock);
        return NULL;
    }
    info = events + events_inp;
    nxt = (events_inp + 1) % MAX_EVENTS;
    if (nxt == events_out) {
        events_buf_overflow = 1;
        semGive(events_signal);
        SPIN_LOCK_ISR_GIVE(&events_lock);
        return NULL;
    }
    memset(info, 0, sizeof(struct event_info));
    info->event = event;
    events_inp = nxt;
    events_cnt++;
    return info;
}
예제 #2
0
STATUS ti81xxSpiChannelConfig
    (
    int module,     /* SPI module number */
    int channel,    /* SPI channel number */
    int cfgValue    /* SPI channel configure value */
    )
    {
    if (ti81xxMcSpiSanityCheck(module, channel) == ERROR)
        {
        TI81XX_SPI_LOG("%s : invalid parameter.\n", __FUNCTION__, 0, 0, 0, 0, 0);
        return (ERROR);
        }

    semTake(mcSpiSem[module], WAIT_FOREVER);

    TI81XX_SPI_REGISTER_WRITE(module, MCSPI_CHxCONF(channel), cfgValue);

    semGive(mcSpiSem[module]);

    return (OK);

    }
예제 #3
0
/*!*****************************************************************************
*******************************************************************************
\note  send_misc_sensors
\date  Nov. 2007
   
\remarks 

sends the entire misc_sim_sensors to shared memory
	

*******************************************************************************
Function Parameters: [in]=input,[out]=output

none

******************************************************************************/
int 
send_misc_sensors(void)
{
  
  int i;

  if (semTake(sm_misc_sim_sensor_sem,ns2ticks(TIME_OUT_NS)) == ERROR) {
    
    ++simulation_servo_errors;
    return FALSE;

  } 

  for (i=1; i<=n_misc_sensors; ++i)
    sm_misc_sim_sensor->value[i] = misc_sim_sensor[i];

  sm_misc_sim_sensor->ts = simulation_servo_time;
  
  semGive(sm_misc_sim_sensor_sem);

  return TRUE;
}
예제 #4
0
PUBLIC void mprSpinUnlock(MprSpin *lock)
{
    if (lock == 0) return;

#if ME_DEBUG
    lock->owner = 0;
#endif

#if USE_MPR_LOCK
    mprUnlock(&lock->cs);
#elif MACOSX
    OSSpinLockUnlock(&lock->cs);
#elif ME_UNIX_LIKE && ME_COMPILER_HAS_SPINLOCK
    pthread_spin_unlock(&lock->cs);
#elif ME_UNIX_LIKE
    pthread_mutex_unlock(&lock->cs);
#elif ME_WIN_LIKE
    LeaveCriticalSection(&lock->cs);
#elif VXWORKS
    semGive(lock->cs);
#endif
}
예제 #5
0
void Semaphore::give()
{
#if defined (PTHREADS)
	if (sem_post(sem))
	{
		throw Exception("Could not release semaphore", errno, __FILE__, __LINE__);
	}

#elif defined(VXWORKS)
	if (semGive(sem))
	{
		throw Exception("Could not release semaphore", -1, __FILE__, __LINE__);
	}

#elif defined(_WINDOWS)
	if (! ReleaseSemaphore(sem,1,NULL))
	{
		throw Exception("Could not release semaphore", GetLastError(), __FILE__, __LINE__);
	}

#endif
}
예제 #6
0
파일: vsLib.c 프로젝트: andy345/vxworks5
STATUS virtualStackNumGet
    (
    VSID vsid,
    int *num
    )
    {
    
    if ((vsid == NULL) && (num == NULL))
        return (ERROR);

    semTake (vsTblLock, WAIT_FOREVER);
    
    for (*num = 0; (*num < VSID_MAX) && (vsTbl[*num] != vsid); (*num)++);

    semGive(vsTblLock);

    if ( vsTbl[*num] != vsid )
	return (ERROR);

    return OK;

    }
예제 #7
0
//------------------------------------------------------------------------------
// Function:    ShbIpcStopSignalingNewData
//
// Description: Stop signaling of new data (called from reading process)
//
// Parameters:  pShbInstance_p        pointer to shared buffer instance
//
// Return:      tShbError      = error code
//------------------------------------------------------------------------------
tShbError ShbIpcStopSignalingNewData(tShbInstance pShbInstance_p)
{
    tShbMemInst         *pShbMemInst;
    tShbMemHeader       *pShbMemHeader;
    tShbError           ShbError;
    INT                 iRetVal = -1;

    if (pShbInstance_p == NULL)
    {
        return (kShbInvalidArg);
    }

    pShbMemHeader = ShbIpcGetShbMemHeader (pShbInstance_p);
    pShbMemInst = ShbIpcGetShbMemInst (pShbInstance_p);

    ShbError = kShbOk;

    if (!pShbMemInst->m_fNewDataThreadStarted)
    {
        ShbError = kShbBufferAlreadyCompleted;
        goto Exit;
    }

    //set termination flag and signal new data to terminate thread
    pShbMemInst->m_fThreadTermFlag = TRUE;
    semGive(pShbMemHeader->m_semNewData);

    iRetVal = semTake(pShbMemHeader->m_semStopSignalingNewData,
    		          TIMEOUT_WAITING_THREAD);
    if (iRetVal == ERROR)
    {
        EPL_DBGLVL_ERROR_TRACE("%s() Stop Sem TIMEOUT %d (%s)\n", __func__,
        		                iRetVal, strerror(errno));
    }

Exit:

    return (ShbError);
}
예제 #8
0
파일: driver.c 프로젝트: hermixy/driver
int devClose(myDev * dev)
{
	fifo * i = NULL; 
	fifo * temp = NULL;
	if(dev==NULL)
	{
		errnoSet(NOT_OPEN);
		return -1;
	}
	//Prevent anyone from accessing this device while we're modifying it :
	if(semTake(dev->semMData,WAIT_FOREVER)==-1)
	{
		errnoSet(SEM_ERR);
		return -1;
	}
	if (dev->openned == 0)
	{
		errnoSet(NOT_OPEN);
		return -1;
	} else {
		//Find fifo corresponding to this task in drv->listFifo and deallocate it
		if (dev->firstFifo->taskId==taskIdSelf())
		{
			temp=dev->firstFifo;
			dev->firstFifo=temp->nextFifo;
			deleteFifo(temp);
			free(temp);
		} else {
			for (i=dev->firstFifo;i->nextFifo->taskId==taskIdSelf();i=i->nextFifo);
			temp=i->nextFifo;
			i->nextFifo=temp->nextFifo;
			deleteFifo(temp);
			free(temp);
		}
		dev->openned--;
	}
	semGive(dev->semMData);
	return 0;
}
BST_ERR_ENUM_UINT8  BST_OS_PalSendSem(
    BST_OS_PAL_SEM_T    stSemHandle,
    BST_VOID           *pvArg )
{
    if( BST_PAL_IsSemInValid( stSemHandle ) )
    {
        return BST_ERR_ILLEGAL_PARAM;
    }

#if (VOS_RTOSCK == VOS_OS_VER)
    if( VOS_OK == VOS_SmV(stSemHandle) )
#else
    if( OK == semGive(stSemHandle) )
#endif
    {
        return BST_NO_ERROR_MSG;
    }
    else
    {
        return BST_ERR_ILLEGAL_PARAM;
    }
}
/* Move execution to netJob. returns 0 if successful. */
int ssh_netjob_synchronous_invoke(FUNCPTR function, void *context)
{
  STATUS stat;
  SEMAPHORE *s;

  s = semBCreate(SEM_Q_PRIORITY, SEM_FULL);
  if (!s) return 2;
  
  semTake(s, WAIT_FOREVER);
  stat = netJobAdd(function, (int)context, (int)s, 0, 0, 0);

  if (stat == OK) 
    {
      semTake(s, WAIT_FOREVER);
      semDelete(s);
      return 0;
    }

  semGive(s);
  semDelete(s);
  return 1;
}
예제 #11
0
파일: m2SysLib.c 프로젝트: andy345/vxworks5
/******************************************************************************
*
* m2SysGroupInfoSet - set system-group MIB-II variables to new values
*
* This routine sets one or more variables in the system group as specified in
* the input structure at <pSysInfo> and the bit field parameter <varToSet>.
*
* RETURNS: 
* OK, or ERROR if <pSysInfo> is not a valid pointer, or <varToSet> has an 
* invalid bit field.
*
* ERRNO:
*  S_m2Lib_INVALID_PARAMETER
*  S_m2Lib_INVALID_VAR_TO_SET
*
* SEE ALSO: m2SysInit(), m2SysGroupInfoGet(), m2SysDelete()
*/
STATUS m2SysGroupInfoSet
    (
    unsigned int varToSet,		/* bit field of variables to set */
    M2_SYSTEM * pSysInfo		/* pointer to the system structure */
    )
    {
 
    /* Validate Pointer to System structure and bit field in varToSet */
 
    if (pSysInfo == NULL ||
        (varToSet & (M2SYSNAME | M2SYSCONTACT | M2SYSLOCATION)) == 0)
	{
	if (pSysInfo == NULL)
	    errnoSet (S_m2Lib_INVALID_PARAMETER);
	else
	    errnoSet (S_m2Lib_INVALID_VAR_TO_SET);

        return (ERROR);
	}
 
    /* Set requested variables */
 
    semTake (m2SystemSem, WAIT_FOREVER);
 
    if (varToSet & M2SYSNAME)
        strcpy ((char *) m2SystemVars.sysName, (char *) pSysInfo->sysName);
 
    if (varToSet & M2SYSCONTACT)
        strcpy ((char *) m2SystemVars.sysContact, (char *)pSysInfo->sysContact);
 
    if (varToSet & M2SYSLOCATION)
        strcpy ((char *) m2SystemVars.sysLocation, 
		(char *) pSysInfo->sysLocation);
 
    semGive (m2SystemSem);
 
    return (OK);
    }
예제 #12
0
int _tmain(int argc, _TCHAR* argv[])
{
	classLibInit();
	memPartLibInit(memBuf, MEM_LEN);

	char* a1 = (char*)memPartAlloc(memSysPartId, 10);
	char* a2 = (char*)memPartAlloc(memSysPartId, 45);
	memPartFree(memSysPartId, a1);
	memPartFree(memSysPartId, a2);

	a1 = (char*)memPartAlloc(memSysPartId, 10);
	a2 = (char*)memPartAlloc(memSysPartId, 45);

	memPartFree(memSysPartId, a2);
	memPartFree(memSysPartId, a1);

	a1 = (char*)memPartAlloc(memSysPartId, 10);
	a2 = (char*)memPartAlloc(memSysPartId, 12);
	char* a3 = (char*)memPartAlloc(memSysPartId, 45);

	memPartFree(memSysPartId, a2);

	char* a4 = (char*)memPartAlloc(memSysPartId, 12);

	testQueue();

	SEM_ID semId = semMCreate(0);

	int c = 0;
	semTake(semId, WAIT_FOREVER);
	c++;
	semGive(semId);

	semDelete(semId);

	gets(a1);
	return 0;
}
/* Function: DisconnectFromHost ================================================
 * Abstract:
 *  Disconnect from the host.
 */
PRIVATE void DisconnectFromHost(int_T numSampTimes)
{
    int i;

    for (i=0; i<NUM_UPINFOS; i++) {
        UploadPrepareForFinalFlush(i);

#if defined(VXWORKS)
        /*
         * UploadPrepareForFinalFlush() has already called semGive(uploadSem)
         * two times.  Now the server thread will wait until the upload thread
         * has processed all of the data in the buffers for the final upload
         * and exhausted the uploadSem semaphores.  If the server thread
         * attempts to call UploadServerWork() while the upload thread is in
         * the middle of processing the buffers, the target code may crash
         * with a NULL pointer exception (the buffers are destroyed after
         * calling UploadLogInfoTerm).
         */
        while(semTake(uploadSem, NO_WAIT) != ERROR) {
            semGive(uploadSem);
            taskDelay(1000);
        }
#else
#ifndef EXTMODE_DISABLESIGNALMONITORING
        if (host_upstatus_is_uploading) {
            UploadServerWork(i, numSampTimes);
        }
#endif
#endif

        UploadLogInfoTerm(i, numSampTimes);
    }
    
    connected       = false;
    commInitialized = false;
    
    ExtCloseConnection(extUD);
} /* end DisconnectFromHost */
예제 #14
0
/**
 * ProcessQueue is called whenever there is a timer interrupt.
 * We need to wake up and process the current top item in the timer queue as long
 * as its scheduled time is after the current time. Then the item is removed or 
 * rescheduled (repetitive events) in the queue.
 */
void Notifier::ProcessQueue(uint32_t mask, void *params)
{
    Notifier *current;
    while (true)                // keep processing past events until no more
    {
        {
            Synchronized sync(queueSemaphore);
            double currentTime = GetClock();
            current = timerQueueHead;
            if (current == NULL || current->m_expirationTime > currentTime)
            {
                break;        // no more timer events to process
            }
            // need to process this entry
            timerQueueHead = current->m_nextEvent;
            if (current->m_periodic)
            {
                // if periodic, requeue the event
                // compute when to put into queue
                current->InsertInQueue(true);
            }
            else
            {
                // not periodic; removed from queue
                current->m_queued = false;
            }
            // Take handler semaphore while holding queue semaphore to make sure
            //  the handler will execute to completion in case we are being deleted.
            semTake(current->m_handlerSemaphore, WAIT_FOREVER);
        }

        current->m_handler(current->m_param);    // call the event handler
        semGive(current->m_handlerSemaphore);
    }
    // reschedule the first item in the queue
    Synchronized sync(queueSemaphore);
    UpdateAlarm();
}
예제 #15
0
파일: driver.c 프로젝트: hermixy/driver
int drvRemove()
{
	myDev * i = first;
	myDev * drv;
	if (semMAdmin == 0)
	{
		errnoSet(NOT_INSTALLED);
		return -1;
	}
	if (semTake(semMAdmin,WAIT_FOREVER)==-1)
	{
		errnoSet(SEM_ERR);
		return -1;
	}
	if (iosDrvRemove(numPilote,1) == -1) //And force closure of open files
	{
		errnoSet(REMOVE_ERROR);
		semGive(semMAdmin);
		return -1;
	}
	taskDelete(tMsgDispatchID);
	msgQDelete(isrmq);
	//Delete all devices  : 
	while (i!=NULL)
	{
		drv = i;
		i = drv->next;
		iosDevDelete((DEV_HDR*)drv);
		semTake(drv->semMData,WAIT_FOREVER); //Let pending ops finish
		semDelete(drv->semMData);
		free(drv);
	}
	numPilote = -1;
	first = NULL;
	semDelete(semMAdmin);
	semMAdmin=0;
	return 0;
}
예제 #16
0
/*!*****************************************************************************
 *******************************************************************************
\note  receive_misc_sensors
\date  Nov. 2007   
\remarks 

        receives the entire misc_sim_sensors from shared memory
	

 *******************************************************************************
 Function Parameters: [in]=input,[out]=output

     none

 ******************************************************************************/
static int 
receive_misc_sensors(void)
{
  
  int i;

  if (n_misc_sensors <= 0)
    return TRUE;

  if (semTake(sm_misc_sim_sensor_sem,ns2ticks(TIME_OUT_NS)) == ERROR) {
    
    ++motor_servo_errors;
    return FALSE;

  } 

  for (i=1; i<=n_misc_sensors; ++i)
    misc_sim_sensor[i] = sm_misc_sim_sensor->value[i];
  
  semGive(sm_misc_sim_sensor_sem);

  return TRUE;
}
예제 #17
0
/* Function: DisconnectFromHost ================================================
 * Abstract:
 *  Disconnect from the host.
 */
PRIVATE void DisconnectFromHost(SimStruct *S)
{
    UploadPrepareForFinalFlush();
#ifdef VXWORKS
    /*
     * Patch by Gopal Santhanam 5/24/2002 (for VXWORKS) We
     * were having problems in RTAI in that the semaphore
     * signaled in UploadPrepareForFinalFlush was taken up by
     * the upload server task.  This meant that the subsequent
     * call to rt_UploadServerWork in this function would
     * block indefinitely!
     */
    semGive(uploadSem);
#endif
    rt_UploadServerWork(S);
    
    UploadLogInfoTerm();

    connected       = FALSE;
    commInitialized = FALSE;

    ExtCloseConnection(extUD);
} /* end DisconnectFromHost */
예제 #18
0
/* --------------------------------------------------------------------------------------
   Name: OS_CloseAllFiles

   Purpose: Closes All open files that were opened through the OSAL

   Returns: OS_FS_ERROR   if one or more file close returned an error
            OS_FS_SUCCESS if the files were all closed without error
 ---------------------------------------------------------------------------------------*/
int32 OS_CloseAllFiles(void)
{
    uint32            i;
    int32             return_status = OS_FS_SUCCESS;
    int               status;

    semTake(OS_FDTableMutex,WAIT_FOREVER);

    for ( i = 0; i < OS_MAX_NUM_OPEN_FILES; i++)
    {
        if ( OS_FDTable[i].IsValid == TRUE )
        {
           /*
           ** Close the file
           */
           status = close ((int) OS_FDTable[i].OSfd);

           /*
           ** Next, remove the file from the OSAL list
           ** to free up that slot
           */
           OS_FDTable[i].OSfd =       -1;
           strcpy(OS_FDTable[i].Path, "\0");
           OS_FDTable[i].User =       0;
           OS_FDTable[i].IsValid =    FALSE;
           if (status == ERROR)
           {
              return_status = OS_FS_ERROR;
           }
        }

    }/* end for */

    semGive(OS_FDTableMutex);
    return (return_status);

}/* end OS_CloseAllFiles */
예제 #19
0
파일: logLib.c 프로젝트: phoboz/vmx
STATUS logFdAdd(
    int fd
    )
{
    STATUS status;

    semTake(&logFdSem, WAIT_FOREVER);

    /* If maximum file descriptor reached */
    if ((numLogFds + 1) > MAX_LOGFDS)
    {
        status = ERROR;
    }
    else
    {
        /* Add file descriptor */
        logFd[numLogFds++] = fd;
        status = OK;
    }

    semGive(&logFdSem);

    return status;
}
예제 #20
0
/*****************************************************************
*
* ArrayStore_T :: fetch
*
* This function looks up a descriptor for the array specified by
* <pObject>. When found, the descriptor is removed from the hash table
* and deleted, then the number of elements is returned. Memory for the
* array descriptor is reclaimed by this function.
*
* RETURNS: the number of elements in the specified array, if found,
*          otherwise -1.
*
* NOMANUAL
*/
int ArrayStore_T :: fetch
    (
    void	* pObject
    )
    {
    int		rval;
    HASH_NODE * pNode;
    ArrayDesc_T	node (pObject, 0);
    semTake (mutexSem, WAIT_FOREVER);
    if ((pNode = hashTblFind (hashId, (HASH_NODE *) (&node), 0)) == 0)
	{
	rval = -1;
	}
    else
	{
	// Cast the fetched pointer back to ArrayDesc_T
	ArrayDesc_T * ad = (ArrayDesc_T *)(pNode);
	rval = ad->nElems;
	hashTblRemove (hashId, (HASH_NODE *) pNode);
	delete ad;
	}
    semGive (mutexSem);
    return rval;
    }
//------------------------------------------------------------------------------
static void addTimer(tTimeruData* pData_p)
{
    tTimeruData*    pTimerData;

    semTake(timeruInstance_l.mutex, WAIT_FOREVER);

    if (timeruInstance_l.pFirstTimer == NULL)
    {
        timeruInstance_l.pFirstTimer = pData_p;
        timeruInstance_l.pLastTimer = pData_p;
        pData_p->pPrevTimer = NULL;
        pData_p->pNextTimer = NULL;
    }
    else
    {
        pTimerData = timeruInstance_l.pLastTimer;
        pTimerData->pNextTimer = pData_p;
        pData_p->pPrevTimer = pTimerData;
        pData_p->pNextTimer = NULL;
        timeruInstance_l.pLastTimer = pData_p;
    }

    semGive(timeruInstance_l.mutex);
}
예제 #22
0
파일: cmd.c 프로젝트: embedthis/mpr
/*
    Executed by the child process
 */
static void cmdTaskEntry(char *program, MprCmdTaskFn entry, int cmdArg)
{
    MprCmd          *cmd;
    MprCmdFile      *files;
    WIND_TCB        *tcb;
    char            *item;
    int             inFd, outFd, errFd, id, next;

    cmd = (MprCmd*) cmdArg;

    /*
        Open standard I/O files (in/out are from the server's perspective)
     */
    files = cmd->files;
    inFd = open(files[MPR_CMD_STDIN].name, O_RDONLY, 0666);
    outFd = open(files[MPR_CMD_STDOUT].name, O_WRONLY, 0666);
    errFd = open(files[MPR_CMD_STDERR].name, O_WRONLY, 0666);

    if (inFd < 0 || outFd < 0 || errFd < 0) {
        exit(255);
    }
    id = taskIdSelf();
    ioTaskStdSet(id, 0, inFd);
    ioTaskStdSet(id, 1, outFd);
    ioTaskStdSet(id, 2, errFd);

    /*
        Now that we have opened the stdin and stdout, wakeup our parent.
     */
    semGive(cmd->startCond);

    /*
        Create the environment
     */
    if (envPrivateCreate(id, -1) < 0) {
        exit(254);
    }
    for (ITERATE_ITEMS(cmd->env, item, next)) {
        putenv(item);
    }

#if !VXWORKS
{
    char    *dir;
    int     rc;

    /*
        Set current directory if required
        WARNING: Setting working directory on VxWorks is global
     */
    if (cmd->dir) {
        rc = chdir(cmd->dir);
    } else {
        dir = mprGetPathDir(cmd->program);
        rc = chdir(dir);
    }
    if (rc < 0) {
        mprLog("error mpr cmd", 0, "Cannot change directory to %s", cmd->dir);
        exit(255);
    }
}
#endif

    /*
        Call the user's entry point
     */
    (entry)(cmd->argc, (char**) cmd->argv, (char**) cmd->env);

    tcb = taskTcb(id);
    cmd->status = tcb->exitCode;

    /*
        Cleanup
     */
    envPrivateDestroy(id);
    close(inFd);
    close(outFd);
    close(errFd);
    semGive(cmd->exitCond);
}
예제 #23
0
파일: test_sem.c 프로젝트: dubrousky/v2lin
void user_sysinit( void )
{
#else
int main ( int argc, char **argv )
{
#endif		
    int randomizer_thread1, randomizer_thread2;
    int other_thread;
    int i;

#ifndef _USR_SYS_INIT_KILL
    v2lin_init();
#endif
    s_binary = semBCreate( SEM_Q_FIFO, 0 );
    s_counting = semCCreate( SEM_Q_FIFO, TEST_SEM_INIT_COUNT );
    s_mutex = semMCreate( SEM_Q_FIFO );

    other_thread = taskSpawn( "other", 0, 0, 0, OtherThreadFunc,
            0,0,0,0,0,0,0,0,0,0 );
    printf("\n===============SEMPAHORE TEST START======================\n");

    Go2State( BINARY_SAME, "BINARY_SAME" );
    if( semGive( s_binary ) != OK )
        perror( "Error giving in BINARY_SAME state");
    if( semTake( s_binary, WAIT_FOREVER ) != OK )
        perror( "Error taking in BINARY_SAME state");

    Go2State( BINARY_OTHER, "BINARY_OTHER" );
    if( semTake( s_binary, WAIT_FOREVER ) != OK )
        perror( "Error taking in BINARY_OTHER state" );

    CheckState( BINARY_OTHER, BINARY_OPPOSITE );

    Go2State( COUNTING_SAME, "COUNTING_SAME" );
    for( i = 0; i < TEST_SEM_INIT_COUNT; i++ )
        if( semTake( s_counting, WAIT_FOREVER ) != OK )
            perror( "Error taking in COUNTING_SAME state (first pass)" );
    for( i = 0; i < TEST_SEM_MAX_COUNT; i++ )
        if( semGive( s_counting ) != OK )
            perror( "Error giving in COUNTING_SAME state" );
    for( i = 0; i < TEST_SEM_MAX_COUNT; i++ )
        if( semTake( s_counting, WAIT_FOREVER ) != OK )
            perror( "Error taking in COUNTING_SAME state (second pass)" );

    Go2State( COUNTING_OTHER, "COUNTING_OTHER" );
    if( semTake( s_counting, WAIT_FOREVER ) != OK )
        perror( "Error taking in COUNTING_OTHER state" );

    CheckState( COUNTING_OTHER, COUNTING_OPPOSITE );

    Go2State( MUTEX_SAME_TAKE, "MUTEX_SAME_TAKE" );
    for( i = 0; i < TEST_MUTEX_MAX; i++ )
        if( semTake( s_mutex, WAIT_FOREVER ) != OK )
            perror( "Error taking in MUTEX_SAME_TAKE state" );

    Go2State( MUTEX_OTHER_GIVE, "MUTEX_OTHER_GIVE" );

    Wait4State( MUTEX_OTHER_WAIT );

    Go2State( MUTEX_GIVE_SOME, "MUTEX_GIVE_SOME" );
    for( i = 0; i < TEST_MUTEX_MAX-1; i++ )
        if( semGive( s_mutex ) != OK )
            perror( "Error giving in MUTEX_GIVE_SOME state" );

    Go2State( MUTEX_GIVE_ALL, "MUTEX_GIVE_ALL" );
    if( semGive( s_mutex ) != OK )
        perror( "Error giving in MUTEX_GIVE_ALL state" );

    Wait4State( MUTEX_OPPOSITE_TO );
    if( semTake( s_mutex, 2000) == OK ) //2 seconds
        printf( "Error: taking in MUTEX_OPPOSITE_TO state must fail\n" );
    if( errno != S_objLib_OBJ_TIMEOUT )
        perror( "Error taking in MUTEX_OPPOSITE_TO" );

    Go2State( MUTEX_OPPOSITE_GIVE, "MUTEX_OPPOSITE_GIVE" );
    if( semTake( s_mutex, WAIT_FOREVER ) != OK )
        perror( "Error taking in MUTEX_OPPOSITE_GIVE" );

    Go2State( MUTEX_UNBLOCK, "MUTEX_UNBLOCK" );

    sleep(1); // to let the other thread finish

    //========================================= RANDOM TEST ===========================================
    printf("\n\nRandom test - press ^C to stop\n");


    srand( (unsigned)time( NULL ) );
    cGive = cTake = cTakeErr = cTakeTimeout = cGiveErr = 0;

    randomizer_thread1 = taskSpawn( "thread1", 0,0,0, RandomizerThreadFunc, 0,0,0,0,0,0,0,0,0,0 );
    randomizer_thread2 = taskSpawn( "thread2", 0,0,0, RandomizerThreadFunc, 0,0,0,0,0,0,0,0,0,0 );
#ifdef _USR_SYS_INIT_KILL
}
예제 #24
0
int32 OS_open   (const char *path,  int32 access,  uint32  mode)
{
    int    status;
    char   local_path[OS_MAX_LOCAL_PATH_LEN];
    uint32 PossibleFD;
    int    perm;

    /*
    ** Check to see if the path pointer is NULL
    */
    if (path == NULL)
    {
        return OS_FS_ERR_INVALID_POINTER;
    }

    /*
    ** Check to see if the path is too long
    */
    if (strlen(path) >= OS_MAX_PATH_LEN)
    {
        return OS_FS_ERR_PATH_TOO_LONG;
    }

    /*
    ** check if the name of the file is too long
    */
    if (OS_check_name_length(path) != OS_FS_SUCCESS)
    {
        return OS_FS_ERR_NAME_TOO_LONG;
    }

    /*
    ** Check for a valid access mode
    */
    switch(access)
    {
        case OS_READ_ONLY:
            perm = O_RDONLY;
            break;
        case OS_WRITE_ONLY:
            perm = O_WRONLY | O_CREAT;
            break;
        case OS_READ_WRITE:
            perm = O_RDWR | O_CREAT;
            break;
        default:
            return OS_FS_ERROR;
    }

    /*
    ** Translate the path
    */
    if ( OS_TranslatePath(path, (char *)local_path) != OS_FS_SUCCESS )
    {
        return OS_FS_ERR_PATH_INVALID;
    }

    semTake(OS_FDTableMutex,WAIT_FOREVER);

    for ( PossibleFD = 0; PossibleFD < OS_MAX_NUM_OPEN_FILES; PossibleFD++)
    {
        if( OS_FDTable[PossibleFD].IsValid == FALSE)
        {
            break;
        }
    }

    if (PossibleFD >= OS_MAX_NUM_OPEN_FILES)
    {
        semGive(OS_FDTableMutex);
        return OS_FS_ERR_NO_FREE_FDS;
    }

    /* Mark the table entry as valid so no other
     * task can take that ID */
    OS_FDTable[PossibleFD].IsValid =    TRUE;

    semGive(OS_FDTableMutex);

    /* Open the file */
    status = open(local_path, (int) perm, (int) mode);

    semTake(OS_FDTableMutex,WAIT_FOREVER);

    if (status != ERROR)
    {
        /* fill in the table before returning */

        OS_FDTable[PossibleFD].OSfd =       status;
        strncpy(OS_FDTable[PossibleFD].Path, path, OS_MAX_PATH_LEN);
        OS_FDTable[PossibleFD].User =       OS_FindCreator();
        semGive(OS_FDTableMutex);

        return PossibleFD;
    }
    else
    {   OS_FDTable[PossibleFD].IsValid = FALSE;
        semGive(OS_FDTableMutex);
        return OS_FS_ERROR;
    }

} /* end OS_open */
예제 #25
0
void StateMachine :: putEvent(std::string myEvent) {
	semTake(semQueue,WAIT_FOREVER);
	queue.push(myEvent);
	semGive(semQueue);
	return;
}
예제 #26
0
파일: vsLib.c 프로젝트: andy345/vxworks5
STATUS virtualStackCreate
    (
    char* pName, 	/* Unique stack name, or NULL for default */
    VSID* pVID 		/* Buffer for storing virtual stack identifier */
    )
    {
    int vsIndex, i;
    char tempName[VS_NAME_MAX + 1];
    
    /* Lock out access until creation is complete or error is returned. */
    semTake (vsTblLock, WAIT_FOREVER);

    /* Find the first empty slot. */

    for (vsIndex = 0; vsIndex < VSID_MAX; vsIndex++)
        {
        if (vsTbl[vsIndex] == NULL)
            break; /* Hey, we found one! */
        }

    if (vsIndex == VSID_MAX)
        {
        semGive (vsTblLock);
        return (ERROR);
        }

    /*
     * If no name is passed simply make the name the
     * VS number.
     */

    if (pName == NULL)
        sprintf (tempName, "%d", vsIndex);
    else
        strncpy (tempName, pName, min(VS_NAME_MAX, (strlen(pName) + 1)));

    /* null-terminate it, just in case... */

    tempName[VS_NAME_MAX] = EOS;

    /* Check that a stack with the same name doesn't already exist */
    for (i = 0; i < VSID_MAX; i++)
        {
        if (vsTbl[i] == NULL)  /* empty slot */
            continue;
        if (strcmp (vsTbl[i]->pName, tempName) == 0)
            {
            semGive (vsTblLock);
            return (ERROR);
            }
        }

    /* Allocate our global structure.  */

    vsTbl[vsIndex] = (BSD_GLOBAL_DATA *) KHEAP_ALLOC ((sizeof(BSD_GLOBAL_DATA)));

    *pVID = vsTbl[vsIndex]; 

    if (vsTbl[vsIndex] == NULL)
        {
        semGive (vsTblLock);
        return (ERROR);
        }

    /* Clear out the structure to NULL */
    bzero ((char *)*pVID, sizeof (BSD_GLOBAL_DATA));

    /* If no name is passed simply make the name the VS number. */

    vsTbl[vsIndex]->pName = (char *)&vsTbl[vsIndex]->name;

    bcopy (tempName, vsTbl[vsIndex]->pName, sizeof(tempName));

    semGive (vsTblLock);

    /*
     * Set the virtual stack number task variable.
     * This allows the initialization code to execute unchanged.
     */

    virtualStackNumTaskIdSet (vsIndex);

    return (OK);
    }
예제 #27
0
Synchronized::~Synchronized()
{
	semGive(m_semaphore);
}
예제 #28
0
void Action(int signal)
{
	if(flag == 1){
		semGive(semMutex);
	}
}
예제 #29
0
void Diagnostics::FlushToDisk() {
	Synchronized sync(m_writing);
	semGive(m_flushing);
}
예제 #30
0
void StateMachine :: sendEvent(std::string myEvent) {
	putEvent (myEvent); // Set the event in the queue of this object
	semGive (semEvent); // Signal the arrival of the event through counting semaphore
	return;
}