コード例 #1
0
void test_case_boosted_thread_loop(void)
{
    boost::thread event_thread(&event_loop);
    signal(SIGINT, &event_loop_trap);

    uint8_t sched_policy = SCHED_FIFO;

    struct sched_param thread_param;
    thread_param.sched_priority = sched_get_priority_max(sched_policy); //select highest prio for scheduler

    pthread_t threadID = (pthread_t) event_thread.native_handle();
    int retcode;
    if ((retcode = pthread_setschedparam(threadID, sched_policy, &thread_param)) != 0)
    {
        errno = retcode;
        perror("pthread_setschedparam");
    }

    std::cout << "Boosted Thread: ";
    std::cout << "policy=" << ((sched_policy == SCHED_FIFO)  ? "SCHED_FIFO" :
                               (sched_policy == SCHED_RR)    ? "SCHED_RR" :
                               (sched_policy == SCHED_OTHER) ? "SCHED_OTHER" :
                               "???")
              << ", priority="  << thread_param.sched_priority
              << " (min/max: "  << sched_get_priority_min(sched_policy) << "/"
              << sched_get_priority_max(sched_policy) << ")" << std::endl;

    event_thread.join();

    std::cout << (float)( (ts_end.tv_sec - ts_beg.tv_sec)  + (ts_end.tv_nsec - ts_beg.tv_nsec) / 1e9)
              << " s." << std::endl;;

}
コード例 #2
0
void test_case_sleep_loop(void)
{

    boost::thread event_thread(&event_loop);
    signal(SIGINT, &event_loop_trap);

    event_thread.join();

    std::cout << (float)( (ts_end.tv_sec - ts_beg.tv_sec)  + (ts_end.tv_nsec - ts_beg.tv_nsec) / 1e9)
              << " s." << std::endl;;
}
コード例 #3
0
ファイル: ws28xx-pru0.c プロジェクト: jadonk/pruduino
int main(int argc, char *argv[])
{
	/* enable OCP master port */
	PRUCFG_SYSCFG &= ~SYSCFG_STANDBY_INIT;
	sc_printf("PRU0: Starting Lighting Firmware");

	PT_INIT(&pt_event);
	PT_INIT(&pt_prompt);
	PT_INIT(&pt_tx);

	resource_setup();
	rx_in = rx_out = rx_cnt = 0;
	tx_in = tx_out = tx_cnt = 0;

	for (;;) {
		event_thread(&pt_event);
		tx_thread(&pt_tx);
		prompt_thread(&pt_prompt);
	}
}
コード例 #4
0
ファイル: schedule.c プロジェクト: dankamongmen/libtorque
// On entry, cancellation ought be disabled, and execution restricted to a
// single processor via hard affinity settings (FIXME: verify?).
static void *
thread(void *void_marshal){
	tguard *marshal = void_marshal;
	evhandler *ev = NULL;
	torque_ctx *ctx;

	ctx = marshal->ctx;
	if(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,NULL)){
		goto earlyerr;
	}
	if((ev = create_evhandler(&ctx->evq,&marshal->stack)) == NULL){
		goto earlyerr;
	}
	if(pthread_mutex_lock(&marshal->lock)){
		destroy_evhandler(ctx,ev);
		goto earlyerr;
	}
	if(marshal->ctx->ev == NULL){
		marshal->ctx->ev = ev;
	}else{
		ev->nexttid = marshal->ctx->ev->nexttid;
	}
	marshal->ctx->ev->nexttid = pthread_self();
	marshal->status = THREAD_STARTED;
	pthread_cond_broadcast(&marshal->cond);
	pthread_mutex_unlock(&marshal->lock);
	// After this point, anything we wish to use from marshal must've been
	// copied onto our own stack (hence broadcasting prior to unlocking).
	event_thread(ctx,ev);
	// Should never reach here (event_thread() is marked ((noreturn)))
	destroy_evhandler(ctx,ev);
	return NULL;

earlyerr:
	pthread_mutex_lock(&marshal->lock); // continue regardless
	marshal->status = THREAD_PREFAIL;
	pthread_cond_broadcast(&marshal->cond);
	pthread_mutex_unlock(&marshal->lock);
	destroy_evhandler(ctx,ev);
	return NULL;
}
コード例 #5
0
ファイル: demo_event.c プロジェクト: Ascronia/fieldtrip
int main(int argc, char *argv[]) {
	host_t host;
    check_datatypes();

	if (argc>2) {
		sprintf(host.name, argv[1]);
		host.port = atoi(argv[2]);
	}
	else {
		sprintf(host.name, DEFAULT_HOSTNAME);
		host.port = DEFAULT_PORT;
	}

    fprintf(stderr, "demo_event: host.name =  %s\n", host.name);
    fprintf(stderr, "demo_event: host.port =  %d\n", host.port);

	/* start the acquisition */
	event_thread((void *)(&host));

	return 0;
}