Author: peter
Date: Wed Jul  3 18:35:21 2013
New Revision: 252584
URL: http://svnweb.freebsd.org/changeset/base/252584

Log:
  Make it clear that there are three separate internal locks.

Modified:
  head/lib/libc/iconv/citrus_csmapper.c
  head/lib/libc/iconv/citrus_iconv.c
  head/lib/libc/iconv/citrus_lock.h
  head/lib/libc/iconv/citrus_mapper.c

Modified: head/lib/libc/iconv/citrus_csmapper.c
==============================================================================
--- head/lib/libc/iconv/citrus_csmapper.c       Wed Jul  3 18:27:45 2013        
(r252583)
+++ head/lib/libc/iconv/citrus_csmapper.c       Wed Jul  3 18:35:21 2013        
(r252584)
@@ -58,6 +58,8 @@
 
 static struct _citrus_mapper_area      *maparea = NULL;
 
+static pthread_rwlock_t                        ma_lock = 
PTHREAD_RWLOCK_INITIALIZER;
+
 #define CS_ALIAS       _PATH_CSMAPPER "/charset.alias"
 #define CS_PIVOT       _PATH_CSMAPPER "/charset.pivot"
 
@@ -314,7 +316,7 @@ get_none(struct _citrus_mapper_area *__r
 {
        int ret;
 
-       WLOCK;
+       WLOCK(&ma_lock);
        if (csm_none) {
                *rcsm = csm_none;
                ret = 0;
@@ -329,7 +331,7 @@ get_none(struct _citrus_mapper_area *__r
        *rcsm = csm_none;
        ret = 0;
 quit:
-       UNLOCK;
+       UNLOCK(&ma_lock);
        return (ret);
 }
 

Modified: head/lib/libc/iconv/citrus_iconv.c
==============================================================================
--- head/lib/libc/iconv/citrus_iconv.c  Wed Jul  3 18:27:45 2013        
(r252583)
+++ head/lib/libc/iconv/citrus_iconv.c  Wed Jul  3 18:35:21 2013        
(r252584)
@@ -68,11 +68,13 @@ static int                   shared_max_reuse, shared_n
 static _CITRUS_HASH_HEAD(, _citrus_iconv_shared, CI_HASH_SIZE) shared_pool;
 static TAILQ_HEAD(, _citrus_iconv_shared) shared_unused;
 
+static pthread_rwlock_t                 ci_lock = PTHREAD_RWLOCK_INITIALIZER;
+
 static __inline void
 init_cache(void)
 {
 
-       WLOCK;
+       WLOCK(&ci_lock);
        if (!isinit) {
                _CITRUS_HASH_INIT(&shared_pool, CI_HASH_SIZE);
                TAILQ_INIT(&shared_unused);
@@ -83,7 +85,7 @@ init_cache(void)
                        shared_max_reuse = CI_INITIAL_MAX_REUSE;
                isinit = true;
        }
-       UNLOCK;
+       UNLOCK(&ci_lock);
 }
 
 static __inline void
@@ -195,7 +197,7 @@ get_shared(struct _citrus_iconv_shared *
 
        snprintf(convname, sizeof(convname), "%s/%s", src, dst);
 
-       WLOCK;
+       WLOCK(&ci_lock);
 
        /* lookup alread existing entry */
        hashval = hash_func(convname);
@@ -222,7 +224,7 @@ get_shared(struct _citrus_iconv_shared *
        *rci = ci;
 
 quit:
-       UNLOCK;
+       UNLOCK(&ci_lock);
 
        return (ret);
 }
@@ -231,7 +233,7 @@ static void
 release_shared(struct _citrus_iconv_shared * __restrict ci)
 {
 
-       WLOCK;
+       WLOCK(&ci_lock);
        ci->ci_used_count--;
        if (ci->ci_used_count == 0) {
                /* put it into unused list */
@@ -247,7 +249,7 @@ release_shared(struct _citrus_iconv_shar
                }
        }
 
-       UNLOCK;
+       UNLOCK(&ci_lock);
 }
 
 /*

Modified: head/lib/libc/iconv/citrus_lock.h
==============================================================================
--- head/lib/libc/iconv/citrus_lock.h   Wed Jul  3 18:27:45 2013        
(r252583)
+++ head/lib/libc/iconv/citrus_lock.h   Wed Jul  3 18:35:21 2013        
(r252584)
@@ -27,10 +27,7 @@
 
 #include <pthread.h>
 
-/* XXX Yes, the original code has three separate file-local lock instances */
-static pthread_rwlock_t        lock = PTHREAD_RWLOCK_INITIALIZER;
-
-#define WLOCK  if (__isthreaded)               \
-                   pthread_rwlock_wrlock(&lock);
-#define UNLOCK if (__isthreaded)               \
-                   pthread_rwlock_unlock(&lock);
+#define WLOCK(lock)    if (__isthreaded)               \
+                           pthread_rwlock_wrlock(lock);
+#define UNLOCK(lock)   if (__isthreaded)               \
+                           pthread_rwlock_unlock(lock);

Modified: head/lib/libc/iconv/citrus_mapper.c
==============================================================================
--- head/lib/libc/iconv/citrus_mapper.c Wed Jul  3 18:27:45 2013        
(r252583)
+++ head/lib/libc/iconv/citrus_mapper.c Wed Jul  3 18:35:21 2013        
(r252584)
@@ -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;
@@ -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_mappe
 
        variable = NULL;
 
-       WLOCK;
+       WLOCK(&cm_lock);
 
        /* search in the cache */
        hashval = hash_func(mapname);
@@ -337,9 +339,9 @@ _citrus_mapper_open(struct _citrus_mappe
                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_mappe
        *rcm = cm;
        ret = 0;
 quit:
-       UNLOCK;
+       UNLOCK(&cm_lock);
 
        return (ret);
 }
@@ -370,7 +372,7 @@ _citrus_mapper_close(struct _citrus_mapp
 {
 
        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_mapp
                }
                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);
 }
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to