View | Details | Raw Unified | Return to bug 56645
Collapse All | Expand All

(-)server/mpm/event/event.c (-14 / +70 lines)
Lines 328-333 Link Here
328
 unsigned int signaled:1;
328
 unsigned int signaled:1;
329
} socket_callback_baton_t;
329
} socket_callback_baton_t;
330
330
331
static apr_array_header_t* te_array;
332
333
static void te_array_init(apr_pool_t *p){
334
    te_array = apr_array_make(p, 0, sizeof(timer_event_t*));
335
}
336
337
static timer_event_t *te_array_pop(void){
338
    timer_event_t **foo = apr_array_pop(te_array);
339
    return foo == NULL ? NULL: *foo;
340
}
341
342
static void te_array_push(timer_event_t* te){
343
    timer_event_t **foo = apr_array_push(te_array);
344
    *foo = te;
345
}
346
347
static timer_event_t *te_array_peek(void){
348
	timer_event_t *foo = te_array_pop();
349
	if(foo != NULL){
350
	    te_array_push(foo);
351
	}
352
	return foo;
353
}
354
355
356
331
/* data retained by event across load/unload of the module
357
/* data retained by event across load/unload of the module
332
 * allocated on first call to pre-config hook; located on
358
 * allocated on first call to pre-config hook; located on
333
 * subsequent calls to pre-config hook
359
 * subsequent calls to pre-config hook
Lines 1433-1438 Link Here
1433
1459
1434
static apr_thread_mutex_t *g_timer_skiplist_mtx;
1460
static apr_thread_mutex_t *g_timer_skiplist_mtx;
1435
1461
1462
static apr_status_t g_timer_skiplist_mtx_lock(const char *file, int line, int module_index){
1463
    apr_status_t rv = apr_thread_mutex_lock(g_timer_skiplist_mtx);
1464
    if(rv != APR_SUCCESS){
1465
        ap_log_error(file, line, module_index, APLOG_CRIT, rv, ap_server_conf,
1466
                    "apr_thread_mutex_lock(g_timer_skiplist_mtx) failed");
1467
    }
1468
    return rv;
1469
}
1470
1471
static apr_status_t g_timer_skiplist_mtx_unlock(const char *file, int line, int module_index){
1472
    apr_status_t rv = apr_thread_mutex_unlock(g_timer_skiplist_mtx);
1473
    if(rv != APR_SUCCESS){
1474
        ap_log_error(file, line, module_index, APLOG_CRIT, rv, ap_server_conf,
1475
                    "apr_thread_mutex_unlock(g_timer_skiplist_mtx) failed");
1476
    }
1477
    return rv;
1478
}
1479
1480
1436
static timer_event_t * event_get_timer_event(apr_time_t t,
1481
static timer_event_t * event_get_timer_event(apr_time_t t,
1437
                                             ap_mpm_callback_fn_t *cbfn,
1482
                                             ap_mpm_callback_fn_t *cbfn,
1438
                                             void *baton,
1483
                                             void *baton,
Lines 1442-1448 Link Here
1442
    timer_event_t *te;
1487
    timer_event_t *te;
1443
    /* oh yeah, and make locking smarter/fine grained. */
1488
    /* oh yeah, and make locking smarter/fine grained. */
1444
1489
1445
    apr_thread_mutex_lock(g_timer_skiplist_mtx);
1490
    g_timer_skiplist_mtx_lock(APLOG_MARK);
1446
1491
1447
    if (!APR_RING_EMPTY(&timer_free_ring, timer_event_t, link)) {
1492
    if (!APR_RING_EMPTY(&timer_free_ring, timer_event_t, link)) {
1448
        te = APR_RING_FIRST(&timer_free_ring);
1493
        te = APR_RING_FIRST(&timer_free_ring);
Lines 1460-1469 Link Here
1460
    te->remove = remove;
1505
    te->remove = remove;
1461
1506
1462
    if (insert) { 
1507
    if (insert) { 
1508
        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf,
1509
             "skiplist insert, when: %llu", te->when);
1463
        /* Okay, insert sorted by when.. */
1510
        /* Okay, insert sorted by when.. */
1464
        apr_skiplist_insert(timer_skiplist, (void *)te);
1511
        te_array_push(te);
1465
    }
1512
    }
1466
    apr_thread_mutex_unlock(g_timer_skiplist_mtx);
1513
    g_timer_skiplist_mtx_unlock(APLOG_MARK);
1467
1514
1468
    return te;
1515
    return te;
1469
}
1516
}
Lines 1740-1747 Link Here
1740
            }
1787
            }
1741
        }
1788
        }
1742
1789
1743
        apr_thread_mutex_lock(g_timer_skiplist_mtx);
1790
        g_timer_skiplist_mtx_lock(APLOG_MARK);
1744
        te = apr_skiplist_peek(timer_skiplist);
1791
        te = te_array_peek();
1745
        if (te) {
1792
        if (te) {
1746
            if (te->when > now) {
1793
            if (te->when > now) {
1747
                timeout_interval = te->when - now;
1794
                timeout_interval = te->when - now;
Lines 1753-1759 Link Here
1753
        else {
1800
        else {
1754
            timeout_interval = apr_time_from_msec(100);
1801
            timeout_interval = apr_time_from_msec(100);
1755
        }
1802
        }
1756
        apr_thread_mutex_unlock(g_timer_skiplist_mtx);
1803
        g_timer_skiplist_mtx_unlock(APLOG_MARK);
1757
1804
1758
#if HAVE_SERF
1805
#if HAVE_SERF
1759
        rc = serf_context_prerun(g_serf);
1806
        rc = serf_context_prerun(g_serf);
Lines 1762-1787 Link Here
1762
        }
1809
        }
1763
#endif
1810
#endif
1764
        now = apr_time_now();
1811
        now = apr_time_now();
1765
        apr_thread_mutex_lock(g_timer_skiplist_mtx);
1812
        g_timer_skiplist_mtx_lock(APLOG_MARK);
1766
        ep = apr_skiplist_peek(timer_skiplist);
1813
        ep = te_array_peek();
1767
        while (ep) {
1814
        while (ep) {
1815
            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf,
1816
                "when: %llu, now+EFF: %llu, result: %d", ep->when, now + EVENT_FUDGE_FACTOR, ep->when < now + EVENT_FUDGE_FACTOR);
1768
            if (ep->when < now + EVENT_FUDGE_FACTOR) {
1817
            if (ep->when < now + EVENT_FUDGE_FACTOR) {
1769
                apr_skiplist_pop(timer_skiplist, NULL);
1818
                timer_event_t *foo = te_array_pop();
1819
                ap_assert(ep == foo);
1820
                ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf,
1821
                   "skiplist poped, when: %llu", ep->when);
1770
                if (!ep->canceled) { 
1822
                if (!ep->canceled) { 
1771
                    if (ep->remove != NULL) {
1823
                    if (ep->remove != NULL) {
1772
                        for (apr_pollfd_t **pfds = (ep->remove); *pfds != NULL; pfds++) { 
1824
                        for (apr_pollfd_t **pfds = (ep->remove); *pfds != NULL; pfds++) { 
1773
                            apr_pollset_remove(event_pollset, *pfds);
1825
                            apr_pollset_remove(event_pollset, *pfds);
1774
                        }
1826
                        }
1775
                    }
1827
                    }
1828
                    push_timer2worker(ep);
1776
                }
1829
                }
1777
                push_timer2worker(ep);
1778
            }
1830
            }
1779
            else {
1831
            else {
1780
                break;
1832
                break;
1781
            }
1833
            }
1782
            ep = apr_skiplist_peek(timer_skiplist);
1834
            ep = te_array_peek();
1783
        }
1835
        }
1784
        apr_thread_mutex_unlock(g_timer_skiplist_mtx);
1836
        g_timer_skiplist_mtx_unlock(APLOG_MARK);
1785
1837
1786
        rc = apr_pollset_poll(event_pollset, timeout_interval, &num, &out_pfd);
1838
        rc = apr_pollset_poll(event_pollset, timeout_interval, &num, &out_pfd);
1787
        if (rc != APR_SUCCESS) {
1839
        if (rc != APR_SUCCESS) {
Lines 1976-1981 Link Here
1976
                socket_callback_baton_t *baton = (socket_callback_baton_t *) pt->baton;
2028
                socket_callback_baton_t *baton = (socket_callback_baton_t *) pt->baton;
1977
                if (baton->cancel_event) {
2029
                if (baton->cancel_event) {
1978
                    baton->cancel_event->canceled = 1;
2030
                    baton->cancel_event->canceled = 1;
2031
                    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0,
2032
                                 ap_server_conf,
2033
                                 "timer_event canceled.");
1979
                }
2034
                }
1980
2035
1981
                /* We only signal once per N sockets with this baton */
2036
                /* We only signal once per N sockets with this baton */
Lines 2148-2156 Link Here
2148
        if (te != NULL) {
2203
        if (te != NULL) {
2149
            te->cbfunc(te->baton);
2204
            te->cbfunc(te->baton);
2150
            {
2205
            {
2151
                apr_thread_mutex_lock(g_timer_skiplist_mtx);
2206
                g_timer_skiplist_mtx_lock(APLOG_MARK);
2152
                APR_RING_INSERT_TAIL(&timer_free_ring, te, timer_event_t, link);
2207
                APR_RING_INSERT_TAIL(&timer_free_ring, te, timer_event_t, link);
2153
                apr_thread_mutex_unlock(g_timer_skiplist_mtx);
2208
                g_timer_skiplist_mtx_unlock(APLOG_MARK);
2154
            }
2209
            }
2155
        }
2210
        }
2156
        else {
2211
        else {
Lines 2472-2477 Link Here
2472
    apr_pool_create(&pskip, pchild);
2527
    apr_pool_create(&pskip, pchild);
2473
    apr_skiplist_init(&timer_skiplist, pskip);
2528
    apr_skiplist_init(&timer_skiplist, pskip);
2474
    apr_skiplist_set_compare(timer_skiplist, indexing_comp, indexing_compk);
2529
    apr_skiplist_set_compare(timer_skiplist, indexing_comp, indexing_compk);
2530
    te_array_init(pskip);
2475
    ap_run_child_init(pchild, ap_server_conf);
2531
    ap_run_child_init(pchild, ap_server_conf);
2476
2532
2477
    /* done with init critical section */
2533
    /* done with init critical section */

Return to bug 56645