123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- #ifndef __PJ_TIMER_H__
- #define __PJ_TIMER_H__
- #include <pj/types.h>
- #include <pj/lock.h>
- #if PJ_TIMER_USE_LINKED_LIST
- # include <pj/list.h>
- #endif
- PJ_BEGIN_DECL
- typedef int pj_timer_id_t;
- struct pj_timer_entry;
- typedef void pj_timer_heap_callback(pj_timer_heap_t *timer_heap,
- struct pj_timer_entry *entry);
- typedef struct pj_timer_entry
- {
- #if !PJ_TIMER_USE_COPY && PJ_TIMER_USE_LINKED_LIST
-
- PJ_DECL_LIST_MEMBER(struct pj_timer_entry);
- #endif
-
- void *user_data;
-
- int id;
-
- pj_timer_heap_callback *cb;
-
- pj_timer_id_t _timer_id;
- #if !PJ_TIMER_USE_COPY
-
- pj_time_val _timer_value;
-
- pj_grp_lock_t *_grp_lock;
- #if PJ_TIMER_DEBUG
- const char *src_file;
- int src_line;
- #endif
- #endif
- } pj_timer_entry;
- PJ_DECL(pj_size_t) pj_timer_heap_mem_size(pj_size_t count);
- PJ_DECL(pj_status_t) pj_timer_heap_create( pj_pool_t *pool,
- pj_size_t count,
- pj_timer_heap_t **ht);
- PJ_DECL(void) pj_timer_heap_destroy( pj_timer_heap_t *ht );
- PJ_DECL(void) pj_timer_heap_set_lock( pj_timer_heap_t *ht,
- pj_lock_t *lock,
- pj_bool_t auto_del );
- PJ_DECL(unsigned) pj_timer_heap_set_max_timed_out_per_poll(pj_timer_heap_t *ht,
- unsigned count );
- PJ_DECL(pj_timer_entry*) pj_timer_entry_init( pj_timer_entry *entry,
- int id,
- void *user_data,
- pj_timer_heap_callback *cb );
- PJ_DECL(pj_bool_t) pj_timer_entry_running( pj_timer_entry *entry );
- #if PJ_TIMER_DEBUG
- # define pj_timer_heap_schedule(ht,e,d) \
- pj_timer_heap_schedule_dbg(ht,e,d,__FILE__,__LINE__)
- PJ_DECL(pj_status_t) pj_timer_heap_schedule_dbg( pj_timer_heap_t *ht,
- pj_timer_entry *entry,
- const pj_time_val *delay,
- const char *src_file,
- int src_line);
- #else
- PJ_DECL(pj_status_t) pj_timer_heap_schedule( pj_timer_heap_t *ht,
- pj_timer_entry *entry,
- const pj_time_val *delay);
- #endif
- #if PJ_TIMER_DEBUG
- # define pj_timer_heap_schedule_w_grp_lock(ht,e,d,id,g) \
- pj_timer_heap_schedule_w_grp_lock_dbg(ht,e,d,id,g,__FILE__,__LINE__)
- PJ_DECL(pj_status_t) pj_timer_heap_schedule_w_grp_lock_dbg(
- pj_timer_heap_t *ht,
- pj_timer_entry *entry,
- const pj_time_val *delay,
- int id_val,
- pj_grp_lock_t *grp_lock,
- const char *src_file,
- int src_line);
- #else
- PJ_DECL(pj_status_t) pj_timer_heap_schedule_w_grp_lock(
- pj_timer_heap_t *ht,
- pj_timer_entry *entry,
- const pj_time_val *delay,
- int id_val,
- pj_grp_lock_t *grp_lock);
- #endif
- PJ_DECL(int) pj_timer_heap_cancel( pj_timer_heap_t *ht,
- pj_timer_entry *entry);
- PJ_DECL(int) pj_timer_heap_cancel_if_active(pj_timer_heap_t *ht,
- pj_timer_entry *entry,
- int id_val);
- PJ_DECL(pj_size_t) pj_timer_heap_count( pj_timer_heap_t *ht );
- PJ_DECL(pj_status_t) pj_timer_heap_earliest_time( pj_timer_heap_t *ht,
- pj_time_val *timeval);
- PJ_DECL(unsigned) pj_timer_heap_poll( pj_timer_heap_t *ht,
- pj_time_val *next_delay);
- #if PJ_TIMER_DEBUG
- PJ_DECL(void) pj_timer_heap_dump(pj_timer_heap_t *ht);
- #endif
- PJ_END_DECL
- #endif
|