aboutsummaryrefslogtreecommitdiffstats
path: root/libibex
diff options
context:
space:
mode:
authorNot Zed <NotZed@HelixCode.com>2000-12-24 08:58:02 +0800
committerMichael Zucci <zucchi@src.gnome.org>2000-12-24 08:58:02 +0800
commit5674966eeb7eecfa109ad419f1c997dba69ff0af (patch)
treea439ac65139c39f3f551573b1c9f14a8e56b1c82 /libibex
parentd5b5b5f0979f0819561fbec36a417a6dcfc3d4d5 (diff)
downloadgsoc2013-evolution-5674966eeb7eecfa109ad419f1c997dba69ff0af.tar.gz
gsoc2013-evolution-5674966eeb7eecfa109ad419f1c997dba69ff0af.tar.zst
gsoc2013-evolution-5674966eeb7eecfa109ad419f1c997dba69ff0af.zip
Merge from camel-mt-branch.
2000-12-24 Not Zed <NotZed@HelixCode.com> * Merge from camel-mt-branch. svn path=/trunk/; revision=7152
Diffstat (limited to 'libibex')
-rw-r--r--libibex/ChangeLog24
-rw-r--r--libibex/Makefile.am5
-rw-r--r--libibex/dumpindex.c4
-rw-r--r--libibex/ibex_block.c38
-rw-r--r--libibex/ibex_internal.h19
-rw-r--r--libibex/testindex.c44
6 files changed, 128 insertions, 6 deletions
diff --git a/libibex/ChangeLog b/libibex/ChangeLog
index 877d9b8e29..2d3fe7bace 100644
--- a/libibex/ChangeLog
+++ b/libibex/ChangeLog
@@ -1,3 +1,27 @@
+2000-12-24 Not Zed <NotZed@HelixCode.com>
+
+ * Merge from camel-mt-branch.
+
+2000-12-18 Not Zed <NotZed@HelixCode.com>
+
+ * dumpindex.c (main): Same here.
+
+ * testindex.c (main): Add a g_thread_init(). Sigh, glib's thread
+ stuff is snot.
+ (read_words): Setup another flat-out thread to test
+ multithreadedness at little bit.
+
+ * ibex_block.c (ibex_index_buffer): Add locking around internal
+ calls.
+ (ibex_open): Init the locking mutex.
+ (ibex_close): Free the locking mutex.
+ (ibex_unindex):
+ (ibex_find):
+ (ibex_find_name):
+ (ibex_contains_name): Add locking around internal calls.
+
+ * ibex_internal.h (struct ibex): Add a lock. Include config.h
+
2000-12-13 Christopher James Lahey <clahey@helixcode.com>
* disktail.c (tail_compress):
diff --git a/libibex/Makefile.am b/libibex/Makefile.am
index 61f3d72004..ab7c92206c 100644
--- a/libibex/Makefile.am
+++ b/libibex/Makefile.am
@@ -18,16 +18,17 @@ noinst_HEADERS = \
index.h
INCLUDES = -I$(srcdir) $(GLIB_CFLAGS) $(UNICODE_CFLAGS) \
+ $(THREADS_CFLAGS) \
-DG_LOG_DOMAIN=\"libibex\"
noinst_PROGRAMS = dumpindex testindex
dumpindex_SOURCES = dumpindex.c
-dumpindex_LDADD = libibex.la $(GLIB_LIBS) $(UNICODE_LIBS)
+dumpindex_LDADD = libibex.la $(GLIB_LIBS) $(UNICODE_LIBS) $(THREADS_LIBS)
testindex_SOURCES = testindex.c
-testindex_LDADD = libibex.la $(GLIB_LIBS) $(UNICODE_LIBS) -lm
+testindex_LDADD = libibex.la $(GLIB_LIBS) $(UNICODE_LIBS) $(THREADS_LIBS) -lm
#noinst_PROGRAMS = mkindex lookup
#
diff --git a/libibex/dumpindex.c b/libibex/dumpindex.c
index cf4f02cc8a..410a7083d6 100644
--- a/libibex/dumpindex.c
+++ b/libibex/dumpindex.c
@@ -37,6 +37,10 @@ int main(int argc, char **argv)
{
ibex *ib;
+#ifdef ENABLE_THREADS
+ g_thread_init(0);
+#endif
+
if (argc != 2) {
printf("Usage: %s ibexfile\n", argv[0]);
return 1;
diff --git a/libibex/ibex_block.c b/libibex/ibex_block.c
index 41388162c4..faeee232ac 100644
--- a/libibex/ibex_block.c
+++ b/libibex/ibex_block.c
@@ -215,12 +215,17 @@ ibex_index_buffer (ibex *ib, char *name, char *buffer, size_t len, size_t *unrea
p = q;
}
done:
+ IBEX_LOCK(ib);
+
d(printf("name %s count %d size %d\n", name, wordlist->len, len));
if (!ib->predone) {
ib->words->klass->index_pre(ib->words);
ib->predone = TRUE;
}
ib->words->klass->add_list(ib->words, name, wordlist);
+
+ IBEX_UNLOCK(ib);
+
ret = 0;
error:
for (i=0;i<wordlist->len;i++)
@@ -246,12 +251,18 @@ ibex *ibex_open (char *file, int flags, int mode)
/* FIXME: the blockcache or the wordindex needs to manage the other one */
ib->words = ib->blocks->words;
+#ifdef ENABLE_THREADS
+ ib->lock = g_mutex_new();
+#endif
return ib;
}
int ibex_save (ibex *ib)
{
d(printf("syncing database\n"));
+
+ IBEX_LOCK(ib);
+
if (ib->predone) {
ib->words->klass->index_post(ib->words);
ib->predone = FALSE;
@@ -259,6 +270,9 @@ int ibex_save (ibex *ib)
ib->words->klass->sync(ib->words);
/* FIXME: some return */
ibex_block_cache_sync(ib->blocks);
+
+ IBEX_UNLOCK(ib);
+
return 0;
}
@@ -275,6 +289,9 @@ int ibex_close (ibex *ib)
ib->words->klass->close(ib->words);
ibex_block_cache_close(ib->blocks);
+#ifdef ENABLE_THREADS
+ g_mutex_free(ib->lock);
+#endif
g_free(ib);
return ret;
}
@@ -282,32 +299,47 @@ int ibex_close (ibex *ib)
void ibex_unindex (ibex *ib, char *name)
{
d(printf("trying to unindex '%s'\n", name));
+ IBEX_LOCK(ib);
ib->words->klass->unindex_name(ib->words, name);
+ IBEX_UNLOCK(ib);
}
GPtrArray *ibex_find (ibex *ib, char *word)
{
char *normal;
int len;
+ GPtrArray *ret;
len = strlen(word);
normal = alloca(len+1);
ibex_normalise_word(word, word+len, normal);
- return ib->words->klass->find(ib->words, normal);
+ IBEX_LOCK(ib);
+ ret = ib->words->klass->find(ib->words, normal);
+ IBEX_UNLOCK(ib);
+ return ret;
}
gboolean ibex_find_name (ibex *ib, char *name, char *word)
{
char *normal;
int len;
+ gboolean ret;
len = strlen(word);
normal = alloca(len+1);
ibex_normalise_word(word, word+len, normal);
- return ib->words->klass->find_name(ib->words, name, normal);
+ IBEX_LOCK(ib);
+ ret = ib->words->klass->find_name(ib->words, name, normal);
+ IBEX_UNLOCK(ib);
+ return ret;
}
gboolean ibex_contains_name(ibex *ib, char *name)
{
- return ib->words->klass->contains_name(ib->words, name);
+ gboolean ret;
+
+ IBEX_LOCK(ib);
+ ret = ib->words->klass->contains_name(ib->words, name);
+ IBEX_UNLOCK(ib);
+ return ret;
}
diff --git a/libibex/ibex_internal.h b/libibex/ibex_internal.h
index 0eb4b625ce..f2212799c6 100644
--- a/libibex/ibex_internal.h
+++ b/libibex/ibex_internal.h
@@ -18,6 +18,8 @@
* Boston, MA 02111-1307, USA.
*/
+#include "config.h"
+
#include <glib.h>
#include "ibex.h"
@@ -29,4 +31,21 @@ struct ibex {
struct _memcache *blocks;
struct _IBEXWord *words;
int predone;
+
+ /* sigh i hate glib's mutex stuff too */
+#ifdef ENABLE_THREADS
+ GMutex *lock;
+#endif
+
};
+
+#ifdef ENABLE_THREADS
+/*#define IBEX_LOCK(ib) (printf(__FILE__ "%d: %s: locking ibex\n", __LINE__, __FUNCTION__), g_mutex_lock(ib->lock))
+ #define IBEX_UNLOCK(ib) (printf(__FILE__ "%d: %s: unlocking ibex\n", __LINE__, __FUNCTION__), g_mutex_unlock(ib->lock))*/
+#define IBEX_LOCK(ib) (g_mutex_lock(ib->lock))
+#define IBEX_UNLOCK(ib) (g_mutex_unlock(ib->lock))
+#else
+#define IBEX_LOCK(ib)
+#define IBEX_UNLOCK(ib)
+#endif
+
diff --git a/libibex/testindex.c b/libibex/testindex.c
index e21d73ff06..a3b6a9ce03 100644
--- a/libibex/testindex.c
+++ b/libibex/testindex.c
@@ -6,6 +6,10 @@
#include <string.h>
#include "ibex_internal.h"
+#ifdef ENABLE_THREADS
+#include <pthread.h>
+#endif
+
void word_index_mem_dump_info(struct _IBEXWord *idx);
/*
@@ -69,6 +73,29 @@ static char *getword(GPtrArray *words, float m, float s)
return words->pdata[index];
}
+#ifdef ENABLE_THREADS
+int do_read_words;
+
+static void *
+read_words(void *in)
+{
+ ibex *ib = in;
+ GPtrArray *a;
+ int lastlen = 0;
+ int i;
+
+ while (do_read_words) {
+ a = ibex_find(ib, "joneses");
+ if (a->len != lastlen) {
+ printf("Found %d joneses!\n", a->len);
+ lastlen = a->len;
+ }
+ for (i=0;i<a->len;i++)
+ g_free(a->pdata[i]);
+ g_ptr_array_free(a, TRUE);
+ }
+}
+#endif
int main(int argc, char **argv)
{
@@ -83,9 +110,15 @@ int main(int argc, char **argv)
int files;
char *dict;
+#ifdef ENABLE_THREADS
+ pthread_t id;
+
+ g_thread_init(0);
+#endif
+
srand(0xABADF00D);
- files = 80000;
+ files = 8000;
dict = "/usr/dict/words";
/* read words into an array */
@@ -119,6 +152,10 @@ int main(int argc, char **argv)
return 1;
}
+#ifdef ENABLE_THREADS
+ do_read_words = 1;
+ pthread_create(&id, 0, read_words, ib);
+#endif
printf("Adding %d files\n", files);
/* simulate adding new words to a bunch of files */
@@ -151,6 +188,11 @@ int main(int argc, char **argv)
word_index_mem_dump_info(ib->words);
+#ifdef ENABLE_THREADS
+ do_read_words = 0;
+ pthread_join(id, 0);
+#endif
+
ibex_close(ib);
return 0;