[Coverity] Fix double_unlock issue in markFilled()
authorEunju Yang <ej.yang@samsung.com>
Wed, 5 Feb 2025 06:53:31 +0000 (15:53 +0900)
committerjijoong.moon <jijoong.moon@samsung.com>
Fri, 7 Feb 2025 02:14:55 +0000 (11:14 +0900)
- The `unique_lock` was manually unlocked before going out of scope,
  causing a double unlock issue.
- This has been fixed by removing the explicit `unlock()` call.
- Additionally, `notify_emptied_cv.notify_all()` is now called without
  holding the lock to avoid unnecessary cntention.

Signed-off-by: Eunju Yang <ej.yang@samsung.com>
nntrainer/dataset/iteration_queue.cpp

index 5e972bb0949297df095155f833e4bcc1ab60c28d..9885c019438615c1717cce03ab633de2c5dd0333 100644 (file)
@@ -153,10 +153,11 @@ void IterationQueue::notifyEndOfRequestEmpty() {
 }
 
 void IterationQueue::markFilled(MarkableIteration *iteration) {
-  std::unique_lock lg(empty_mutex);
-  num_being_filled--;
-  filled_q.push(iteration);
-  lg.unlock();
+  {
+    std::lock_guard lg(empty_mutex);
+    --num_being_filled;
+    filled_q.push(iteration);
+  }
   notify_emptied_cv.notify_all();
 }