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

Comparing libev/ev.c (file contents):
Revision 1.228 by root, Fri May 2 08:07:37 2008 UTC vs.
Revision 1.230 by root, Fri May 2 08:13:16 2008 UTC

325 325
326typedef ev_watcher *W; 326typedef ev_watcher *W;
327typedef ev_watcher_list *WL; 327typedef ev_watcher_list *WL;
328typedef ev_watcher_time *WT; 328typedef ev_watcher_time *WT;
329 329
330#define ev_active(w) ((W)(w))->active
330#define ev_at(w) ((WT)(w))->at 331#define ev_at(w) ((WT)(w))->at
331 332
332#if EV_USE_MONOTONIC 333#if EV_USE_MONOTONIC
333/* sig_atomic_t is used to avoid per-thread variables or locking but still */ 334/* sig_atomic_t is used to avoid per-thread variables or locking but still */
334/* giving it a reasonably high chance of working on typical architetcures */ 335/* giving it a reasonably high chance of working on typical architetcures */
771 /* maybe we could use a dummy element at heap [0]? */ 772 /* maybe we could use a dummy element at heap [0]? */
772 if (!p || heap [p]->at <= w->at) 773 if (!p || heap [p]->at <= w->at)
773 break; 774 break;
774 775
775 heap [k] = heap [p]; 776 heap [k] = heap [p];
776 ((W)heap [k])->active = k; 777 ev_active (heap [k]) = k;
777 k = p; 778 k = p;
778 } 779 }
779 780
780 heap [k] = w; 781 heap [k] = w;
781 ((W)heap [k])->active = k; 782 ev_active (heap [k]) = k;
782} 783}
783 784
784/* away from the root */ 785/* away from the root */
785void inline_speed 786void inline_speed
786downheap (WT *heap, int N, int k) 787downheap (WT *heap, int N, int k)
799 800
800 if (w->at <= heap [c]->at) 801 if (w->at <= heap [c]->at)
801 break; 802 break;
802 803
803 heap [k] = heap [c]; 804 heap [k] = heap [c];
804 ((W)heap [k])->active = k; 805 ev_active (heap [k]) = k;
805 806
806 k = c; 807 k = c;
807 } 808 }
808 809
809 heap [k] = w; 810 heap [k] = w;
810 ((W)heap [k])->active = k; 811 ev_active (heap [k]) = k;
811} 812}
812 813
813void inline_size 814void inline_size
814adjustheap (WT *heap, int N, int k) 815adjustheap (WT *heap, int N, int k)
815{ 816{
1894 ev_start (EV_A_ (W)w, ++timercnt); 1895 ev_start (EV_A_ (W)w, ++timercnt);
1895 array_needsize (WT, timers, timermax, timercnt + 1, EMPTY2); 1896 array_needsize (WT, timers, timermax, timercnt + 1, EMPTY2);
1896 timers [timercnt] = (WT)w; 1897 timers [timercnt] = (WT)w;
1897 upheap (timers, timercnt); 1898 upheap (timers, timercnt);
1898 1899
1899 /*assert (("internal timer heap corruption", timers [((W)w)->active] == w));*/ 1900 /*assert (("internal timer heap corruption", timers [ev_active (w)] == w));*/
1900} 1901}
1901 1902
1902void noinline 1903void noinline
1903ev_timer_stop (EV_P_ ev_timer *w) 1904ev_timer_stop (EV_P_ ev_timer *w)
1904{ 1905{
1905 clear_pending (EV_A_ (W)w); 1906 clear_pending (EV_A_ (W)w);
1906 if (expect_false (!ev_is_active (w))) 1907 if (expect_false (!ev_is_active (w)))
1907 return; 1908 return;
1908 1909
1909 assert (("internal timer heap corruption", timers [((W)w)->active] == (WT)w));
1910
1911 { 1910 {
1912 int active = ((W)w)->active; 1911 int active = ev_active (w);
1912
1913 assert (("internal timer heap corruption", timers [active] == (WT)w));
1913 1914
1914 if (expect_true (active < timercnt)) 1915 if (expect_true (active < timercnt))
1915 { 1916 {
1916 timers [active] = timers [timercnt]; 1917 timers [active] = timers [timercnt];
1917 adjustheap (timers, timercnt, active); 1918 adjustheap (timers, timercnt, active);
1931 if (ev_is_active (w)) 1932 if (ev_is_active (w))
1932 { 1933 {
1933 if (w->repeat) 1934 if (w->repeat)
1934 { 1935 {
1935 ev_at (w) = mn_now + w->repeat; 1936 ev_at (w) = mn_now + w->repeat;
1936 adjustheap (timers, timercnt, ((W)w)->active); 1937 adjustheap (timers, timercnt, ev_active (w));
1937 } 1938 }
1938 else 1939 else
1939 ev_timer_stop (EV_A_ w); 1940 ev_timer_stop (EV_A_ w);
1940 } 1941 }
1941 else if (w->repeat) 1942 else if (w->repeat)
1942 { 1943 {
1943 w->at = w->repeat; 1944 ev_at (w) = w->repeat;
1944 ev_timer_start (EV_A_ w); 1945 ev_timer_start (EV_A_ w);
1945 } 1946 }
1946} 1947}
1947 1948
1948#if EV_PERIODIC_ENABLE 1949#if EV_PERIODIC_ENABLE
1966 ev_start (EV_A_ (W)w, ++periodiccnt); 1967 ev_start (EV_A_ (W)w, ++periodiccnt);
1967 array_needsize (WT, periodics, periodicmax, periodiccnt + 1, EMPTY2); 1968 array_needsize (WT, periodics, periodicmax, periodiccnt + 1, EMPTY2);
1968 periodics [periodiccnt] = (WT)w; 1969 periodics [periodiccnt] = (WT)w;
1969 upheap (periodics, periodiccnt); 1970 upheap (periodics, periodiccnt);
1970 1971
1971 /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/ 1972 /*assert (("internal periodic heap corruption", periodics [ev_active (w)] == w));*/
1972} 1973}
1973 1974
1974void noinline 1975void noinline
1975ev_periodic_stop (EV_P_ ev_periodic *w) 1976ev_periodic_stop (EV_P_ ev_periodic *w)
1976{ 1977{
1977 clear_pending (EV_A_ (W)w); 1978 clear_pending (EV_A_ (W)w);
1978 if (expect_false (!ev_is_active (w))) 1979 if (expect_false (!ev_is_active (w)))
1979 return; 1980 return;
1980 1981
1981 assert (("internal periodic heap corruption", periodics [((W)w)->active] == (WT)w));
1982
1983 { 1982 {
1984 int active = ((W)w)->active; 1983 int active = ev_active (w);
1984
1985 assert (("internal periodic heap corruption", periodics [active] == (WT)w));
1985 1986
1986 if (expect_true (active < periodiccnt)) 1987 if (expect_true (active < periodiccnt))
1987 { 1988 {
1988 periodics [active] = periodics [periodiccnt]; 1989 periodics [active] = periodics [periodiccnt];
1989 adjustheap (periodics, periodiccnt, active); 1990 adjustheap (periodics, periodiccnt, active);
2367 clear_pending (EV_A_ (W)w); 2368 clear_pending (EV_A_ (W)w);
2368 if (expect_false (!ev_is_active (w))) 2369 if (expect_false (!ev_is_active (w)))
2369 return; 2370 return;
2370 2371
2371 { 2372 {
2372 int active = ((W)w)->active; 2373 int active = ev_active (w);
2373 2374
2374 idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]]; 2375 idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]];
2375 ((W)idles [ABSPRI (w)][active - 1])->active = active; 2376 ev_active (idles [ABSPRI (w)][active - 1]) = active;
2376 2377
2377 ev_stop (EV_A_ (W)w); 2378 ev_stop (EV_A_ (W)w);
2378 --idleall; 2379 --idleall;
2379 } 2380 }
2380} 2381}
2397 clear_pending (EV_A_ (W)w); 2398 clear_pending (EV_A_ (W)w);
2398 if (expect_false (!ev_is_active (w))) 2399 if (expect_false (!ev_is_active (w)))
2399 return; 2400 return;
2400 2401
2401 { 2402 {
2402 int active = ((W)w)->active; 2403 int active = ev_active (w);
2404
2403 prepares [active - 1] = prepares [--preparecnt]; 2405 prepares [active - 1] = prepares [--preparecnt];
2404 ((W)prepares [active - 1])->active = active; 2406 ev_active (prepares [active - 1]) = active;
2405 } 2407 }
2406 2408
2407 ev_stop (EV_A_ (W)w); 2409 ev_stop (EV_A_ (W)w);
2408} 2410}
2409 2411
2424 clear_pending (EV_A_ (W)w); 2426 clear_pending (EV_A_ (W)w);
2425 if (expect_false (!ev_is_active (w))) 2427 if (expect_false (!ev_is_active (w)))
2426 return; 2428 return;
2427 2429
2428 { 2430 {
2429 int active = ((W)w)->active; 2431 int active = ev_active (w);
2432
2430 checks [active - 1] = checks [--checkcnt]; 2433 checks [active - 1] = checks [--checkcnt];
2431 ((W)checks [active - 1])->active = active; 2434 ev_active (checks [active - 1]) = active;
2432 } 2435 }
2433 2436
2434 ev_stop (EV_A_ (W)w); 2437 ev_stop (EV_A_ (W)w);
2435} 2438}
2436 2439
2532 clear_pending (EV_A_ (W)w); 2535 clear_pending (EV_A_ (W)w);
2533 if (expect_false (!ev_is_active (w))) 2536 if (expect_false (!ev_is_active (w)))
2534 return; 2537 return;
2535 2538
2536 { 2539 {
2537 int active = ((W)w)->active; 2540 int active = ev_active (w);
2541
2538 forks [active - 1] = forks [--forkcnt]; 2542 forks [active - 1] = forks [--forkcnt];
2539 ((W)forks [active - 1])->active = active; 2543 ev_active (forks [active - 1]) = active;
2540 } 2544 }
2541 2545
2542 ev_stop (EV_A_ (W)w); 2546 ev_stop (EV_A_ (W)w);
2543} 2547}
2544#endif 2548#endif
2563 clear_pending (EV_A_ (W)w); 2567 clear_pending (EV_A_ (W)w);
2564 if (expect_false (!ev_is_active (w))) 2568 if (expect_false (!ev_is_active (w)))
2565 return; 2569 return;
2566 2570
2567 { 2571 {
2568 int active = ((W)w)->active; 2572 int active = ev_active (w);
2573
2569 asyncs [active - 1] = asyncs [--asynccnt]; 2574 asyncs [active - 1] = asyncs [--asynccnt];
2570 ((W)asyncs [active - 1])->active = active; 2575 ev_active (asyncs [active - 1]) = active;
2571 } 2576 }
2572 2577
2573 ev_stop (EV_A_ (W)w); 2578 ev_stop (EV_A_ (W)w);
2574} 2579}
2575 2580

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines