]> git.sur5r.net Git - openldap/commitdiff
Changed global ad_mutex into per-attributeType mutex. Added
authorHoward Chu <hyc@openldap.org>
Fri, 16 Nov 2001 07:39:14 +0000 (07:39 +0000)
committerHoward Chu <hyc@openldap.org>
Fri, 16 Nov 2001 07:39:14 +0000 (07:39 +0000)
ad_find_lang() to search an AttributeType for a given language variant.
(Will be used in back-bdb/back-ldbm index code...)

servers/slapd/ad.c
servers/slapd/at.c
servers/slapd/init.c
servers/slapd/proto-slap.h
servers/slapd/slap.h

index 07f7aacd80020f3962e4186c49747b3c7d81ef8e..f570c0b6d69fc0b3e33ce86e74b3346632eb715f 100644 (file)
@@ -18,8 +18,6 @@
 #include "ldap_pvt.h"
 #include "slap.h"
 
-extern ldap_pvt_thread_mutex_t ad_mutex;       /* init.c */
-
 static int ad_keystring(
        struct berval *bv )
 {
@@ -47,6 +45,24 @@ void ad_destroy( void *in )
        }
 }
 
+/* Is there an AttributeDescription for this type that uses this language? */
+AttributeDescription * ad_find_lang(
+       AttributeType *type,
+       struct berval *lang )
+{
+       AttributeDescription *ad;
+
+       ldap_pvt_thread_mutex_lock( &type->sat_ad_mutex );
+       for (ad = type->sat_ad; ad; ad=ad->ad_next)
+       {
+               if (ad->ad_lang.bv_len == lang->bv_len &&
+                       !strcasecmp(ad->ad_lang.bv_val, lang->bv_val))
+                       break;
+       }
+       ldap_pvt_thread_mutex_unlock( &type->sat_ad_mutex );
+       return ad;
+}
+
 int slap_str2ad(
        const char *str,
        AttributeDescription **ad,
@@ -143,6 +159,7 @@ int slap_bv2ad(
                }
        }
 
+       ldap_pvt_thread_mutex_lock( &desc.ad_type->sat_ad_mutex );
        /* see if a matching description is already cached */
        for (d2 = desc.ad_type->sat_ad; d2; d2=d2->ad_next) {
                if (d2->ad_flags != desc.ad_flags)
@@ -159,28 +176,6 @@ int slap_bv2ad(
        /* Not found, add new one */
        while (d2 == NULL) {
                int dlen = 0;
-               /* uses a single mutex instead of one per attributetype.
-                * I don't believe this is a significant bottleneck. If
-                * necessary, could change to a per-AttrType rwlock.
-                */
-               ldap_pvt_thread_mutex_lock( &ad_mutex );
-               /* Check again just in case another thread added it */
-               for (d2 = desc.ad_type->sat_ad; d2; d2=d2->ad_next) {
-                       if (d2->ad_flags != desc.ad_flags)
-                               continue;
-                       if (d2->ad_lang.bv_len != desc.ad_lang.bv_len)
-                               continue;
-                       if (d2->ad_lang.bv_len == 0)
-                               break;
-                       if (strncasecmp(d2->ad_lang.bv_val,desc.ad_lang.bv_val,
-                               desc.ad_lang.bv_len) == 0)
-                               break;
-               }
-               /* Some other thread added it before we got the lock. */
-               if (d2 != NULL) {
-                       ldap_pvt_thread_mutex_unlock( &ad_mutex );
-                       break;
-               }
 
                /* Allocate a single contiguous block. If there are no
                 * options, we just need space for the AttrDesc structure.
@@ -191,7 +186,7 @@ int slap_bv2ad(
                if (desc.ad_lang.bv_len || desc.ad_flags != SLAP_DESC_NONE) {
                        if (desc.ad_lang.bv_len)
                                dlen = desc.ad_lang.bv_len+1;
-                       dlen += strlen(desc.ad_type->sat_cname)+1;
+                       dlen += desc.ad_type->sat_cname.bv_len+1;
                        if( slap_ad_is_binary( &desc ) ) {
                                dlen += sizeof("binary");
                        }
@@ -203,11 +198,11 @@ int slap_bv2ad(
                d2->ad_cname.bv_len = desc.ad_cname.bv_len;
                d2->ad_lang.bv_len = desc.ad_lang.bv_len;
                if (dlen == 0) {
-                       d2->ad_cname.bv_val = d2->ad_type->sat_cname;
+                       d2->ad_cname.bv_val = d2->ad_type->sat_cname.bv_val;
                        d2->ad_lang.bv_val = NULL;
                } else {
                        d2->ad_cname.bv_val = (char *)(d2+1);
-                       strcpy(d2->ad_cname.bv_val, d2->ad_type->sat_cname);
+                       strcpy(d2->ad_cname.bv_val, d2->ad_type->sat_cname.bv_val);
                        if( slap_ad_is_binary( &desc ) ) {
                                strcpy(d2->ad_cname.bv_val+d2->ad_cname.bv_len,
                                        ";binary");
@@ -235,8 +230,8 @@ int slap_bv2ad(
                        d2->ad_next = desc.ad_type->sat_ad->ad_next;
                        desc.ad_type->sat_ad->ad_next = d2;
                }
-               ldap_pvt_thread_mutex_unlock( &ad_mutex );
        }
+       ldap_pvt_thread_mutex_unlock( &desc.ad_type->sat_ad_mutex );
 
        if( *ad == NULL ) {
                *ad = d2;
index e90cc23d8d9fc5cbf05873c0eb8cb65b5fa0495d..4bec7c10543060f42f30a40038222b8c39308a2d 100644 (file)
@@ -181,6 +181,7 @@ at_destroy( void )
                n = a->sat_next;
                ldap_memfree(a->sat_subtypes);
                ad_destroy(a->sat_ad);
+               ldap_pvt_thread_mutex_destroy(&a->sat_ad_mutex);
                ldap_attributetype_free((LDAPAttributeType *)a);
        }
 }
@@ -276,6 +277,7 @@ at_add(
        AC_MEMCPY( &sat->sat_atype, at, sizeof(LDAPAttributeType));
 
        sat->sat_cname = cname;
+       ldap_pvt_thread_mutex_init(&sat->sat_ad_mutex);
 
        if ( at->at_sup_oid ) {
                AttributeType *supsat = at_find(at->at_sup_oid);
index 0d29037e9090eb432594e5087393cd6d654485b2..508650b36b22251f0b4ac29de40dc962790fdd67 100644 (file)
@@ -43,7 +43,6 @@ ldap_pvt_thread_mutex_t       gmtime_mutex;
 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
 ldap_pvt_thread_mutex_t        passwd_mutex;
 #endif
-ldap_pvt_thread_mutex_t ad_mutex;
 
 int                            num_conns;
 long                   num_ops_initiated;
@@ -115,7 +114,6 @@ slap_init( int mode, const char *name )
                        ldap_pvt_thread_mutex_init( &num_sent_mutex );
 
                        ldap_pvt_thread_mutex_init( &gmtime_mutex );
-                       ldap_pvt_thread_mutex_init( &ad_mutex );
 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
                        ldap_pvt_thread_mutex_init( &passwd_mutex );
 #endif
index 63457cad41136023bd64e9560b08d16e39f19e1a..0b60f5e6935a7fa0ebec9218954dd837fd37dfb2 100644 (file)
@@ -49,6 +49,10 @@ LDAP_SLAPD_F (int) slap_bv2undef_ad LDAP_P((
        AttributeDescription **ad,
        const char **text ));
 
+LDAP_SLAPD_F (AttributeDescription *) ad_find_lang LDAP_P((
+       AttributeType *type,
+       struct berval *lang ));
+
 /*
  * acl.c
  */
index d37fc0d481bbbb27ac7bbdb9c119e68440256148..bfca2373da304c2032a64b4a467663eae6a4dcf6 100644 (file)
@@ -378,6 +378,7 @@ typedef struct slap_attribute_type {
        MatchingRule                    *sat_ordering;
        MatchingRule                    *sat_substr;
        Syntax                          *sat_syntax;
+       ldap_pvt_thread_mutex_t         sat_ad_mutex;
        struct slap_attr_desc           *sat_ad;
        struct slap_attribute_type      *sat_next;
 #define sat_oid                        sat_atype.at_oid