这篇教程C++ timer_create函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中timer_create函数的典型用法代码示例。如果您正苦于以下问题:C++ timer_create函数的具体用法?C++ timer_create怎么用?C++ timer_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了timer_create函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: settimeout/* Start the timeout after which we'll receive a SIGALRM. Round DURATION up to the next representable value. Treat out-of-range values as if they were maximal, as that's more useful in practice than reporting an error. '0' means don't timeout. */static voidsettimeout (double duration, bool warn){/* timer_settime() provides potentially nanosecond resolution. setitimer() is more portable (to Darwin for example), but only provides microsecond resolution and thus is a little more awkward to use with timespecs, as well as being deprecated by POSIX. Instead we fallback to single second resolution provided by alarm(). */#if HAVE_TIMER_SETTIME struct timespec ts = dtotimespec (duration); struct itimerspec its = { {0, 0}, ts }; timer_t timerid; if (timer_create (CLOCK_REALTIME, NULL, &timerid) == 0) { if (timer_settime (timerid, 0, &its, NULL) == 0) return; else { if (warn) error (0, errno, _("warning: timer_settime")); timer_delete (timerid); } } else if (warn && errno != ENOSYS) error (0, errno, _("warning: timer_create"));#endif unsigned int timeint; if (UINT_MAX <= duration) timeint = UINT_MAX; else { unsigned int duration_floor = duration; timeint = duration_floor + (duration_floor < duration); } alarm (timeint);}
开发者ID:coreutils,项目名称:coreutils,代码行数:45,
示例2: mainint main(int argc, char *argv[]){ struct sigevent ev; timer_t tid; struct itimerspec its; ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = SIGTOTEST; if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { perror("timer_create() did not return success/n"); return PTS_UNRESOLVED; } if (timer_delete(tid) != 0) { perror("timer_delete() did not return success/n"); return PTS_UNRESOLVED; } its.it_interval.tv_sec = 0; its.it_interval.tv_nsec = 0; its.it_value.tv_sec = TIMERSEC; its.it_value.tv_nsec = 0; if (timer_settime(tid, 0, &its, NULL) == -1) { if (errno==EINVAL) { printf("Test PASSED/n"); return PTS_PASS; } else { printf("errno!=EINVAL after a timer_delete()/n"); return PTS_FAIL; } } else { printf("timer_settime() did not fail after timer_delete()/n"); return PTS_FAIL; } printf("This code should not be executed/n"); return PTS_UNRESOLVED;}
开发者ID:chathhorn,项目名称:posixtestsuite,代码行数:40,
示例3: mainintmain(int argc, char **argv){ struct sigevent ev; struct itimerspec ts; sigset_t set; timer_t tid; char *cmd = argv[0]; ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = SIGUSR1; if (timer_create(CLOCK_REALTIME, &ev, &tid) == -1) { (void) fprintf(stderr, "%s: cannot create CLOCK_HIGHRES " "timer: %s/n", cmd, strerror(errno)); exit(EXIT_FAILURE); } (void) sigemptyset(&set); (void) sigaddset(&set, SIGUSR1); (void) sigprocmask(SIG_BLOCK, &set, NULL); ts.it_value.tv_sec = 1; ts.it_value.tv_nsec = 0; ts.it_interval.tv_sec = 0; ts.it_interval.tv_nsec = NANOSEC / 2; if (timer_settime(tid, TIMER_RELTIME, &ts, NULL) == -1) { (void) fprintf(stderr, "%s: timer_settime() failed: %s/n", cmd, strerror(errno)); exit(EXIT_FAILURE); } for (;;) { (void) sigwait(&set); } /*NOTREACHED*/ return (0);}
开发者ID:AlainODea,项目名称:illumos-gate,代码行数:40,
示例4: mainint main(){ struct itimerspec ts; struct sigaction sa; struct sigevent sev; timer_t tid; int j; /* Establish handler for notification signal */ sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = handler; sigemptyset(&sa.sa_mask); if (sigaction(TIMER_SIG, &sa, NULL) == -1){ perror("sigaction"); } /* Create and start timer */ ts.it_interval.tv_sec = 2; ts.it_interval.tv_nsec = 10; ts.it_value.tv_sec = 1; ts.it_value.tv_nsec = 20; /* pass timer id to handler */ sev.sigev_value.sival_ptr = &tid; sev.sigev_notify = SIGEV_SIGNAL; /* Notify via signal */ sev.sigev_signo = SIGRTMAX; /* Notify using this signal */ if (timer_create(CLOCK_REALTIME, &sev, &tid) == -1){ perror("timer_create"); exit(1); } if (timer_settime(tid, 0, &ts, NULL) == -1) perror("timer_settime"); for (;;) /* Wait for incoming timer signals */ pause();}
开发者ID:md-jamal,项目名称:Linuxpro,代码行数:40,
示例5: dynticks_start_timerstatic int dynticks_start_timer(struct qemu_alarm_timer *t){ struct sigevent ev; timer_t host_timer; struct sigaction act; sigfillset(&act.sa_mask); act.sa_flags = 0; act.sa_handler = host_alarm_handler; sigaction(SIGALRM, &act, NULL); /* * Initialize ev struct to 0 to avoid valgrind complaining * about uninitialized data in timer_create call */ memset(&ev, 0, sizeof(ev)); ev.sigev_value.sival_int = 0; ev.sigev_notify = SIGEV_SIGNAL;#ifdef SIGEV_THREAD_ID if (qemu_signalfd_available()) { ev.sigev_notify = SIGEV_THREAD_ID; ev._sigev_un._tid = qemu_get_thread_id(); }#endif /* SIGEV_THREAD_ID */ ev.sigev_signo = SIGALRM; if (timer_create(CLOCK_REALTIME, &ev, &host_timer)) { perror("timer_create"); /* disable dynticks */ fprintf(stderr, "Dynamic Ticks disabled/n"); return -1; } t->timer = host_timer; return 0;}
开发者ID:MatzeB,项目名称:qemu-fixes,代码行数:40,
示例6: fprintfasyncOp *selectNewAsyncOp(asyncBase *base){ asyncOp *op = new asyncOp; if (op) { struct sigevent sEvent; op->internalBuffer = 0; op->internalBufferSize = 0; op->list = 0; op->next = 0; op->prev = 0; sEvent.sigev_notify = SIGEV_SIGNAL; sEvent.sigev_signo = SIGRTMIN; sEvent.sigev_value.sival_ptr = op; if (timer_create(CLOCK_REALTIME, &sEvent, &op->timerId) == -1) { fprintf(stderr, " * newSelectOp: timer_create error %s/n", strerror(errno)); } } return op;}
开发者ID:eXtremal-ik7,项目名称:libp2p,代码行数:22,
示例7: jl_profile_start_timerDLLEXPORT int jl_profile_start_timer(void){ struct sigevent sigprof; struct sigaction sa; sigset_t ss; // Make sure SIGUSR2 is unblocked sigemptyset(&ss); sigaddset(&ss, SIGUSR2); if (sigprocmask(SIG_UNBLOCK, &ss, NULL) == -1) return -4; // Establish the signal handler memset(&sa, 0, sizeof(struct sigaction)); sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = profile_bt; sigemptyset(&sa.sa_mask); if (sigaction(SIGUSR2, &sa, NULL) == -1) return -1; // Establish the signal event memset(&sigprof, 0, sizeof(struct sigevent)); sigprof.sigev_notify = SIGEV_SIGNAL; sigprof.sigev_signo = SIGUSR2; sigprof.sigev_value.sival_ptr = &timerprof; if (timer_create(CLOCK_REALTIME, &sigprof, &timerprof) == -1) return -2; // Start the timer itsprof.it_interval.tv_sec = nsecprof/GIGA; itsprof.it_interval.tv_nsec = nsecprof%GIGA; itsprof.it_value.tv_sec = nsecprof/GIGA; itsprof.it_value.tv_nsec = nsecprof%GIGA; if (timer_settime(timerprof, 0, &itsprof, NULL) == -1) return -3; running = 1; return 0;}
开发者ID:Clemens-H,项目名称:julia,代码行数:39,
示例8: streamVideovoid streamVideo(send_frame_data_t *data) { // The following snippet is used to create and start a new timer that runs // every 40 ms. deleteTimer(data); struct sigevent play_event; struct itimerspec play_interval; memset(&play_event, 0, sizeof(play_event)); play_event.sigev_notify = SIGEV_THREAD; play_event.sigev_value.sival_ptr = data; play_event.sigev_notify_function = send_frame; play_interval.it_interval.tv_sec = 0; play_interval.it_interval.tv_nsec = 40 * 1000000; // 40 ms in ns play_interval.it_value.tv_sec = 0; play_interval.it_value.tv_nsec = 1; // can't be zero timer_create(CLOCK_REALTIME, &play_event, &data->play_timer); timer_settime(data->play_timer, 0, &play_interval, NULL);}
开发者ID:NeilCBAndrews,项目名称:CS317Assignment3,代码行数:22,
示例9: http_cache_initerr_t http_cache_init(struct ip_addr server, const char *path, void (*callback)(void)){ struct timer *cache_timer; /* timer for triggering cache timeouts */ init_callback = callback; /* FIXME: Start the trace */#if ENABLE_WEB_TRACING printf("Starting tracing/n"); errval_t err = trace_control(TRACE_EVENT(TRACE_SUBSYS_NET, TRACE_EVENT_NET_START, 0), TRACE_EVENT(TRACE_SUBSYS_NET, TRACE_EVENT_NET_STOP, 0), 0); if(err_is_fail(err)) { USER_PANIC_ERR(err, "trace_control failed"); } trace_event(TRACE_SUBSYS_NET, TRACE_EVENT_NET_START, 0);#else // ENABLE_WEB_TRACING printf("Tracing not enabled/n");#endif // ENABLE_WEB_TRACING my_nfs_client = nfs_mount(server, path, mount_callback, NULL); assert(my_nfs_client != NULL); /* creating the empty cache */ cache_table = NULL; create_404_page_cache(); cache_timer = timer_create(MAX_STALENESS, true, cache_timeout_event, cache_table); assert (cache_timer != NULL); if (cache_timer == NULL) { printf ("http_cache_init failed in timer_create/n"); return ERR_MEM; } timer_start(cache_timer); DEBUGPRINT ("http_cache_init done/n"); return ERR_OK;} /* end function: http_cache_init */
开发者ID:CoryXie,项目名称:BarrelfishOS,代码行数:39,
示例10: ChannelCreatevoid *time_update( void *ptr ){ struct sigevent event; struct itimerspec itime; timer_t timer_id; int chid, rcvid; my_message_t msg; chid = ChannelCreate(0); event.sigev_notify = SIGEV_PULSE; event.sigev_coid = ConnectAttach(ND_LOCAL_NODE, 0, chid, _NTO_SIDE_CHANNEL, 0); event.sigev_priority = getprio(0); event.sigev_code = MY_PULSE_CODE; timer_create(CLOCK_REALTIME, &event, &timer_id); itime.it_value.tv_sec = 0; /* 100 ms = .1 secs */ itime.it_value.tv_nsec = 100000000; itime.it_interval.tv_sec = 0; /* 100 ms = .1 secs */ itime.it_interval.tv_nsec = 100000000; timer_settime(timer_id, 0, &itime, NULL); // This for loop will update the global_time for every 100 ms which is 1 minute in simulation time. for (;;) { rcvid = MsgReceive(chid, &msg, sizeof(msg), NULL); if (rcvid == 0) { /* we got a pulse */ if (msg.pulse.code == MY_PULSE_CODE) { if (global_time > 0) global_time--; else break; //printf("we got a pulse from our timer and time = %d/n", global_time); } /* else other pulses ... */ } /* else other messages ... */ }}
开发者ID:rajeevakarv,项目名称:Bank_Model_QNX,代码行数:39,
示例11: set_timerstatic int set_timer(timer_t *tid, unsigned int timeout){ struct sigevent sigev = {}; struct itimerspec it = {}; sigev.sigev_notify = SIGEV_SIGNAL; sigev.sigev_signo = SIGRTMIN; sigev.sigev_value.sival_ptr = tid; if (timer_create(CLOCK_MONOTONIC, &sigev, tid)) { ploop_err(errno, "timer_create"); return -1; } it.it_value.tv_sec = timeout; it.it_value.tv_nsec = 0; if (timer_settime(*tid, 0, &it, NULL)) { ploop_err(errno, "timer_settime"); return -1; } return 0;}
开发者ID:avagin,项目名称:ploop,代码行数:22,
示例12: TESTTEST(time, timer_create) { sigevent_t se; memset(&se, 0, sizeof(se)); se.sigev_notify = SIGEV_THREAD; se.sigev_notify_function = NoOpNotifyFunction; timer_t timer_id; ASSERT_EQ(0, timer_create(CLOCK_MONOTONIC, &se, &timer_id)); pid_t pid = fork(); ASSERT_NE(-1, pid) << strerror(errno); if (pid == 0) { // Timers are not inherited by the child. ASSERT_EQ(-1, timer_delete(timer_id)); ASSERT_EQ(EINVAL, errno); _exit(0); } AssertChildExited(pid, 0); ASSERT_EQ(0, timer_delete(timer_id));}
开发者ID:LjBLincoln,项目名称:platform_bionic,代码行数:22,
示例13: sigemptysetAlarmTimer::AlarmTimer(void) :timerId(0),armed(false),expired(false) { /* Initialize the alarm timer class if this is the first one: */ if(numAlarmTimers==0) { /* Install the signal handler: */ struct sigaction sigAction; sigAction.sa_sigaction=signalHandler; sigemptyset(&sigAction.sa_mask); sigAction.sa_flags=SA_SIGINFO; sigaction(SIGRTMIN,&sigAction,NULL); } ++numAlarmTimers; /* Create a per-process timer: */ struct sigevent timerEvent; timerEvent.sigev_notify=SIGEV_SIGNAL; timerEvent.sigev_signo=SIGRTMIN; timerEvent.sigev_value.sival_ptr=this; timer_create(CLOCK_REALTIME,&timerEvent,&timerId); }
开发者ID:VisualIdeation,项目名称:Vrui,代码行数:22,
示例14: setTimerint setTimer(long long int duration_ns, TimerCallback callback, int signo){ printf("duration_ns = %lld/n", duration_ns); struct sigaction action; struct sigevent evp; struct itimerspec ispec; timer_t timerid = 0; memset(&action, 0, sizeof(action)); memset(&evp, 0, sizeof(evp)); /* set signal handler */ action.sa_sigaction = SignalHandler; action.sa_flags = SA_SIGINFO | SA_RESTART; sigemptyset(&action.sa_mask); if(sigaction(SIGRTMIN + 1, &action, NULL) < 0){ perror("sigaction error"); exit(1); } /* set intarval timer (10ms) */ evp.sigev_notify = SIGEV_SIGNAL; evp.sigev_signo = signo; evp.sigev_value.sival_ptr = (void*)(callback); if(timer_create(CLOCK_REALTIME, &evp, &timerid) < 0){ perror("timer_create error"); exit(1); } ispec.it_interval.tv_sec = 0; ispec.it_interval.tv_nsec = 0; // 10000000; One shot timer ispec.it_value.tv_sec = int(duration_ns / 1000000000LL); ispec.it_value.tv_nsec = int(duration_ns % 1000000000LL); if(timer_settime(timerid, 0, &ispec, NULL) < 0){ perror("timer_settime error"); exit(1); } return 0;}
开发者ID:hbjpn,项目名称:synthctrl,代码行数:39,
示例15: GKI_initvoid GKI_init(void){ pthread_mutexattr_t attr; tGKI_OS *p_os; memset (&gki_cb, 0, sizeof (gki_cb)); gki_buffer_init(); gki_timers_init(); alarm_service_init(); gki_cb.com.OSTicks = (UINT32) times(0); pthread_mutexattr_init(&attr);#ifndef __CYGWIN__ pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);#endif p_os = &gki_cb.os; pthread_mutex_init(&p_os->GKI_mutex, &attr); /* pthread_mutex_init(&GKI_sched_mutex, NULL); */#if (GKI_DEBUG == TRUE) pthread_mutex_init(&p_os->GKI_trace_mutex, NULL);#endif /* pthread_mutex_init(&thread_delay_mutex, NULL); */ /* used in GKI_delay */ /* pthread_cond_init (&thread_delay_cond, NULL); */ struct sigevent sigevent; memset(&sigevent, 0, sizeof(sigevent)); sigevent.sigev_notify = SIGEV_THREAD; sigevent.sigev_notify_function = (void (*)(union sigval))bt_alarm_cb; sigevent.sigev_value.sival_ptr = NULL; if (timer_create(CLOCK_REALTIME, &sigevent, &posix_timer) == -1) { ALOGE("%s unable to create POSIX timer: %s", __func__, strerror(errno)); timer_created = false; } else { timer_created = true; }}
开发者ID:daddy366,项目名称:anarchy-bluetooth-bluedroid,代码行数:39,
示例16: systimer_createstatic int systimer_create(systimer_t* id, unsigned int period, int oneshot, systimer_proc callback, void* cbparam){ struct sigevent sev; struct itimerspec tv; timer_context_t* ctx; ctx = (timer_context_t*)malloc(sizeof(timer_context_t)); if(!ctx) return -ENOMEM;; memset(ctx, 0, sizeof(timer_context_t)); ctx->callback = callback; ctx->cbparam = cbparam; memset(&sev, 0, sizeof(sev)); sev.sigev_notify = SIGEV_THREAD; sev.sigev_value.sival_ptr = ctx; sev.sigev_notify_function = timer_schd_worker; if(0 != timer_create(CLOCK_MONOTONIC, &sev, &ctx->timerId)) { free(ctx); return -errno; } tv.it_interval.tv_sec = period / 1000; tv.it_interval.tv_nsec = (period % 1000) * 1000000; // 10(-9)second tv.it_value.tv_sec = tv.it_interval.tv_sec; tv.it_value.tv_nsec = tv.it_interval.tv_nsec; if(0 != timer_settime(ctx->timerId, 0, &tv, NULL)) { timer_delete(ctx->timerId); free(ctx); return -errno; } *id = (systimer_t)ctx; return 0;}
开发者ID:xsmart,项目名称:sdk,代码行数:38,
示例17: rb_ports_sched_eventintrb_ports_sched_event(struct ev_entry *event, int when){ timer_t *id; struct sigevent ev; port_notify_t not; struct itimerspec ts; event->comm_ptr = rb_malloc(sizeof(timer_t)); id = event->comm_ptr; memset(&ev, 0, sizeof(ev)); ev.sigev_notify = SIGEV_PORT; ev.sigev_value.sival_ptr = ¬ memset(¬, 0, sizeof(not)); not.portnfy_port = pe; not.portnfy_user = event; if(timer_create(CLOCK_REALTIME, &ev, id) < 0) { rb_lib_log("timer_create: %s/n", strerror(errno)); return 0; } memset(&ts, 0, sizeof(ts)); ts.it_value.tv_sec = when; ts.it_value.tv_nsec = 0; if(event->frequency != 0) ts.it_interval = ts.it_value; if(timer_settime(*id, 0, &ts, NULL) < 0) { rb_lib_log("timer_settime: %s/n", strerror(errno)); return 0; } return 1;}
开发者ID:dwfreed,项目名称:charybdis,代码行数:38,
示例18: mainint main(void){ struct sigevent ev; timer_t tid; struct itimerspec its, oits; ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = SIGCONT; its.it_interval.tv_sec = 0; its.it_interval.tv_nsec = 0; its.it_value.tv_sec = TIMERSEC; its.it_value.tv_nsec = 0; if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { perror("timer_create() did not return success/n"); return PTS_UNRESOLVED; } if (timer_settime(tid, 0, &its, &oits) != 0) { perror("timer_settime() did not return success/n"); return PTS_UNRESOLVED; } if ((0 == oits.it_value.tv_sec) && (0 == oits.it_value.tv_nsec) && (0 == oits.it_interval.tv_sec) && (0 == oits.it_interval.tv_nsec)) { printf("Test PASSED/n"); return PTS_PASS; } printf("Test FAILED: value: tv_sec %d tv_nsec %d/n", (int)oits.it_value.tv_sec, (int)oits.it_value.tv_nsec); printf("Test FAILED: interval: tv_sec %d tv_nsec %d/n", (int)oits.it_interval.tv_sec, (int)oits.it_interval.tv_nsec); return PTS_FAIL;}
开发者ID:1587,项目名称:ltp,代码行数:38,
示例19: event_queue_add_timerint event_queue_add_timer(int eq, int *id, int sec) { static int timer_id = 0xffffff00; port_notify_t pnotif; struct sigevent sigev; itimerspec_t it; timer_t tid; timer_id++; pnotif.portnfy_port = eq; pnotif.portnfy_user = (void *) (long) timer_id; sigev.sigev_notify = SIGEV_PORT; sigev.sigev_value.sival_ptr = &pnotif; if (timer_create(CLOCK_REALTIME, &sigev, &tid) < 0) { uwsgi_error("timer_create()"); return -1; } it.it_value.tv_sec = sec; it.it_value.tv_nsec = 0; it.it_interval.tv_sec = sec; it.it_interval.tv_nsec = 0; if (timer_settime(tid, 0, &it, NULL) < 0) { uwsgi_error("timer_settime()"); return -1; } *id = timer_id; return *id;}
开发者ID:sashka,项目名称:uwsgi,代码行数:38,
示例20: utimerutimer_t* utimer( socket_t* socket, packet_t* packet, timer_type_t type){ utimer_t* new_timer = calloc(1, sizeof(utimer_t)); new_timer->event = calloc(1, sizeof(struct sigevent)); new_timer->event->sigev_notify = SIGEV_THREAD; new_timer->event->sigev_notify_function = socket_timer_handler; new_timer->event->sigev_notify_attributes = NULL; new_timer->event->sigev_signo = RUDP_SOCKET_SIGNAL; new_timer->event->sigev_value.sival_ptr = new_timer; new_timer->socket = socket; new_timer->packet = packet; new_timer->type = type; timer_create(CLOCK_REALTIME, new_timer->event, &new_timer->timer); debug_print("utimer(): %p/n", new_timer); return new_timer;}
开发者ID:AnwarMohamed,项目名称:librudp,代码行数:23,
示例21: MW_setTaskPeriodvoid MW_setTaskPeriod(double periodInSeconds, int sigNo){ timer_t timerId; struct sigevent sev; struct itimerspec its; int ret; /* Create a timer */ sev.sigev_notify = SIGEV_SIGNAL; sev.sigev_signo = sigNo; sev.sigev_value.sival_ptr = &timerId; ret = timer_create(CLOCK_REALTIME, &sev, &timerId); CHECK_STATUS(ret, "timer_create"); /* Arm real-time scheduling timer */ its.it_value.tv_sec = (time_t)periodInSeconds; its.it_value.tv_nsec = (periodInSeconds - (time_t)periodInSeconds) * 1000000000; its.it_interval.tv_sec = its.it_value.tv_sec; its.it_interval.tv_nsec = its.it_value.tv_nsec; ret = timer_settime(timerId, 0, &its, NULL); CHECK_STATUS(ret, "timer_settime");}
开发者ID:gte999s,项目名称:QuadCopter,代码行数:23,
示例22: mainint main(int argc, char *argv[]){ struct sigevent ev; timer_t tid; ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = SIGALRM; if (timer_create(INVALIDCLOCKID, &ev, &tid) == -1) { if (EINVAL == errno) { printf("Test PASSED/n"); return PTS_PASS; } else { printf("errno != EINVAL/n"); printf("Test FAILED/n"); return PTS_FAIL; } } else { printf("timer_create returned success/n"); return PTS_UNRESOLVED; } return PTS_UNRESOLVED;}
开发者ID:Nan619,项目名称:ltp-ddt,代码行数:23,
示例23: TESTTEST(time, timer_create_SIGEV_SIGNAL) { sigevent_t se; memset(&se, 0, sizeof(se)); se.sigev_notify = SIGEV_SIGNAL; se.sigev_signo = SIGUSR1; timer_t timer_id; ASSERT_EQ(0, timer_create(CLOCK_MONOTONIC, &se, &timer_id)); ScopedSignalHandler ssh(SIGUSR1, timer_create_SIGEV_SIGNAL_signal_handler); ASSERT_EQ(0, timer_create_SIGEV_SIGNAL_signal_handler_invocation_count); itimerspec ts; ts.it_value.tv_sec = 0; ts.it_value.tv_nsec = 1; ts.it_interval.tv_sec = 0; ts.it_interval.tv_nsec = 0; ASSERT_EQ(0, timer_settime(timer_id, TIMER_ABSTIME, &ts, NULL)); usleep(500000); ASSERT_EQ(1, timer_create_SIGEV_SIGNAL_signal_handler_invocation_count);}
开发者ID:WTree,项目名称:platform_bionic,代码行数:23,
示例24: jl_profile_start_timerJL_DLLEXPORT int jl_profile_start_timer(void){ struct sigevent sigprof; // Establish the signal event memset(&sigprof, 0, sizeof(struct sigevent)); sigprof.sigev_notify = SIGEV_SIGNAL; sigprof.sigev_signo = SIGUSR1; sigprof.sigev_value.sival_ptr = &timerprof; if (timer_create(CLOCK_REALTIME, &sigprof, &timerprof) == -1) return -2; // Start the timer itsprof.it_interval.tv_sec = nsecprof/GIGA; itsprof.it_interval.tv_nsec = nsecprof%GIGA; itsprof.it_value.tv_sec = nsecprof/GIGA; itsprof.it_value.tv_nsec = nsecprof%GIGA; if (timer_settime(timerprof, 0, &itsprof, NULL) == -1) return -3; running = 1; return 0;}
开发者ID:JediKoder,项目名称:julia,代码行数:23,
示例25: sigemptyset/*int timer_helper::m_settimer(int timerID,callback_func func,int expireMS, int intervalMS){ int res = -1; timer_t *t_timerid = new timer_t; struct sigevent evp; struct itimerspec its; struct sigaction sa; struct arg_callback *uc=new arg_callback; uc->timerid=timerID; uc->timerID=t_timerid; uc->mclass=this; sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = timer_helper::timer_callback; sigemptyset(&sa.sa_mask); sigaction(SIGUSR1, &sa, NULL); evp.sigev_value.sival_ptr = uc; evp.sigev_notify = SIGEV_SIGNAL; evp.sigev_signo = SIGUSR1; res = timer_create(CLOCK_REALTIME, &evp, t_timerid); this->tt.insert(std::pair<int,timer_t *>(timerID,t_timerid)); its.it_interval.tv_sec = 0; its.it_interval.tv_nsec = intervalMS * 1000000; its.it_value.tv_sec = 0; its.it_value.tv_nsec = expireMS * 1000000; timer_settime(*t_timerid, 0, &its, NULL); return res;}*/void timer_helper::m_initTimer(timer_t *timerId, callback_func function){ struct sigevent sev; struct sigaction sa; struct arg_callback *uc=new arg_callback; uc->timerID = timerId; uc->func = function; uc->mclass = this;// sev.sigev_notify = SIGEV_THREAD; sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = timer_helper::timer_callback; sigemptyset(&sa.sa_mask); sigaction(SIGUSR1, &sa, NULL); sev.sigev_notify = SIGEV_SIGNAL; sev.sigev_signo = SIGUSR1; sev.sigev_value.sival_ptr = uc;// sev.sigev_notify_function = function; sev.sigev_notify_attributes = NULL; if (timer_create(CLOCK_REALTIME, &sev, timerId) == -1){ throw std::runtime_error(std::string("ERROR:[email C++ timer_del函数代码示例 C++ timer_alloc函数代码示例
|