这篇教程C++ xSemaphoreTakeRecursive函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中xSemaphoreTakeRecursive函数的典型用法代码示例。如果您正苦于以下问题:C++ xSemaphoreTakeRecursive函数的具体用法?C++ xSemaphoreTakeRecursive怎么用?C++ xSemaphoreTakeRecursive使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了xSemaphoreTakeRecursive函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: prvRecursiveMutexPollingTaskstatic 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 }}
开发者ID:channgo2203,项目名称:TinyROS,代码行数:57,
示例2: __malloc_lockvoid __malloc_lock(struct _reent *ptr){ UNUSED_PARAMETER( ptr ); if( malloc_mutex ) { xSemaphoreTakeRecursive( malloc_mutex, WICED_WAIT_FOREVER ); } return;}
开发者ID:fishbaoz,项目名称:wiced-emw3165,代码行数:9,
示例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;}
开发者ID:MAVProxyUser,项目名称:NinjaPilot-15.02.ninja,代码行数:57,
示例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}
开发者ID:LeeSaferite,项目名称:OpenPilot,代码行数:59,
示例5: simpleQueueFrontSimpleQueueValue* 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;}
开发者ID:ntonjeta,项目名称:Nodo-Sensore,代码行数:10,
示例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); }
开发者ID:LeeSaferite,项目名称:OpenPilot,代码行数:16,
示例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;}
开发者ID:LeeSaferite,项目名称:OpenPilot,代码行数:64,
示例8: prvRecursiveMutexBlockingTaskstatic 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++; }}
开发者ID:AldenHiggins,项目名称:ELEC424-Lab06-Scheduling-with-FreeRTOS,代码行数:54,
示例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;}
开发者ID:EvalZero,项目名称:TauLabs,代码行数:22,
示例10: pbntf_lost_socketvoid 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);}
开发者ID:evanbeard,项目名称:c-core,代码行数:12,
示例11: xSemaphoreTakeRecursivevoid 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);}
开发者ID:typelogic,项目名称:embedded-resources,代码行数:13,
示例12: __env_lockvoid __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;}
开发者ID:AlexShiLucky,项目名称:FreeLwIP-Nios-II,代码行数:13,
示例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); }
开发者ID:auuuux,项目名称:raspberrypilot,代码行数:20,
示例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);}
开发者ID:auuuux,项目名称:raspberrypilot,代码行数:18,
示例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);}
开发者ID:auuuux,项目名称:raspberrypilot,代码行数:19,
示例16: prvRecursiveMutexBlockingTaskstatic void prvRecursiveMutexBlockingTask( void *pvParameters ){ /* Just to remove compiler warning. */ ( void ) pvParameters; for( ;; ) { /* Attempt to obtain the mutex. We should block until the controlling task has given up the mutex, and not actually execute past this call until the controlling task is suspended. */ if( xSemaphoreTakeRecursive( xMutex, portMAX_DELAY ) == 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++; }}
开发者ID:nganmomo,项目名称:avropendous,代码行数:50,
示例17: g_printf void g_printf(const char *format, ...) { if (semPrintfGate == 0) vCreatePrintfSemaphore(); if (xSemaphoreTakeRecursive(semPrintfGate, MUTEX_WAIT_TIME)) { va_list arguments; va_start(arguments,format); print(0, format, arguments); xSemaphoreGiveRecursive(semPrintfGate); } }
开发者ID:AlexShiLucky,项目名称:freertos,代码行数:14,
示例18: TaskMonitorRemove/** * Remove a task handle from the library */int32_t TaskMonitorRemove(TaskInfoRunningElem task){ if (task < TASKINFO_RUNNING_NUMELEM) { xSemaphoreTakeRecursive(lock, portMAX_DELAY); handles[task] = 0; xSemaphoreGiveRecursive(lock); return 0; } else { return -1; }}
开发者ID:quang102,项目名称:openpilot,代码行数:17,
示例19: UAVObjSetInstanceDataField/** * Set the data of a specific object instance * /param[in] obj The object handle * /param[in] instId The object instance ID * /param[in] dataIn The object's data structure * /return 0 if success or -1 if failure */int32_t UAVObjSetInstanceDataField(UAVObjHandle obj, uint16_t instId, const void* dataIn, uint32_t offset, uint32_t size){ ObjectList* objEntry; ObjectInstList* instEntry; UAVObjMetadata* mdata; // Lock xSemaphoreTakeRecursive(mutex, portMAX_DELAY); // Cast to object info objEntry = (ObjectList*)obj; // Check access level if ( !objEntry->isMetaobject ) { mdata = (UAVObjMetadata*)(objEntry->linkedObj->instances.data); if ( mdata->access == ACCESS_READONLY ) { xSemaphoreGiveRecursive(mutex); return -1; } } // Get instance information instEntry = getInstance(objEntry, instId); if ( instEntry == NULL ) { // Error, unlock and return xSemaphoreGiveRecursive(mutex); return -1; } // return if we set too much of what we have if ( (size + offset) > objEntry->numBytes) { // Error, unlock and return xSemaphoreGiveRecursive(mutex); return -1; } // Set data memcpy(instEntry->data + offset, dataIn, size); // Fire event sendEvent(objEntry, instId, EV_UPDATED); // Unlock xSemaphoreGiveRecursive(mutex); return 0;}
开发者ID:LeeSaferite,项目名称:OpenPilot,代码行数:56,
示例20: g_printf_rcc void g_printf_rcc(uint8_t row, uint8_t col, const char *color, const char *format, ...) { if (semPrintfGate == 0) vCreatePrintfSemaphore(); if (xSemaphoreTakeRecursive(semPrintfGate, MUTEX_WAIT_TIME )) { UngatedMoveToScreenPosition(row, col); printf("%s",color); va_list arguments; va_start(arguments,format); print(0, format, arguments); xSemaphoreGiveRecursive(semPrintfGate); }}
开发者ID:AlexShiLucky,项目名称:freertos,代码行数:15,
示例21: TaskMonitorAdd/** * Register a task handle with the library */int32_t TaskMonitorAdd(TaskInfoRunningElem task, xTaskHandle handle){ uint32_t task_idx = (uint32_t) task; if (task_idx < TASKINFO_RUNNING_NUMELEM) { xSemaphoreTakeRecursive(lock, portMAX_DELAY); handles[task_idx] = handle; xSemaphoreGiveRecursive(lock); return 0; } else { return -1; }}
开发者ID:MAVProxyUser,项目名称:TeamBlackSheepTauGCS,代码行数:18,
示例22: UAVTalkRelayPacket/** * Send a parsed packet received on one connection handle out on a different connection handle. * The packet must be in a complete state, meaning it is completed parsing. * The packet is re-assembled from the component parts into a complete message and sent. * This can be used to relay packets from one UAVTalk connection to another. * /param[in] connection UAVTalkConnection to be used * /param[in] rxbyte Received byte * /return 0 Success * /return -1 Failure */int32_t UAVTalkRelayPacket(UAVTalkConnection inConnectionHandle, UAVTalkConnection outConnectionHandle){ UAVTalkConnectionData *inConnection; CHECKCONHANDLE(inConnectionHandle, inConnection, return -1); UAVTalkInputProcessor *inIproc = &inConnection->iproc; // The input packet must be completely parsed. if (inIproc->state != UAVTALK_STATE_COMPLETE) { inConnection->stats.rxErrors++; return -1; } UAVTalkConnectionData *outConnection; CHECKCONHANDLE(outConnectionHandle, outConnection, return -1); if (!outConnection->outStream) { outConnection->stats.txErrors++; return -1; } // Lock xSemaphoreTakeRecursive(outConnection->lock, portMAX_DELAY); outConnection->txBuffer[0] = UAVTALK_SYNC_VAL; // Setup type outConnection->txBuffer[1] = inIproc->type; // next 2 bytes are reserved for data length (inserted here later) // Setup object ID outConnection->txBuffer[4] = (uint8_t)(inIproc->objId & 0xFF); outConnection->txBuffer[5] = (uint8_t)((inIproc->objId >> 8) & 0xFF); outConnection->txBuffer[6] = (uint8_t)((inIproc->objId >> 16) & 0xFF); outConnection->txBuffer[7] = (uint8_t)((inIproc->objId >> 24) & 0xFF); // Setup instance ID outConnection->txBuffer[8] = (uint8_t)(inIproc->instId & 0xFF); outConnection->txBuffer[9] = (uint8_t)((inIproc->instId >> 8) & 0xFF); int32_t headerLength = 10; // Add timestamp when the transaction type is appropriate if (inIproc->type & UAVTALK_TIMESTAMPED) { portTickType time = xTaskGetTickCount(); outConnection->txBuffer[10] = (uint8_t)(time & 0xFF); outConnection->txBuffer[11] = (uint8_t)((time >> 8) & 0xFF); headerLength += 2; }
开发者ID:MAVProxyUser,项目名称:NinjaPilot-15.02.ninja,代码行数:57,
示例23: UAVTalkSetOutputStream/** * Set the communication output stream * /param[in] connection UAVTalkConnection to be used * /param[in] outputStream Function pointer that is called to send a data buffer * /return 0 Success * /return -1 Failure */int32_t UAVTalkSetOutputStream(UAVTalkConnection connectionHandle, UAVTalkOutputStream outputStream){ UAVTalkConnectionData *connection; CHECKCONHANDLE(connectionHandle, connection, return -1); // Lock xSemaphoreTakeRecursive(connection->lock, portMAX_DELAY); // set output stream connection->outStream = outputStream; // Release lock xSemaphoreGiveRecursive(connection->lock); return 0;}
开发者ID:MAVProxyUser,项目名称:NinjaPilot-15.02.ninja,代码行数:24,
示例24: prvSanityCheckCreatedRecursiveMutexstatic void prvSanityCheckCreatedRecursiveMutex( SemaphoreHandle_t xSemaphore ){const BaseType_t xLoops = 5;BaseType_t x, xReturned; /* A very basic test that the recursive semaphore behaved like a recursive semaphore. First the semaphore should not be able to be given, as it has not yet been taken. */ xReturned = xSemaphoreGiveRecursive( xSemaphore ); if( xReturned != pdFAIL ) { xErrorOccurred = pdTRUE; } /* Now it should be possible to take the mutex a number of times. */ for( x = 0; x < xLoops; x++ ) { xReturned = xSemaphoreTakeRecursive( xSemaphore, staticDONT_BLOCK ); if( xReturned != pdPASS ) { xErrorOccurred = pdTRUE; } } /* Should be possible to give the semaphore the same number of times as it was given in the loop above. */ for( x = 0; x < xLoops; x++ ) { xReturned = xSemaphoreGiveRecursive( xSemaphore ); if( xReturned != pdPASS ) { xErrorOccurred = pdTRUE; } } /* No more gives should be possible though. */ xReturned = xSemaphoreGiveRecursive( xSemaphore ); if( xReturned != pdFAIL ) { xErrorOccurred = pdTRUE; }}
开发者ID:radiolok,项目名称:RelayComputer2,代码行数:46,
示例25: socket_watcher_taskvoid socket_watcher_task(void *arg){ TickType_t xTimePrev = xTaskGetTickCount(); struct SocketWatcherData *pWatcher = (struct SocketWatcherData *)arg; for (;;) { ulTaskNotifyTake(pdTRUE, TICKS_TO_WAIT); if (pdFALSE == xSemaphoreTakeRecursive(m_watcher.mutw, TICKS_TO_WAIT)) { continue; } if (pWatcher->apb_size > 0) { if (FreeRTOS_select(pWatcher->xFD_set, TICKS_TO_WAIT) != 0) { pubnub_t **ppbp; for (ppbp = pWatcher->apb; ppbp < pWatcher->apb + pWatcher->apb_size; ++ppbp) { if (FreeRTOS_FD_ISSET((*ppbp)->pal.socket, pWatcher->xFD_set)) { pbnc_fsm(*ppbp); } } } } if (PUBNUB_TIMERS_API) { TickType_t xTimeNow = xTaskGetTickCount(); int elapsed = elapsed_ms(xTimePrev, xTimeNow); if (elapsed > 0) { pubnub_t *expired = pubnub_timer_list_as_time_goes_by(&m_watcher.timer_head, elapsed); while (expired != NULL) { pubnub_t *next = expired->next; pbnc_stop(expired, PNR_TIMEOUT); expired->previous = NULL; expired->next = NULL; expired = next; } xTimePrev = xTimeNow; } } xSemaphoreGiveRecursive(m_watcher.mutw); }}
开发者ID:evanbeard,项目名称:c-core,代码行数:45,
示例26: UAVObjSaveToFile/** * Save the data of the specified object instance to the file system (SD card). * The object will be appended and the file will not be closed. * 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 UAVObjSaveToFile(UAVObjHandle obj, uint16_t instId, FILEINFO * file){#if defined(PIOS_INCLUDE_SDCARD) uint32_t bytesWritten; ObjectList *objEntry; ObjectInstList *instEntry; // Check for file system availability if (PIOS_SDCARD_IsMounted() == 0) { return -1; } // Lock xSemaphoreTakeRecursive(mutex, portMAX_DELAY); // Cast to object objEntry = (ObjectList *) obj; // Get the instance information instEntry = getInstance(objEntry, instId); if (instEntry == NULL) { xSemaphoreGiveRecursive(mutex); return -1; } // Write the object ID PIOS_FWRITE(file, &objEntry->id, sizeof(objEntry->id), &bytesWritten); // Write the instance ID if (!objEntry->isSingleInstance) { PIOS_FWRITE(file, &instEntry->instId, sizeof(instEntry->instId), &bytesWritten); } // Write the data and check that the write was successful PIOS_FWRITE(file, instEntry->data, objEntry->numBytes, &bytesWritten); if (bytesWritten != objEntry->numBytes) { xSemaphoreGiveRecursive(mutex); return -1; } // Done xSemaphoreGiveRecursive(mutex);#endif /* PIOS_INCLUDE_SDCARD */ return 0;}
开发者ID:LeeSaferite,项目名称:OpenPilot,代码行数:54,
示例27: prvRecursiveMutexPollingTaskstatic 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. */ if( xSemaphoreTakeRecursive( xMutex, recmuNO_DELAY ) == pdPASS ) { /* Is the blocking task suspended? */ if( xBlockingIsSuspended != 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. */ vTaskResume( xBlockingTaskHandle ); vTaskResume( xControllingTaskHandle ); /* Release the mutex, disinheriting the higher priority again. */ if( xSemaphoreGiveRecursive( xMutex ) != pdPASS ) { xErrorOccurred = pdTRUE; } } } #if configUSE_PREEMPTION == 0 { taskYIELD(); } #endif }}
开发者ID:nganmomo,项目名称:avropendous,代码行数:45,
示例28: mrb_freertos_rwlock_wrlockintmrb_freertos_rwlock_wrlock(mrb_state *mrb, mrb_rwlock_t *lock, uint32_t timeout_ms){ debugc('L'); xSemaphoreHandle mutex = (xSemaphoreHandle)lock->rwlock; if (mutex == NULL) { return RWLOCK_STATUS_INVALID_ARGUMENTS; } portTickType timeout_tick = timeout_ms / portTICK_RATE_MS; if (pdTRUE == xSemaphoreTakeRecursive(mutex, timeout_tick)) { debugc('l'); return RWLOCK_STATUS_OK; }else{ debugc('x'); return RWLOCK_STATUS_TIMEOUT; }}
开发者ID:kyab,项目名称:mruby-thread-freertos,代码行数:18,
示例29: UAVLinkSetStreamForwarder/** * Set the stream forwarder * /param[in] connection UAVLinkConnection to be used * /param[in] the forwarder to use * /return 0 Success * /return -1 Failure */int32_t UAVLinkSetStreamForwarder(UAVLinkConnection connectionHandle, uavLinkStreamForwarder forwarder){ UAVLinkConnectionData *connection; CHECKCONHANDLE(connectionHandle,connection,return -1); // Lock xSemaphoreTakeRecursive(connection->lock, portMAX_DELAY); // set output stream connection->streamForwarder = forwarder; // Release lock xSemaphoreGiveRecursive(connection->lock); return 0;}
开发者ID:auuuux,项目名称:raspberrypilot,代码行数:25,
示例30: PHReleaseRXPacket/** * Release a packet from the receive packet buffer window. * /param[in] h The packet handler instance data pointer. * /param[in] p A pointer to the packet buffer. * /return Nothing */void PHReleaseRXPacket(PHInstHandle h, PHPacketHandle p){ PHPacketDataHandle data = (PHPacketDataHandle)h; // Lock xSemaphoreTakeRecursive(data->lock, portMAX_DELAY); // Change the packet type so we know this packet is unused. p->header.type = PACKET_TYPE_NONE; // If this packet is at the start of the window, increment the start index. while ((data->rx_win_start != data->rx_win_end) && (data->rx_packets[data->rx_win_start].header.type == PACKET_TYPE_NONE)) data->rx_win_start = (data->rx_win_start + 1) % data->cfg.winSize; // Release lock xSemaphoreGiveRecursive(data->lock);}
开发者ID:01iv3r,项目名称:OpenPilot,代码行数:24,
注:本文中的xSemaphoreTakeRecursive函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ xSerialPutChar函数代码示例 C++ xSemaphoreTake函数代码示例 |