determine timer length and put on a correct timer list * WARNING: - don't try to use it to "move" a timer from one list * to another, you'll run into races * - reset_timer; set_timer might not work, a reset'ed timer * has no set_timer guarantee, it might be lost; * same for an expired timer: only it's handler can * set it again, an exte
| 926 | * set it again, an external set_timer has no guarantee |
| 927 | */ |
| 928 | void set_timer( struct timer_link *new_tl, enum lists list_id, |
| 929 | utime_t* ext_timeout ) |
| 930 | { |
| 931 | utime_t timeout; |
| 932 | struct timer* list; |
| 933 | |
| 934 | if (list_id>=NR_OF_TIMER_LISTS) { |
| 935 | LM_CRIT("unknown list: %d\n", list_id); |
| 936 | #ifdef EXTRA_DEBUG |
| 937 | abort(); |
| 938 | #endif |
| 939 | return; |
| 940 | } |
| 941 | |
| 942 | if (!ext_timeout) { |
| 943 | timeout = timer_id2timeout[ list_id ]; |
| 944 | } else { |
| 945 | timeout = *ext_timeout; |
| 946 | } |
| 947 | LM_DBG("relative timeout is %lld\n",timeout); |
| 948 | |
| 949 | list= &(timertable[new_tl->set].timers[ list_id ]); |
| 950 | |
| 951 | lock(list->mutex); |
| 952 | /* check first if we are on the "detached" timer_routine list, |
| 953 | * if so do nothing, the timer is not valid anymore |
| 954 | * (side effect: reset_timer ; set_timer is not safe, a reseted timer |
| 955 | * might be lost, depending on this race condition ) */ |
| 956 | if (new_tl->timer_list==DETACHED_LIST){ |
| 957 | LM_CRIT("set_timer for %d list called on a \"detached\" " |
| 958 | "timer -- ignoring: %p\n", list_id, new_tl); |
| 959 | goto end; |
| 960 | } |
| 961 | /* make sure I'm not already on a list */ |
| 962 | remove_timer_unsafe( new_tl ); |
| 963 | |
| 964 | insert_timer_unsafe( list, new_tl, timeout + |
| 965 | ((timer_id2type[list_id]==UTIME_TYPE)?get_uticks():get_ticks())); |
| 966 | end: |
| 967 | unlock(list->mutex); |
| 968 | } |
| 969 | |
| 970 | |
| 971 |
no test coverage detected