]> git.stg.codes - stg.git/commitdiff
Усунуто проблему race conditions у rscriptd
authorMaxim Mamontov <faust@gts.dp.ua>
Fri, 21 Jan 2011 15:57:35 +0000 (17:57 +0200)
committerMaxim Mamontov <faust@gts.dp.ua>
Fri, 21 Jan 2011 15:57:35 +0000 (17:57 +0200)
projects/rscriptd/listener.cpp

index f6d77c96b2ddf4b4b2edb9c122a13c70d054b58e..aca5da445c4dec4346d4c38dc9cd0374313f7c56 100644 (file)
@@ -333,9 +333,16 @@ return false;
 //-----------------------------------------------------------------------------
 void LISTENER::ProcessPending()
 {
-printfd(__FILE__, "Pending data size: %d\n", pending.size());
-std::list<PendingData>::iterator it(pending.begin());
-while (it != pending.end())
+std::list<PendingData> localPending;
+
+    {
+    STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+    printfd(__FILE__, "Pending data size: %d\n", pending.size());
+    localPending.swap(pending);
+    }
+
+std::list<PendingData>::iterator it(localPending.begin());
+while (it != localPending.end())
     {
     std::vector<AliveData>::iterator uit(
             std::lower_bound(
@@ -375,9 +382,7 @@ while (it != pending.end())
             users.erase(uit);
             }
         }
-
-    STG_LOCKER lock(&mutex, __FILE__, __LINE__);
-    pending.erase(it++);
+    ++it;
     }
 }
 //-----------------------------------------------------------------------------