~ubuntu-branches/ubuntu/vivid/sflphone/vivid

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.0.1/pjlib/src/pj/timer.c

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2013-06-30 11:40:56 UTC
  • mfrom: (4.1.18 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130630114056-0np50jkyqo6vnmii
Tags: 1.2.3-2
* changeset_r92d62cfc54732bbbcfff2b1d36c096b120b981a5.diff 
  - fixes automatic endian detection 
* Update Vcs: fixes vcs-field-not-canonical

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: timer.c 4154 2012-06-05 10:41:17Z bennylp $ */
 
2
/*
 
3
 * The PJLIB's timer heap is based (or more correctly, copied and modied)
 
4
 * from ACE library by Douglas C. Schmidt. ACE is an excellent OO framework
 
5
 * that implements many core patterns for concurrent communication software.
 
6
 * If you're looking for C++ alternative of PJLIB, then ACE is your best
 
7
 * solution.
 
8
 *
 
9
 * You may use this file according to ACE open source terms or PJLIB open
 
10
 * source terms. You can find the fine ACE library at:
 
11
 *  http://www.cs.wustl.edu/~schmidt/ACE.html
 
12
 *
 
13
 * ACE is Copyright (C)1993-2006 Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
 
14
 *
 
15
 * GNU Public License:
 
16
 * This program is free software; you can redistribute it and/or modify
 
17
 * it under the terms of the GNU General Public License as published by
 
18
 * the Free Software Foundation; either version 2 of the License, or
 
19
 * (at your option) any later version.
 
20
 *
 
21
 * This program is distributed in the hope that it will be useful,
 
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
24
 * GNU General Public License for more details.
 
25
 *
 
26
 * You should have received a copy of the GNU General Public License
 
27
 * along with this program; if not, write to the Free Software
 
28
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
29
 */
 
30
#include <pj/timer.h>
 
31
#include <pj/pool.h>
 
32
#include <pj/os.h>
 
33
#include <pj/string.h>
 
34
#include <pj/assert.h>
 
35
#include <pj/errno.h>
 
36
#include <pj/lock.h>
 
37
#include <pj/log.h>
 
38
 
 
39
#define THIS_FILE       "timer.c"
 
40
 
 
41
#define HEAP_PARENT(X)  (X == 0 ? 0 : (((X) - 1) / 2))
 
42
#define HEAP_LEFT(X)    (((X)+(X))+1)
 
43
 
 
44
 
 
45
#define DEFAULT_MAX_TIMED_OUT_PER_POLL  (64)
 
46
 
 
47
 
 
48
/**
 
49
 * The implementation of timer heap.
 
50
 */
 
51
struct pj_timer_heap_t
 
52
{
 
53
    /** Pool from which the timer heap resize will get the storage from */
 
54
    pj_pool_t *pool;
 
55
 
 
56
    /** Maximum size of the heap. */
 
57
    pj_size_t max_size;
 
58
 
 
59
    /** Current size of the heap. */
 
60
    pj_size_t cur_size;
 
61
 
 
62
    /** Max timed out entries to process per poll. */
 
63
    unsigned max_entries_per_poll;
 
64
 
 
65
    /** Lock object. */
 
66
    pj_lock_t *lock;
 
67
 
 
68
    /** Autodelete lock. */
 
69
    pj_bool_t auto_delete_lock;
 
70
 
 
71
    /**
 
72
     * Current contents of the Heap, which is organized as a "heap" of
 
73
     * pj_timer_entry *'s.  In this context, a heap is a "partially
 
74
     * ordered, almost complete" binary tree, which is stored in an
 
75
     * array.
 
76
     */
 
77
    pj_timer_entry **heap;
 
78
 
 
79
    /**
 
80
     * An array of "pointers" that allows each pj_timer_entry in the
 
81
     * <heap_> to be located in O(1) time.  Basically, <timer_id_[i]>
 
82
     * contains the slot in the <heap_> array where an pj_timer_entry
 
83
     * with timer id <i> resides.  Thus, the timer id passed back from
 
84
     * <schedule_entry> is really an slot into the <timer_ids> array.  The
 
85
     * <timer_ids_> array serves two purposes: negative values are
 
86
     * treated as "pointers" for the <freelist_>, whereas positive
 
87
     * values are treated as "pointers" into the <heap_> array.
 
88
     */
 
89
    pj_timer_id_t *timer_ids;
 
90
 
 
91
    /**
 
92
     * "Pointer" to the first element in the freelist contained within
 
93
     * the <timer_ids_> array, which is organized as a stack.
 
94
     */
 
95
    pj_timer_id_t timer_ids_freelist;
 
96
 
 
97
    /** Callback to be called when a timer expires. */
 
98
    pj_timer_heap_callback *callback;
 
99
 
 
100
};
 
101
 
 
102
 
 
103
 
 
104
PJ_INLINE(void) lock_timer_heap( pj_timer_heap_t *ht )
 
105
{
 
106
    if (ht->lock) {
 
107
        pj_lock_acquire(ht->lock);
 
108
    }
 
109
}
 
110
 
 
111
PJ_INLINE(void) unlock_timer_heap( pj_timer_heap_t *ht )
 
112
{
 
113
    if (ht->lock) {
 
114
        pj_lock_release(ht->lock);
 
115
    }
 
116
}
 
117
 
 
118
 
 
119
static void copy_node( pj_timer_heap_t *ht, int slot, pj_timer_entry *moved_node )
 
120
{
 
121
    PJ_CHECK_STACK();
 
122
 
 
123
    // Insert <moved_node> into its new location in the heap.
 
124
    ht->heap[slot] = moved_node;
 
125
 
 
126
    // Update the corresponding slot in the parallel <timer_ids_> array.
 
127
    ht->timer_ids[moved_node->_timer_id] = slot;
 
128
}
 
129
 
 
130
static pj_timer_id_t pop_freelist( pj_timer_heap_t *ht )
 
131
{
 
132
    // We need to truncate this to <int> for backwards compatibility.
 
133
    pj_timer_id_t new_id = ht->timer_ids_freelist;
 
134
 
 
135
    PJ_CHECK_STACK();
 
136
 
 
137
    // The freelist values in the <timer_ids_> are negative, so we need
 
138
    // to negate them to get the next freelist "pointer."
 
139
    ht->timer_ids_freelist =
 
140
        -ht->timer_ids[ht->timer_ids_freelist];
 
141
 
 
142
    return new_id;
 
143
 
 
144
}
 
145
 
 
146
static void push_freelist (pj_timer_heap_t *ht, pj_timer_id_t old_id)
 
147
{
 
148
    PJ_CHECK_STACK();
 
149
 
 
150
    // The freelist values in the <timer_ids_> are negative, so we need
 
151
    // to negate them to get the next freelist "pointer."
 
152
    ht->timer_ids[old_id] = -ht->timer_ids_freelist;
 
153
    ht->timer_ids_freelist = old_id;
 
154
}
 
155
 
 
156
 
 
157
static void reheap_down(pj_timer_heap_t *ht, pj_timer_entry *moved_node,
 
158
                        size_t slot, size_t child)
 
159
{
 
160
    PJ_CHECK_STACK();
 
161
 
 
162
    // Restore the heap property after a deletion.
 
163
 
 
164
    while (child < ht->cur_size)
 
165
    {
 
166
        // Choose the smaller of the two children.
 
167
        if (child + 1 < ht->cur_size
 
168
            && PJ_TIME_VAL_LT(ht->heap[child + 1]->_timer_value, ht->heap[child]->_timer_value))
 
169
            child++;
 
170
 
 
171
        // Perform a <copy> if the child has a larger timeout value than
 
172
        // the <moved_node>.
 
173
        if (PJ_TIME_VAL_LT(ht->heap[child]->_timer_value, moved_node->_timer_value))
 
174
        {
 
175
            copy_node( ht, slot, ht->heap[child]);
 
176
            slot = child;
 
177
            child = HEAP_LEFT(child);
 
178
        }
 
179
        else
 
180
            // We've found our location in the heap.
 
181
            break;
 
182
    }
 
183
 
 
184
    copy_node( ht, slot, moved_node);
 
185
}
 
186
 
 
187
static void reheap_up( pj_timer_heap_t *ht, pj_timer_entry *moved_node,
 
188
                       size_t slot, size_t parent)
 
189
{
 
190
    // Restore the heap property after an insertion.
 
191
 
 
192
    while (slot > 0)
 
193
    {
 
194
        // If the parent node is greater than the <moved_node> we need
 
195
        // to copy it down.
 
196
        if (PJ_TIME_VAL_LT(moved_node->_timer_value, ht->heap[parent]->_timer_value))
 
197
        {
 
198
            copy_node(ht, slot, ht->heap[parent]);
 
199
            slot = parent;
 
200
            parent = HEAP_PARENT(slot);
 
201
        }
 
202
        else
 
203
            break;
 
204
    }
 
205
 
 
206
    // Insert the new node into its proper resting place in the heap and
 
207
    // update the corresponding slot in the parallel <timer_ids> array.
 
208
    copy_node(ht, slot, moved_node);
 
209
}
 
210
 
 
211
 
 
212
static pj_timer_entry * remove_node( pj_timer_heap_t *ht, size_t slot)
 
213
{
 
214
    pj_timer_entry *removed_node = ht->heap[slot];
 
215
 
 
216
    // Return this timer id to the freelist.
 
217
    push_freelist( ht, removed_node->_timer_id );
 
218
 
 
219
    // Decrement the size of the heap by one since we're removing the
 
220
    // "slot"th node.
 
221
    ht->cur_size--;
 
222
 
 
223
    // Set the ID
 
224
    removed_node->_timer_id = -1;
 
225
 
 
226
    // Only try to reheapify if we're not deleting the last entry.
 
227
 
 
228
    if (slot < ht->cur_size)
 
229
    {
 
230
        int parent;
 
231
        pj_timer_entry *moved_node = ht->heap[ht->cur_size];
 
232
 
 
233
        // Move the end node to the location being removed and update
 
234
        // the corresponding slot in the parallel <timer_ids> array.
 
235
        copy_node( ht, slot, moved_node);
 
236
 
 
237
        // If the <moved_node->time_value_> is great than or equal its
 
238
        // parent it needs be moved down the heap.
 
239
        parent = HEAP_PARENT (slot);
 
240
 
 
241
        if (PJ_TIME_VAL_GTE(moved_node->_timer_value, ht->heap[parent]->_timer_value))
 
242
            reheap_down( ht, moved_node, slot, HEAP_LEFT(slot));
 
243
        else
 
244
            reheap_up( ht, moved_node, slot, parent);
 
245
    }
 
246
 
 
247
    return removed_node;
 
248
}
 
249
 
 
250
static void grow_heap(pj_timer_heap_t *ht)
 
251
{
 
252
    // All the containers will double in size from max_size_
 
253
    size_t new_size = ht->max_size * 2;
 
254
    pj_timer_id_t *new_timer_ids;
 
255
    pj_size_t i;
 
256
 
 
257
    // First grow the heap itself.
 
258
 
 
259
    pj_timer_entry **new_heap = 0;
 
260
 
 
261
    new_heap = (pj_timer_entry**)
 
262
               pj_pool_alloc(ht->pool, sizeof(pj_timer_entry*) * new_size);
 
263
    memcpy(new_heap, ht->heap, ht->max_size * sizeof(pj_timer_entry*));
 
264
    //delete [] this->heap_;
 
265
    ht->heap = new_heap;
 
266
 
 
267
    // Grow the array of timer ids.
 
268
 
 
269
    new_timer_ids = 0;
 
270
    new_timer_ids = (pj_timer_id_t*)
 
271
                    pj_pool_alloc(ht->pool, new_size * sizeof(pj_timer_id_t));
 
272
 
 
273
    memcpy( new_timer_ids, ht->timer_ids, ht->max_size * sizeof(pj_timer_id_t));
 
274
 
 
275
    //delete [] timer_ids_;
 
276
    ht->timer_ids = new_timer_ids;
 
277
 
 
278
    // And add the new elements to the end of the "freelist".
 
279
    for (i = ht->max_size; i < new_size; i++)
 
280
        ht->timer_ids[i] = -((pj_timer_id_t) (i + 1));
 
281
 
 
282
    ht->max_size = new_size;
 
283
}
 
284
 
 
285
static void insert_node(pj_timer_heap_t *ht, pj_timer_entry *new_node)
 
286
{
 
287
    if (ht->cur_size + 2 >= ht->max_size)
 
288
        grow_heap(ht);
 
289
 
 
290
    reheap_up( ht, new_node, ht->cur_size, HEAP_PARENT(ht->cur_size));
 
291
    ht->cur_size++;
 
292
}
 
293
 
 
294
 
 
295
static pj_status_t schedule_entry( pj_timer_heap_t *ht,
 
296
                                   pj_timer_entry *entry,
 
297
                                   const pj_time_val *future_time )
 
298
{
 
299
    if (ht->cur_size < ht->max_size)
 
300
    {
 
301
        // Obtain the next unique sequence number.
 
302
        // Set the entry
 
303
        entry->_timer_id = pop_freelist(ht);
 
304
        entry->_timer_value = *future_time;
 
305
        insert_node( ht, entry);
 
306
        return 0;
 
307
    }
 
308
    else
 
309
        return -1;
 
310
}
 
311
 
 
312
 
 
313
static int cancel( pj_timer_heap_t *ht,
 
314
                   pj_timer_entry *entry,
 
315
                   int dont_call)
 
316
{
 
317
  long timer_node_slot;
 
318
 
 
319
  PJ_CHECK_STACK();
 
320
 
 
321
  // Check to see if the timer_id is out of range
 
322
  if (entry->_timer_id < 0 || (pj_size_t)entry->_timer_id > ht->max_size)
 
323
    return 0;
 
324
 
 
325
  timer_node_slot = ht->timer_ids[entry->_timer_id];
 
326
 
 
327
  if (timer_node_slot < 0) // Check to see if timer_id is still valid.
 
328
    return 0;
 
329
 
 
330
  if (entry != ht->heap[timer_node_slot])
 
331
    {
 
332
      pj_assert(entry == ht->heap[timer_node_slot]);
 
333
      return 0;
 
334
    }
 
335
  else
 
336
    {
 
337
      remove_node( ht, timer_node_slot);
 
338
 
 
339
      if (dont_call == 0)
 
340
        // Call the close hook.
 
341
        (*ht->callback)(ht, entry);
 
342
      return 1;
 
343
    }
 
344
}
 
345
 
 
346
 
 
347
/*
 
348
 * Calculate memory size required to create a timer heap.
 
349
 */
 
350
PJ_DEF(pj_size_t) pj_timer_heap_mem_size(pj_size_t count)
 
351
{
 
352
    return /* size of the timer heap itself: */
 
353
           sizeof(pj_timer_heap_t) +
 
354
           /* size of each entry: */
 
355
           (count+2) * (sizeof(pj_timer_entry*)+sizeof(pj_timer_id_t)) +
 
356
           /* lock, pool etc: */
 
357
           132;
 
358
}
 
359
 
 
360
/*
 
361
 * Create a new timer heap.
 
362
 */
 
363
PJ_DEF(pj_status_t) pj_timer_heap_create( pj_pool_t *pool,
 
364
                                          pj_size_t size,
 
365
                                          pj_timer_heap_t **p_heap)
 
366
{
 
367
    pj_timer_heap_t *ht;
 
368
    pj_size_t i;
 
369
 
 
370
    PJ_ASSERT_RETURN(pool && p_heap, PJ_EINVAL);
 
371
 
 
372
    *p_heap = NULL;
 
373
 
 
374
    /* Magic? */
 
375
    size += 2;
 
376
 
 
377
    /* Allocate timer heap data structure from the pool */
 
378
    ht = PJ_POOL_ALLOC_T(pool, pj_timer_heap_t);
 
379
    if (!ht)
 
380
        return PJ_ENOMEM;
 
381
 
 
382
    /* Initialize timer heap sizes */
 
383
    ht->max_size = size;
 
384
    ht->cur_size = 0;
 
385
    ht->max_entries_per_poll = DEFAULT_MAX_TIMED_OUT_PER_POLL;
 
386
    ht->timer_ids_freelist = 1;
 
387
    ht->pool = pool;
 
388
 
 
389
    /* Lock. */
 
390
    ht->lock = NULL;
 
391
    ht->auto_delete_lock = 0;
 
392
 
 
393
    // Create the heap array.
 
394
    ht->heap = (pj_timer_entry**)
 
395
               pj_pool_alloc(pool, sizeof(pj_timer_entry*) * size);
 
396
    if (!ht->heap)
 
397
        return PJ_ENOMEM;
 
398
 
 
399
    // Create the parallel
 
400
    ht->timer_ids = (pj_timer_id_t *)
 
401
                    pj_pool_alloc( pool, sizeof(pj_timer_id_t) * size);
 
402
    if (!ht->timer_ids)
 
403
        return PJ_ENOMEM;
 
404
 
 
405
    // Initialize the "freelist," which uses negative values to
 
406
    // distinguish freelist elements from "pointers" into the <heap_>
 
407
    // array.
 
408
    for (i=0; i<size; ++i)
 
409
        ht->timer_ids[i] = -((pj_timer_id_t) (i + 1));
 
410
 
 
411
    *p_heap = ht;
 
412
    return PJ_SUCCESS;
 
413
}
 
414
 
 
415
PJ_DEF(void) pj_timer_heap_destroy( pj_timer_heap_t *ht )
 
416
{
 
417
    if (ht->lock && ht->auto_delete_lock) {
 
418
        pj_lock_destroy(ht->lock);
 
419
        ht->lock = NULL;
 
420
    }
 
421
}
 
422
 
 
423
PJ_DEF(void) pj_timer_heap_set_lock(  pj_timer_heap_t *ht,
 
424
                                      pj_lock_t *lock,
 
425
                                      pj_bool_t auto_del )
 
426
{
 
427
    if (ht->lock && ht->auto_delete_lock)
 
428
        pj_lock_destroy(ht->lock);
 
429
 
 
430
    ht->lock = lock;
 
431
    ht->auto_delete_lock = auto_del;
 
432
}
 
433
 
 
434
 
 
435
PJ_DEF(unsigned) pj_timer_heap_set_max_timed_out_per_poll(pj_timer_heap_t *ht,
 
436
                                                          unsigned count )
 
437
{
 
438
    unsigned old_count = ht->max_entries_per_poll;
 
439
    ht->max_entries_per_poll = count;
 
440
    return old_count;
 
441
}
 
442
 
 
443
PJ_DEF(pj_timer_entry*) pj_timer_entry_init( pj_timer_entry *entry,
 
444
                                             int id,
 
445
                                             void *user_data,
 
446
                                             pj_timer_heap_callback *cb )
 
447
{
 
448
    pj_assert(entry && cb);
 
449
 
 
450
    entry->_timer_id = -1;
 
451
    entry->id = id;
 
452
    entry->user_data = user_data;
 
453
    entry->cb = cb;
 
454
 
 
455
    return entry;
 
456
}
 
457
 
 
458
#if PJ_TIMER_DEBUG
 
459
PJ_DEF(pj_status_t) pj_timer_heap_schedule_dbg( pj_timer_heap_t *ht,
 
460
                                                pj_timer_entry *entry,
 
461
                                                const pj_time_val *delay,
 
462
                                                const char *src_file,
 
463
                                                int src_line)
 
464
#else
 
465
PJ_DEF(pj_status_t) pj_timer_heap_schedule( pj_timer_heap_t *ht,
 
466
                                            pj_timer_entry *entry,
 
467
                                            const pj_time_val *delay)
 
468
#endif
 
469
{
 
470
    pj_status_t status;
 
471
    pj_time_val expires;
 
472
 
 
473
    PJ_ASSERT_RETURN(ht && entry && delay, PJ_EINVAL);
 
474
    PJ_ASSERT_RETURN(entry->cb != NULL, PJ_EINVAL);
 
475
 
 
476
    /* Prevent same entry from being scheduled more than once */
 
477
    PJ_ASSERT_RETURN(entry->_timer_id < 1, PJ_EINVALIDOP);
 
478
 
 
479
#if PJ_TIMER_DEBUG
 
480
    entry->src_file = src_file;
 
481
    entry->src_line = src_line;
 
482
#endif
 
483
    pj_gettickcount(&expires);
 
484
    PJ_TIME_VAL_ADD(expires, *delay);
 
485
 
 
486
    lock_timer_heap(ht);
 
487
    status = schedule_entry(ht, entry, &expires);
 
488
    unlock_timer_heap(ht);
 
489
 
 
490
    return status;
 
491
}
 
492
 
 
493
PJ_DEF(int) pj_timer_heap_cancel( pj_timer_heap_t *ht,
 
494
                                  pj_timer_entry *entry)
 
495
{
 
496
    int count;
 
497
 
 
498
    PJ_ASSERT_RETURN(ht && entry, PJ_EINVAL);
 
499
 
 
500
    lock_timer_heap(ht);
 
501
    count = cancel(ht, entry, 1);
 
502
    unlock_timer_heap(ht);
 
503
 
 
504
    return count;
 
505
}
 
506
 
 
507
PJ_DEF(unsigned) pj_timer_heap_poll( pj_timer_heap_t *ht,
 
508
                                     pj_time_val *next_delay )
 
509
{
 
510
    pj_time_val now;
 
511
    unsigned count;
 
512
 
 
513
    PJ_ASSERT_RETURN(ht, 0);
 
514
 
 
515
    if (!ht->cur_size && next_delay) {
 
516
        next_delay->sec = next_delay->msec = PJ_MAXINT32;
 
517
        return 0;
 
518
    }
 
519
 
 
520
    count = 0;
 
521
    pj_gettickcount(&now);
 
522
 
 
523
    lock_timer_heap(ht);
 
524
    while ( ht->cur_size &&
 
525
            PJ_TIME_VAL_LTE(ht->heap[0]->_timer_value, now) &&
 
526
            count < ht->max_entries_per_poll )
 
527
    {
 
528
        pj_timer_entry *node = remove_node(ht, 0);
 
529
        ++count;
 
530
 
 
531
        unlock_timer_heap(ht);
 
532
        if (node->cb)
 
533
            (*node->cb)(ht, node);
 
534
        lock_timer_heap(ht);
 
535
    }
 
536
    if (ht->cur_size && next_delay) {
 
537
        *next_delay = ht->heap[0]->_timer_value;
 
538
        PJ_TIME_VAL_SUB(*next_delay, now);
 
539
        if (next_delay->sec < 0 || next_delay->msec < 0)
 
540
            next_delay->sec = next_delay->msec = 0;
 
541
    } else if (next_delay) {
 
542
        next_delay->sec = next_delay->msec = PJ_MAXINT32;
 
543
    }
 
544
    unlock_timer_heap(ht);
 
545
 
 
546
    return count;
 
547
}
 
548
 
 
549
PJ_DEF(pj_size_t) pj_timer_heap_count( pj_timer_heap_t *ht )
 
550
{
 
551
    PJ_ASSERT_RETURN(ht, 0);
 
552
 
 
553
    return ht->cur_size;
 
554
}
 
555
 
 
556
PJ_DEF(pj_status_t) pj_timer_heap_earliest_time( pj_timer_heap_t * ht,
 
557
                                                 pj_time_val *timeval)
 
558
{
 
559
    pj_assert(ht->cur_size != 0);
 
560
    if (ht->cur_size == 0)
 
561
        return PJ_ENOTFOUND;
 
562
 
 
563
    lock_timer_heap(ht);
 
564
    *timeval = ht->heap[0]->_timer_value;
 
565
    unlock_timer_heap(ht);
 
566
 
 
567
    return PJ_SUCCESS;
 
568
}
 
569
 
 
570
#if PJ_TIMER_DEBUG
 
571
PJ_DEF(void) pj_timer_heap_dump(pj_timer_heap_t *ht)
 
572
{
 
573
    lock_timer_heap(ht);
 
574
 
 
575
    PJ_LOG(3,(THIS_FILE, "Dumping timer heap:"));
 
576
    PJ_LOG(3,(THIS_FILE, "  Cur size: %d entries, max: %d",
 
577
                         (int)ht->cur_size, (int)ht->max_size));
 
578
 
 
579
    if (ht->cur_size) {
 
580
        unsigned i;
 
581
        pj_time_val now;
 
582
 
 
583
        PJ_LOG(3,(THIS_FILE, "  Entries: "));
 
584
        PJ_LOG(3,(THIS_FILE, "    _id\tId\tElapsed\tSource"));
 
585
        PJ_LOG(3,(THIS_FILE, "    ----------------------------------"));
 
586
 
 
587
        pj_gettickcount(&now);
 
588
 
 
589
        for (i=0; i<(unsigned)ht->cur_size; ++i) {
 
590
            pj_timer_entry *e = ht->heap[i];
 
591
            pj_time_val delta;
 
592
 
 
593
            if (PJ_TIME_VAL_LTE(e->_timer_value, now))
 
594
                delta.sec = delta.msec = 0;
 
595
            else {
 
596
                delta = e->_timer_value;
 
597
                PJ_TIME_VAL_SUB(delta, now);
 
598
            }
 
599
 
 
600
            PJ_LOG(3,(THIS_FILE, "    %d\t%d\t%d.%03d\t%s:%d",
 
601
                      e->_timer_id, e->id,
 
602
                      (int)delta.sec, (int)delta.msec,
 
603
                      e->src_file, e->src_line));
 
604
        }
 
605
    }
 
606
 
 
607
    unlock_timer_heap(ht);
 
608
}
 
609
#endif