소스 검색

Bugfix in Semaphore::Acquire for non-windows platforms (#1456)

The count was updated before waiting, meaning that the counter would become -(number of waiting threads) and the semaphore would not wake up until at least the same amount of releases was done. In practice this meant that the main thread had to do the last (number of threads) jobs, slowing down the simulation a bit.
Jorrit Rouwe 7 달 전
부모
커밋
cb3f34f61c
2개의 변경된 파일4개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 0
      Docs/ReleaseNotes.md
  2. 3 1
      Jolt/Core/Semaphore.cpp

+ 1 - 0
Docs/ReleaseNotes.md

@@ -35,6 +35,7 @@ For breaking API changes see [this document](https://github.com/jrouwe/JoltPhysi
 * Fixed CharacterVirtual::Contact::mIsSensorB not being persisted in SaveState.
 * Fixed CharacterVirtual::Contact::mHadContact not being true for collisions with sensors. They will still be marked as mWasDiscarded to prevent any further interaction.
 * Fixed numerical inaccuracy in penetration depth calculation when CollideShapeSettings::mMaxSeparationDistance was set to a really high value (e.g. 1000).
+* Bugfix in Semaphore::Acquire for non-windows platform. The count was updated before waiting, meaning that the counter would become -(number of waiting threads) and the semaphore would not wake up until at least the same amount of releases was done. In practice this meant that the main thread had to do the last (number of threads) jobs, slowing down the simulation a bit.
 
 ## v5.2.0
 

+ 3 - 1
Jolt/Core/Semaphore.cpp

@@ -74,8 +74,10 @@ void Semaphore::Acquire(uint inNumber)
 	}
 #else
 	std::unique_lock lock(mLock);
+	mWaitVariable.wait(lock, [this, inNumber]() {
+		return mCount.load(std::memory_order_relaxed) >= int(inNumber);
+	});
 	mCount.fetch_sub(inNumber, std::memory_order_relaxed);
-	mWaitVariable.wait(lock, [this]() { return mCount >= 0; });
 #endif
 }