aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/include
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-05-05 11:09:45 +0200
committerGitHub <[email protected]>2023-05-05 11:09:45 +0200
commit5fee41301ff4488503e64f8d79c1a07508dd27be (patch)
tree0fffdaa8993c78b518118dfa2a65ea43e90487f3 /src/zencore/include
parentUpdate README.md (diff)
downloadzen-5fee41301ff4488503e64f8d79c1a07508dd27be.tar.xz
zen-5fee41301ff4488503e64f8d79c1a07508dd27be.zip
247 complete httpclient implementation (#269)
* implemented HttpClient connection pooling * implemented missing verbs * added response helpers (CbObject/CbPackage/text) * added RwLock::WithSharedLock and RwLock::WithExclusiveLock * added some noexcept annotations on RwLock * removed CPR dependency in httpclient.h
Diffstat (limited to 'src/zencore/include')
-rw-r--r--src/zencore/include/zencore/thread.h24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/zencore/include/zencore/thread.h b/src/zencore/include/zencore/thread.h
index a9c96d422..09c25996f 100644
--- a/src/zencore/include/zencore/thread.h
+++ b/src/zencore/include/zencore/thread.h
@@ -25,18 +25,18 @@ void SetCurrentThreadName(std::string_view ThreadName);
class RwLock
{
public:
- ZENCORE_API void AcquireShared();
- ZENCORE_API void ReleaseShared();
+ ZENCORE_API void AcquireShared() noexcept;
+ ZENCORE_API void ReleaseShared() noexcept;
- ZENCORE_API void AcquireExclusive();
- ZENCORE_API void ReleaseExclusive();
+ ZENCORE_API void AcquireExclusive() noexcept;
+ ZENCORE_API void ReleaseExclusive() noexcept;
struct SharedLockScope
{
SharedLockScope(RwLock& Lock) : m_Lock(&Lock) { Lock.AcquireShared(); }
~SharedLockScope() { ReleaseNow(); }
- void ReleaseNow()
+ void ReleaseNow() noexcept
{
if (m_Lock)
{
@@ -49,12 +49,18 @@ public:
RwLock* m_Lock;
};
+ inline void WithSharedLock(auto&& Fun)
+ {
+ SharedLockScope $(*this);
+ Fun();
+ }
+
struct ExclusiveLockScope
{
ExclusiveLockScope(RwLock& Lock) : m_Lock(&Lock) { Lock.AcquireExclusive(); }
~ExclusiveLockScope() { ReleaseNow(); }
- void ReleaseNow()
+ void ReleaseNow() noexcept
{
if (m_Lock)
{
@@ -67,6 +73,12 @@ public:
RwLock* m_Lock;
};
+ inline void WithExclusiveLock(auto&& Fun)
+ {
+ ExclusiveLockScope $(*this);
+ Fun();
+ }
+
private:
std::shared_mutex m_Mutex;
};