diff options
author | Rene Mayrhofer <rene@mayrhofer.eu.org> | 2008-02-08 18:04:42 +0000 |
---|---|---|
committer | Rene Mayrhofer <rene@mayrhofer.eu.org> | 2008-02-08 18:04:42 +0000 |
commit | 73ac0ec24bdf4bf3d82850b80dba4905c3e4f884 (patch) | |
tree | f36bb7f5967d4aaeb6621860639df312c1dcad7c /src/manager/lib/dispatcher.c | |
parent | 61c73fef76f2fb057e3dde2fc4d32e933f22bc74 (diff) | |
download | vyos-strongswan-73ac0ec24bdf4bf3d82850b80dba4905c3e4f884.tar.gz vyos-strongswan-73ac0ec24bdf4bf3d82850b80dba4905c3e4f884.zip |
- Updated to new upstream release.
- Updated ja.po.
Diffstat (limited to 'src/manager/lib/dispatcher.c')
-rw-r--r-- | src/manager/lib/dispatcher.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/manager/lib/dispatcher.c b/src/manager/lib/dispatcher.c index df669ceb6..ce53d39ea 100644 --- a/src/manager/lib/dispatcher.c +++ b/src/manager/lib/dispatcher.c @@ -30,6 +30,7 @@ #include <signal.h> #include <unistd.h> +#include <debug.h> #include <utils/linked_list.h> typedef struct private_dispatcher_t private_dispatcher_t; @@ -122,8 +123,8 @@ typedef struct { session_t *session; /** condvar to wait for session */ pthread_cond_t cond; - /** number of threads waiting for session */ - int waiting; + /** TRUE if session is in use */ + bool in_use; /** last use of the session */ time_t used; } session_entry_t; @@ -164,7 +165,7 @@ static session_entry_t *session_entry_create(private_dispatcher_t *this) session_entry_t *entry; entry = malloc_thing(session_entry_t); - entry->waiting = 1; + entry->in_use = FALSE; pthread_cond_init(&entry->cond, NULL); entry->session = load_session(this); entry->used = time(NULL); @@ -228,11 +229,12 @@ static void dispatch(private_dispatcher_t *this) now = time(NULL); /* find session */ - iterator = this->sessions->create_iterator_locked(this->sessions, &this->mutex); + pthread_mutex_lock(&this->mutex); + iterator = this->sessions->create_iterator(this->sessions, TRUE); while (iterator->iterate(iterator, (void**)¤t)) { /* check all sessions for timeout */ - if (current->waiting == 0 && + if (!current->in_use && current->used < now - this->timeout) { iterator->remove(iterator); @@ -243,27 +245,24 @@ static void dispatch(private_dispatcher_t *this) streq(current->session->get_sid(current->session), sid)) { found = current; - found->waiting++; } } iterator->destroy(iterator); if (found) { /* wait until session is unused */ - pthread_mutex_lock(&this->mutex); - while (found->waiting > 1) + while (found->in_use) { pthread_cond_wait(&found->cond, &this->mutex); } - pthread_mutex_unlock(&this->mutex); } else { /* create a new session if not found */ found = session_entry_create(this); - pthread_mutex_lock(&this->mutex); this->sessions->insert_first(this->sessions, found); - pthread_mutex_unlock(&this->mutex); } + found->in_use = TRUE; + pthread_mutex_unlock(&this->mutex); /* start processing */ found->session->process(found->session, request); @@ -271,7 +270,7 @@ static void dispatch(private_dispatcher_t *this) /* release session */ pthread_mutex_lock(&this->mutex); - found->waiting--; + found->in_use = FALSE; pthread_cond_signal(&found->cond); pthread_mutex_unlock(&this->mutex); |