void stop_start_thread() { pthread_attr_t attr; pthread_attr_init(&attr); /* Cancel */ cancel_thread(); pthread_create(&threadid, &attr, &timer_runner, NULL); }
static void delete_event( GtkWidget *widget, GdkEvent *event, gpointer data ) { LOG(LOG_DEBUG, "IN : delete_event()"); cancel_thread(NULL, NULL); LOG(LOG_DEBUG, "OUT : delete_event()"); }
int discovery_service_stop(discovery_service *svc) { JNXCHECK(svc); svc->isrunning = 0; if (svc->update_thread != NULL) { cancel_thread(&svc->update_thread); } send_stop_packet(svc); pthread_join(svc->listening_thread->system_thread, NULL); jnx_socket_destroy(&svc->sock_send); jnx_socket_udp_listener_destroy(&svc->udp_listener); return 0; }
void cleanup_io_work_queue_threads(struct tcmu_device *dev) { struct tcmur_handler *r_handler = tcmu_get_runner_handler(dev); struct tcmur_device *rdev = tcmu_get_daemon_dev_private(dev); struct tcmu_io_queue *io_wq = &rdev->work_queue; int i, nr_threads = r_handler->nr_threads; if (!io_wq->io_wq_threads) { return; } for (i = 0; i < nr_threads; i++) { if (io_wq->io_wq_threads[i]) { cancel_thread(io_wq->io_wq_threads[i]); } } }
int threads ( char *args[] ) { thread_t thread[THR_NUM]; int i; sleep.sec = 1; sleep.nsec = 0; for ( i = 0; i < THR_NUM; i++ ) create_thread ( simple_thread, (void *) i, SCHED_FIFO, THR_DEFAULT_PRIO - 1, &thread[i] ); delay ( &sleep ); delay ( &sleep ); cancel_thread ( &thread[0] ); print ( "Thread 0 canceled!\n" ); for ( i = 0; i < THR_NUM; i++ ) wait_for_thread ( &thread[i], IPC_WAIT ); return 0; }
void timer_write( unsigned int address, unsigned int value) { //zpudebug("Timer write, 0x%08x = 0x%08x\n",address,value); int reset_thread=0; switch(address & 0xF) { case 0: ctrl = value; /* printf("Timer bits: EN %d CCM %d DIR %d IEN %d\n", !!(ctrl & BIT(TCTLENA)), !!(ctrl & BIT(TCTLCCM)), !!(ctrl & BIT(TCTLDIR)), !!(ctrl & BIT(TCTLIEN))); */ switch (bit_range(ctrl,6,4)) { case 0: timer_prescaler=0; break; case 1: timer_prescaler=1; break; case 2: timer_prescaler=2; break; case 3: timer_prescaler=4; break; case 4: timer_prescaler=8; break; case 5: timer_prescaler=32; break; case 6: timer_prescaler=128; break; case 7: timer_prescaler=512; break; } //printf("Timer prescaler is now %d\n",timer_prescaler); timer_prescaleCount=0; break; case 4: // Counter //printf("# Timer: set counter to %04x\n",value); timer_cnt = value & 0xffff; reset_thread=1; break; case 8: // Compare //printf("Timer: set compare to %04x\n",value); timer_match = value & 0xffff; reset_thread=1; break; case 12: break; } // Compute wall time. if (ctrl & BIT(TCTLENA) && ctrl & BIT(TCTLCCM) && ctrl & BIT(TCTLDIR) && ctrl & BIT(TCTLIEN)) { //fprintf(stderr,"TIMER: Using wall clock for timer interrupt\n"); // Compute delay unsigned long long cl = zpuinoclock / (timer_prescaler? (timer_prescaler<<1) : 1); unsigned long long count = (timer_match+1); count *= 1000000000ULL; count/=cl; //fprintf(stderr,"Timer delay is %llu nanoseconds\n",count); sleepreq.tv_sec = count/1000000000; sleepreq.tv_nsec = count% 1000000000; if (threadid==-1 || reset_thread) stop_start_thread(); } else { if (!(ctrl&BIT(TCTLENA) & (ctrl&BIT(TCTLIEN)))) { // Cancel thread cancel_thread(); } } }