本文整理汇总了C++中xSemaphoreTakeRecursive函数的典型用法代码示例。如果您正苦于以下问题:C++ xSemaphoreTakeRecursive函数的具体用法?C++ xSemaphoreTakeRecursive怎么用?C++ xSemaphoreTakeRecursive使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xSemaphoreTakeRecursive函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: prvRecursiveMutexPollingTask
static void prvRecursiveMutexPollingTask( void *pvParameters )
{
/* Just to remove compiler warning. */
( void ) pvParameters;
for( ;; )
{
/* Keep attempting to obtain the mutex. We should only obtain it when
the blocking task has suspended itself, which in turn should only
happen when the controlling task is also suspended. */
if( xSemaphoreTakeRecursive( xMutex, recmuNO_DELAY ) == pdPASS )
{
/* Is the blocking task suspended? */
if( ( xBlockingIsSuspended != pdTRUE ) || ( xControllingIsSuspended != pdTRUE ) )
{
xErrorOccurred = pdTRUE;
}
else
{
/* Keep count of the number of cycles this task has performed
so a stall can be detected. */
uxPollingCycles++;
/* We can resume the other tasks here even though they have a
higher priority than the polling task. When they execute they
will attempt to obtain the mutex but fail because the polling
task is still the mutex holder. The polling task (this task)
will then inherit the higher priority. The Blocking task will
block indefinitely when it attempts to obtain the mutex, the
Controlling task will only block for a fixed period and an
error will be latched if the polling task has not returned the
mutex by the time this fixed period has expired. */
vTaskResume( xBlockingTaskHandle );
vTaskResume( xControllingTaskHandle );
/* The other two tasks should now have executed and no longer
be suspended. */
if( ( xBlockingIsSuspended == pdTRUE ) || ( xControllingIsSuspended == pdTRUE ) )
{
xErrorOccurred = pdTRUE;
}
/* Release the mutex, disinheriting the higher priority again. */
if( xSemaphoreGiveRecursive( xMutex ) != pdPASS )
{
xErrorOccurred = pdTRUE;
}
}
}
#if configUSE_PREEMPTION == 0
{
taskYIELD();
}
#endif
}
}
示例2: __malloc_lock
void __malloc_lock(struct _reent *ptr)
{
UNUSED_PARAMETER( ptr );
if( malloc_mutex )
{
xSemaphoreTakeRecursive( malloc_mutex, WICED_WAIT_FOREVER );
}
return;
}
示例3: objectTransaction
/**
* Execute the requested transaction on an object.
* \param[in] connection UAVTalkConnection to be used
* \param[in] type Transaction type
* UAVTALK_TYPE_OBJ: send object,
* UAVTALK_TYPE_OBJ_REQ: request object update
* UAVTALK_TYPE_OBJ_ACK: send object with an ack
* \param[in] obj Object
* \param[in] instId The instance ID of UAVOBJ_ALL_INSTANCES for all instances.
* \param[in] timeoutMs Time to wait for the ack, when zero it will return immediately
* \return 0 Success
* \return -1 Failure
*/
static int32_t objectTransaction(UAVTalkConnectionData *connection, uint8_t type, UAVObjHandle obj, uint16_t instId, int32_t timeoutMs)
{
int32_t respReceived;
int32_t ret = -1;
// Send object depending on if a response is needed
if (type == UAVTALK_TYPE_OBJ_ACK || type == UAVTALK_TYPE_OBJ_ACK_TS || type == UAVTALK_TYPE_OBJ_REQ) {
// Get transaction lock (will block if a transaction is pending)
xSemaphoreTakeRecursive(connection->transLock, portMAX_DELAY);
// Send object
xSemaphoreTakeRecursive(connection->lock, portMAX_DELAY);
// expected response type
connection->respType = (type == UAVTALK_TYPE_OBJ_REQ) ? UAVTALK_TYPE_OBJ : UAVTALK_TYPE_ACK;
connection->respObjId = UAVObjGetID(obj);
connection->respInstId = instId;
ret = sendObject(connection, type, UAVObjGetID(obj), instId, obj);
xSemaphoreGiveRecursive(connection->lock);
// Wait for response (or timeout) if sending the object succeeded
respReceived = pdFALSE;
if (ret == 0) {
respReceived = xSemaphoreTake(connection->respSema, timeoutMs / portTICK_RATE_MS);
}
// Check if a response was received
if (respReceived == pdTRUE) {
// We are done successfully
xSemaphoreGiveRecursive(connection->transLock);
ret = 0;
} else {
// Cancel transaction
xSemaphoreTakeRecursive(connection->lock, portMAX_DELAY);
// non blocking call to make sure the value is reset to zero (binary sema)
xSemaphoreTake(connection->respSema, 0);
connection->respObjId = 0;
xSemaphoreGiveRecursive(connection->lock);
xSemaphoreGiveRecursive(connection->transLock);
return -1;
}
} else if (type == UAVTALK_TYPE_OBJ || type == UAVTALK_TYPE_OBJ_TS) {
xSemaphoreTakeRecursive(connection->lock, portMAX_DELAY);
ret = sendObject(connection, type, UAVObjGetID(obj), instId, obj);
xSemaphoreGiveRecursive(connection->lock);
}
return ret;
}
示例4: TaskMonitorUpdateAll
/**
* Update the status of all tasks
*/
void TaskMonitorUpdateAll(void)
{
#if defined(DIAGNOSTICS)
TaskInfoData data;
int n;
// Lock
xSemaphoreTakeRecursive(lock, portMAX_DELAY);
#if ( configGENERATE_RUN_TIME_STATS == 1 )
uint32_t currentTime;
uint32_t deltaTime;
/*
* Calculate the amount of elapsed run time between the last time we
* measured and now. Scale so that we can convert task run times
* directly to percentages.
*/
currentTime = portGET_RUN_TIME_COUNTER_VALUE();
deltaTime = ((currentTime - lastMonitorTime) / 100) ? : 1; /* avoid divide-by-zero if the interval is too small */
lastMonitorTime = currentTime;
#endif
// Update all task information
for (n = 0; n < TASKINFO_RUNNING_NUMELEM; ++n)
{
if (handles[n] != 0)
{
data.Running[n] = TASKINFO_RUNNING_TRUE;
#if defined(ARCH_POSIX) || defined(ARCH_WIN32)
data.StackRemaining[n] = 10000;
#else
data.StackRemaining[n] = uxTaskGetStackHighWaterMark(handles[n]) * 4;
#if ( configGENERATE_RUN_TIME_STATS == 1 )
/* Generate run time stats */
data.RunningTime[n] = uxTaskGetRunTime(handles[n]) / deltaTime;
#endif
#endif
}
else
{
data.Running[n] = TASKINFO_RUNNING_FALSE;
data.StackRemaining[n] = 0;
data.RunningTime[n] = 0;
}
}
// Update object
TaskInfoSet(&data);
// Done
xSemaphoreGiveRecursive(lock);
#endif
}
示例5: simpleQueueFront
SimpleQueueValue* simpleQueueFront(struct SimpleQueue* queue){
while(xSemaphoreTakeRecursive(queue->xSemHandle,(TickType_t)0) != pdTRUE){}
SimpleQueueValue* return_Value = NULL;
if (simpleQueueEmpty(queue))
return_Value = NULL;
else
return_Value = queue->head->value;
xSemaphoreGiveRecursive(queue->xSemHandle);
return return_Value;
}
示例6: UAVObjIterate
/**
* Iterate through all objects in the list.
* \param iterator This function will be called once for each object,
* the object will be passed as a parameter
*/
void UAVObjIterate(void (*iterator) (UAVObjHandle obj))
{
ObjectList *objEntry;
// Get lock
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
// Iterate through the list and invoke iterator for each object
LL_FOREACH(objList, objEntry) {
(*iterator) ((UAVObjHandle) objEntry);
}
示例7: UAVObjSave
/**
* Save the data of the specified object to the file system (SD card).
* If the object contains multiple instances, all of them will be saved.
* A new file with the name of the object will be created.
* The object data can be restored using the UAVObjLoad function.
* @param[in] obj The object handle.
* @param[in] instId The instance ID
* @param[in] file File to append to
* @return 0 if success or -1 if failure
*/
int32_t UAVObjSave(UAVObjHandle obj, uint16_t instId)
{
#if defined(PIOS_INCLUDE_FLASH_SECTOR_SETTINGS)
ObjectList *objEntry = (ObjectList *) obj;
if (objEntry == NULL)
return -1;
ObjectInstList *instEntry = getInstance(objEntry, instId);
if (instEntry == NULL)
return -1;
if (instEntry->data == NULL)
return -1;
if (PIOS_FLASHFS_ObjSave(obj, instId, instEntry->data) != 0)
return -1;
#endif
#if defined(PIOS_INCLUDE_SDCARD)
FILEINFO file;
ObjectList *objEntry;
uint8_t filename[14];
// Check for file system availability
if (PIOS_SDCARD_IsMounted() == 0) {
return -1;
}
// Lock
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
// Cast to object
objEntry = (ObjectList *) obj;
// Get filename
objectFilename(objEntry, filename);
// Open file
if (PIOS_FOPEN_WRITE(filename, file)) {
xSemaphoreGiveRecursive(mutex);
return -1;
}
// Append object
if (UAVObjSaveToFile(obj, instId, &file) == -1) {
PIOS_FCLOSE(file);
xSemaphoreGiveRecursive(mutex);
return -1;
}
// Done, close file and unlock
PIOS_FCLOSE(file);
xSemaphoreGiveRecursive(mutex);
#endif /* PIOS_INCLUDE_SDCARD */
return 0;
}
示例8: prvRecursiveMutexBlockingTask
static void prvRecursiveMutexBlockingTask( void *pvParameters )
{
/* Just to remove compiler warning. */
( void ) pvParameters;
for( ;; )
{
/* This task will run while the controlling task is blocked, and the
controlling task will block only once it has the mutex - therefore
this call should block until the controlling task has given up the
mutex, and not actually execute past this call until the controlling
task is suspended. portMAX_DELAY - 1 is used instead of portMAX_DELAY
to ensure the task's state is reported as Blocked and not Suspended in
a later call to configASSERT() (within the polling task). */
if( xSemaphoreTakeRecursive( xMutex, ( portMAX_DELAY - 1 ) ) == pdPASS )
{
if( xControllingIsSuspended != pdTRUE )
{
/* Did not expect to execute until the controlling task was
suspended. */
xErrorOccurred = pdTRUE;
}
else
{
/* Give the mutex back before suspending ourselves to allow
the polling task to obtain the mutex. */
if( xSemaphoreGiveRecursive( xMutex ) != pdPASS )
{
xErrorOccurred = pdTRUE;
}
xBlockingIsSuspended = pdTRUE;
vTaskSuspend( NULL );
xBlockingIsSuspended = pdFALSE;
}
}
else
{
/* We should not leave the xSemaphoreTakeRecursive() function
until the mutex was obtained. */
xErrorOccurred = pdTRUE;
}
/* The controlling and blocking tasks should be in lock step. */
if( uxControllingCycles != ( uxBlockingCycles + 1 ) )
{
xErrorOccurred = pdTRUE;
}
/* Keep count of the number of cycles this task has performed so a
stall can be detected. */
uxBlockingCycles++;
}
}
示例9: PIOS_Recursive_Mutex_Lock
/**
*
* @brief Locks a recursive mutex.
*
* @param[in] mtx pointer to instance of @p struct pios_recursive_mutex
* @param[in] timeout_ms timeout for acquiring the lock in milliseconds
*
* @returns true on success or false on timeout or failure
*
*/
bool PIOS_Recursive_Mutex_Lock(struct pios_recursive_mutex *mtx, uint32_t timeout_ms)
{
PIOS_Assert(mtx != NULL);
portTickType timeout_ticks;
if (timeout_ms == PIOS_MUTEX_TIMEOUT_MAX)
timeout_ticks = portMAX_DELAY;
else
timeout_ticks = MS2TICKS(timeout_ms);
return xSemaphoreTakeRecursive((xSemaphoreHandle)mtx->mtx_handle, timeout_ticks) == pdTRUE;
}
示例10: pbntf_lost_socket
void pbntf_lost_socket(pubnub_t *pb, pb_socket_t socket)
{
PUBNUB_UNUSED(socket);
if (pdFALSE == xSemaphoreTakeRecursive(m_watcher.mutw, TICKS_TO_WAIT)) {
return ;
}
remove_socket(&m_watcher, pb);
remove_timer_safe(pb);
xSemaphoreGiveRecursive(m_watcher.mutw);
xTaskNotifyGive(m_watcher.task);
}
示例11: xSemaphoreTakeRecursive
void dispatch_queue::dispatch(fp_t&& op)
{
BaseType_t status = xSemaphoreTakeRecursive(mutex_, portMAX_DELAY);
assert(status == pdTRUE && "Failed to lock mutex!");
q_.push(std::move(op));
status = xSemaphoreGiveRecursive(mutex_);
assert(status == pdTRUE && "Failed to unlock mutex!");
// Notifies threads that new work has been added to the queue
xEventGroupSetBits(notify_flags_, DISPATCH_WAKE_EVT);
}
示例12: __env_lock
void __env_lock ( struct _reent *_r )
{
#if OS_THREAD_SAFE_NEWLIB
if (!xTaskGetSchedulerState())
return;
// wait for the mutex to be released
while (xSemaphoreTakeRecursive(alt_envsem, 10) != pdTRUE)
vTaskDelay(1);
#endif /* OS_THREAD_SAFE_NEWLIB */
return;
}
示例13: UAVLinkProcessInputStream
/**
* Process an byte from the telemetry stream.
* \param[in] connection UAVLinkConnection to be used
* \param[in] rxbyte Received byte
* \return UAVLinkRxState
*/
UAVLinkRxState UAVLinkProcessInputStream(UAVLinkConnection connectionHandle, uint8_t rxbyte)
{
UAVLinkRxState state = UAVLinkProcessInputStreamQuiet(connectionHandle, rxbyte);
if (state == UAVLINK_STATE_COMPLETE)
{
UAVLinkConnectionData *connection;
CHECKCONHANDLE(connectionHandle,connection,return -1);
UAVLinkInputProcessor *iproc = &connection->iproc;
xSemaphoreTakeRecursive(connection->lock, portMAX_DELAY);
receivePacket(connection, iproc->type, iproc->rxId, iproc->instId, connection->rxBuffer, iproc->length);
xSemaphoreGiveRecursive(connection->lock);
}
示例14: UAVLinkResetStats
/**
* Reset the statistics counters.
* \param[in] connection UAVLinkConnection to be used
*/
void UAVLinkResetStats(UAVLinkConnection connectionHandle)
{
UAVLinkConnectionData *connection;
CHECKCONHANDLE(connectionHandle,connection,return);
// Lock
xSemaphoreTakeRecursive(connection->lock, portMAX_DELAY);
// Clear stats
memset(&connection->stats, 0, sizeof(UAVLinkStats));
// Release lock
xSemaphoreGiveRecursive(connection->lock);
}
示例15: UAVLinkGetStats
/**
* Get communication statistics counters
* \param[in] connection UAVLinkConnection to be used
* @param[out] statsOut Statistics counters
*/
void UAVLinkGetStats(UAVLinkConnection connectionHandle, UAVLinkStats* statsOut)
{
UAVLinkConnectionData *connection;
CHECKCONHANDLE(connectionHandle,connection,return );
// Lock
xSemaphoreTakeRecursive(connection->lock, portMAX_DELAY);
// Copy stats
memcpy(statsOut, &connection->stats, sizeof(UAVLinkStats));
// Release lock
xSemaphoreGiveRecursive(connection->lock);
}