File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ tests: bin/unittests$(EXT) bin/fuzztests$(EXT)
2929
3030benchmarks : bin/benchmarks$(EXT )
3131
32- bin/unittests$(EXT ) : ../concurrentqueue.h ../blockingconcurrentqueue.h ../tests/unittests/unittests.cpp ../tests/unittests/mallocmacro.cpp ../tests/common/simplethread.h ../tests/common/simplethread.cpp ../tests/common/systemtime.h ../tests/common/systemtime.cpp ../tests/corealgos.h ../tests/unittests/minitest.h makefile
32+ bin/unittests$(EXT ) : ../concurrentqueue.h ../blockingconcurrentqueue.h ../lightweightsemaphore.h ../ tests/unittests/unittests.cpp ../tests/unittests/mallocmacro.cpp ../tests/common/simplethread.h ../tests/common/simplethread.cpp ../tests/common/systemtime.h ../tests/common/systemtime.cpp ../tests/corealgos.h ../tests/unittests/minitest.h makefile
3333 test -d bin || mkdir bin
3434 g++ -std=c++11 -Wall -pedantic-errors -Wpedantic -Wconversion $(OPTS ) -fno-elide-constructors ../tests/common/simplethread.cpp ../tests/common/systemtime.cpp ../tests/unittests/unittests.cpp -o bin/unittests$(EXT ) $(LD_OPTS )
3535
Original file line number Diff line number Diff line change @@ -274,8 +274,11 @@ class LightweightSemaphore
274274 if (oldCount > 0 )
275275 return true ;
276276 if (timeout_usecs < 0 )
277- return m_sema.wait ();
278- if (m_sema.timed_wait ((std::uint64_t )timeout_usecs))
277+ {
278+ if (m_sema.wait ())
279+ return true ;
280+ }
281+ if (timeout_usecs > 0 && m_sema.timed_wait ((std::uint64_t )timeout_usecs))
279282 return true ;
280283 // At this point, we've timed out waiting for the semaphore, but the
281284 // count is still decremented indicating we may still be waiting on
@@ -311,12 +314,7 @@ class LightweightSemaphore
311314 oldCount = m_count.fetch_sub (1 , std::memory_order_acquire);
312315 if (oldCount <= 0 )
313316 {
314- if (timeout_usecs < 0 )
315- {
316- if (!m_sema.wait ())
317- return 0 ;
318- }
319- else if (!m_sema.timed_wait ((std::uint64_t )timeout_usecs))
317+ if ((timeout_usecs == 0 ) || (timeout_usecs < 0 && !m_sema.wait ()) || (timeout_usecs > 0 && !m_sema.timed_wait ((std::uint64_t )timeout_usecs)))
320318 {
321319 while (true )
322320 {
You can’t perform that action at this time.
0 commit comments