/** * Install a signal handler for the given signal. This can't be called once the * thread has stared. */ bool SignalThread::InstallSignalHandler(int signal, SignalHandler *handler) { if (BlockSignal(signal)) { ola::STLReplaceAndDelete(&m_signal_handlers, signal, handler); return true; } return false; }
int main(void) { sigset_t set; sigset_t bset; sigemptyset(&set); sigaddset(&set, SIGINT); sigprocmask(SIG_BLOCK, &set, NULL); if (SIG_ERR == signal(SIGINT, IntHandler)) { perror("Install SIGINT error:\n"); } if (SIG_ERR == signal(SIGQUIT, QuitHandler)) { perror("Install SIGINT error:\n"); } BlockSignal(); while (1) { sigpending(&bset); PrintSet(&bset); sleep(2); } return 0; }
/** * Exposed function, that enables user to schedule new thread. You can also \ * specify priority via @pr parameter. **/ int UThreadSchedThread(void (*func)(void *),void * argument,int pr,unsigned int stacksize) { if(uThreadContext->isInitialized == 0) { return -1; } ThreadBlock * threadBlock = NULL; if(stacksize == 0) { threadBlock = CreateThread(func,argument,uThreadContext->uThreadOptions.stackSize); } else { threadBlock = CreateThread(func,argument,stacksize); } BlockSignal(TIMER_SIGNAL_NO); RegisterThreadBlockRelation(threadBlock); switch(pr) { case PRIORITY_HIGH: uThreadContext->queueHeads[QUEUE_HIGH_PRIORITY] = AddThreadBlockToList(uThreadContext->queueHeads[QUEUE_HIGH_PRIORITY],threadBlock); break; case PRIORITY_MEDIUM: uThreadContext->queueHeads[QUEUE_MEDIUM_PRIORITY] = AddThreadBlockToList(uThreadContext->queueHeads[QUEUE_MEDIUM_PRIORITY],threadBlock); break; case PRIORITY_LOW: uThreadContext->queueHeads[QUEUE_LOW_PRIORITY] = AddThreadBlockToList(uThreadContext->queueHeads[QUEUE_LOW_PRIORITY],threadBlock); break; } ReScheduleThreads(0); UnblockSignal(TIMER_SIGNAL_NO); return threadBlock->id; }
void GtkMenuItem::SetStateImpl(bool newState) { if (!this->IsCheck()) return; std::vector< ::GtkMenuItem*>::iterator i = this->nativeItems.begin(); while (i != this->nativeItems.end()) { ::GtkMenuItem* nativeItem = *i++; BlockSignal(nativeItem, this); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(nativeItem), newState); UnblockSignal(nativeItem, this); } }
/** * Exits running thread. * Blocks timer signal, to prevent context switch, while we * are removing this thread. **/ static void ExitRunningThread() { BlockSignal(TIMER_SIGNAL_NO); ReScheduleThreads(1); }