Changeset 1259:82280e745a89 in freeDiameter for extensions/rt_redirect/redir_expiry.c
- Timestamp:
- Mar 24, 2014, 9:13:38 PM (10 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/rt_redirect/redir_expiry.c
r740 r1259 41 41 /* Entries by their ascending expiration date, to accelerate the work of the expire thread */ 42 42 static struct fd_list expire_list = FD_LIST_INITIALIZER(expire_list); 43 static pthread_cond_t exp_cnd = PTHREAD_COND_INITIALIZER; 43 static pthread_cond_t exp_cnd = PTHREAD_COND_INITIALIZER; 44 44 45 45 pthread_mutex_t redir_exp_peer_lock = PTHREAD_MUTEX_INITIALIZER; 46 46 47 47 /* The thread that handles expired entries cleanup. */ 48 void * redir_exp_thr_fct(void * arg) 48 void * redir_exp_thr_fct(void * arg) 49 49 { 50 50 fd_log_threadname ( "Redirects/expire" ); … … 53 53 CHECK_POSIX_DO( pthread_mutex_lock(&redir_exp_peer_lock), goto fatal_error ); 54 54 pthread_cleanup_push( fd_cleanup_mutex, &redir_exp_peer_lock ); 55 55 56 56 do { 57 57 struct timespec now; 58 58 struct redir_entry * first; 59 again: 59 again: 60 60 /* Check if there are expiring entries available */ 61 61 if (FD_IS_LIST_EMPTY(&expire_list)) { … … 65 65 goto again; 66 66 } 67 67 68 68 /* Get the pointer to the entry that expires first */ 69 69 first = (struct redir_entry *)(expire_list.next->o); 70 70 71 71 /* Get the current time */ 72 72 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), break ); … … 74 74 /* If first session is not expired, we just wait until it happens */ 75 75 if ( TS_IS_INFERIOR( &now, &first->timeout ) ) { 76 77 CHECK_POSIX_DO2( pthread_cond_timedwait( &exp_cnd, &redir_exp_peer_lock, &first->timeout ), 76 77 CHECK_POSIX_DO2( pthread_cond_timedwait( &exp_cnd, &redir_exp_peer_lock, &first->timeout ), 78 78 ETIMEDOUT, /* ETIMEDOUT is a normal error, continue */, 79 79 /* on other error, */ break ); 80 80 81 81 /* on wakeup, loop */ 82 82 goto again; 83 83 } 84 84 85 85 /* Now, the first entry in the list is expired; destroy it */ 86 86 87 87 CHECK_FCT_DO( redir_entry_destroy( first ), break ); 88 88 89 89 } while (1); 90 90 91 91 pthread_cleanup_pop( 0 ); 92 92 CHECK_POSIX_DO( pthread_mutex_unlock(&redir_exp_peer_lock), ); 93 93 94 94 fatal_error: 95 95 TRACE_DEBUG(INFO, "A system error occurred in redirect module! Expiry thread is terminating..."); … … 104 104 TRACE_ENTRY("%p %d", e, duration); 105 105 CHECK_PARAMS(e && (e->eyec == REDIR_ENTRY_EYEC) && duration ); 106 106 107 107 /* Unlink in case it was already set before */ 108 108 fd_list_unlink(&e->exp_list); 109 109 110 110 /* Get current time */ 111 111 CHECK_SYS( clock_gettime(CLOCK_REALTIME, &e->timeout) ); 112 112 113 113 /* Add the duration */ 114 114 e->timeout.tv_sec += duration; 115 115 116 116 /* now search the next element in the list */ 117 117 for (li = expire_list.next; li != &expire_list; li = li->next) { 118 118 struct redir_entry * n = li->o; 119 119 120 120 if ( TS_IS_INFERIOR( &e->timeout, &n->timeout ) ) 121 121 break; 122 122 123 123 } 124 124 125 125 /* Insert before this element */ 126 126 fd_list_insert_before(li, &e->exp_list); 127 127 128 128 /* Signal the expiry thread if needed */ 129 129 if (e->exp_list.prev == &expire_list) { /* it is the first element */ 130 130 CHECK_POSIX( pthread_cond_signal(&exp_cnd) ); 131 131 } 132 132 133 133 /* Done */ 134 134 return 0;
Note: See TracChangeset
for help on using the changeset viewer.