]> git.sur5r.net Git - openldap/commitdiff
Fix reader txn locking
authorHoward Chu <hyc@symas.com>
Wed, 10 Aug 2011 23:09:29 +0000 (16:09 -0700)
committerHoward Chu <hyc@symas.com>
Thu, 1 Sep 2011 23:17:07 +0000 (16:17 -0700)
libraries/libmdb/mdb.c

index 7cb64417a46981bfe13b96c50cb479f9e0c2f2a0..545c7632db6cf7c96bc0211f6834049ae55fa841 100644 (file)
@@ -621,21 +621,20 @@ mdb_txn_begin(MDB_env *env, int rdonly, MDB_txn **ret)
                if (!r) {
                        unsigned int i;
                        pthread_mutex_lock(&env->me_txns->mt_mutex);
-                       for (i=0; i<env->me_maxreaders; i++) {
-                               if (env->me_txns->mt_readers[i].mr_pid == 0) {
-                                       env->me_txns->mt_readers[i].mr_pid = getpid();
-                                       env->me_txns->mt_readers[i].mr_tid = pthread_self();
-                                       r = &env->me_txns->mt_readers[i];
-                                       pthread_setspecific(env->me_txkey, r);
-                                       if (i >= env->me_txns->mt_numreaders)
-                                               env->me_txns->mt_numreaders = i+1;
+                       for (i=0; i<env->me_txns->mt_numreaders; i++)
+                               if (env->me_txns->mt_readers[i].mr_pid == 0)
                                        break;
-                               }
-                       }
-                       pthread_mutex_unlock(&env->me_txns->mt_mutex);
                        if (i == env->me_maxreaders) {
+                               pthread_mutex_unlock(&env->me_txns->mti_mutex);
                                return ENOSPC;
                        }
+                       env->me_txns->mt_readers[i].mr_pid = getpid();
+                       env->me_txns->mt_readers[i].mr_tid = pthread_self();
+                       r = &env->me_txns->mt_readers[i];
+                       pthread_setspecific(env->me_txkey, r);
+                       if (i >= env->me_txns->mt_numreaders)
+                               env->me_txns->mt_numreaders = i+1;
+                       pthread_mutex_unlock(&env->me_txns->mt_mutex);
                }
                r->mr_txnid = txn->mt_txnid;
                txn->mt_u.reader = r;