Пример #1
0
MprCmd *mprCreateCmd(MprCtx ctx)
{
    MprCmdService   *cs;
    MprCmd          *cmd;
    MprCmdFile      *files;
    int             i;
    
    cmd = mprAllocObjWithDestructorZeroed(ctx, MprCmd, cmdDestructor);
    if (cmd == 0) {
        return 0;
    }
    cmd->completeCond = mprCreateCond(cmd);
    cmd->timeoutPeriod = MPR_TIMEOUT_CMD;
    cmd->timestamp = mprGetTime(cmd);
    cmd->forkCallback = (MprForkCallback) closeFiles;

#if VXWORKS
    cmd->startCond = semCCreate(SEM_Q_PRIORITY, SEM_EMPTY);
    cmd->exitCond = semCCreate(SEM_Q_PRIORITY, SEM_EMPTY);
#endif
    files = cmd->files;
    for (i = 0; i < MPR_CMD_MAX_PIPE; i++) {
        files[i].clientFd = -1;
        files[i].fd = -1;
    }
#if BLD_FEATURE_MULTITHREAD
    cmd->mutex = mprCreateLock(cmd);
#endif
    cs = mprGetMpr(ctx)->cmdService;
    mprLock(cs->mutex);
    mprAddItem(cs->cmds, cmd);
    mprUnlock(cs->mutex);
    return cmd;
}
Пример #2
0
PUBLIC MprCmd *mprCreateCmd(MprDispatcher *dispatcher)
{
    MprCmd          *cmd;
    MprCmdFile      *files;
    int             i;

    if ((cmd = mprAllocObj(MprCmd, manageCmd)) == 0) {
        return 0;
    }
    cmd->forkCallback = (MprForkCallback) closeFiles;
    cmd->dispatcher = dispatcher ? dispatcher : MPR->dispatcher;
    cmd->status = -1;
    cmd->searchPath = MPR->pathEnv;

#if VXWORKS
    cmd->startCond = semCCreate(SEM_Q_PRIORITY, SEM_EMPTY);
    cmd->exitCond = semCCreate(SEM_Q_PRIORITY, SEM_EMPTY);
#endif
    files = cmd->files;
    for (i = 0; i < MPR_CMD_MAX_PIPE; i++) {
        files[i].clientFd = -1;
        files[i].fd = -1;
    }
    cmd->mutex = mprCreateLock();
    return cmd;
}
Пример #3
0
SemaphoreImpl::SemaphoreImpl(int n, int max)
{
	poco_assert (n >= 0 && max > 0 && n <= max);

	_sem = semCCreate(SEM_Q_PRIORITY, n);
	if (_sem == 0)
		throw Poco::SystemException("cannot create semaphore");
}
Пример #4
0
StateMachine :: StateMachine() {
	// Create the semaphores needed
	semQueue = semBCreate(SEM_Q_PRIORITY, SEM_FULL);
	semEvent = semCCreate(SEM_Q_PRIORITY, 0);
	int diagramNo;
	for (diagramNo = 0; diagramNo < diagrams; diagramNo++) {
		diaTimerTable[diagramNo] = new DiaTimer(this); // Create one timer object for each diagram
		diaTimerTable[diagramNo]->timerName = timerNames[diagramNo]; // Assign numbers to timer objects
		}
	return;
}
Пример #5
0
struct osip_sem *
osip_sem_init (unsigned int value)
{
  SEM_ID initsem;
  osip_sem_t *x;

  x = (osip_sem_t *) osip_malloc (sizeof (osip_sem_t));
  if (x == NULL)
    return NULL;
  initsem = semCCreate (SEM_Q_FIFO, value);
  x->semId = initsem;
  x->refCnt = value;
  x->sem_name = NULL;
  return (struct osip_sem *) x;
}
Пример #6
0
PUBLIC void mprResetCond(MprCond *cp)
{
    mprLock(cp->mutex);
    cp->triggered = 0;
#if ME_WIN_LIKE
    ResetEvent(cp->cv);
#elif VXWORKS
    semDelete(cp->cv);
    cp->cv = semCCreate(SEM_Q_PRIORITY, SEM_EMPTY);
#else
    pthread_cond_destroy(&cp->cv);
    pthread_cond_init(&cp->cv, NULL);
#endif
    mprUnlock(cp->mutex);
}
Пример #7
0
/**********************************************************************
*
* FUNCTION
*    cs_sema_create
*
* DESCRIPTION
*    Initialize a counting semaphore object for use.
*
* INPUTS
*    handle   - A pointer to a semaphore object to be filled in by
*               the routine.
*    count    - The initial value for the semaphore.
*
* OUTPUTS
*    Status_t - On success VSTATUS_OK is returned, otherwise
*    the cause of the error.
*
* RESPONSIBLE ENGINEER: 
*    CS Developers.
*
* HISTORY
*
*   NAME    DATE        REMARKS
*   MGR     03/14/02    Initial creation of function.
*
**********************************************************************/
Status_t
cs_sema_create (Sema_t *handle,
                    uint32_t count)
{
  Status_t          rc;

  IB_ENTER (function,
            (unint)handle,
            (uint32_t)count,
            (uint32_t)0U,
	    (uint32_t)0U);

  /*
  ** Validate handle
  */
  if (handle == (Sema_t *) 0)
  {
    IB_LOG_ERROR0 ("NULL handle pointer");
    IB_EXIT (function, VSTATUS_ILLPARM);
    return VSTATUS_ILLPARM;
  }

#ifdef __VXWORKS__
  handle->magic = SEMAPHORE_MAGIC;
  handle->semId = semCCreate(SEM_Q_FIFO, count);
  handle->count = count;
  if (!handle->semId)
  {
      IB_LOG_ERROR0 ("failed to allocate semaphore");
      rc = VSTATUS_ILLPARM;
      IB_EXIT(function, rc);
      return rc;
  }
#else
  // LINUX USER SEMA
  handle->magic = SEMAPHORE_MAGIC;
  if (sem_init((sem_t *)&handle->osdSema, 0, 0) != 0)
  {
      IB_LOG_ERROR0 ("failed to allocate semaphore");
      rc = VSTATUS_ILLPARM;
      IB_EXIT(function, rc);
      return rc;
  }
#endif // vxworks

  IB_EXIT (function, VSTATUS_OK);
  return VSTATUS_OK;
}
BST_OS_PAL_SEM_T  BST_OS_PalCreateSem( BST_UINT32 ulSmInit )
{
#if (VOS_RTOSCK == VOS_OS_VER)
    BST_OS_PAL_SEM_T stSemHandle;
    if(VOS_OK != VOS_SmCCreate("BST",ulSmInit,VOS_SEMA4_PRIOR,&stSemHandle))
    {
        return BST_NULL_PTR;
    }
    else
    {
        return stSemHandle;
    }
#else
    return semCCreate(SEM_Q_PRIORITY, (BST_INT32)ulSmInit);
#endif
}
Пример #9
0
STATUS ossSemCreate 
    (
    UINT32 maxCount,		    /* Max count allowed for semaphore */
    UINT32 curCount,		    /* initial count for semaphore */
    pSEM_HANDLE pSemHandle	    /* newly created semaphore handle */
    )

    {
    /* Validate parameters */

    if (pSemHandle == NULL) 
	return ossStatus (S_ossLib_BAD_PARAMETER);

    if ((*pSemHandle = (SEM_HANDLE) semCCreate (SEM_Q_FIFO, curCount)) == NULL)
	return ossStatus (S_ossLib_GENERAL_FAULT);

    return OK;
    }
Пример #10
0
static int __wind_sem_ccreate(struct pt_regs *regs)
{
	int flags, count;
	wind_sem_t *sem;
	SEM_ID sem_id;

	flags = __xn_reg_arg1(regs);
	count = __xn_reg_arg2(regs);
	sem = (wind_sem_t *)semCCreate(flags, count);

	if (!sem)
		return wind_errnoget();

	sem_id = sem->handle;

	return __xn_safe_copy_to_user((void __user *)__xn_reg_arg3(regs), &sem_id,
				      sizeof(sem_id));
}
Пример #11
0
int main(int argc, char *const argv[])
{
	int ret;

	traceobj_init(&trobj, argv[0], sizeof(tseq) / sizeof(int));

	sem_id = semCCreate(SEM_Q_PRIORITY, 0);
	traceobj_assert(&trobj, sem_id != 0);

	traceobj_mark(&trobj, 8);

	btid = taskSpawn("backgroundTask", 11, 0, 0, backgroundTask,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
	traceobj_assert(&trobj, btid != ERROR);

	traceobj_mark(&trobj, 9);

	ftid = taskSpawn("foregroundTask", 10, 0, 0, foregroundTask,
			 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
	traceobj_assert(&trobj, ftid != ERROR);

	traceobj_mark(&trobj, 10);

	ret = semGive(sem_id);

	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 11);

	ret = semGive(sem_id);

	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 12);

	ret = taskDelete(btid);
	traceobj_assert(&trobj, ret == OK);

	traceobj_join(&trobj);

	traceobj_verify(&trobj, tseq, sizeof(tseq) / sizeof(int));

	exit(0);
}
Пример #12
0
PUBLIC MprCond *mprCreateCond()
{
    MprCond     *cp;

    if ((cp = mprAllocObjNoZero(MprCond, manageCond)) == 0) {
        return 0;
    }
    cp->triggered = 0;
    cp->mutex = mprCreateLock();

#if ME_WIN_LIKE
    cp->cv = CreateEvent(NULL, FALSE, FALSE, NULL);
#elif VXWORKS
    cp->cv = semCCreate(SEM_Q_PRIORITY, SEM_EMPTY);
#else
    pthread_cond_init(&cp->cv, NULL);
#endif
    return cp;
}
Пример #13
0
static void rootTask(long a0, long a1, long a2, long a3, long a4,
		     long a5, long a6, long a7, long a8, long a9)
{
	ULONG start;
	int ret;

	traceobj_enter(&trobj);

	sem_id = semCCreate(SEM_Q_PRIORITY, 0);
	traceobj_assert(&trobj, sem_id != 0);

	start = tickGet();
	ret = semTake(sem_id, WAIT_TIME);
	traceobj_assert(&trobj, ret == ERROR && errno == S_objLib_OBJ_TIMEOUT);
	traceobj_assert(&trobj, tickGet() - start >= MIN_WAIT);

	start = tickGet();
	ret = semTake(sem_id, WAIT_TIME);
	traceobj_assert(&trobj, ret == ERROR && errno == S_objLib_OBJ_TIMEOUT);
	traceobj_assert(&trobj, tickGet() - start >= MIN_WAIT);

	start = tickGet();
	ret = semTake(sem_id, WAIT_TIME);
	traceobj_assert(&trobj, ret == ERROR && errno == S_objLib_OBJ_TIMEOUT);
	traceobj_assert(&trobj, tickGet() - start >= MIN_WAIT);

	ret = semGive(sem_id);
	traceobj_assert(&trobj, ret == OK);
	ret = semTake(sem_id, WAIT_TIME);
	traceobj_assert(&trobj, ret == OK);
	ret = semGive(sem_id);
	traceobj_assert(&trobj, ret == OK);
	ret = semGive(sem_id);
	traceobj_assert(&trobj, ret == OK);
	ret = semTake(sem_id, WAIT_FOREVER);
	traceobj_assert(&trobj, ret == OK);
	ret = semTake(sem_id, WAIT_FOREVER);
	traceobj_assert(&trobj, ret == OK);

	traceobj_exit(&trobj);
}
Пример #14
0
SEM_HANDLE sem_create(INT32_T option, INT32_T init_count, INT32_T max_count)
{
    SEM_HANDLE sem_handle = AII_NULL;

#ifdef LINUX_OS
    sem_handle = (SEM_HANDLE)malloc(sizeof(sem_t));
    if (sem_handle == AII_NULL)
    {
        return AII_NULL;
    }
    
    if (sem_init((sem_t*)sem_handle, option, init_count) != 0)
    {
        free(sem_handle);
        return AII_NULL;
    }
    
#endif

#ifdef VXWORKS_OS
    sem_handle = (SEM_HANDLE) semCCreate(option, init_count);
    if (sem_handle == NULL)
    {
        return AII_NULL;
    }
#endif

#ifdef WINDOWS_OS_32
    sem_handle = (SEM_HANDLE) CreateSemaphore( 
        NULL,        /* default security attributes */
        init_count,  /* initial count */
        max_count,   /* maximum count */
        NULL);       /* unnamed semaphore */
    if (sem_handle == NULL)
    {
        return AII_NULL;
    }
#endif

    return sem_handle;
}
Пример #15
0
/* Use counting semaphore */
IX_STATUS
ixOsalSemaphoreInit (IxOsalSemaphore * sid, UINT32 value)
{

    SEM_ID semId;

    /*
     * Allocate counting semaphore, tasks are queued on FIFO. 
     */
    semId = semCCreate (SEM_Q_FIFO, value);

    if (semId == NULL)
    {
        ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
            IX_OSAL_LOG_DEV_STDOUT,
            "ixOsalSemaphoreInit: NULL semId \n", 0, 0, 0, 0, 0, 0);
        return IX_FAIL;
    }
    *sid = semId;
    return IX_SUCCESS;
}
Пример #16
0
Semaphore::Semaphore(unsigned int value, int max)
{
#if defined (PTHREADS)
	sem = (sem_t *)malloc(sizeof(sem_t));
	if (sem == NULL)
	{
		throw Exception("Could not allocate semaphore handle", errno, __FILE__, __LINE__);
	}

	if (sem_init(sem, 0, value) != 0)
	{
		sem = NULL;
		throw Exception("Could not create Semaphore", errno, __FILE__, __LINE__);
	}

#elif defined(VXWORKS)
	sem = semCCreate(SEM_Q_FIFO,value);
	if (sem == NULL)
	{
		throw Exception("Could not create Semaphore", -1, __FILE__, __LINE__);
	}

#elif defined(_WINDOWS)
	sem = NULL;
	SECURITY_ATTRIBUTES attr;

	attr.nLength = sizeof(attr);
	attr.lpSecurityDescriptor = NULL;
	attr.bInheritHandle = TRUE;

	sem = CreateSemaphore(&attr,value,max,NULL);
	if (sem == NULL)
	{
		throw Exception("Could not create Semaphore", -1, __FILE__, __LINE__);
	}

#endif

}
Пример #17
0
SEM_ID semCreate(
    int type,
    int options
    )
{
    SEM_ID semId;

    if (semLibInstalled != TRUE)
    {
        errnoSet(S_semLib_NOT_INSTALLED);
        semId = NULL;
    }
    else
    {
        /* Create semaphore of correct type */
        switch(type & SEM_TYPE_MASK)
        {
            case SEM_TYPE_BINARY:
                semId = semBCreate(options, SEM_FULL);
                break;

            case SEM_TYPE_MUTEX:
                semId = semMCreate(options);
                break;

            case SEM_TYPE_COUNTING:
                semId = semCCreate(options, 1);
                break;

            default:
                semId = NULL;
                errnoSet(S_semLib_INVALID_OPTION);
                break;
        }
    }

    return semId;
}
Пример #18
0
static int __wind_sem_ccreate(struct task_struct *curr, struct pt_regs *regs)
{
	int flags, count;
	wind_sem_t *sem;
	SEM_ID sem_id;

	if (!__xn_access_ok
	    (curr, VERIFY_WRITE, __xn_reg_arg3(regs), sizeof(sem_id)))
		return -EFAULT;

	flags = __xn_reg_arg1(regs);
	count = __xn_reg_arg2(regs);
	sem = (wind_sem_t *)semCCreate(flags, count);

	if (!sem)
		return wind_errnoget();

	sem_id = sem->handle;
	__xn_copy_to_user(curr, (void __user *)__xn_reg_arg3(regs), &sem_id,
			  sizeof(sem_id));

	return 0;
}
Пример #19
0
ADC_ID adcCreate(char* baseAddr,int vector,int level)
/* char* baseAddr - base address of ADC */
/* int   vector  - VME Interrupt vector number */
/* int   level   - VME Interrupt level */
{
    char sr;

     /* ------- malloc space for adc Object --------- */
     if ( (adcObj = (ADC_OBJ *) malloc( sizeof(ADC_OBJ) ) ) == NULL )
     {
       LOGMSG(ALL_PORTS,ERROR,"adcCreate: ");
       return(NULL);
     }

     /* zero out structure so we don't free something by mistake */
     memset(adcObj,0,sizeof(ADC_OBJ));

     /* ------ Translate Bus address to CPU Board local address ----- */
     if (sysBusToLocalAdrs(VME_AM_SUP_SHORT_IO,
                         baseAddr,&(adcObj->adcBaseAddr)) == -1)
     {
       LOGMSG(ALL_PORTS,ERROR,"adcCreate: ");
       free(adcObj);
       return(NULL);
     }

     /* ------ Test for Boards Presents ---------- */
     if ( vxMemProbe((char*) (adcObj->adcBaseAddr + ADC_SR), 
		     VX_READ, BYTE, &sr) == ERROR)
     { 
       LOGMSG(ALL_PORTS,OK,"adcCreate: Could not read ADC's Status register\n");
       free(adcObj);
       return(NULL);
     }
     else
     {
        adcObj->adcBrdVersion = (sr >> 4) & 0x0f;
        LOGMSG1(ALL_PORTS,OK,"adcCreate: ADC Board Version %d present.\n",
		adcObj->adcBrdVersion);
     }
     
     adcObj->pSemAdcStateChg = semBCreate(SEM_Q_FIFO,SEM_EMPTY);

     adcObj->pAdcMutex =  semMCreate(SEM_Q_PRIORITY | 
				            SEM_INVERSION_SAFE |
                                            SEM_DELETE_SAFE);

     pSemAdcOvrFlow = semCCreate(SEM_Q_FIFO,SEM_EMPTY);

     if ( (adcObj->pSemAdcStateChg == NULL) || 
          (adcObj->pAdcMutex == NULL) || 
          (pSemAdcOvrFlow == NULL) )
     {
        LOGMSG(ALL_PORTS,ERROR,"adcCreate: ");

	if (adcObj->pSemAdcStateChg != NULL)
	   semDelete(adcObj->pSemAdcStateChg);
	if (adcObj->pAdcMutex != NULL)
	   semDelete(adcObj->pAdcMutex);

	if (pSemAdcOvrFlow != NULL)
	   semDelete(pSemAdcOvrFlow);

        return(NULL);
     }

     if ( (vector < MIN_VME_ITRP_VEC) || (vector > MAX_VME_ITRP_VEC) )
     {
        LOGMSG3(ALL_PORTS,OK,"adcCreate: vector: 0x%x out of bounds (0x%x-0x%x)\n",
		vector,MIN_VME_ITRP_VEC,MAX_VME_ITRP_VEC);
	semDelete(adcObj->pSemAdcStateChg);
	semDelete(adcObj->pAdcMutex);
        free(adcObj);
	return(NULL);
     }
     else
     {
        adcObj->vmeItrVector = vector;
     }

     if ( (level >= MIN_VME_ITRP_LEVEL) && (level <= MAX_VME_ITRP_LEVEL) )
     {
       adcObj->vmeItrLevel = level;
     }
     else
     {
        LOGMSG3(ALL_PORTS,OK,"stmCreate: vme level: %d out of bounds (%d-%d)\n",
	   level,MIN_VME_ITRP_LEVEL,MAX_VME_ITRP_LEVEL);
	semDelete(adcObj->pSemAdcStateChg);
	semDelete(adcObj->pAdcMutex);
        free(adcObj);
        return(NULL);
     }

     adcObj->adcControl = 0;
     adcObj->adcState = OK;

     /*
     intConnect( INUM_TO_IVEC( adcObj->vmeItrVector ),  semGive, pSemAdcOvrFlow);
     */

     /* Spawn the Interrupt Service Tasks */

/*
     taskSpawn("tAdcOvrFlow", ADC_FULL_IST_PRIORTY, ADC_IST_TASK_OPTIONS,
		ADC_IST_STACK_SIZE, adcOvrFlow, adcObj, ARG2,
		ARG3,ARG4,ARG5,ARG6,ARG7,ARG8,ARG9,ARG10);
*/

     return( adcObj );
}
Пример #20
0
EventImpl::EventImpl(EventTypeImpl type): _auto(type == EVENT_AUTORESET_IMPL), _state(false)
{
	_sem = semCCreate(SEM_Q_PRIORITY, 0);
	if (_sem == 0)
		throw Poco::SystemException("cannot create event");
}
Пример #21
0
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
}
Пример #22
0
//------------------------------------------------------------------------------
// Function:    ShbIpcAllocBuffer
//
// Description: Allocates memory for the shared buffers
//
// Parameters:
//   ulBufferSize_p          size of the shared buffer to allocate
//   pszBufferId_p           string containing the shared buffer identifier
//   ppShbInstance_p         pointer to store the instance of this shared
//                           buffer
//   pfShbNewCreated_p       pointer to store the buffer creation flag
//
// Return:      tShbError = error
//------------------------------------------------------------------------------
tShbError ShbIpcAllocBuffer (ULONG ulBufferSize_p, const char* pszBufferID_p,
                              tShbInstance* ppShbInstance_p,
                              UINT* pfShbNewCreated_p)
{
    tShbError               ShbError;
    UINT                    uiBufferKey;
    BOOL                    fShbNewCreated;
    ULONG                   ulShMemSize;
    tShbMemHeader*          pShbMemHeader;
    tShbMemInst*            pShbMemInst = NULL;
    tShbInstance            pShbInstance;

    ulShMemSize      = ulBufferSize_p + sizeof(tShbMemHeader);

    //create Buffer Key
    uiBufferKey = ShbIpcCrc32GetCrc(pszBufferID_p);

    EPL_DBGLVL_SHB_TRACE("%s() Allocate %lu Bytes, sBufferID:%s BufferKey:%08x\n",
    		          __func__, ulShMemSize, pszBufferID_p, (key_t)uiBufferKey);
    //---------------------------------------------------------------
    // (1) open an existing or create a new shared memory
    //---------------------------------------------------------------
    // try to create shared memory

    if ((pShbMemHeader = ShbIpcFindMem(uiBufferKey)) == NULL)
    {
        fShbNewCreated = TRUE;
        if ((pShbMemHeader = ShbIpcAlloc(uiBufferKey, ulShMemSize)) == NULL)
        {
            //unable to create mem
            EPL_DBGLVL_ERROR_TRACE("%s() Shared memory allocation error!\n",
                                    __func__);
            ShbError = kShbOutOfMem;
            goto Exit;
        }
        else
        {
            EPL_DBGLVL_SHB_TRACE("%s() Shared memory allocated, Addr:%p Key:%08x size:%ld\n",
            		__func__, (void *)pShbMemHeader, uiBufferKey, ulShMemSize);
        }
    }
    else
    {
        EPL_DBGLVL_SHB_TRACE("%s() Attached to shared memory, Addr:%p Key:%08x size:%ld\n",
        		     __func__, (void *)pShbMemHeader, uiBufferKey, ulShMemSize);
        fShbNewCreated = FALSE;
    }

    //---------------------------------------------------------------
    // (2) setup or update header and management information
    //---------------------------------------------------------------

    // allocate a memory block from process specific mempool to save
    // process local information to administrate/manage the shared buffer
    if ((pShbMemInst = (tShbMemInst*)ShbIpcAllocPrivateMem(sizeof(tShbMemInst)))
    		 == NULL)
    {
        EPL_DBGLVL_ERROR_TRACE("%s() Couldn't alloc private mem!\n", __func__);
        ShbError = kShbOutOfMem;
        goto Exit;
    }

    memset(pShbMemInst, 0, sizeof(tShbMemInst));

    // reset complete header to default values
    pShbMemInst->m_SbiMagicID = SBI_MAGIC_ID;
    pShbMemInst->m_uiSharedMemId = uiBufferKey;
    strncpy(pShbMemInst->m_sBufId, pszBufferID_p, MAX_LEN_BUFFER_ID - 1);
    pShbMemInst->m_pfnSigHndlrNewData = NULL;
    pShbMemInst->m_fNewDataThreadStarted = FALSE;
    pShbMemInst->m_ulTimeOutMsJobReady = 0;
    pShbMemInst->m_pfnSigHndlrJobReady = NULL;
    pShbMemInst->m_pShbMemHeader = pShbMemHeader;
    pShbMemInst->m_fThreadTermFlag = FALSE;

    ShbError = kShbOk;

    if (fShbNewCreated)
    {
        memset (pShbMemHeader, 0, sizeof(tShbMemHeader));

        // this process was the first who wanted to use the shared memory,
        // so a new shared memory was created
        // -> setup new header information inside the shared memory region
        //    itself
        pShbMemHeader->m_ulShMemSize = ulShMemSize;
        pShbMemHeader->m_ulRefCount = 1;
        pShbMemHeader->m_uiBufferKey = uiBufferKey;

        //create semaphores for buffer access and signal new data
        if ((pShbMemHeader->m_mutexBuffAccess =
        		       semMCreate(SEM_Q_PRIORITY | SEM_INVERSION_SAFE)) == NULL)
        {
            ShbError = kShbOutOfMem;
            goto Exit;
        }

        if ((pShbMemHeader->m_semNewData = semCCreate(SEM_Q_PRIORITY, 0)) == NULL)
        {
            ShbError = kShbOutOfMem;
            goto Exit;
        }

        if ((pShbMemHeader->m_semStopSignalingNewData =
        		                         semCCreate(SEM_Q_PRIORITY, 0)) == NULL)
        {
            ShbError = kShbOutOfMem;
            goto Exit;
        }

        if ((pShbMemHeader->m_semJobReady = semCCreate(SEM_Q_PRIORITY, 0)) == NULL)
        {
            ShbError = kShbOutOfMem;
            goto Exit;
        }
    }
    else
    {
        // any other process has created the shared memory and this
        // process has only attached to it
        // -> check and update existing header information inside the
        //    shared memory region itself
        if (pShbMemHeader->m_uiBufferKey != uiBufferKey)
        {
            EPL_DBGLVL_ERROR_TRACE("%s() Shared Mem mismatch buffer key %x:%x!\n",
            		__func__, uiBufferKey, pShbMemHeader->m_uiBufferKey);
            ShbError = kShbOpenMismatch;
            goto Exit;

        }
        //TRACEX("%s() Check mem size is:%ld should be:%ld \n", __func__,
        //       pShbMemHeader->m_ulShMemSize, ulShMemSize);
        if (pShbMemHeader->m_ulShMemSize != ulShMemSize)
        {
            EPL_DBGLVL_ERROR_TRACE("%s() Shared Mem mismatch size! %ld:%ld\n",
            		      __func__, ulShMemSize, pShbMemHeader->m_ulShMemSize);
            ShbError = kShbOpenMismatch;
            goto Exit;
        }
        pShbMemHeader->m_ulRefCount++;
    }

Exit:
    if (ShbError != kShbOk)
    {
        EPL_DBGLVL_ERROR_TRACE("%s() allocating shared buf failed!\n (%d)",
        		                __func__, ShbError);
        if (pShbMemInst != NULL)
        {
            ShbIpcReleasePrivateMem (pShbMemInst);
        }
        if ((pShbMemHeader != NULL) && (fShbNewCreated))
        {
            ShbIpcFree(uiBufferKey);
        }
    }

    pShbInstance = (tShbInstance*)pShbMemInst;
    *pfShbNewCreated_p = fShbNewCreated;
    *ppShbInstance_p   = pShbInstance;

    return (ShbError);
}
Пример #23
0
//STATUS dac3550DevCreate (char *devName, int port, int irq)
DEV_HDR* dac3550DevCreate (char *devName, int port, int irq)
{
  SND_DEV *pDev;

  if (DrvNum < 1)
  {
    errno = S_ioLib_NO_DRIVER;
    return ERROR;
  }
  if(dac3550Dev) 
  	return &(dac3550Dev->devHdr);
  pDev = (SND_DEV *)malloc (sizeof(SND_DEV));
  if (!pDev) return 0;

  bzero ((char *)pDev, sizeof(SND_DEV));
  if(port==0) port = (int)AT91C_BASE_SSC1;
  if(irq==0) irq = AT91C_ID_SSC1;
  pDev->port   = port;
  pDev->irq    = irq;
/*  pDev->dma8   = dma8;
  pDev->dma16  = dma16;
*/
  pDev->devSem = semBCreate (SEM_Q_FIFO, SEM_FULL);
  pDev->intSem = semCCreate (SEM_Q_FIFO, 0);
  pDev->bufSem = semCCreate (SEM_Q_FIFO, MAX_DMA_MSGS);
  pDev->dmaQ   = msgQCreate (MAX_DMA_MSGS, sizeof (DMA_MSG), MSG_Q_FIFO);

  pDev->dmaIndex = 0;

  if (createDmaBuffer () < 0)
  {
    free (pDev);
    return 0;
  }

  if (dsp_init (pDev) < 0)
  {
    free (pDev);
    return 0;
  }



  if (iosDevAdd (&pDev->devHdr, devName, DrvNum) == ERROR)
  {
    free ((char *)pDev);
    return 0;
  }
/*
  pDev->tid = taskSpawn ("tSndTask", TASK_PRIORITY, TASK_OPTIONS,
			 TASK_STACK_SIZE, dspHelperTask, (int)pDev,
			 0, 0, 0, 0, 0, 0, 0, 0, 0);

  if (pDev->tid == ERROR)
  {
    free (pDev);
    return ERROR;
  }
*/
  intConnect (INUM_TO_IVEC (	(irq)), dspInterrupt, (int)pDev);
  dac3550Dev = pDev;
  return &(pDev->devHdr);
}