本文整理汇总了C++中semGive函数的典型用法代码示例。如果您正苦于以下问题:C++ semGive函数的具体用法?C++ semGive怎么用?C++ semGive使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了semGive函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: event_info_alloc
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: TI81XX_SPI_LOG
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: send_misc_sensors
/*!*****************************************************************************
*******************************************************************************
\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: defined
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
}
示例5: return
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;
}
示例6: ShbIpcStopSignalingNewData
//------------------------------------------------------------------------------
// 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);
}
示例7: devClose
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;
}
示例8: BST_OS_PalSendSem
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;
}
}
示例9: ssh_netjob_synchronous_invoke
/* 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;
}
示例10: errnoSet
/******************************************************************************
*
* 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);
}
示例11: _tmain
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;
}
示例12: DisconnectFromHost
/* 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 */
示例13: while
/**
* 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();
}
示例14: drvRemove
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;
}
示例15: receive_misc_sensors
/*!*****************************************************************************
*******************************************************************************
\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;
}