int dds_cond_broadcast (cond_t *cv) { int have_waiters, res; /* Ensure that waiters and was_broadcast are consistent. */ lock_take (cv->waiters_lock); have_waiters = 0; if (cv->waiters > 0) { cv->was_broadcast = 1; have_waiters = 1; } lock_release (cv->waiters_lock); res = DDS_RETCODE_OK; if (have_waiters) { /* Wake up all the waiters. */ if (!sema_release (cv->sema)) res = DDS_RETCODE_ERROR; /* Wait for all the awakened threads to acquire their part of the counting semaphore. */ else if (!ev_wait (cv->waiters_done)) res = DDS_RETCODE_ERROR; cv->was_broadcast = 0; } return (res); }
// Reads input events, handles special hot keys, and adds to the key queue. static void *input_thread(void *cookie) { for (;;) { if (!ev_wait(-1)) ev_dispatch(); } return NULL; }
// Reads input events, handles special hot keys, and adds to the key queue. void* RecoveryUI::input_thread(void *cookie) { for (;;) { if (!ev_wait(-1)) ev_dispatch(); } return NULL; }
static int ev_wait1(struct k9_ev *ev, unsigned tmout) { struct k9_ev_wait_desc wait[1]; wait->ev = ev; return (ev_wait(1, wait, tmout)); }
void* input_thread(void *cookie) { for(;;) { if(!ev_wait(-1)) //查看是否有输入事件 ev_dispatch();//有输入事件,那么将派发输入事件 } return NULL; }
static void *run_test(void *mod) { signal(SIGUSR1, signal_handler); if(mod == NULL) return NULL; while(!pcba_success) { if(!ev_wait(-1)) ev_dispatch(); } return NULL; }
static void *input_listener_thread(void *arg) { pr_verbose("begin input listener thread\n"); while (1) { if (!ev_wait(-1)) ev_dispatch(); } pr_verbose("exit input listener thread\n"); return NULL; }
int k9_ev_wait(unsigned nwait, struct k9_ev_wait_desc *wait, unsigned tmout) { int result; uint32 old; old = k9_cpu_intr_dis(); result = ev_wait(nwait, wait, tmout); k9_cpu_intr_restore(old); return (result); }
int main(int argc, char *argv[]){ int sfd; sfd = tcpsock_create(); sock_setopt(sfd); sock_listen(sfd, SERVER_PORT, BACKLOG); fd_setnb(sfd); int evfd; evfd = ev_create(); ev_add(evfd, sfd, EV_IN); struct ev_event events[MAX_EVENT]; int n; int i; int cfd; unsigned char buf[BUF_SIZE]; ssize_t rbytes; while(1) { n = ev_wait(evfd, events, MAX_EVENT, -1); printf("%d\n", n); for(i=0; i < n; i++){ printf("%d, %d, %d, %d, %d\n", events[i].events, events[i].fd, events[i].readable, events[i].writable, events[i].closable); if (events[i].fd == sfd) { while(1) { cfd = sock_accept(sfd); if (cfd == -1) { break; } fd_setnb(cfd); ev_add(evfd, cfd, EV_IN); } } else if (events[i].closable == true) { close(events[i].fd); } else if (events[i].readable == true) { while(1) { rbytes = sock_recv(events[i].fd, buf, BUF_SIZE); if (rbytes == -1) { break; } buf[rbytes] = '\0'; printf("%s", buf); } } } } }
int main(int argc, char **argv) { int key_code = -1; int input = false; int opt; long int timeout = NEXT_TIMEOUT_MS; int64_t start; while ((opt = getopt(argc, argv, "t:")) != -1) { switch (opt) { case 't': timeout = strtol(optarg, NULL, 0); if (timeout < 0 || timeout >= LONG_MAX) { timeout = NEXT_TIMEOUT_MS; LOGE("invalid timeout %s, defaulting to %ld\n", optarg, timeout); } break; default: return usage(); } } if (optind >= argc) { return usage(); } if (gr_init() == -1 || ev_init(input_cb, &key_code) == -1) { LOGE("failed to initialize minui\n"); return EXIT_FAILURE; } /* display all images except the last one, switch to next image after * timeout or user input */ while (optind < argc - 1) { draw(argv[optind++]); start = android::uptimeMillis(); long int timeout_remaining = timeout; do { if (ev_wait(timeout_remaining) == 0) { ev_dispatch(); if (key_code != -1) { input = true; break; } } timeout_remaining -= android::uptimeMillis() - start; } while (timeout_remaining > 0); }; /* if there was user input while showing the images, display the last * image and wait until the power button is pressed or LAST_TIMEOUT_MS * has elapsed */ if (input) { start = android::uptimeMillis(); draw(argv[optind]); do { if (ev_wait(timeout) == 0) { ev_dispatch(); } if (android::uptimeMillis() - start >= LAST_TIMEOUT_MS) { break; } } while (key_code != KEY_POWER); } clear(); gr_exit(); ev_exit(); return EXIT_SUCCESS; }