aboutsummaryrefslogtreecommitdiffstats
path: root/src/dirvec.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dirvec.c')
-rw-r--r--src/dirvec.c46
1 files changed, 16 insertions, 30 deletions
diff --git a/src/dirvec.c b/src/dirvec.c
index 3df08e9ab..fa6b7b5f6 100644
--- a/src/dirvec.c
+++ b/src/dirvec.c
@@ -20,6 +20,7 @@
#include "config.h"
#include "dirvec.h"
#include "directory.h"
+#include "db_lock.h"
#include <glib.h>
@@ -27,8 +28,6 @@
#include <string.h>
#include <stdlib.h>
-static GMutex *nr_lock = NULL;
-
static size_t dv_size(const struct dirvec *dv)
{
return dv->nr * sizeof(struct directory *);
@@ -42,24 +41,11 @@ static int dirvec_cmp(const void *d1, const void *d2)
return g_utf8_collate(a->path, b->path);
}
-void dirvec_init(void)
-{
- g_assert(nr_lock == NULL);
- nr_lock = g_mutex_new();
-}
-
-void dirvec_deinit(void)
-{
- g_assert(nr_lock != NULL);
- g_mutex_free(nr_lock);
- nr_lock = NULL;
-}
-
void dirvec_sort(struct dirvec *dv)
{
- g_mutex_lock(nr_lock);
+ db_lock();
qsort(dv->base, dv->nr, sizeof(struct directory *), dirvec_cmp);
- g_mutex_unlock(nr_lock);
+ db_unlock();
}
struct directory *dirvec_find(const struct dirvec *dv, const char *path)
@@ -70,13 +56,13 @@ struct directory *dirvec_find(const struct dirvec *dv, const char *path)
base = g_path_get_basename(path);
- g_mutex_lock(nr_lock);
+ db_lock();
for (i = dv->nr; --i >= 0; )
if (!strcmp(directory_get_name(dv->base[i]), base)) {
ret = dv->base[i];
break;
}
- g_mutex_unlock(nr_lock);
+ db_unlock();
g_free(base);
return ret;
@@ -86,13 +72,13 @@ int dirvec_delete(struct dirvec *dv, struct directory *del)
{
size_t i;
- g_mutex_lock(nr_lock);
+ db_lock();
for (i = 0; i < dv->nr; ++i) {
if (dv->base[i] != del)
continue;
/* we _don't_ call directory_free() here */
if (!--dv->nr) {
- g_mutex_unlock(nr_lock);
+ db_unlock();
g_free(dv->base);
dv->base = NULL;
return i;
@@ -103,25 +89,25 @@ int dirvec_delete(struct dirvec *dv, struct directory *del)
}
break;
}
- g_mutex_unlock(nr_lock);
+ db_unlock();
return i;
}
void dirvec_add(struct dirvec *dv, struct directory *add)
{
- g_mutex_lock(nr_lock);
+ db_lock();
++dv->nr;
dv->base = g_realloc(dv->base, dv_size(dv));
dv->base[dv->nr - 1] = add;
- g_mutex_unlock(nr_lock);
+ db_unlock();
}
void dirvec_destroy(struct dirvec *dv)
{
- g_mutex_lock(nr_lock);
+ db_lock();
dv->nr = 0;
- g_mutex_unlock(nr_lock);
+ db_unlock();
if (dv->base) {
g_free(dv->base);
dv->base = NULL;
@@ -134,20 +120,20 @@ int dirvec_for_each(const struct dirvec *dv,
size_t i;
size_t prev_nr;
- g_mutex_lock(nr_lock);
+ db_lock();
for (i = 0; i < dv->nr; ) {
struct directory *dir = dv->base[i];
assert(dir);
prev_nr = dv->nr;
- g_mutex_unlock(nr_lock);
+ db_unlock();
if (fn(dir, arg) < 0)
return -1;
- g_mutex_lock(nr_lock); /* dv->nr may change in fn() */
+ db_lock(); /* dv->nr may change in fn() */
if (prev_nr == dv->nr)
++i;
}
- g_mutex_unlock(nr_lock);
+ db_unlock();
return 0;
}