| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2000-2004 Niels Provos <provos@citi.umich.edu> | 2 * Copyright (c) 2000-2004 Niels Provos <provos@citi.umich.edu> |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 &win32ops, | 102 &win32ops, |
| 103 #endif | 103 #endif |
| 104 NULL | 104 NULL |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 /* Global state */ | 107 /* Global state */ |
| 108 struct event_base *current_base = NULL; | 108 struct event_base *current_base = NULL; |
| 109 extern struct event_base *evsignal_base; | 109 extern struct event_base *evsignal_base; |
| 110 static int use_monotonic = 1; | 110 static int use_monotonic = 1; |
| 111 | 111 |
| 112 /* Handle signals - This is a deprecated interface */ | |
| 113 int (*event_sigcb)(void); /* Signal callback when gotsig is set */ | |
| 114 volatile sig_atomic_t event_gotsig; /* Set in signal handler */ | |
| 115 | |
| 116 /* Prototypes */ | 112 /* Prototypes */ |
| 117 static void event_queue_insert(struct event_base *, struct event *, int); | 113 static void event_queue_insert(struct event_base *, struct event *, int); |
| 118 static void event_queue_remove(struct event_base *, struct event *, int); | 114 static void event_queue_remove(struct event_base *, struct event *, int); |
| 119 static int event_haveevents(struct event_base *); | 115 static int event_haveevents(struct event_base *); |
| 120 | 116 |
| 121 static void event_process_active(struct event_base *); | 117 static void event_process_active(struct event_base *); |
| 122 | 118 |
| 123 static int timeout_next(struct event_base *, struct timeval **); | 119 static int timeout_next(struct event_base *, struct timeval **); |
| 124 static void timeout_process(struct event_base *); | 120 static void timeout_process(struct event_base *); |
| 125 static void timeout_correct(struct event_base *, struct timeval *); | 121 static void timeout_correct(struct event_base *, struct timeval *); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 157 |
| 162 struct event_base * | 158 struct event_base * |
| 163 event_base_new(void) | 159 event_base_new(void) |
| 164 { | 160 { |
| 165 int i; | 161 int i; |
| 166 struct event_base *base; | 162 struct event_base *base; |
| 167 | 163 |
| 168 if ((base = calloc(1, sizeof(struct event_base))) == NULL) | 164 if ((base = calloc(1, sizeof(struct event_base))) == NULL) |
| 169 event_err(1, "%s: calloc", __func__); | 165 event_err(1, "%s: calloc", __func__); |
| 170 | 166 |
| 171 event_sigcb = NULL; | |
| 172 event_gotsig = 0; | |
| 173 | |
| 174 gettime(base, &base->event_tv); | 167 gettime(base, &base->event_tv); |
| 175 | 168 |
| 176 min_heap_ctor(&base->timeheap); | 169 min_heap_ctor(&base->timeheap); |
| 177 TAILQ_INIT(&base->eventqueue); | 170 TAILQ_INIT(&base->eventqueue); |
| 178 base->sig.ev_signal_pair[0] = -1; | 171 base->sig.ev_signal_pair[0] = -1; |
| 179 base->sig.ev_signal_pair[1] = -1; | 172 base->sig.ev_signal_pair[1] = -1; |
| 180 | 173 |
| 181 base->evbase = NULL; | 174 base->evbase = NULL; |
| 182 for (i = 0; eventops[i] && !base->evbase; i++) { | 175 for (i = 0; eventops[i] && !base->evbase; i++) { |
| 183 base->evsel = eventops[i]; | 176 base->evsel = eventops[i]; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 else | 372 else |
| 380 event_del(ev); | 373 event_del(ev); |
| 381 | 374 |
| 382 /* Allows deletes to work */ | 375 /* Allows deletes to work */ |
| 383 ncalls = ev->ev_ncalls; | 376 ncalls = ev->ev_ncalls; |
| 384 ev->ev_pncalls = &ncalls; | 377 ev->ev_pncalls = &ncalls; |
| 385 while (ncalls) { | 378 while (ncalls) { |
| 386 ncalls--; | 379 ncalls--; |
| 387 ev->ev_ncalls = ncalls; | 380 ev->ev_ncalls = ncalls; |
| 388 (*ev->ev_callback)((int)ev->ev_fd, ev->ev_res, ev->ev_ar
g); | 381 (*ev->ev_callback)((int)ev->ev_fd, ev->ev_res, ev->ev_ar
g); |
| 389 » » » if (event_gotsig || base->event_break) | 382 » » » if (base->event_break) |
| 390 return; | 383 return; |
| 391 } | 384 } |
| 392 } | 385 } |
| 393 } | 386 } |
| 394 | 387 |
| 395 /* | 388 /* |
| 396 * Wait continously for events. We exit only if no events are left. | 389 * Wait continously for events. We exit only if no events are left. |
| 397 */ | 390 */ |
| 398 | 391 |
| 399 int | 392 int |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 if (base->event_gotterm) { | 477 if (base->event_gotterm) { |
| 485 base->event_gotterm = 0; | 478 base->event_gotterm = 0; |
| 486 break; | 479 break; |
| 487 } | 480 } |
| 488 | 481 |
| 489 if (base->event_break) { | 482 if (base->event_break) { |
| 490 base->event_break = 0; | 483 base->event_break = 0; |
| 491 break; | 484 break; |
| 492 } | 485 } |
| 493 | 486 |
| 494 /* You cannot use this interface for multi-threaded apps */ | |
| 495 while (event_gotsig) { | |
| 496 event_gotsig = 0; | |
| 497 if (event_sigcb) { | |
| 498 res = (*event_sigcb)(); | |
| 499 if (res == -1) { | |
| 500 errno = EINTR; | |
| 501 return (-1); | |
| 502 } | |
| 503 } | |
| 504 } | |
| 505 | |
| 506 timeout_correct(base, &tv); | 487 timeout_correct(base, &tv); |
| 507 | 488 |
| 508 tv_p = &tv; | 489 tv_p = &tv; |
| 509 if (!base->event_count_active && !(flags & EVLOOP_NONBLOCK)) { | 490 if (!base->event_count_active && !(flags & EVLOOP_NONBLOCK)) { |
| 510 timeout_next(base, &tv_p); | 491 timeout_next(base, &tv_p); |
| 511 } else { | 492 } else { |
| 512 /* | 493 /* |
| 513 * if we have active events, we just poll new events | 494 * if we have active events, we just poll new events |
| 514 * without waiting. | 495 * without waiting. |
| 515 */ | 496 */ |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1008 /* | 989 /* |
| 1009 * No thread-safe interface needed - the information should be the same | 990 * No thread-safe interface needed - the information should be the same |
| 1010 * for all threads. | 991 * for all threads. |
| 1011 */ | 992 */ |
| 1012 | 993 |
| 1013 const char * | 994 const char * |
| 1014 event_get_method(void) | 995 event_get_method(void) |
| 1015 { | 996 { |
| 1016 return (current_base->evsel->name); | 997 return (current_base->evsel->name); |
| 1017 } | 998 } |
| OLD | NEW |