~ubuntu-branches/ubuntu/maverick/bind9/maverick

« back to all changes in this revision

Viewing changes to lib/isc/unix/app.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2005-04-19 10:21:58 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050419102158-kp20cp1bqf4ivpzy
Tags: 1:9.3.1-2ubuntu1
resync with debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
3
 
 * Copyright (C) 1999-2002  Internet Software Consortium.
 
3
 * Copyright (C) 1999-2003  Internet Software Consortium.
4
4
 *
5
5
 * Permission to use, copy, modify, and distribute this software for any
6
6
 * purpose with or without fee is hereby granted, provided that the above
15
15
 * PERFORMANCE OF THIS SOFTWARE.
16
16
 */
17
17
 
18
 
/* $Id: app.c,v 1.43.2.4 2004/03/09 06:12:09 marka Exp $ */
 
18
/* $Id: app.c,v 1.43.2.3.8.5 2004/03/08 02:08:05 marka Exp $ */
19
19
 
20
20
#include <config.h>
21
21
 
101
101
        struct sigaction sa;
102
102
        char strbuf[ISC_STRERRORSIZE];
103
103
 
104
 
        memset(&sa, 0, sizeof sa);
 
104
        memset(&sa, 0, sizeof(sa));
105
105
        sa.sa_handler = handler;
106
106
 
107
107
        if (sigfillset(&sa.sa_mask) != 0 ||
274
274
         */
275
275
        isc_task_attach(task, &cloned_task);
276
276
        event = isc_event_allocate(mctx, cloned_task, ISC_APPEVENT_SHUTDOWN,
277
 
                                   action, arg, sizeof *event);
 
277
                                   action, arg, sizeof(*event));
278
278
        if (event == NULL) {
279
279
                result = ISC_R_NOMEMORY;
280
280
                goto unlock;
304
304
                fd_set readfds, writefds;
305
305
                int maxfd;
306
306
                isc_boolean_t readytasks;
 
307
                isc_boolean_t call_timer_dispatch = ISC_FALSE;
307
308
 
308
309
                readytasks = isc__taskmgr_ready();
309
310
                if (readytasks) {
310
311
                        tv.tv_sec = 0;
311
312
                        tv.tv_usec = 0;
312
313
                        tvp = &tv;
 
314
                        call_timer_dispatch = ISC_TRUE;
313
315
                } else {
314
316
                        result = isc__timermgr_nextevent(&when);
315
317
                        if (result != ISC_R_SUCCESS)
317
319
                        else {
318
320
                                isc_uint64_t us;
319
321
 
320
 
                                (void)isc_time_now(&now);
 
322
                                TIME_NOW(&now);
321
323
                                us = isc_time_microdiff(&when, &now);
 
324
                                if (us == 0)
 
325
                                        call_timer_dispatch = ISC_TRUE;
322
326
                                tv.tv_sec = us / 1000000;
323
327
                                tv.tv_usec = us % 1000000;
324
328
                                tvp = &tv;
328
332
                isc__socketmgr_getfdsets(&readfds, &writefds, &maxfd);
329
333
                n = select(maxfd, &readfds, &writefds, NULL, tvp);
330
334
 
331
 
                (void)isc__timermgr_dispatch();
 
335
                if (n == 0 || call_timer_dispatch) {
 
336
                        /*
 
337
                         * We call isc__timermgr_dispatch() only when
 
338
                         * necessary, in order to reduce overhead.  If the
 
339
                         * select() call indicates a timeout, we need the
 
340
                         * dispatch.  Even if not, if we set the 0-timeout 
 
341
                         * for the select() call, we need to check the timer
 
342
                         * events.  In the 'readytasks' case, there may be no
 
343
                         * timeout event actually, but there is no other way
 
344
                         * to reduce the overhead.
 
345
                         * Note that we do not have to worry about the case
 
346
                         * where a new timer is inserted during the select()
 
347
                         * call, since this loop only runs in the non-thread
 
348
                         * mode.
 
349
                         */
 
350
                        isc__timermgr_dispatch();
 
351
                }
332
352
                if (n > 0)
333
353
                        (void)isc__socketmgr_dispatch(&readfds, &writefds,
334
354
                                                      maxfd);
367
387
isc_result_t
368
388
isc__nothread_wait_hack(isc_condition_t *cp, isc_mutex_t *mp) {
369
389
        isc_result_t result;
370
 
        
 
390
 
371
391
        UNUSED(cp);
372
392
        UNUSED(mp);
373
 
        
 
393
 
374
394
        INSIST(!in_recursive_evloop);
375
395
        in_recursive_evloop = ISC_TRUE;
376
396
 
377
397
        INSIST(*mp == 1); /* Mutex must be locked on entry. */
378
398
        --*mp;
379
 
        
 
399
 
380
400
        result = evloop();
381
401
        if (result == ISC_R_RELOAD)
382
402
                want_reload = ISC_TRUE;
394
414
isc__nothread_signal_hack(isc_condition_t *cp) {
395
415
 
396
416
        UNUSED(cp);
397
 
        
 
417
 
398
418
        INSIST(in_recursive_evloop);
399
419
 
400
420
        want_shutdown = ISC_TRUE;
528
548
        if (result != ISC_R_SUCCESS)
529
549
                return (result);
530
550
 
531
 
        while (isc__taskmgr_ready())
532
 
                (void)isc__taskmgr_dispatch();
533
 
 
534
551
#endif /* ISC_PLATFORM_USETHREADS */
535
552
 
536
553
        return (ISC_R_SUCCESS);