bool DLL_EXPORT check(Queue_t queue){ if(Queue_getSize(queue) < 3) return false; while(Queue_getSize(queue) > 3){ Queue_dequeue(queue); } while(!Queue_isEmpty(queue)){ if(Queue_dequeue(queue) > 0) return false; } return true; }
static int test_dequeue() { Queue* queue = Queue_new(0); nu_assert_eq_ptr(NULL, Queue_dequeue(queue)); int array[] = {1, 2, 3}; Queue_enqueue(queue, &array[0]); Queue_enqueue(queue, &array[1]); Queue_enqueue(queue, &array[2]); nu_assert_eq_ptr(&array[0], Queue_dequeue(queue)); nu_assert_eq_int(2, Queue_size(queue)); Queue_free(queue); return 0; }
/******************************************************************************* * @fn SensorTagOad_processEvent * * @brief Process the write events to the OAD characteristics * * @param a0, a1 (not used) * * @return none */ void SensorTagOad_processEvent(void) { while (!Queue_empty(hOadQ)) { oadTargetWrite_t *oadWriteEvt = Queue_dequeue(hOadQ); // Identify new image. if (oadWriteEvt->event == OAD_WRITE_IDENTIFY_REQ) { // Request image identification OAD_imgIdentifyWrite(oadWriteEvt->connHandle, oadWriteEvt->pData); } // Write a next block request. else if (oadWriteEvt->event == OAD_WRITE_BLOCK_REQ) { OAD_imgBlockWrite(oadWriteEvt->connHandle, oadWriteEvt->pData); } // Free buffer. ICall_free(oadWriteEvt); } }
/* * ======== GIO_prime ======== */ Int GIO_prime(GIO_Object *obj, Ptr buf, SizeT size, UArg arg) { Queue_Handle freeList; IOM_Packet *packet; UInt key; Assert_isTrue((obj->model == GIO_Model_ISSUERECLAIM), GIO_A_badModel); /* GIO_prime() can only be used in output mode */ if (obj->mode != GIO_OUTPUT) { return (IOM_EBADMODE); } freeList = GIO_Instance_State_freeList(obj); if (obj->freeCount == 0) { return (IOM_ENOPACKETS); } key = Hwi_disable(); obj->freeCount--; packet = Queue_dequeue(freeList); Hwi_restore(key); packet->cmd = IOM_WRITE; packet->addr = buf; packet->size = size; packet->arg = arg; packet->status = IOM_COMPLETED; callback((Ptr)obj, packet); return (IOM_COMPLETED); }
void CPU_scheduler(CPU_p cpu, Interrupt_type interrupt_type, int PC) { while (!Queue_isEmpty(cpu->newProcessesQueue)) { PCB_p temp_pcb = Queue_dequeue(cpu->newProcessesQueue); PCB_set_state(temp_pcb, ready); //PCB_set_pc(temp_pcb, PC); Queue_enqueue(cpu->readyQueue, temp_pcb); fprintf(file, "Process ID: %u Enqueued\n", temp_pcb->pid); fprintf(file, "%s", PCB_toString(temp_pcb)); } fprintf(file, "\n"); switch (interrupt_type) { case timer: // 1. Put process back into the readyQueue Queue_enqueue(cpu->readyQueue, cpu->currentProcess); // 2. Change its state from interrupted to ready PCB_set_state(cpu->currentProcess, ready); // 3. Make call to dispatcher CPU_dispatcher(cpu, timer); // 4. Returned from dispatcher, do any housekeeping // Nothing here to do at the moment! // 5. Returns to pseudo-ISR return; break; default: CPU_dispatcher(cpu, normal); break; } return; }
/* * ======== GIO_reclaim ======== */ Int GIO_reclaim(GIO_Object *obj, Ptr *pBuf, SizeT *pSize, UArg *pArg) { IOM_Packet *packet; Queue_Handle doneList; Queue_Handle freeList; UInt key; Int status; Error_Block eb; doneList = GIO_Instance_State_doneList(obj); freeList = GIO_Instance_State_freeList(obj); Error_init(&eb); while (obj->doneCount == 0) { if (Sync_wait(obj->sync, obj->timeout, &eb) == Sync_WaitStatus_TIMEOUT) { return (IOM_ETIMEOUT); } } key = Hwi_disable(); obj->doneCount--; packet = Queue_dequeue(doneList); Hwi_restore(key); if (pArg != NULL) { *pArg = packet->arg; } /* pBuf is set to NULL by GIO_read() and GIO_write() */ if (pBuf != NULL) { *pBuf = packet->addr; } if (pSize != NULL) { *pSize = packet->size; } status = packet->status; /* * re-signal if more buffers are ready * This is required in the case of ISyncEvent and ISyncSwi to allow * clients to reclaim a single buffer and not force them to bleed the * stream. */ if (obj->doneCount > 0) { Sync_signal(obj->sync); } /* recycle packet back onto free list */ key = Hwi_disable(); obj->freeCount++; Queue_enqueue(freeList, (Queue_Elem *)packet); Hwi_restore(key); return (status); }
int Queue_drop(Queue *q, const char *id) { if (q->first != NULL) { if (strcmp(q->first->id, id) == 0) { Queue_dequeue(q); return 1; } else { struct student* next_student = q->first; struct student* last_student; do { if (strcmp(next_student->id, id) == 0) { struct student* student_to_delete = next_student; last_student->next = student_to_delete->next; if (student_to_delete == q->last) { q->last = last_student; last_student->next = NULL; } free_student(student_to_delete); return 1; } last_student = next_student; next_student = next_student->next; } while(next_student != NULL); } } return 0; }
Packet Packets_getNext(){ static Queue* queue; queue = Packets_getQueue(); Packet packet; Queue_dequeue(queue, &packet); return packet; }
void bfs(BFSVertex* vertices, int nelem, int s) { Queue q; for (int u = 0; u < nelem; u++) { if (vertices[u].super.n != s) { vertices[u].super.color = WHITE; vertices[u].d = 1E10; vertices[u].super.parent = -1; } } vertices[s].super.color = GRAY; vertices[s].d = 0; vertices[s].super.parent = -1; Queue_init(&q); Queue_create_queue(&q, nelem); Queue_enqueue(&q, s); while (!Queue_is_empty(&q)) { int u = Queue_dequeue(&q); for (Adj* adj_v = vertices[u].super.first; adj_v; adj_v = adj_v->next) { if (vertices[adj_v->n].super.color == WHITE) { vertices[adj_v->n].super.color = GRAY; vertices[adj_v->n].d = vertices[u].d + 1; vertices[adj_v->n].super.parent = u; Queue_enqueue(&q, adj_v->n); } } vertices[u].super.color = BLACK; } }
int main() { // moduleTests_Queue(); Queue_t queue1 = Queue_new(); Queue_t queue2 = Queue_new(); for(int i = 0; i < 10; i++){ Queue_enqueue(queue1, randInt()); Queue_enqueue(queue2, randInt()); } Queue_bindQueues(queue1, queue2); Queue_subscribeSingleOverflowEvent(queue1, singleQueueOverflow1, "queue1"); Queue_subscribeSingleOverflowEvent(queue1, singleQueueOverflow2, "queue1"); Queue_subscribeSingleOverflowEvent(queue2, singleQueueOverflow1, "queue2"); Queue_subscribeSingleOverflowEvent(queue2, singleQueueOverflow2, "queue2"); Queue_subscribePairOverflowEvent(queue1, queuePairOverflow, "queue1"); Queue_subscribePairEmptyEvent(queue1, queuePairEmpty, "queue1"); Queue_subscribePairOverflowEvent(queue2, queuePairOverflow, "queue2"); Queue_subscribePairEmptyEvent(queue2, queuePairEmpty, "queue2"); for(int i = 0; i < 50; i++){ int rndInt = randInt(); if(randBool()){ if(rndInt >= 0){ Queue_enqueue(queue1, rndInt); }else{ Queue_dequeue(queue1); } }else{ if(rndInt >= 0){ Queue_enqueue(queue2, rndInt); }else{ Queue_dequeue(queue2); } } } Queue_delete(queue1); Queue_delete(queue2); return 0; }
static int test_capacity() { Queue* queue = Queue_new(2); int array[] = {1, 2, 3}; nu_assert(Queue_enqueue(queue, &array[0])); nu_assert(Queue_enqueue(queue, &array[1])); nu_assert(!Queue_enqueue(queue, &array[2])); Queue_dequeue(queue); nu_assert(Queue_enqueue(queue, &array[2])); Queue_free(queue); return 0; }
static int test_empty() { Queue* queue = Queue_new(0); nu_assert(Queue_empty(queue)); int array[] = {1}; Queue_enqueue(queue, &array[0]); nu_assert(!Queue_empty(queue)); Queue_dequeue(queue); nu_assert(Queue_empty(queue)); Queue_free(queue); return 0; }
static int test_size() { Queue* queue = Queue_new(0); nu_assert_eq_int(0, Queue_size(queue)); int array[] = {1}; Queue_enqueue(queue, &array[0]); nu_assert_eq_int(1, Queue_size(queue)); Queue_dequeue(queue); nu_assert_eq_int(0, Queue_size(queue)); Queue_free(queue); return 0; }
/* * ======== GIO_issue ======== */ Int GIO_issue(GIO_Object *obj, Ptr buf, SizeT size, UArg arg) { IOM_Packet *packet; Queue_Handle freeList; Int status; UInt key; UInt cmd; IOM_Fxns *iomFxns; iomFxns = (IOM_Fxns *)obj->fxns; Assert_isTrue((obj->model == GIO_Model_ISSUERECLAIM), GIO_A_badModel); freeList = GIO_Instance_State_freeList(obj); if (obj->freeCount == 0) { return (IOM_ENOPACKETS); } if (obj->mode == GIO_INPUT) { cmd = IOM_READ; } else { cmd = IOM_WRITE; } key = Hwi_disable(); obj->freeCount--; packet = Queue_dequeue(freeList); Hwi_restore(key); packet->cmd = cmd; packet->addr = buf; packet->size = size; packet->arg = arg; packet->status = IOM_COMPLETED; packet->misc = 1; /* used n callback to indicate asynch packet */ status = iomFxns->mdSubmitChan(obj->mdChan, packet); key = Hwi_disable(); obj->submitCount++; Hwi_restore(key); if (status == IOM_COMPLETED) { callback(obj, packet); } return (status); }
// ----------------------------------------------------------------------------- //! \brief Dequeues the message from the RTOS queue. //! //! \param msgQueue - queue handle. //! //! \return pointer to dequeued message, NULL otherwise. // ----------------------------------------------------------------------------- uint8_t *NPIUtil_dequeueMsg(Queue_Handle msgQueue) { if (!Queue_empty(msgQueue)) { queueRec_t *pRec = Queue_dequeue(msgQueue); uint8_t *pData = pRec->pData; // Free the queue node // Note: this does not free space allocated by data within the node. NPIUTIL_FREE(pRec); return pData; } return NULL; }
/* * ======== Semaphore_post ======== */ Void Semaphore_post(Semaphore_Object *sem) { UInt tskKey, hwiKey; Semaphore_PendElem *elem; Queue_Handle pendQ; /* Event_post will do a Log_write, should we do one here too? */ Log_write2(Semaphore_LM_post, (UArg)sem, (UArg)sem->count); pendQ = Semaphore_Instance_State_pendQ(sem); hwiKey = Hwi_disable(); if (Queue_empty(pendQ)) { if (((UInt)sem->mode & 0x1) != 0) { /* if BINARY bit is set */ sem->count = 1; } else { sem->count++; Assert_isTrue((sem->count != 0), Semaphore_A_overflow); } Hwi_restore(hwiKey); if (Semaphore_supportsEvents && (sem->event != NULL)) { Semaphore_eventPost(sem->event, sem->eventId); } return; } /* lock task scheduler */ tskKey = Task_disable(); /* dequeue tsk from semaphore queue */ elem = (Semaphore_PendElem *)Queue_dequeue(pendQ); /* mark the Semaphore as having been posted */ elem->pendState = Semaphore_PendState_POSTED; /* put task back into readyQ */ Task_unblockI(elem->tpElem.task, hwiKey); Hwi_restore(hwiKey); Task_restore(tskKey); }
//downloader dequeues void *deq_helper(void* argPtr) { Queue_dequeue(((DPacket_t*)argPtr)->q,((DPacket_t*)argPtr)->returnvalue); printf("%d: dequeuehelper getting mainmutex\n", pthread_self()); pthread_mutex_lock(&mainMutex); printf("%d: dequeuehelper got mainmutex, --work; workInSystem = %d \n", pthread_self(), workInSystem); workInSystem--; printf("%d: dequeuehelper finish dec, workInSystem = %d \n", pthread_self(), workInSystem); if (workInSystem <= 0){ printf("%d: dequeuehelper waking main up, no more work\n", pthread_self()); pthread_cond_signal(&noWorkInSystem); } printf("%d: dequeuehelper unlocking mainmutex\n", pthread_self()); pthread_mutex_unlock(&mainMutex); printf("%d: dequeuehelper released mainmutex\n", pthread_self()); //Remember that in the real crawler, workinsystem only incremented when something enqueued to linkqueue, dec when dequeued from pagequeue }
/** * usage: this method does the work, checkes the queue, writes to the UART and post's * the Event * @method uart_method * @author: patrik.szabo * @param arg0 - not used param for the task * @return *none* */ void uart_method(UArg arg0) { // char input; UART_Handle uart; UART_Params uartParams; /* Create a UART with data processing off. */ UART_Params_init(&uartParams); uartParams.writeDataMode = UART_DATA_BINARY; uartParams.readDataMode = UART_DATA_BINARY; uartParams.readReturnMode = UART_RETURN_FULL; uartParams.readEcho = UART_ECHO_OFF; uartParams.baudRate = 9600; uart = UART_open(Board_UART0, &uartParams); if (uart == NULL) { System_abort("Error opening the UART"); } QueueObject* queueObjectPointer; char altData[22] = ""; char pressData[16] = ""; char tempData[18] = ""; while (1) { while (!Queue_empty(uartQueue)) { queueObjectPointer = Queue_dequeue(uartQueue); sprintf(altData, "Altitude: %d | ", (int) queueObjectPointer->myInformationPointer->alt); System_printf("%s", altData); UART_write(uart, altData, sizeof(altData)); sprintf(pressData, "Pressure: %d | ", queueObjectPointer->myInformationPointer->press); System_printf("%s", pressData); UART_write(uart, pressData, sizeof(pressData)); sprintf(tempData, "Temparature: %d\n\r", queueObjectPointer->myInformationPointer->temp); System_printf("%s", tempData); UART_write(uart, tempData, sizeof(tempData)); Event_post(uartReadyEvent, Event_Id_02); } Task_sleep(500); } }
/********************************************************************* * @fn Util_dequeueMsg * * @brief Dequeues the message from the RTOS queue. * * @param msgQueue - queue handle. * * @return pointer to dequeued message, NULL otherwise. */ uint8_t *Util_dequeueMsg(Queue_Handle msgQueue) { if (!Queue_empty(msgQueue)) { queueRec_t *pRec = Queue_dequeue(msgQueue); uint8_t *pData = pRec->pData; // Free the queue node // Note: this does not free space allocated by data within the node. #ifdef USE_ICALL ICall_free(pRec); #else free(pRec); #endif return pData; } return NULL; }
/* * ======== Task_yield ======== */ Void Task_yield() { UInt tskKey, hwiKey; tskKey = Task_disable(); hwiKey = Hwi_disable(); if (Task_module->curQ) { /* move current task to end of curQ */ Queue_enqueue(Task_module->curQ, Queue_dequeue(Task_module->curQ)); } Task_module->curQ = NULL; /* force a Task_switch() */ Task_module->workFlag = 1; Hwi_restore(hwiKey); Log_write3(Task_LM_yield, (UArg)Task_module->curTask, (UArg)(Task_module->curTask->fxn), (UArg)(BIOS_getThreadType())); Task_restore(tskKey); }
void CPU_dispatcher(CPU_p cpu, Interrupt_type interrupt_type) { // Save pointers to the previous and next process (needed so we can print) PCB_p prevProcess = cpu->currentProcess; PCB_p nextProcess = Queue_peek(cpu->readyQueue); if (CTX_SWITCH_COUNT % 4 == 0) { if (prevProcess != NULL) fprintf(file, "Running process: %s", PCB_toString(prevProcess)); if (nextProcess != NULL) fprintf(file, "Switching to: %s", PCB_toString(nextProcess)); } // 1. Save the state of current process into its PCB (PC value) // Per Canvas Discussions, DON'T DO THIS AGAIN HERE! It's in ISR. // 2. Then dequeue next waiting process if (!Queue_isEmpty(cpu->readyQueue)) cpu->currentProcess = Queue_dequeue(cpu->readyQueue); // 3. Change its state to running PCB_set_state(cpu->currentProcess, running); if (interrupt_type == timer) { // 4. Copy its PC value to sysStack, replacing the interrupted process CPU_push_sysStack(cpu, PCB_get_PC(cpu->currentProcess)); } else if (interrupt_type == normal) { CPU_set_pc(cpu, cpu->sysStack); } if (CTX_SWITCH_COUNT % 4 == 0) { if (prevProcess != NULL) fprintf(file, "Last Process: %s", PCB_toString(prevProcess)); if (nextProcess != NULL) fprintf(file, "Current running Process: %s", PCB_toString(nextProcess)); fprintf(file, "Ready Queue: %s", Queue_toString(cpu->readyQueue, 0)); } // 5. Return to the scheduler // returns prevalent stuff to scheduler, but not for this project return; }
/* * ======== Swi_runLoop ======== */ Void Swi_runLoop() { Queue_Handle curQ, maxQ; Swi_Object *swi; /* Remember current Swi priority */ curQ = Swi_module->curQ; /* refresh maxQ */ maxQ = (Queue_Handle)((UInt8 *)(Swi_module->readyQ) + (UInt)(Intrinsics_maxbit(Swi_module->curSet)*(2*sizeof(Ptr)))); /* * Run all Swis of higher priority than * the current Swi priority. * Will pre-empt any currently running swi. */ do { swi = (Swi_Object *)Queue_dequeue(maxQ); /* remove from curSet if last one in this ready list */ if (Queue_empty(maxQ)) { Swi_module->curSet &= ~swi->mask; } Swi_run(swi); if (Swi_module->curSet == 0) { break; } maxQ = (Queue_Handle)((UInt8 *)(Swi_module->readyQ) + (UInt)(Intrinsics_maxbit(Swi_module->curSet)*(2*sizeof(Ptr)))); } while (maxQ > curQ); }
Void Swi_restoreHwi(UInt swiKey) { Queue_Handle curQ, maxQ; Swi_Object *swi; if (swiKey == FALSE) { if (Swi_module->curSet && (Core_getId() == 0)) { /* Remember current Swi priority */ curQ = Swi_module->curQ; /* determine current highest priority Q */ maxQ = (Queue_Handle)((UInt8 *)(Swi_module->readyQ) + (UInt)(Intrinsics_maxbit(Swi_module->curSet)*(2*sizeof(Ptr)))); /* Run all Swis of higher priority than the current Swi priority */ /* Will pre-empt any currently running swi. */ while (maxQ > curQ) { swi = (Swi_Object *)Queue_dequeue(maxQ); /* remove from curSet if last one in this ready list */ if (Queue_empty(maxQ)) { Swi_module->curSet &= ~swi->mask; } Swi_run(swi); if (Swi_module->curSet == 0) { break; } maxQ = (Queue_Handle)((UInt8 *)(Swi_module->readyQ) + (UInt)(Intrinsics_maxbit(Swi_module->curSet)*(2*sizeof(Ptr)))); } } Swi_module->locked = FALSE; } }
void Queue_delete(Queue *q) { if (q) { while(Queue_dequeue(q)); free(q); } }
/* * ======== GIO_submit ======== */ Int GIO_submit(GIO_Object *obj, Uns cmd, Ptr buf, SizeT *pSize, GIO_AppCallback *appCallback) { IOM_Packet syncPacket; IOM_Packet *packet; SizeT nullSize; Int status; UInt key; Queue_Handle list; Error_Block eb; IOM_Fxns *iomFxns; iomFxns = (IOM_Fxns *)obj->fxns; if (appCallback == NULL) { packet = &syncPacket; } else { list = GIO_Instance_State_freeList(obj); if (obj->freeCount == 0) { return (IOM_ENOPACKETS); } key = Hwi_disable(); obj->freeCount--; packet = Queue_dequeue(list); Hwi_restore(key); } if (pSize == NULL) { nullSize = 0; pSize = &nullSize; } packet->cmd = cmd; packet->addr = buf; packet->size = *pSize; packet->status = IOM_COMPLETED; /* * 'appCallback' will be NULL for synchronous calls. * 'packet->misc' is used in the callback to call asynch callback * or post semaphore (sync). */ packet->misc = (UArg)appCallback; status = iomFxns->mdSubmitChan(obj->mdChan, packet); if ((status == IOM_COMPLETED) || (status < 0)) { if (status == IOM_COMPLETED) { *pSize = packet->size; status = packet->status; } /* if asynch, put packet back on freeList */ if (appCallback != NULL) { key = Hwi_disable(); obj->freeCount++; Queue_enqueue(list, (Queue_Elem *)packet); Hwi_restore(key); } return (status); } /* * call Sync_wait only if synchronous I/O and mdSubmitChan did not * return an error (status < 0) */ if (appCallback == NULL) { Error_init(&eb); if (Sync_wait(obj->sync, obj->timeout, &eb) == Sync_WaitStatus_SUCCESS) { *pSize = packet->size; status = packet->status; } else { *pSize = 0; /* * NOTE: A channel timeout needs special handling. Timeouts are * usually due to some serious underlying device or system state * and may require the channel, or possibly the device,to be reset. * Because the mini-driver may still own the IOM_Packet here * driver's will need to perform timeout processing. We will call * the mini-driver's control fxn with the IOM_CHAN_TIMEDOUT command * code. */ status = iomFxns->mdControlChan(obj->mdChan, IOM_CHAN_TIMEDOUT, NULL); if (status != IOM_COMPLETED) { return (IOM_ETIMEOUTUNREC); /* fatal, may have lost packet */ } return (IOM_ETIMEOUT); } } return (status); }
/********************************************************************* * @fn SimplePropBeacon_taskFxn * * @brief Application task entry point for the Simple Proprietary Beacon. * * @param a0, a1 - not used. * * @return None. */ static void SimplePropBeacon_taskFxn(UArg a0, UArg a1) { // Initialize application SimplePropBeacon_init(); // Application main loop for (;;) { // Waits for a signal to the semaphore associated with the calling thread. // Note that the semaphore associated with a thread is signaled when a // message is queued to the message receive queue of the thread or when // ICall_signal() function is called onto the semaphore. ICall_Errno errno = ICall_wait(ICALL_TIMEOUT_FOREVER); if (errno == ICALL_ERRNO_SUCCESS) { ICall_EntityID dest; ICall_ServiceEnum src; ICall_HciExtEvt *pMsg = NULL; if (ICall_fetchServiceMsg(&src, &dest, (void **)&pMsg) == ICALL_ERRNO_SUCCESS) { uint8 safeToDealloc = TRUE; if ((src == ICALL_SERVICE_CLASS_BLE) && (dest == selfEntity)) { ICall_Stack_Event *pEvt = (ICall_Stack_Event *)pMsg; // Check for BLE stack events first if (pEvt->signature == 0xffff) { if (pEvt->event_flag & SPB_CONN_EVT_END_EVT) { // Try to retransmit pending ATT Response (if any) SimplePropBeacon_sendAttRsp(); } } else { // Process inter-task message safeToDealloc = SimplePropBeacon_processStackMsg((ICall_Hdr *)pMsg); } } if (pMsg && safeToDealloc) { ICall_freeMsg(pMsg); } } // If RTOS queue is not empty, process app message. while (!Queue_empty(appMsgQueue)) { spbEvt_t *pMsg = (spbEvt_t *)Util_dequeueMsg(appMsgQueue); if (pMsg) { // Process message. SimplePropBeacon_processAppMsg(pMsg); // Free the space from the message. ICall_free(pMsg); } } } #ifdef FEATURE_OAD while (!Queue_empty(hOadQ)) { oadTargetWrite_t *oadWriteEvt = Queue_dequeue(hOadQ); // Identify new image. if (oadWriteEvt->event == OAD_WRITE_IDENTIFY_REQ) { OAD_imgIdentifyWrite(oadWriteEvt->connHandle, oadWriteEvt->pData); } // Write a next block request. else if (oadWriteEvt->event == OAD_WRITE_BLOCK_REQ) { OAD_imgBlockWrite(oadWriteEvt->connHandle, oadWriteEvt->pData); } // Free buffer. ICall_free(oadWriteEvt); } #endif //FEATURE_OAD } }
/******************************************************************************* * @fn SensorTag_taskFxn * * @brief Application task entry point for the SensorTag * * @param a0, a1 (not used) * * @return none */ static void SensorTag_taskFxn(UArg a0, UArg a1) { // Initialize application SensorTag_init(); // Application main loop for (;;) { // Waits for a signal to the semaphore associated with the calling thread. // Note that the semaphore associated with a thread is signalled when a // message is queued to the message receive queue of the thread or when // ICall_signal() function is called onto the semaphore. ICall_Errno errno = ICall_wait(ICALL_TIMEOUT_FOREVER); if (errno == ICALL_ERRNO_SUCCESS) { ICall_EntityID dest; ICall_ServiceEnum src; ICall_HciExtEvt *pMsg = NULL; if (ICall_fetchServiceMsg(&src, &dest, (void **)&pMsg) == ICALL_ERRNO_SUCCESS) { if ((src == ICALL_SERVICE_CLASS_BLE) && (dest == selfEntity)) { // Process inter-task message SensorTag_processStackMsg((ICall_Hdr *)pMsg); } if (pMsg) { ICall_freeMsg(pMsg); } } // If RTOS queue is not empty, process app message. while (!Queue_empty(appMsgQueue)) { stEvt_t *pMsg = (stEvt_t *)Util_dequeueMsg(appMsgQueue); if (pMsg) { // Process message. SensorTag_processAppMsg(pMsg); // Free the space from the message. ICall_free(pMsg); } } // Process new data if available SensorTagKeys_processEvent(); SensorTagOpt_processSensorEvent(); SensorTagMov_processSensorEvent(); } if (!!(events & ST_PERIODIC_EVT)) { events &= ~ST_PERIODIC_EVT; if (gapProfileState == GAPROLE_CONNECTED || gapProfileState == GAPROLE_ADVERTISING) { Util_startClock(&periodicClock); } // Perform periodic application task if (gapProfileState == GAPROLE_CONNECTED) { SensorTag_performPeriodicTask(); } // Blink green LED when advertising if (gapProfileState == GAPROLE_ADVERTISING) { SensorTag_blinkLed(Board_LED2,1); #ifdef FEATURE_LCD SensorTag_displayBatteryVoltage(); #endif } } #ifdef FEATURE_OAD while (!Queue_empty(hOadQ)) { oadTargetWrite_t *oadWriteEvt = Queue_dequeue(hOadQ); // Identify new image. if (oadWriteEvt->event == OAD_WRITE_IDENTIFY_REQ) { OAD_imgIdentifyWrite(oadWriteEvt->connHandle, oadWriteEvt->pData); } // Write a next block request. else if (oadWriteEvt->event == OAD_WRITE_BLOCK_REQ) { OAD_imgBlockWrite(oadWriteEvt->connHandle, oadWriteEvt->pData); } // Free buffer. ICall_free(oadWriteEvt); } #endif //FEATURE_OAD } // task loop }
Void Swi_schedule() { Queue_Handle curQ, maxQ; Swi_Object *swi; UInt hwiKey; UInt tskKey; Char *oldTaskSP; volatile Bool taskEnabled; /* Remember current Swi priority */ curQ = Swi_module->curQ; hwiKey = Hwi_disable(); /* required for Swi's posted from Tasks */ /* determine current highest priority Q */ maxQ = (Queue_Handle)((UInt8 *)(Swi_module->readyQ) + (UInt)(Intrinsics_maxbit(Swi_module->curSet)*(2*sizeof(Ptr)))); if (maxQ > curQ) { if (BIOS_taskEnabled) { tskKey = TASK_DISABLE(); /* required for Swi's posted from Tasks */ /* Switch to HWI stack if not already on it */ oldTaskSP = ti_sysbios_family_xxx_Hwi_switchToIsrStack(); /* must refresh local variables after stack switch */ /* refresh curQ */ curQ = Swi_module->curQ; /* refresh maxQ */ maxQ = (Queue_Handle)((UInt8 *)(Swi_module->readyQ) + (UInt)(Intrinsics_maxbit(Swi_module->curSet)*(2*sizeof(Ptr)))); /* set local variable inited after stack switch */ taskEnabled = TRUE; } else { taskEnabled = FALSE; } /* * Run all Swis of higher priority than * the current Swi priority. * Will pre-empt any currently running swi. */ do { swi = (Swi_Object *)Queue_dequeue(maxQ); /* remove from curSet if last one in this ready list */ if (Queue_empty(maxQ)) { Swi_module->curSet &= ~swi->mask; } Swi_run(swi); if (Swi_module->curSet == 0) { break; } maxQ = (Queue_Handle)((UInt8 *)(Swi_module->readyQ) + (UInt)(Intrinsics_maxbit(Swi_module->curSet)*(2*sizeof(Ptr)))); } while (maxQ > curQ); /* check local variable inited after stack switch */ if (taskEnabled) { /* Switch back to Task stack if at bottom of HWI stack */ ti_sysbios_family_xxx_Hwi_switchToTaskStack(oldTaskSP); } /* MUST(!) unlock the scheduler before enabling interrupts */ Swi_module->locked = FALSE; Hwi_restore(hwiKey); if (BIOS_taskEnabled) { TASK_RESTORE(tskKey); } } else { Swi_module->locked = FALSE; Hwi_restore(hwiKey); } }
PCB_p CPU_dequeue_readyQueue(CPU_p cpu) { return Queue_dequeue(CPU_get_readyQueue(cpu)); }
/* * ======== GateMutexPri_leave ======== * Only releases the gate if key == FIRST_ENTER. */ Void GateMutexPri_leave(GateMutexPri_Object *obj, IArg key) { UInt tskKey, hwiKey; Task_Handle owner; Task_Handle newOwner; Task_PendElem *elem; Queue_Handle pendQ; pendQ = GateMutexPri_Instance_State_pendQ(obj); owner = Task_self(); /* * Prior to tasks starting, Task_self() will return NULL. * Simply return here as, by definition, there is * is only one thread running at this time. */ if (owner == NULL) { return; } /* * Gate may only be called from task context, so Task_disable is sufficient * protection. */ tskKey = Task_disable(); /* Assert that caller is gate owner. */ // ASSERT(owner == obj->owner); /* If this is not the outermost call to leave, just return. */ if (key != FIRST_ENTER) { Task_restore(tskKey); return; } /* * Restore this task's priority. The if-test is worthwhile because of the * cost of a call to setPri. */ if (obj->ownerOrigPri != Task_getPri(owner)) { Task_setPri(owner, obj->ownerOrigPri); } /* If the list of waiting tasks is not empty... */ if (!Queue_empty(pendQ)) { /* * Get the next owner from the front of the queue (the task with the * highest priority of those waiting on the queue). */ elem = (Task_PendElem *)Queue_dequeue(pendQ); newOwner = elem->task; /* Setup the gate. */ obj->owner = newOwner; obj->ownerOrigPri = Task_getPri(newOwner); /* Task_unblockI must be called with interrupts disabled. */ hwiKey = Hwi_disable(); Task_unblockI(newOwner, hwiKey); Hwi_restore(hwiKey); } /* If the gate is to be posted... */ else { obj->mutexCnt = 1; } Task_restore(tskKey); }