static void cmd_rms(BaseSequentialStream *chp) { /* * Creating dynamic threads using the heap allocator */ Thread *tp1 = chThdCreateFromHeap(NULL, WA_SIZE, NORMALPRIO-2, thread1, chp); Thread *tp2 = chThdCreateFromHeap(NULL, WA_SIZE, NORMALPRIO, thread2, chp); Thread *tp3 = chThdCreateFromHeap(NULL, WA_SIZE, NORMALPRIO-1, thread3, chp); Thread *tp4 = chThdCreateFromHeap(NULL, WA_SIZE, NORMALPRIO-3, thread4, chp); chThdSleepUntil(chTimeNow() + MS2ST(500)); /* * Try to kill threads */ chThdTerminate(tp1); chThdTerminate(tp2); chThdTerminate(tp3); chThdTerminate(tp4); /* * Wait for the thread to terminate (if it has not terminated * already) then get the thread exit message (msg) and returns the * terminated thread memory to the heap. */ msg_t msg = chThdWait(tp1); msg = chThdWait(tp2); msg = chThdWait(tp3); msg = chThdWait(tp4); }
/** * Kills previously spawned threads */ void KillMavlinkThreads(void) { clearGlobalFlag(GlobalFlags.tlm_link_ready); chThdTerminate(linkout_tp); chThdTerminate(linkin_tp); chThdWait(linkout_tp); chThdWait(linkin_tp); }
/* * Terminate autopilot threads * Wait until proper stop */ void pprz_terminate_autopilot_threads(void) { if (apThdPtr != NULL) { chThdTerminate(apThdPtr); chThdWait(apThdPtr); apThdPtr = NULL; } if (fbwThdPtr != NULL) { chThdTerminate(fbwThdPtr); chThdWait(fbwThdPtr); fbwThdPtr = NULL; } }
static void term_can_tread(Thread* tp){ if (tp != NULL){ chThdTerminate(tp); chThdWait(tp); } CanStopLocal(); }
static int init(t_hydra_console *con, t_tokenline_parsed *p) { mode_config_proto_t* proto = &con->mode->proto; int tokens_used = 0; proto->dev_function = NFC_TYPEA; if(init_gpio(con) == FALSE) { deinit_gpio(); return tokens_used; } if(key_sniff_thread != NULL) { chThdTerminate(key_sniff_thread); chThdWait(key_sniff_thread); key_sniff_thread = NULL; } key_sniff_thread = chThdCreateStatic(key_sniff_mem, sizeof(key_sniff_mem), HIGHPRIO, key_sniff, NULL); /* Process cmdline arguments, skipping "nfc". */ if(p != NULL) { tokens_used = 1 + exec(con, p, 1); } return tokens_used; }
void Blinker::stop(void){ ready = false; if (nullptr != redworker) { chThdTerminate(redworker); chThdWait(redworker); redworker = nullptr; } if (nullptr != blueworker) { chThdTerminate(blueworker); chThdWait(blueworker); blueworker = nullptr; } }
//----------------------------------------------------------------------------- int kuroBoxStop(void) { kbg_setLED3(1); extStop(&EXTD1); kuroBoxExternalDisplayStop(); kuroBoxConfigStop(); kuroBoxMenuStop(); kuroBoxWriterStop(); kuroBoxVectorNavStop(&VND1); kuroBoxTimeStop(); kuroBoxGPSStop(); kuroBoxButtonsStop(); kuroBoxScreenStop(); kuroBoxADCStop(); #ifdef HAVE_BLINK_THREAD chThdTerminate(blinkerThread); chThdWait(blinkerThread); #endif // HAVE_BLINK_THREAD sdcStop(&SDCD1); spiStop(&SPID1); kuroBoxSerialStop(); chSysDisable(); kbg_setLED1(0); kbg_setLED2(0); kbg_setLED3(0); return KB_OK; }
/* * @brief Private function for signaling critical tasks for shutdown and * waiting for them to finish execution. */ static void vSystemTerminateCriticalTasks(void) { /* Check if the base pointer in null on not */ if (base_subscription != NULL) { /* Base pointer is not null, search the list to find the end */ system_critical_subscription_t *tmp_sub = base_subscription; /* Set all critical thread to terminate */ while (tmp_sub != NULL) { chThdTerminate(tmp_sub->thread); tmp_sub = tmp_sub->next; } /* All threads signaled, wait for termination */ tmp_sub = base_subscription; while (tmp_sub != NULL) { chThdWait(tmp_sub->thread); tmp_sub = tmp_sub->next; } /* All threads terminated, clear the list */ base_subscription = NULL; } }
/*-----------------------------------------------------------------------------*/ void StopTask(tfunc_t pf) { int16_t i; Thread *tp; for(i=0;i<RC_TASKS;i++) { if( rcTasks[i].pf == pf ) { if( rcTasks[i].tp != NULL ) { tp = rcTasks[i].tp; // We cannot stop ourself if( tp == chThdSelf() ) return; // Set terminate flag - the other thread has to see this and exit chThdTerminate( tp ); // this will cause a higher priority task to run immeadiately chThdResume( tp ); // wait for termination chThdWait( tp ); // may already be NULL for high priority task rcTasks[i].tp = NULL; rcTasks[i].pf = NULL; } } } }
void ThreadReference::requestTerminate(void) { chDbgAssert(thread_ref != NULL, "not referenced"); chThdTerminate(thread_ref); }
static void term_usb_tread(Thread* tp){ if (tp != NULL){ chThdTerminate(tp); chThdWait(tp); } UsbStopLocal(); }
/** * @brief Sets a termination request in all the test-spawned threads. */ void test_terminate_threads(void) { int i; for (i = 0; i < MAX_THREADS; i++) if (threads[i]) chThdTerminate(threads[i]); }
// Caller: control thread (highest priority) msg_t SampleBuffer::flush_and_close() { if (tp_write_thread_) { chThdTerminate(tp_write_thread_); return chThdWait(tp_write_thread_); } return -1; }
void sigint (void){ if (current_cmd_tp != NULL){ chThdTerminate(current_cmd_tp); chThdWait(current_cmd_tp); current_cmd_tp = NULL; } cli_print("^C pressed\n\r"); }
void osDeleteTask(OsTask *task) { //Delete the specified task if(task == NULL) chThdExit(RDY_OK); else chThdTerminate(task->tp); }
void TimeKeeper::stop(void) { ready = false; chThdTerminate(worker); ppstimesync_sem.signal(); /* speed up termination */ chThdWait(worker); worker = nullptr; Exti.pps(false); }
void mp45dt02Shutdown(void) { i2sStopExchange(&MP45DT02_I2S_DRIVER); i2sStop(&MP45DT02_I2S_DRIVER); chThdTerminate(pMp45dt02ProcessingThd); chSemReset(&mp45dt02ProcessingSem, 1); chThdWait(pMp45dt02ProcessingThd); pMp45dt02ProcessingThd = NULL; }
void wf_terminate (void) { struct wrapper_msg_base msg; if (workerThread) { msg.action = eTERMINATE; chThdTerminate(workerThread); chMsgSend(workerThread, (msg_t) &msg); } return; }
void Blinker::start(void){ if (nullptr != this->redworker) { chThdTerminate(this->redworker); chThdWait(this->redworker); } this->redworker = chThdCreateStatic(RedBlinkThreadWA, sizeof(RedBlinkThreadWA), NORMALPRIO - 10, RedBlinkThread, nullptr); osalDbgCheck(nullptr != this->redworker); if (nullptr != this->blueworker) { chThdTerminate(this->blueworker); chThdWait(this->blueworker); } this->blueworker = chThdCreateStatic(BlueBlinkThreadWA, sizeof(BlueBlinkThreadWA), NORMALPRIO - 10, BlueBlinkThread, nullptr); osalDbgCheck(nullptr != this->blueworker); ready = true; }
/** * @brief Thread termination. * @note The thread is not really terminated but asked to terminate which * is not compliant. */ osStatus osThreadTerminate(osThreadId thread_id) { if (thread_id == osThreadGetId()) { /* Note, no memory will be recovered unless a cleaner thread is implemented using the registry.*/ chThdExit(0); } chThdTerminate(thread_id); chThdWait((thread_t *)thread_id); return osOK; }
/** * * @brief Destroys an instance of @p struct pios_thread. * * @param[in] threadp pointer to instance of @p struct pios_thread * */ void PIOS_Thread_Delete(struct pios_thread *threadp) { if (threadp == NULL) { chThdExit(0); } else { chThdTerminate(threadp->threadp); chThdWait(threadp->threadp); } }
//----------------------------------------------------------------------------- int kuroBoxWriterStop(void) { chThdTerminate(loggerThread); chThdTerminate(writerThread); chThdWait(loggerThread); // this thread may be in its own sleep chSysLock(); if (writerThreadForSleep) { writerThreadForSleep->p_u.rdymsg = (msg_t)10; // just a random non-0 chSchReadyI(writerThreadForSleep); writerThreadForSleep = NULL; } chSysUnlock(); chThdWait(writerThread); return KB_OK; }
void oscAutosendEnable(bool enabled) { if (enabled && osc.autosendThd == 0) { // load up the interval and destination, and start the thread oscAutosendInterval(); oscAutosendDestination(); osc.autosendThd = chThdCreateStatic(waAutosendThd, sizeof(waAutosendThd), NORMALPRIO - 2, OscAutosendThread, NULL); } else if (!enabled && osc.autosendThd != 0) { chThdTerminate(osc.autosendThd); osc.autosendThd = 0; } }
static clarityError clarityMgmtShutdown(void) { if (mgmtData.activeProcesses != 0) { return CLARITY_ERROR_STATE; } #if 0 clarityMgmtMtxLock(); chThdTerminate(connectivityMonThd); clarityMgmtMtxUnlock(); chThdWait(connectivityMonThd); #endif if (responseMonThd != NULL) { chThdTerminate(responseMonThd); chThdWait(responseMonThd); } return CLARITY_SUCCESS; }
bool oscUsbEnable(bool on) { if (on && osc.usbThd == 0) { chMtxInit(&osc.usb.lock); osc.usb.sendMessage = usbserialWriteSlip; osc.usbThd = chThdCreateStatic(waUsbThd, sizeof(waUsbThd), NORMALPRIO, OscUsbSerialThread, NULL); return true; } if (!on && osc.usbThd != 0) { chThdTerminate(osc.usbThd); osc.usbThd = 0; return true; } return false; }
/** \brief DeInit/Cleanup HydraNFC functions * * \param con t_hydra_console*: hydra console (optional can be NULL if unused) * \return void * */ void hydranfc_cleanup(t_hydra_console *con) { (void)con; if(key_sniff_thread != NULL) { chThdTerminate(key_sniff_thread); chThdWait(key_sniff_thread); key_sniff_thread = NULL; } bsp_spi_deinit(BSP_DEV_SPI2); extStop(&EXTD1); /* deinit GPIO config (reinit using hydrabus_init() */ deinit_gpio(); }
static void wavePlayEventHandler(uint8_t evt) { static uint8_t prevEvt=0; if (evt && evt < 15) if (prevEvt!=evt) { prevEvt=evt; codec_sendBeep(); } switch (evt) { case BTN_RIGHT: lcd_cls(); ui_displayPreviousMenu(); break; case BTN_LEFT: chThdTerminate(playerThread); chThdWait(playerThread); playerThread=NULL; break; case BTN_MID_DOWN: vol--; if (vol < 150) vol=150; codec_volCtl(vol); break; case BTN_MID_UP: vol++; if (vol > 220) vol=220; codec_volCtl(vol); break; case BTN_MID_SEL: if (!pause) { pause=1; ui_drawBottomBar("Stop", "Play", "Exit"); } else { pause=0; ui_drawBottomBar("Stop", "Pause", "Exit"); } codec_pauseResumePlayback(pause); break; } }
//----------------------------------------------------------------------------- int kuroBoxExternalDisplayStop(void) { chThdTerminate(eDisplayThread); chSysLock(); if (eDisplayThreadForSleep) { eDisplayThreadForSleep->p_u.rdymsg = (msg_t)1; // just a random non-0 chSchReadyI(eDisplayThreadForSleep); eDisplayThreadForSleep = NULL; } chSysUnlock(); chThdWait(eDisplayThread); eDisplayThread = NULL; return KB_OK; }
bool oscUdpEnable(bool on) { if (on && osc.udpThd == 0) { osc.udpListenPort = OSC_UDP_DEFAULT_PORT; oscUdpReplyPort(); osc.udp.sendMessage = oscSendMessageUDP; chMtxInit(&osc.udp.lock); osc.udpThd = chThdCreateStatic(waUdpThd, sizeof(waUdpThd), NORMALPRIO, OscUdpThread, NULL); return true; } if (!on && osc.udpThd != 0) { chThdTerminate(osc.udpThd); osc.udpThd = 0; return true; } return false; }
static void bridge(t_hydra_console *con) { uint8_t tx_data[UART_BRIDGE_BUFF_SIZE]; uint8_t bytes_read; //uint8_t bytes_read; mode_config_proto_t* proto = &con->mode->proto; cprintf(con, "Interrupt by pressing user button.\r\n"); cprint(con, "\r\n", 2); thread_t *bthread = chThdCreateFromHeap(NULL, CONSOLE_WA_SIZE, "bridge_thread", LOWPRIO, bridge_thread, con); while(!USER_BUTTON) { bytes_read = chnReadTimeout(con->sdu, tx_data, UART_BRIDGE_BUFF_SIZE, US2ST(100)); if(bytes_read > 0) { bsp_uart_write_u8(proto->dev_num, tx_data, bytes_read); } } chThdTerminate(bthread); chThdWait(bthread); }