Mercurial > hg > waaad
changeset 357:6c2198aa037c
Worker thread pick messages
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Wed, 20 May 2009 10:24:46 +0900 |
parents | 555dc5a58aef |
children | 505a9ee1244b |
files | extensions/radius_gw/rgw_work.c |
diffstat | 1 files changed, 49 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/extensions/radius_gw/rgw_work.c Tue May 19 17:21:54 2009 +0900 +++ b/extensions/radius_gw/rgw_work.c Wed May 20 10:24:46 2009 +0900 @@ -53,29 +53,62 @@ static pthread_t workers[NB_WORKERS]; +static void cleanup_release_mtx(void * mtx) +{ + CHECK_POSIX_DO( pthread_mutex_unlock((pthread_mutex_t *)mtx), ); +} + + static void * work_th(void * arg) { + char thname[10]; + TRACE_ENTRY("%p", arg); - THREAD_NAME("worker"); + snprintf(thname, sizeof(thname), "worker %2d", (int)arg); + THREAD_NAME(thname); - CHECK_POSIX_DO( pthread_mutex_lock(&work_mtx), return NULL ); + while (1) { /* The thread will be cancelled */ + + rad_t * msg; + void * cli; + struct work_item * wi; -in: - /* wait for new work data */ - if (rg_list_is_empty(&work_data)) { - CHECK_POSIX_DO( pthread_cond_wait( &work_cond, &work_mtx ), goto out ); - goto in; + /* Pick the next message */ + CHECK_POSIX_DO( pthread_mutex_lock(&work_mtx), return NULL ); + + pthread_cleanup_push(cleanup_release_mtx, &work_mtx); + + /* wait for new work data */ + while (rg_list_is_empty(&work_data)) { + CHECK_POSIX_DO( pthread_cond_wait( &work_cond, &work_mtx ), + { + pthread_mutex_unlock(&work_mtx); + return NULL; + } ); + } + + /* Retrieve the next element */ + wi = (struct work_item *)(work_data.next); + rg_list_unlink(&wi->chain); + msg = wi->msg; + cli = wi->cli; + free(wi); + + /* Release the mutex */ + pthread_cleanup_pop(0); + CHECK_POSIX_DO( pthread_mutex_unlock(&work_mtx), return NULL ); + + TRACE_DEBUG(FULL, "Processing next message: %p received on client: %p", msg, cli); + + /* process the data */ + + /* Check authenticator */ + + + } - - - /* process the data */ - - - -out: - CHECK_POSIX_DO( pthread_mutex_unlock(&work_mtx), ); return NULL; } @@ -90,7 +123,7 @@ /* Create the worker thread(s) */ for (i = 0; i < NB_WORKERS; i++) { - CHECK_POSIX( pthread_create(&workers[i], NULL, work_th, NULL) ); + CHECK_POSIX( pthread_create(&workers[i], NULL, work_th, (void *)i) ); } return 0;