Mercurial > hg > freeDiameter
comparison extensions/rt_redirect/redir_expiry.c @ 1259:82280e745a89
Remove whitespace at end of line.
author | Thomas Klausner <tk@giga.or.at> |
---|---|
date | Mon, 24 Mar 2014 13:13:38 +0100 |
parents | 4a9f08d6b6ba |
children | 25fad6714991 |
comparison
equal
deleted
inserted
replaced
1258:97caad40b665 | 1259:82280e745a89 |
---|---|
38 /* Expiration management */ | 38 /* Expiration management */ |
39 | 39 |
40 | 40 |
41 /* Entries by their ascending expiration date, to accelerate the work of the expire thread */ | 41 /* Entries by their ascending expiration date, to accelerate the work of the expire thread */ |
42 static struct fd_list expire_list = FD_LIST_INITIALIZER(expire_list); | 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 pthread_mutex_t redir_exp_peer_lock = PTHREAD_MUTEX_INITIALIZER; | 45 pthread_mutex_t redir_exp_peer_lock = PTHREAD_MUTEX_INITIALIZER; |
46 | 46 |
47 /* The thread that handles expired entries cleanup. */ | 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 fd_log_threadname ( "Redirects/expire" ); | 50 fd_log_threadname ( "Redirects/expire" ); |
51 TRACE_ENTRY( "" ); | 51 TRACE_ENTRY( "" ); |
52 | 52 |
53 CHECK_POSIX_DO( pthread_mutex_lock(&redir_exp_peer_lock), goto fatal_error ); | 53 CHECK_POSIX_DO( pthread_mutex_lock(&redir_exp_peer_lock), goto fatal_error ); |
54 pthread_cleanup_push( fd_cleanup_mutex, &redir_exp_peer_lock ); | 54 pthread_cleanup_push( fd_cleanup_mutex, &redir_exp_peer_lock ); |
55 | 55 |
56 do { | 56 do { |
57 struct timespec now; | 57 struct timespec now; |
58 struct redir_entry * first; | 58 struct redir_entry * first; |
59 again: | 59 again: |
60 /* Check if there are expiring entries available */ | 60 /* Check if there are expiring entries available */ |
61 if (FD_IS_LIST_EMPTY(&expire_list)) { | 61 if (FD_IS_LIST_EMPTY(&expire_list)) { |
62 /* Just wait for a change or cancelation */ | 62 /* Just wait for a change or cancelation */ |
63 CHECK_POSIX_DO( pthread_cond_wait( &exp_cnd, &redir_exp_peer_lock ), break /* this might not pop the cleanup handler, but since we ASSERT(0), it is not the big issue... */ ); | 63 CHECK_POSIX_DO( pthread_cond_wait( &exp_cnd, &redir_exp_peer_lock ), break /* this might not pop the cleanup handler, but since we ASSERT(0), it is not the big issue... */ ); |
64 /* Restart the loop on wakeup */ | 64 /* Restart the loop on wakeup */ |
65 goto again; | 65 goto again; |
66 } | 66 } |
67 | 67 |
68 /* Get the pointer to the entry that expires first */ | 68 /* Get the pointer to the entry that expires first */ |
69 first = (struct redir_entry *)(expire_list.next->o); | 69 first = (struct redir_entry *)(expire_list.next->o); |
70 | 70 |
71 /* Get the current time */ | 71 /* Get the current time */ |
72 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), break ); | 72 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), break ); |
73 | 73 |
74 /* If first session is not expired, we just wait until it happens */ | 74 /* If first session is not expired, we just wait until it happens */ |
75 if ( TS_IS_INFERIOR( &now, &first->timeout ) ) { | 75 if ( TS_IS_INFERIOR( &now, &first->timeout ) ) { |
76 | 76 |
77 CHECK_POSIX_DO2( pthread_cond_timedwait( &exp_cnd, &redir_exp_peer_lock, &first->timeout ), | 77 CHECK_POSIX_DO2( pthread_cond_timedwait( &exp_cnd, &redir_exp_peer_lock, &first->timeout ), |
78 ETIMEDOUT, /* ETIMEDOUT is a normal error, continue */, | 78 ETIMEDOUT, /* ETIMEDOUT is a normal error, continue */, |
79 /* on other error, */ break ); | 79 /* on other error, */ break ); |
80 | 80 |
81 /* on wakeup, loop */ | 81 /* on wakeup, loop */ |
82 goto again; | 82 goto again; |
83 } | 83 } |
84 | 84 |
85 /* Now, the first entry in the list is expired; destroy it */ | 85 /* Now, the first entry in the list is expired; destroy it */ |
86 | 86 |
87 CHECK_FCT_DO( redir_entry_destroy( first ), break ); | 87 CHECK_FCT_DO( redir_entry_destroy( first ), break ); |
88 | 88 |
89 } while (1); | 89 } while (1); |
90 | 90 |
91 pthread_cleanup_pop( 0 ); | 91 pthread_cleanup_pop( 0 ); |
92 CHECK_POSIX_DO( pthread_mutex_unlock(&redir_exp_peer_lock), ); | 92 CHECK_POSIX_DO( pthread_mutex_unlock(&redir_exp_peer_lock), ); |
93 | 93 |
94 fatal_error: | 94 fatal_error: |
95 TRACE_DEBUG(INFO, "A system error occurred in redirect module! Expiry thread is terminating..."); | 95 TRACE_DEBUG(INFO, "A system error occurred in redirect module! Expiry thread is terminating..."); |
96 ASSERT(0); | 96 ASSERT(0); |
97 return NULL; | 97 return NULL; |
98 } | 98 } |
101 int redir_exp_set(struct redir_entry * e, uint32_t duration) | 101 int redir_exp_set(struct redir_entry * e, uint32_t duration) |
102 { | 102 { |
103 struct fd_list * li; | 103 struct fd_list * li; |
104 TRACE_ENTRY("%p %d", e, duration); | 104 TRACE_ENTRY("%p %d", e, duration); |
105 CHECK_PARAMS(e && (e->eyec == REDIR_ENTRY_EYEC) && duration ); | 105 CHECK_PARAMS(e && (e->eyec == REDIR_ENTRY_EYEC) && duration ); |
106 | 106 |
107 /* Unlink in case it was already set before */ | 107 /* Unlink in case it was already set before */ |
108 fd_list_unlink(&e->exp_list); | 108 fd_list_unlink(&e->exp_list); |
109 | 109 |
110 /* Get current time */ | 110 /* Get current time */ |
111 CHECK_SYS( clock_gettime(CLOCK_REALTIME, &e->timeout) ); | 111 CHECK_SYS( clock_gettime(CLOCK_REALTIME, &e->timeout) ); |
112 | 112 |
113 /* Add the duration */ | 113 /* Add the duration */ |
114 e->timeout.tv_sec += duration; | 114 e->timeout.tv_sec += duration; |
115 | 115 |
116 /* now search the next element in the list */ | 116 /* now search the next element in the list */ |
117 for (li = expire_list.next; li != &expire_list; li = li->next) { | 117 for (li = expire_list.next; li != &expire_list; li = li->next) { |
118 struct redir_entry * n = li->o; | 118 struct redir_entry * n = li->o; |
119 | 119 |
120 if ( TS_IS_INFERIOR( &e->timeout, &n->timeout ) ) | 120 if ( TS_IS_INFERIOR( &e->timeout, &n->timeout ) ) |
121 break; | 121 break; |
122 | 122 |
123 } | 123 } |
124 | 124 |
125 /* Insert before this element */ | 125 /* Insert before this element */ |
126 fd_list_insert_before(li, &e->exp_list); | 126 fd_list_insert_before(li, &e->exp_list); |
127 | 127 |
128 /* Signal the expiry thread if needed */ | 128 /* Signal the expiry thread if needed */ |
129 if (e->exp_list.prev == &expire_list) { /* it is the first element */ | 129 if (e->exp_list.prev == &expire_list) { /* it is the first element */ |
130 CHECK_POSIX( pthread_cond_signal(&exp_cnd) ); | 130 CHECK_POSIX( pthread_cond_signal(&exp_cnd) ); |
131 } | 131 } |
132 | 132 |
133 /* Done */ | 133 /* Done */ |
134 return 0; | 134 return 0; |
135 } | 135 } |
136 | 136 |