Blame SOURCES/0002-Avoid-deadlock-in-TestIndexSearcher.patch

21ead4
From bdc374bfbb0ca34ddb40713eb51d8535fdf11952 Mon Sep 17 00:00:00 2001
21ead4
From: Stephan Bergmann <sbergman@redhat.com>
21ead4
Date: Wed, 31 Jul 2019 16:27:33 +0200
21ead4
Subject: [PATCH 2/2] Avoid deadlock in TestIndexSearcher
21ead4
21ead4
---
21ead4
 src/test/search/TestIndexSearcher.cpp | 51 +++++++++++++++++++++------
21ead4
 1 file changed, 41 insertions(+), 10 deletions(-)
21ead4
21ead4
diff --git a/src/test/search/TestIndexSearcher.cpp b/src/test/search/TestIndexSearcher.cpp
21ead4
index 02c21aaf..a6dde5ba 100644
21ead4
--- a/src/test/search/TestIndexSearcher.cpp
21ead4
+++ b/src/test/search/TestIndexSearcher.cpp
21ead4
@@ -8,9 +8,11 @@
21ead4
 
21ead4
 DEFINE_MUTEX(searchMutex);
21ead4
 DEFINE_CONDITION(searchCondition);
21ead4
+bool searchReady;
21ead4
 
21ead4
 DEFINE_MUTEX(deleteMutex);
21ead4
 DEFINE_CONDITION(deleteCondition);
21ead4
+bool deleteReady;
21ead4
 
21ead4
 _LUCENE_THREAD_FUNC(searchDocs, _searcher) {
21ead4
 
21ead4
@@ -19,15 +21,20 @@ _LUCENE_THREAD_FUNC(searchDocs, _searcher) {
21ead4
     Query * query = QueryParser::parse(_T("one"), _T("content"), &an);
21ead4
     Hits * hits = searcher->search(query);
21ead4
     
21ead4
-//    _LUCENE_SLEEP(9999); //make sure that searchMutex is being waited on...
21ead4
+    {
21ead4
+        SCOPED_LOCK_MUTEX(searchMutex);
21ead4
+        searchReady = true;
21ead4
+        CONDITION_NOTIFYALL(searchCondition);
21ead4
+    }
21ead4
 
21ead4
-    CONDITION_NOTIFYALL(searchCondition);
21ead4
     SCOPED_LOCK_MUTEX(deleteMutex);
21ead4
 
21ead4
     _CLLDELETE(hits);
21ead4
     _CLLDELETE(query);
21ead4
 
21ead4
-    CONDITION_WAIT(deleteMutex, deleteCondition);
21ead4
+    while (!deleteReady) {
21ead4
+        CONDITION_WAIT(deleteMutex, deleteCondition);
21ead4
+    }
21ead4
     _LUCENE_THREAD_FUNC_RETURN(0);
21ead4
 }
21ead4
 
21ead4
@@ -55,13 +62,24 @@ void testEndThreadException(CuTest *tc) {
21ead4
     
21ead4
     // this sequence is OK: delete searcher after search thread finish
21ead4
     {
21ead4
+        searchReady = false;
21ead4
+        deleteReady = false;
21ead4
+
21ead4
         IndexSearcher * searcher = _CLNEW IndexSearcher(&ram;;
21ead4
         _LUCENE_THREADID_TYPE thread = _LUCENE_THREAD_CREATE(&searchDocs, searcher);
21ead4
-        SCOPED_LOCK_MUTEX(searchMutex);
21ead4
 
21ead4
-        CONDITION_WAIT(searchMutex, searchCondition);
21ead4
-//        _LUCENE_SLEEP(9999); //make sure that deleteMutex is being waited on...
21ead4
-        CONDITION_NOTIFYALL(deleteCondition);
21ead4
+        {
21ead4
+            SCOPED_LOCK_MUTEX(searchMutex);
21ead4
+            while (!searchReady) {
21ead4
+                CONDITION_WAIT(searchMutex, searchCondition);
21ead4
+            }
21ead4
+        }
21ead4
+
21ead4
+        {
21ead4
+            SCOPED_LOCK_MUTEX(deleteMutex);
21ead4
+            deleteReady = true;
21ead4
+            CONDITION_NOTIFYALL(deleteCondition);
21ead4
+        }
21ead4
 
21ead4
         _LUCENE_THREAD_JOIN(thread);
21ead4
 
21ead4
@@ -71,14 +89,27 @@ void testEndThreadException(CuTest *tc) {
21ead4
 
21ead4
     // this produces memory exception: delete searcher after search finish but before thread finish
21ead4
     {
21ead4
+        searchReady = false;
21ead4
+        deleteReady = false;
21ead4
+
21ead4
         IndexSearcher * searcher = _CLNEW IndexSearcher(&ram;;
21ead4
         _LUCENE_THREADID_TYPE thread = _LUCENE_THREAD_CREATE(&searchDocs, searcher);
21ead4
-        SCOPED_LOCK_MUTEX(searchMutex);
21ead4
 
21ead4
-        CONDITION_WAIT(searchMutex, searchCondition);
21ead4
+        {
21ead4
+            SCOPED_LOCK_MUTEX(searchMutex);
21ead4
+            while (!searchReady) {
21ead4
+                CONDITION_WAIT(searchMutex, searchCondition);
21ead4
+            }
21ead4
+        }
21ead4
+
21ead4
         searcher->close();
21ead4
         _CLLDELETE(searcher);
21ead4
-        CONDITION_NOTIFYALL(deleteCondition);
21ead4
+
21ead4
+        {
21ead4
+            SCOPED_LOCK_MUTEX(deleteMutex);
21ead4
+            deleteReady = true;
21ead4
+            CONDITION_NOTIFYALL(deleteCondition);
21ead4
+        }
21ead4
 
21ead4
         _LUCENE_THREAD_JOIN(thread);
21ead4
     }
21ead4
-- 
21ead4
2.21.0
21ead4