-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- `resume_on` improvements - `binary_semaphore` polyfill for appleclang - enable dynamic linking on Windows - typo fixes Co-authored-by: chausner <[email protected]> Co-authored-by: autoantwort <[email protected]>
- Loading branch information
1 parent
cbfc4a1
commit 93890e3
Showing
22 changed files
with
221 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...rrencpp/results/result_fwd_declerations.h → ...rrencpp/results/result_fwd_declarations.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#ifndef CONCURRENCPP_BINARY_SEMAPHORE_H | ||
#define CONCURRENCPP_BINARY_SEMAPHORE_H | ||
|
||
#include "concurrencpp/platform_defs.h" | ||
|
||
#if defined(CRCPP_MAC_OS) && defined(CRCPP_LIBCPP_LIB) | ||
|
||
# include <mutex> | ||
# include <chrono> | ||
# include <condition_variable> | ||
|
||
# include <cstddef> | ||
|
||
namespace concurrencpp::details { | ||
|
||
class binary_semaphore { | ||
|
||
private: | ||
std::mutex m_lock; | ||
std::condition_variable m_condition; | ||
bool m_is_signaled; | ||
|
||
bool try_acquire_until_impl(const std::chrono::time_point<std::chrono::system_clock>& abs_time); | ||
|
||
public: | ||
binary_semaphore(std::ptrdiff_t desired); | ||
|
||
void release(std::ptrdiff_t update = 1); | ||
void acquire(); | ||
bool try_acquire() noexcept; | ||
|
||
template<class Rep, class Period> | ||
bool try_acquire_for(const std::chrono::duration<Rep, Period>& rel_time) { | ||
const auto deadline = std::chrono::system_clock::now() + rel_time; | ||
return try_acquire_until_impl(deadline); | ||
} | ||
|
||
template<class Clock, class Duration> | ||
bool try_acquire_until(const std::chrono::time_point<Clock, Duration>& abs_time) { | ||
const auto src_now = Clock::now(); | ||
const auto dst_now = std::chrono::system_clock::now(); | ||
const auto deadline = dst_now + std::chrono::duration_cast<std::chrono::milliseconds>(abs_time - src_now); | ||
return try_acquire_until_impl(deadline); | ||
} | ||
}; | ||
|
||
} // namespace concurrencpp::details | ||
|
||
#else | ||
|
||
# include <semaphore> | ||
|
||
namespace concurrencpp::details { | ||
using binary_semaphore = std::binary_semaphore; | ||
} | ||
|
||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "concurrencpp/threads/binary_semaphore.h" | ||
|
||
#if defined(CRCPP_MAC_OS) && defined(CRCPP_LIBCPP_LIB) | ||
|
||
# include <cassert> | ||
|
||
using concurrencpp::details::binary_semaphore; | ||
|
||
binary_semaphore::binary_semaphore(std::ptrdiff_t desired) : m_is_signaled(desired != 0) {} | ||
|
||
void binary_semaphore::release(std::ptrdiff_t update) { | ||
auto was_signaled = false; | ||
|
||
{ | ||
std::unique_lock<std::mutex> lock(m_lock); | ||
was_signaled = m_is_signaled; | ||
m_is_signaled = true; | ||
} | ||
|
||
if (!was_signaled) { | ||
m_condition.notify_one(); | ||
} | ||
} | ||
|
||
void binary_semaphore::acquire() { | ||
std::unique_lock<std::mutex> lock(m_lock); | ||
m_condition.wait(lock, [this] { | ||
return m_is_signaled; | ||
}); | ||
|
||
assert(m_is_signaled); | ||
m_is_signaled = false; | ||
} | ||
|
||
bool binary_semaphore::try_acquire() noexcept { | ||
std::unique_lock<std::mutex> lock(m_lock); | ||
if (m_is_signaled) { | ||
m_is_signaled = false; | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool binary_semaphore::try_acquire_until_impl(const std::chrono::time_point<std::chrono::system_clock>& abs_time) { | ||
std::unique_lock<std::mutex> lock(m_lock); | ||
m_condition.wait_until(lock, abs_time, [this] { | ||
return m_is_signaled; | ||
}); | ||
|
||
if (m_is_signaled) { | ||
m_is_signaled = false; | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.