ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.221 by root, Sun Apr 6 12:44:49 2008 UTC vs.
Revision 1.227 by root, Fri May 2 07:20:01 2008 UTC

269#endif 269#endif
270 270
271#if EV_USE_EVENTFD 271#if EV_USE_EVENTFD
272/* our minimum requirement is glibc 2.7 which has the stub, but not the header */ 272/* our minimum requirement is glibc 2.7 which has the stub, but not the header */
273# include <stdint.h> 273# include <stdint.h>
274# ifdef __cplusplus
275extern "C" {
276# endif
274int eventfd (unsigned int initval, int flags); 277int eventfd (unsigned int initval, int flags);
278# ifdef __cplusplus
279}
280# endif
275#endif 281#endif
276 282
277/**/ 283/**/
278 284
279/* 285/*
294# define expect(expr,value) __builtin_expect ((expr),(value)) 300# define expect(expr,value) __builtin_expect ((expr),(value))
295# define noinline __attribute__ ((noinline)) 301# define noinline __attribute__ ((noinline))
296#else 302#else
297# define expect(expr,value) (expr) 303# define expect(expr,value) (expr)
298# define noinline 304# define noinline
299# if __STDC_VERSION__ < 199901L 305# if __STDC_VERSION__ < 199901L && __GNUC__ < 2
300# define inline 306# define inline
301# endif 307# endif
302#endif 308#endif
303 309
304#define expect_false(expr) expect ((expr) != 0, 0) 310#define expect_false(expr) expect ((expr) != 0, 0)
354 perror (msg); 360 perror (msg);
355 abort (); 361 abort ();
356 } 362 }
357} 363}
358 364
365static void *
366ev_realloc_emul (void *ptr, long size)
367{
368 /* some systems, notably openbsd and darwin, fail to properly
369 * implement realloc (x, 0) (as required by both ansi c-98 and
370 * the single unix specification, so work around them here.
371 */
372
373 if (size)
374 return realloc (ptr, size);
375
376 free (ptr);
377 return 0;
378}
379
359static void *(*alloc)(void *ptr, long size); 380static void *(*alloc)(void *ptr, long size) = ev_realloc_emul;
360 381
361void 382void
362ev_set_allocator (void *(*cb)(void *ptr, long size)) 383ev_set_allocator (void *(*cb)(void *ptr, long size))
363{ 384{
364 alloc = cb; 385 alloc = cb;
365} 386}
366 387
367inline_speed void * 388inline_speed void *
368ev_realloc (void *ptr, long size) 389ev_realloc (void *ptr, long size)
369{ 390{
370 ptr = alloc ? alloc (ptr, size) : realloc (ptr, size); 391 ptr = alloc (ptr, size);
371 392
372 if (!ptr && size) 393 if (!ptr && size)
373 { 394 {
374 fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); 395 fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size);
375 abort (); 396 abort ();
733 } 754 }
734} 755}
735 756
736/*****************************************************************************/ 757/*****************************************************************************/
737 758
759/* towards the root */
738void inline_speed 760void inline_speed
739upheap (WT *heap, int k) 761upheap (WT *heap, int k)
740{ 762{
741 WT w = heap [k]; 763 WT w = heap [k];
742 764
754 776
755 heap [k] = w; 777 heap [k] = w;
756 ((W)heap [k])->active = k + 1; 778 ((W)heap [k])->active = k + 1;
757} 779}
758 780
781/* away from the root */
759void inline_speed 782void inline_speed
760downheap (WT *heap, int N, int k) 783downheap (WT *heap, int N, int k)
761{ 784{
762 WT w = heap [k]; 785 WT w = heap [k];
763 786
1164 if (!(flags & EVFLAG_NOENV) 1187 if (!(flags & EVFLAG_NOENV)
1165 && !enable_secure () 1188 && !enable_secure ()
1166 && getenv ("LIBEV_FLAGS")) 1189 && getenv ("LIBEV_FLAGS"))
1167 flags = atoi (getenv ("LIBEV_FLAGS")); 1190 flags = atoi (getenv ("LIBEV_FLAGS"));
1168 1191
1169 if (!(flags & 0x0000ffffUL)) 1192 if (!(flags & 0x0000ffffU))
1170 flags |= ev_recommended_backends (); 1193 flags |= ev_recommended_backends ();
1171 1194
1172#if EV_USE_PORT 1195#if EV_USE_PORT
1173 if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); 1196 if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags);
1174#endif 1197#endif
1262#endif 1285#endif
1263 1286
1264 backend = 0; 1287 backend = 0;
1265} 1288}
1266 1289
1290#if EV_USE_INOTIFY
1267void inline_size infy_fork (EV_P); 1291void inline_size infy_fork (EV_P);
1292#endif
1268 1293
1269void inline_size 1294void inline_size
1270loop_fork (EV_P) 1295loop_fork (EV_P)
1271{ 1296{
1272#if EV_USE_PORT 1297#if EV_USE_PORT

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines