… | |
… | |
196 | # define EV_SELECT_IS_WINSOCKET 1 |
196 | # define EV_SELECT_IS_WINSOCKET 1 |
197 | # endif |
197 | # endif |
198 | # undef EV_AVOID_STDIO |
198 | # undef EV_AVOID_STDIO |
199 | #endif |
199 | #endif |
200 | |
200 | |
|
|
201 | /* OS X, in its infinite idiocy, actually HARDCODES |
|
|
202 | * a limit of 1024 into their select. Where people have brains, |
|
|
203 | * OS X engineers apparently have a vacuum. Or maybe they were |
|
|
204 | * ordered to have a vacuum, or they do anything for money. |
|
|
205 | * This might help. Or not. |
|
|
206 | */ |
|
|
207 | #define _DARWIN_UNLIMITED_SELECT 1 |
|
|
208 | |
201 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
209 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
202 | |
210 | |
203 | /* try to deduce the maximum number of signals on this platform */ |
211 | /* try to deduce the maximum number of signals on this platform */ |
204 | #if defined (EV_NSIG) |
212 | #if defined (EV_NSIG) |
205 | /* use what's provided */ |
213 | /* use what's provided */ |
… | |
… | |
440 | # ifdef __cplusplus |
448 | # ifdef __cplusplus |
441 | } |
449 | } |
442 | # endif |
450 | # endif |
443 | #endif |
451 | #endif |
444 | |
452 | |
445 | |
|
|
446 | /**/ |
453 | /**/ |
447 | |
454 | |
448 | #if EV_VERIFY >= 3 |
455 | #if EV_VERIFY >= 3 |
449 | # define EV_FREQUENT_CHECK ev_verify (EV_A) |
456 | # define EV_FREQUENT_CHECK ev_verify (EV_A) |
450 | #else |
457 | #else |
… | |
… | |
462 | #define TIME_EPSILON 0.0001220703125 /* 1/8192 */ |
469 | #define TIME_EPSILON 0.0001220703125 /* 1/8192 */ |
463 | |
470 | |
464 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
471 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
465 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
472 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
466 | |
473 | |
|
|
474 | #define EV_TV_SET(tv,t) do { tv.tv_sec = (long)t; tv.tv_usec = (long)((t - tv.tv_sec) * 1e6); } while (0) |
|
|
475 | #define EV_TS_SET(ts,t) do { ts.tv_sec = (long)t; tv.tv_nsec = (long)((t - tv.tv_sec) * 1e9); } while (0) |
|
|
476 | |
467 | #if __GNUC__ >= 4 |
477 | #if __GNUC__ >= 4 |
468 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
478 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
469 | # define noinline __attribute__ ((noinline)) |
479 | # define noinline __attribute__ ((noinline)) |
470 | #else |
480 | #else |
471 | # define expect(expr,value) (expr) |
481 | # define expect(expr,value) (expr) |
… | |
… | |
503 | #define ev_active(w) ((W)(w))->active |
513 | #define ev_active(w) ((W)(w))->active |
504 | #define ev_at(w) ((WT)(w))->at |
514 | #define ev_at(w) ((WT)(w))->at |
505 | |
515 | |
506 | #if EV_USE_REALTIME |
516 | #if EV_USE_REALTIME |
507 | /* sig_atomic_t is used to avoid per-thread variables or locking but still */ |
517 | /* sig_atomic_t is used to avoid per-thread variables or locking but still */ |
508 | /* giving it a reasonably high chance of working on typical architetcures */ |
518 | /* giving it a reasonably high chance of working on typical architectures */ |
509 | static EV_ATOMIC_T have_realtime; /* did clock_gettime (CLOCK_REALTIME) work? */ |
519 | static EV_ATOMIC_T have_realtime; /* did clock_gettime (CLOCK_REALTIME) work? */ |
510 | #endif |
520 | #endif |
511 | |
521 | |
512 | #if EV_USE_MONOTONIC |
522 | #if EV_USE_MONOTONIC |
513 | static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
523 | static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
… | |
… | |
761 | if (delay > 0.) |
771 | if (delay > 0.) |
762 | { |
772 | { |
763 | #if EV_USE_NANOSLEEP |
773 | #if EV_USE_NANOSLEEP |
764 | struct timespec ts; |
774 | struct timespec ts; |
765 | |
775 | |
766 | ts.tv_sec = (time_t)delay; |
776 | EV_SET_TS (ts, delay); |
767 | ts.tv_nsec = (long)((delay - (ev_tstamp)(ts.tv_sec)) * 1e9); |
|
|
768 | |
|
|
769 | nanosleep (&ts, 0); |
777 | nanosleep (&ts, 0); |
770 | #elif defined(_WIN32) |
778 | #elif defined(_WIN32) |
771 | Sleep ((unsigned long)(delay * 1e3)); |
779 | Sleep ((unsigned long)(delay * 1e3)); |
772 | #else |
780 | #else |
773 | struct timeval tv; |
781 | struct timeval tv; |
774 | |
782 | |
775 | tv.tv_sec = (time_t)delay; |
|
|
776 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
|
|
777 | |
|
|
778 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
783 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
779 | /* something not guaranteed by newer posix versions, but guaranteed */ |
784 | /* something not guaranteed by newer posix versions, but guaranteed */ |
780 | /* by older ones */ |
785 | /* by older ones */ |
|
|
786 | EV_SET_TV (tv, delay); |
781 | select (0, 0, 0, 0, &tv); |
787 | select (0, 0, 0, 0, &tv); |
782 | #endif |
788 | #endif |
783 | } |
789 | } |
784 | } |
790 | } |
785 | |
791 | |
786 | /*****************************************************************************/ |
792 | /*****************************************************************************/ |
787 | |
793 | |
788 | #define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */ |
794 | #define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */ |
789 | |
795 | |
790 | /* find a suitable new size for the given array, */ |
796 | /* find a suitable new size for the given array, */ |
791 | /* hopefully by rounding to a ncie-to-malloc size */ |
797 | /* hopefully by rounding to a nice-to-malloc size */ |
792 | inline_size int |
798 | inline_size int |
793 | array_nextsize (int elem, int cur, int cnt) |
799 | array_nextsize (int elem, int cur, int cnt) |
794 | { |
800 | { |
795 | int ncur = cur + 1; |
801 | int ncur = cur + 1; |
796 | |
802 | |
… | |
… | |
1063 | } |
1069 | } |
1064 | |
1070 | |
1065 | /*****************************************************************************/ |
1071 | /*****************************************************************************/ |
1066 | |
1072 | |
1067 | /* |
1073 | /* |
1068 | * the heap functions want a real array index. array index 0 uis guaranteed to not |
1074 | * the heap functions want a real array index. array index 0 is guaranteed to not |
1069 | * be in-use at any time. the first heap entry is at array [HEAP0]. DHEAP gives |
1075 | * be in-use at any time. the first heap entry is at array [HEAP0]. DHEAP gives |
1070 | * the branching factor of the d-tree. |
1076 | * the branching factor of the d-tree. |
1071 | */ |
1077 | */ |
1072 | |
1078 | |
1073 | /* |
1079 | /* |
… | |
… | |
1273 | uint64_t counter = 1; |
1279 | uint64_t counter = 1; |
1274 | write (evfd, &counter, sizeof (uint64_t)); |
1280 | write (evfd, &counter, sizeof (uint64_t)); |
1275 | } |
1281 | } |
1276 | else |
1282 | else |
1277 | #endif |
1283 | #endif |
|
|
1284 | /* win32 people keep sending patches that change this write() to send() */ |
|
|
1285 | /* and then run away. but send() is wrong, it wants a socket handle on win32 */ |
|
|
1286 | /* so when you think this write should be a send instead, please find out */ |
|
|
1287 | /* where your send() is from - it's definitely not the microsoft send, and */ |
|
|
1288 | /* tell me. thank you. */ |
1278 | write (evpipe [1], &dummy, 1); |
1289 | write (evpipe [1], &dummy, 1); |
1279 | |
1290 | |
1280 | errno = old_errno; |
1291 | errno = old_errno; |
1281 | } |
1292 | } |
1282 | } |
1293 | } |
… | |
… | |
1296 | } |
1307 | } |
1297 | else |
1308 | else |
1298 | #endif |
1309 | #endif |
1299 | { |
1310 | { |
1300 | char dummy; |
1311 | char dummy; |
|
|
1312 | /* see discussion in evpipe_write when you think this read should be recv in win32 */ |
1301 | read (evpipe [0], &dummy, 1); |
1313 | read (evpipe [0], &dummy, 1); |
1302 | } |
1314 | } |
1303 | |
1315 | |
1304 | if (sig_pending) |
1316 | if (sig_pending) |
1305 | { |
1317 | { |
… | |
… | |
2171 | feed_reverse_done (EV_A_ EV_PERIODIC); |
2183 | feed_reverse_done (EV_A_ EV_PERIODIC); |
2172 | } |
2184 | } |
2173 | } |
2185 | } |
2174 | |
2186 | |
2175 | /* simply recalculate all periodics */ |
2187 | /* simply recalculate all periodics */ |
2176 | /* TODO: maybe ensure that at leats one event happens when jumping forward? */ |
2188 | /* TODO: maybe ensure that at least one event happens when jumping forward? */ |
2177 | static void noinline |
2189 | static void noinline |
2178 | periodics_reschedule (EV_P) |
2190 | periodics_reschedule (EV_P) |
2179 | { |
2191 | { |
2180 | int i; |
2192 | int i; |
2181 | |
2193 | |