summaryrefslogtreecommitdiffstats
path: root/lib/libc/iconv/citrus_mapper.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/iconv/citrus_mapper.c')
-rw-r--r--lib/libc/iconv/citrus_mapper.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/lib/libc/iconv/citrus_mapper.c b/lib/libc/iconv/citrus_mapper.c
index b5ae96d..b1ee8fb 100644
--- a/lib/libc/iconv/citrus_mapper.c
+++ b/lib/libc/iconv/citrus_mapper.c
@@ -55,6 +55,8 @@
#define CM_HASH_SIZE 101
#define REFCOUNT_PERSISTENT -1
+static pthread_rwlock_t cm_lock = PTHREAD_RWLOCK_INITIALIZER;
+
struct _citrus_mapper_area {
_CITRUS_HASH_HEAD(, _citrus_mapper, CM_HASH_SIZE) ma_cache;
char *ma_dir;
@@ -75,7 +77,7 @@ _citrus_mapper_create_area(
char path[PATH_MAX];
int ret;
- WLOCK;
+ WLOCK(&cm_lock);
if (*rma != NULL) {
ret = 0;
@@ -96,7 +98,7 @@ _citrus_mapper_create_area(
ma->ma_dir = strdup(area);
if (ma->ma_dir == NULL) {
ret = errno;
- free(ma->ma_dir);
+ free(ma);
goto quit;
}
_CITRUS_HASH_INIT(&ma->ma_cache, CM_HASH_SIZE);
@@ -104,7 +106,7 @@ _citrus_mapper_create_area(
*rma = ma;
ret = 0;
quit:
- UNLOCK;
+ UNLOCK(&cm_lock);
return (ret);
}
@@ -316,7 +318,7 @@ _citrus_mapper_open(struct _citrus_mapper_area *__restrict ma,
variable = NULL;
- WLOCK;
+ WLOCK(&cm_lock);
/* search in the cache */
hashval = hash_func(mapname);
@@ -337,9 +339,9 @@ _citrus_mapper_open(struct _citrus_mapper_area *__restrict ma,
goto quit;
/* open mapper */
- UNLOCK;
+ UNLOCK(&cm_lock);
ret = mapper_open(ma, &cm, module, variable);
- WLOCK;
+ WLOCK(&cm_lock);
if (ret)
goto quit;
cm->cm_key = strdup(mapname);
@@ -356,7 +358,7 @@ _citrus_mapper_open(struct _citrus_mapper_area *__restrict ma,
*rcm = cm;
ret = 0;
quit:
- UNLOCK;
+ UNLOCK(&cm_lock);
return (ret);
}
@@ -370,7 +372,7 @@ _citrus_mapper_close(struct _citrus_mapper *cm)
{
if (cm) {
- WLOCK;
+ WLOCK(&cm_lock);
if (cm->cm_refcount == REFCOUNT_PERSISTENT)
goto quit;
if (cm->cm_refcount > 0) {
@@ -381,7 +383,7 @@ _citrus_mapper_close(struct _citrus_mapper *cm)
}
mapper_close(cm);
quit:
- UNLOCK;
+ UNLOCK(&cm_lock);
}
}
@@ -393,7 +395,7 @@ void
_citrus_mapper_set_persistent(struct _citrus_mapper * __restrict cm)
{
- WLOCK;
+ WLOCK(&cm_lock);
cm->cm_refcount = REFCOUNT_PERSISTENT;
- UNLOCK;
+ UNLOCK(&cm_lock);
}
OpenPOWER on IntegriCloud