summaryrefslogtreecommitdiff
path: root/src/analysis/db
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-06-12 23:46:47 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-06-12 23:46:47 (GMT)
commit04d108111fe7ddd01713b4ca22f8d96961ec2486 (patch)
tree72ca086e0db2568bc93acb865b84e29c7d206897 /src/analysis/db
parent64aee7b4301e720a7420ab8942ef88f72d7a2c99 (diff)
Improved loading speed with binary search of sorted arrays.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@538 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/analysis/db')
-rw-r--r--src/analysis/db/cdb.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/analysis/db/cdb.c b/src/analysis/db/cdb.c
index b96e0fe..46cfc23 100644
--- a/src/analysis/db/cdb.c
+++ b/src/analysis/db/cdb.c
@@ -96,6 +96,8 @@ struct _GCdbArchive
GMutex clients_access; /* Verrou pour l'accès */
GThread *process; /* Procédure de traitement */
+ GMutex id_access; /* Accès à l'identifiant */
+ GCond id_cond; /* Condition d'attente */
pthread_t process_id; /* Identifiant de la procédure */
};
@@ -201,6 +203,9 @@ static void g_cdb_archive_init(GCdbArchive *archive)
{
g_mutex_init(&archive->clients_access);
+ g_mutex_init(&archive->id_access);
+ g_cond_init(&archive->id_cond);
+
}
@@ -218,6 +223,11 @@ static void g_cdb_archive_init(GCdbArchive *archive)
static void g_cdb_archive_dispose(GCdbArchive *archive)
{
+ g_cond_clear(&archive->id_cond);
+ g_mutex_clear(&archive->id_access);
+
+ g_mutex_clear(&archive->clients_access);
+
G_OBJECT_CLASS(g_cdb_archive_parent_class)->dispose(G_OBJECT(archive));
}
@@ -805,7 +815,10 @@ static void *g_cdb_archive_process(GCdbArchive *archive)
signal(SIGUSR1, interrupt_poll_with_sigusr1);
+ g_mutex_lock(&archive->id_access);
archive->process_id = pthread_self();
+ g_cond_signal(&archive->id_cond);
+ g_mutex_unlock(&archive->id_access);
fds = NULL;
@@ -824,11 +837,11 @@ static void *g_cdb_archive_process(GCdbArchive *archive)
fds[i].events = POLLIN | POLLPRI;
}
+ g_mutex_unlock(&archive->clients_access);
+
if (nfds == 0)
goto gcap_no_more_clients;
- g_mutex_unlock(&archive->clients_access);
-
/* Lancement d'une phase de surveillance */
printf("(%p) POLL %d\n", archive, nfds);
@@ -918,14 +931,14 @@ static void *g_cdb_archive_process(GCdbArchive *archive)
/* On disparaît des écrans... */
- g_mutex_lock(&archive->clients_access);
-
gcap_no_more_clients:
archive->process = NULL;
- archive->process_id = 0;
- g_mutex_unlock(&archive->clients_access);
+ g_mutex_lock(&archive->id_access);
+ archive->process_id = 0;
+ g_cond_signal(&archive->id_cond);
+ g_mutex_unlock(&archive->id_access);
if (fds != NULL)
free(fds);
@@ -980,7 +993,13 @@ DBError g_cdb_archive_add_client(GCdbArchive *archive, int fd, const rle_string
archive->process = g_thread_new("cdb_process", (GThreadFunc)g_cdb_archive_process, archive);
/* On attend que le processus parallèle soit prêt */
- for (process_id = &archive->process_id; *process_id == 0; );
+
+ process_id = &archive->process_id;
+
+ g_mutex_lock(&archive->id_access);
+ while (process_id == 0)
+ g_cond_wait(&archive->id_cond, &archive->id_access);
+ g_mutex_unlock(&archive->id_access);
}
else