From b00f863a4678468210d000c2389745d58078d9f4 Mon Sep 17 00:00:00 2001 From: Angel Ortega Date: Tue, 25 Jan 2011 16:03:19 +0100 Subject: [PATCH] Added value deletion in its own thread (disabled by now). --- mpdm.h | 12 +++++++----- mpdm_v.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/mpdm.h b/mpdm.h index 10c1b27..70b544f 100644 --- a/mpdm.h +++ b/mpdm.h @@ -1,7 +1,7 @@ /* MPDM - Minimum Profit Data Manager - Copyright (C) 2003/2010 Angel Ortega + Copyright (C) 2003/2011 Angel Ortega This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -72,10 +72,12 @@ struct mpdm_val { /* the main control structure */ struct mpdm_control { - mpdm_t root; /* the root hash */ - mpdm_t del; /* list of deleted values */ - int count; /* total count of values */ - int hash_buckets; /* default hash buckets */ + mpdm_t root; /* the root hash */ + mpdm_t del; /* list of deleted values */ + int count; /* total count of values */ + int hash_buckets; /* default hash buckets */ + mpdm_t del_queue_mutex; /* delete queue mutex */ + mpdm_t del_queue_sem; /* delete queue semaphore */ }; extern struct mpdm_control *mpdm; diff --git a/mpdm_v.c b/mpdm_v.c index a8ec33d..f555339 100644 --- a/mpdm_v.c +++ b/mpdm_v.c @@ -1,7 +1,7 @@ /* MPDM - Minimum Profit Data Manager - Copyright (C) 2003/2010 Angel Ortega + Copyright (C) 2003/2011 Angel Ortega mpdm_v.c - Basic value management @@ -64,7 +64,42 @@ static void cleanup_value(mpdm_t v) static void destroy_value(mpdm_t v) /* destroys a value */ { - cleanup_value(v); + if (mpdm->del_queue_mutex != NULL) { + /* atomically enqueue this value */ + mpdm_mutex_lock(mpdm->del_queue_mutex); + + v->next = mpdm->del; + mpdm->del = v; + + mpdm_mutex_unlock(mpdm->del_queue_mutex); + + /* notify the del queue thread */ + mpdm_semaphore_post(mpdm->del_queue_sem); + } + else + cleanup_value(v); +} + + +static mpdm_t del_queue_thread(mpdm_t args, mpdm_t ctxt) +/* delete queue processing thread */ +{ + for (;;) { + mpdm_t v; + + /* wait for next value */ + mpdm_semaphore_wait(mpdm->del_queue_sem); + + /* atomically dequeue */ + mpdm_mutex_lock(mpdm->del_queue_mutex); + + v = mpdm->del; + mpdm->del = v->next; + + mpdm_mutex_unlock(mpdm->del_queue_mutex); + + cleanup_value(v); + } } @@ -520,6 +555,17 @@ int mpdm_startup(void) /* sets the defaults */ mpdm->hash_buckets = 31; +#ifdef CONFOPT_THREADED_DELETE + /* create the concurrent delete control */ + mpdm->del_queue_mutex = mpdm_new_mutex(); + mpdm->del_queue_sem = mpdm_new_semaphore(0); +#endif + + /* if the mutex and the semaphore exist, spawn the delete thread */ + if (mpdm->del_queue_mutex != NULL && + mpdm->del_queue_sem != NULL) + mpdm_exec_thread(MPDM_X(del_queue_thread), NULL, NULL); + /* sets the locale */ if (setlocale(LC_ALL, "") == NULL) setlocale(LC_ALL, "C"); -- 2.11.4.GIT