本文整理汇总了C++中semTake函数的典型用法代码示例。如果您正苦于以下问题:C++ semTake函数的具体用法?C++ semTake怎么用?C++ semTake使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了semTake函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sem2Task
void sem2Task (long a0, long a1, long a2, long a3, long a4,
long a5, long a6, long a7, long a8, long a9)
{
WIND_TCB *pTcb = taskTcb(taskIdSelf());
ULONG date;
int n;
TEST_ASSERT(pTcb != NULL);
TEST_ASSERT(taskNameToId("Test2") == (TASK_ID)pTcb);
TEST_MARK();
TEST_ASSERT_OK(semTake(bsemid,WAIT_FOREVER));
TEST_MARK();
TEST_ASSERT_OK(semTake(bsemid,WAIT_FOREVER));
TEST_MARK();
TEST_ASSERT_OK(taskResume(a0));
TEST_MARK();
date = tickGet();
for (n = 0; n < 1000000; n++) {
ULONG old_date = date;
date = tickGet();
if (date != old_date)
TEST_MARK();
}
TEST_MARK(); /* Should not pass this mark */
}
示例2: pe_dispatcher
void pe_dispatcher()
{
int i;
Message msg;
for(;;)
{
msgQReceive(msgQ_dispatcher, (char*)&msg, sizeof(msg), WAIT_FOREVER);
semTake(mut_table_capt, WAIT_FOREVER);
// On cherche si
for(i=0; i < DEVICE_MAX_COUNT; ++i)
{
if(table_capt[i].specific.state == opened &&
table_capt[i].specific.address == msg.date.tv_nsec)
// On fait passer l'adresse par la date non initialisé pour éviter des champs de mémoire supplémentaire inutile.
{
// Trouvé : on ne drop pas le message.
clock_gettime(CLOCK_REALTIME, &(msg.date));
semTake(mut_table_buffer, WAIT_FOREVER);
memcpy((char*)&(table_buffer[i]), (char*)&msg, sizeof(Message));
semGive(mut_table_buffer);
break;
}
}
semGive(mut_table_capt);
}
}
示例3: Philosopher
void Philosopher (int i, int Philos) {
while (1) {
if (i==Philos-1){
taskDelay (DELAY_TICKS);
printf("Philosopher %d - start thinking\n", i+1);
semTake(Sema_fork[0], WAIT_FOREVER);
taskDelay(X);
semTake (Sema_fork[Philos-1], WAIT_FOREVER);
printf("Philosopher %d - start eating\n", i+1);
taskDelay(10);
semGive(Sema_fork[Philos-1]);
semGive(Sema_fork[0]);
p[i]++;
}
else {
taskDelay (DELAY_TICKS);
printf("Philosopher %d - start thinking\n", i+1);
semTake(Sema_fork[i], WAIT_FOREVER);
taskDelay(X);
semTake (Sema_fork[i+1], WAIT_FOREVER);
printf("Philosopher %d - start eating\n", i+1);
taskDelay(10);
semGive(Sema_fork[i]);
semGive(Sema_fork[i+1]);
p[i]++;
}
};
}
示例4: pe_deviceRemove
/**
* @brief Enlever un périphérique.
* @param i L'index du device à enlever
* @return OK pour un succès, ERROR sinon.
*/
int pe_deviceRemove(int i)
{
semTake(mut_table_capt, WAIT_FOREVER);
if(i < DEVICE_MAX_COUNT && table_capt[i].specific.state != notcreated)
{
iosDevDelete((DEV_HDR*)&(table_capt[i]));
table_capt[i].specific.state = notcreated;
table_capt[i].specific.address = -1;
semGive(mut_table_capt);
semTake(mut_table_capt, WAIT_FOREVER);
table_buffer[i].id = -1;
semGive(mut_table_buffer);
return OK;
}
else
{
// Le capteur n'a pas été crée :
// " If the device was never added to the device list,
// unpredictable results may occur."
semGive(mut_table_capt);
errnoSet(ENEXIST);
return ERROR;
}
}
示例5: send_sim_state
/*!*****************************************************************************
*******************************************************************************
\note send_sim_state
\date Nov. 2007
\remarks
sends the entire joint_sim_state to shared memory
*******************************************************************************
Function Parameters: [in]=input,[out]=output
none
******************************************************************************/
int
send_sim_state(void)
{
int i;
// joint state
if (semTake(sm_joint_sim_state_sem,ns2ticks(TIME_OUT_NS)) == ERROR) {
++simulation_servo_errors;
return FALSE;
}
cSL_Jstate(joint_sim_state,sm_joint_sim_state_data,n_dofs,DOUBLE2FLOAT);
for (i=1; i<=n_dofs; ++i)
sm_joint_sim_state->joint_sim_state[i] = sm_joint_sim_state_data[i];
sm_joint_sim_state->ts = simulation_servo_time;
semGive(sm_joint_sim_state_sem);
// base state
if (semTake(sm_base_state_sem,ns2ticks(TIME_OUT_NS)) == ERROR) {
++simulation_servo_errors;
return FALSE;
}
cSL_Cstate((&base_state)-1, sm_base_state_data, 1, DOUBLE2FLOAT);
sm_base_state->state[1] = sm_base_state_data[1];
sm_base_state->ts = simulation_servo_time;
semGive(sm_base_state_sem);
// base orient
if (semTake(sm_base_orient_sem,ns2ticks(TIME_OUT_NS)) == ERROR) {
++simulation_servo_errors;
return FALSE;
}
cSL_quat(&base_orient-1, sm_base_orient_data, 1, DOUBLE2FLOAT);
sm_base_orient->orient[1] = sm_base_orient_data[1];
sm_base_orient->ts = simulation_servo_time;
semGive(sm_base_orient_sem);
return TRUE;
}
示例6: os_mutexInit
os_result os_mutexInit (os_mutex *mutex, const os_mutexAttr *mutexAttr)
{
os_mutexAttr defAttr;
os_result rv;
int options;
SEM_ID id;
assert (mutex != NULL);
#ifdef OSPL_STRICT_MEM
assert (mutex->signature != OS_MUTEX_MAGIC_SIG);
#endif
if(!mutexAttr) {
os_mutexAttrInit(&defAttr);
mutexAttr = &defAttr;
}
options = (SEM_Q_PRIORITY | SEM_DELETE_SAFE);
/* Set option for priority inheritance if feature is enabled */
if (ospl_mtx_prio_inherit) {
options = options | SEM_INVERSION_SAFE;
}
if (mutexAttr->scopeAttr == OS_SCOPE_SHARED) {
/* create named mutex using shared address as unique name */
snprintf (mutex->name, sizeof (mutex->name), "/%lu", (os_uint32) mutex);
id = semOpen (mutex->name, SEM_TYPE_MUTEX, SEM_EMPTY, options, OM_CREATE|OM_EXCL, NULL);
/* As it may exist from a previous run. remove leftover semaphore object */
if (id != NULL) {
/* a fresh one, initialise it and cache the SEM_ID */
pa_st32 ((void *) &mutex->info.id, 0);
semTake (cache_lock, WAIT_FOREVER);
(void) ut_tableInsert ((ut_table) cache, mutex, id);
semGive (cache_lock);
} else {
/* re-using an old one: it should have been destroyed and hence should have a marker in info.id */
id = get_mutex (mutex);
if (id != NULL) {
semTake (id, WAIT_FOREVER);
semGive (id);
/*cas_mutex_info_id ((void*)&mutex->info.id, invalid_sem_id, 0);*/
} else {
mutex_panic ("init: attempt to reuse semaphore currently in use", 0);
}
}
rv = (id != NULL) ? os_resultSuccess : os_resultFail;
} else {
int result;
mutex->name[0] = '\0';
/* TODO attrs */
result = pthread_mutex_init(&mutex->info.posix_mutex, NULL);
rv = (result == 0) ? os_resultSuccess : os_resultFail;
}
#ifdef OSPL_STRICT_MEM
mutex->signature = OS_MUTEX_MAGIC_SIG;
#endif
return rv;
}
示例7: semTake
Preferences::~Preferences()
{
semTake(m_tableLock, WAIT_FOREVER);
semDelete(m_tableLock);
semTake(m_fileLock, WAIT_FOREVER);
semDelete(m_fileOpStarted);
semDelete(m_fileLock);
}
示例8: RandomizerThreadFunc
int RandomizerThreadFunc(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, int p9, int p10)
{
int operation, semIdx, semTimeout;
int stat=0;
while(1)
{
operation = (int) (rand() * 2.) / RAND_MAX;
semIdx = (int) (rand() * 2.) / RAND_MAX;
semTimeout = (int) rand() * 5. / RAND_MAX;
switch( operation )
{
case 0:
cTake++;
switch( semIdx )
{
case 0: stat = semTake( s_binary, semTimeout );break;
case 1: stat = semTake( s_counting, semTimeout );break;
}
if ( OK != stat )
{
if( S_objLib_OBJ_TIMEOUT == errno || S_objLib_OBJ_UNAVAILABLE == errno )
{
cTakeTimeout++;
}
else
{
cTakeErr++;
puts("");
perror("Error taking semaphore");
}
}
break;
case 1:
cGive++;
switch( semIdx )
{
case 0: stat = semGive( s_binary );break;
case 1: stat = semGive( s_counting );break;
}
if ( OK != stat )
cGiveErr++;
break;
default:break;
} //switch( operation )
} //while(1)
}
示例9: semTake
static DMA_MSG *getDmaBuffer (SND_DEV *pDev)
{
DMA_MSG *dmaBuffer;
semTake (pDev->bufSem, WAIT_FOREVER);
semTake (pDev->devSem, WAIT_FOREVER);
/* dmaBuffer = snd_dmaBuffer + pDev->dmaIndex * MAX_DMA_SIZE;*/
dmaBuffer = &snd_buffer[pDev->dmaIndex];
pDev->dmaIndex = (pDev->dmaIndex + 1) % MAX_DMA_MSGS;
semGive (pDev->devSem);
return dmaBuffer;
}
示例10: devDelete
int devDelete(char* devName)
{
myDev * i = first;
char * pNameTail;
myDev * dev = (myDev*) iosDevFind (devName,&pNameTail);
if ((*pNameTail)!='\0' || dev==NULL)
//If pNameTail is not '\0', either we don't have an exact match
//or we have no match at all
{
errnoSet(UNKNOWN_DEVICE);
semGive(semMAdmin);
return -1;
}
if(semMAdmin==0)
{
errnoSet(NOT_INSTALLED);
return -1;
}
if(semTake(semMAdmin,WAIT_FOREVER)==-1)
{
errnoSet(SEM_ERR);
return -1;
}
if (dev->openned != 0)
{
//There are still openned file descriptors on this device,
//we can't delete it, give back semaphores and leave.
semGive(dev->semMData);
errnoSet(OPENNED_DEV);
semGive(semMAdmin);
return -1;
}
iosDevDelete((DEV_HDR*)dev); //This only prevents further oppenings.
//Find and delete the device in device list :
if (dev==first)
{
first=dev->next;
} else {
for (i=first;i->next!=dev;i=i->next);
i->next=dev->next;
}
semTake(dev->semMData,WAIT_FOREVER); //Let pending ops on this dev finish
semDelete(dev->semMData); //We don't need to release it to delete it
free(dev);
semGive(semMAdmin);
return 0;
}
示例11: ShbIpcThreadSignalJobReady
//------------------------------------------------------------------------------
// Function: ShbIpcThreadSignalJobReady
//
// Description: Thread for new data Job Ready signaling
//
// Parameters:
// pvThreadParam_p user parameters for thread
//
// Return: void * thread exit value (not used)
//------------------------------------------------------------------------------
int ShbIpcThreadSignalJobReady (int pvThreadParam_p)
{
tShbInstance pShbInstance;
tShbMemInst *pShbMemInst;
tShbMemHeader* pShbMemHeader;
INT iRetVal;
UINT fTimeOut;
EPL_DBGLVL_SHB_TRACE("%s(): ThreadId:%ld\n", __func__);
pShbInstance = (tShbMemInst*)pvThreadParam_p;
pShbMemInst = ShbIpcGetShbMemInst (pShbInstance);
pShbMemHeader = ShbIpcGetShbMemHeader (pShbInstance);
pShbMemInst->m_fJobReadyThreadStarted = TRUE;
if (pShbMemInst->m_ulTimeOutMsJobReady != 0)
{
// todo: timeout is in ticks!!
iRetVal = semTake(pShbMemHeader->m_semJobReady,
pShbMemInst->m_ulTimeOutMsJobReady);
}
else
{
iRetVal = semTake(pShbMemHeader->m_semJobReady, WAIT_FOREVER);
}
if (iRetVal == OK)
{
fTimeOut = FALSE;
}
else
{
/* timeout or error */
fTimeOut = TRUE;
}
if (pShbMemInst->m_pfnSigHndlrJobReady != NULL)
{
//call Handler
pShbMemInst->m_pfnSigHndlrJobReady(pShbInstance, fTimeOut);
}
pShbMemInst->m_pfnSigHndlrJobReady = NULL;
pShbMemInst->m_fJobReadyThreadStarted = FALSE;
return 0;
}
示例12: semTake
NetworkTable::~NetworkTable()
{
delete m_hasAdded;
delete m_hasChanged;
delete m_transaction;
semTake(m_listenerLock, WAIT_FOREVER);
m_connectionListeners.clear();
m_additionListeners.clear();
m_listeners.clear();
m_listenToAllListeners.clear();
semDelete(m_listenerLock);
semTake(m_dataLock, WAIT_FOREVER);
m_connections.clear();
m_data.clear();
semDelete(m_dataLock);
}
示例13: ShbIpcEnterAtomicSection
//------------------------------------------------------------------------------
// Function: ShbIpcEnterAtomicSection
//
// Description: Enter atomic section for Shared Buffer access
//
// Parameters: pShbInstance_p pointer to shared buffer instance
//
// Return: tShbError = error code
//------------------------------------------------------------------------------
tShbError ShbIpcEnterAtomicSection (tShbInstance pShbInstance_p)
{
tShbMemInst *pShbMemInst;
tShbMemHeader *pShbMemHeader;
tShbError ShbError;
if (pShbInstance_p == NULL)
{
return (kShbInvalidArg);
}
pShbMemInst = ShbIpcGetShbMemInst (pShbInstance_p);
pShbMemHeader = ShbIpcGetShbMemHeader (pShbMemInst);
if (semTake (pShbMemHeader->m_mutexBuffAccess, TIMEOUT_ENTER_ATOMIC) == OK)
{
ShbError = kShbOk;
}
else
{
ShbError = kShbBufferInvalid;
}
return (ShbError);
}
示例14: ShbIpcThreadSignalNewData
//------------------------------------------------------------------------------
// Function: ShbIpcThreadSignalNewData
//
// Description: Thread for new data signaling
//
// Parameters:
// pvThreadParam_p user parameters for thread
//
// Return: void * thread exit value (not used)
//------------------------------------------------------------------------------
int ShbIpcThreadSignalNewData (int pvThreadParam_p)
{
tShbInstance pShbInstance;
tShbMemInst* pShbMemInst;
tShbMemHeader* pShbMemHeader;
INT iRetVal;
/* thread parameter contains pointer to shared memory */
pShbInstance = (tShbMemInst*)pvThreadParam_p;
pShbMemInst = ShbIpcGetShbMemInst (pShbInstance);
pShbMemHeader = ShbIpcGetShbMemHeader (pShbInstance);
/* signal that thread is running */
pShbMemInst->m_fNewDataThreadStarted = TRUE;
do
{
if ((iRetVal = semTake(pShbMemHeader->m_semNewData,
TIMEOUT_CANCEL_THREAD)) == OK)
{
//check terminate flag
if (!pShbMemInst->m_fThreadTermFlag)
{
pShbMemInst->m_pfnSigHndlrNewData(pShbInstance);
}
}
} while(!pShbMemInst->m_fThreadTermFlag);
//set sem thread terminated
pShbMemInst->m_fNewDataThreadStarted = FALSE;
semGive(pShbMemHeader->m_semStopSignalingNewData);
return 0;
}
示例15: semTake
/**
* Execute a transaction with a Jaguar that sets some property.
*
* Jaguar always acks when it receives a message. If we don't wait for an ack,
* the message object in the Jaguar could get overwritten before it is handled.
*
* @param messageID The messageID to be used on the CAN bus (device number is added internally)
* @param data The up to 8 bytes of data to be sent with the message
* @param dataSize Specify how much of the data in "data" to send
*/
void CANJaguar::setTransaction(uint32_t messageID, const uint8_t *data, uint8_t dataSize)
{
uint32_t ackMessageID = LM_API_ACK | m_deviceNumber;
int32_t localStatus = 0;
// If there was an error on this object and it wasn't a timeout, refuse to talk to the device
// Call ClearError() on the object to try again
if (StatusIsFatal() && GetError().GetCode() != -44087)
return;
// Make sure we don't have more than one transaction with the same Jaguar outstanding.
semTake(m_transactionSemaphore, WAIT_FOREVER);
// Throw away any stale acks.
receiveMessage(&ackMessageID, NULL, 0, 0.0f);
// Send the message with the data.
localStatus = sendMessage(messageID | m_deviceNumber, data, dataSize);
wpi_setErrorWithContext(localStatus, "sendMessage");
// Wait for an ack.
localStatus = receiveMessage(&ackMessageID, NULL, 0);
wpi_setErrorWithContext(localStatus, "receiveMessage");
// Transaction complete.
semGive(m_transactionSemaphore);
}