Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #include <sys/netmgr.h>
- #include <sys/neutrino.h>
- #include <sys/time.h>
- #define MY_PULSE_CODE _PULSE_CODE_MINAVAIL
- typedef union {
- struct _pulse pulse;
- /* your other message structures would go
- here too */
- } my_message_t;
- main()
- {
- struct sigevent event;
- struct itimerspec itime;
- timer_t timer_id;
- int chid;
- int rcvid;
- my_message_t msg;
- struct timeval tv;
- time_t start_time;
- 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_MONOTONIC /*CLOCK_REALTIME*/, &event, &timer_id);
- itime.it_value.tv_sec = 150;
- itime.it_value.tv_nsec = 0;
- itime.it_interval.tv_sec = 0;
- itime.it_interval.tv_nsec = 0;
- timer_settime(timer_id, 0, &itime, NULL);
- gettimeofday(&tv, 0);
- start_time = tv.tv_sec;
- for (;;) {
- rcvid = MsgReceive(chid, &msg, sizeof(msg), NULL);
- if (rcvid == 0) { /* we got a pulse */
- if (msg.pulse.code == MY_PULSE_CODE) {
- gettimeofday(&tv, 0);
- printf("Got a pulse: %d seconds\n", (tv.tv_sec - start_time));
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement