mirror of
https://github.com/greg7mdp/parallel-hashmap.git
synced 2026-08-29 08:34:39 +08:00
Add support for Windows phmap::srwlock
This commit is contained in:
@@ -8,18 +8,9 @@
|
||||
#include <vector>
|
||||
#include <ppl.h>
|
||||
|
||||
class srwlock {
|
||||
SRWLOCK _lock;
|
||||
|
||||
public:
|
||||
srwlock() { InitializeSRWLock(&_lock); }
|
||||
void lock() { AcquireSRWLockExclusive(&_lock); }
|
||||
void unlock() { ReleaseSRWLockExclusive(&_lock); }
|
||||
};
|
||||
|
||||
using Map = phmap::parallel_flat_hash_map<std::string, int, phmap::priv::hash_default_hash<std::string>,
|
||||
phmap::priv::hash_default_eq<std::string>,
|
||||
std::allocator<std::pair<const std::string, int>>, 8, srwlock>;
|
||||
std::allocator<std::pair<const std::string, int>>, 8, phmap::srwlock>;
|
||||
|
||||
class Dict
|
||||
{
|
||||
|
||||
Vendored
+37
@@ -5000,6 +5000,7 @@ public:
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Abseil Mutex support (read and write lock support)
|
||||
// use: `phmap::AbslMutex` instead of `std::mutex`
|
||||
// --------------------------------------------------------------------------
|
||||
#ifdef ABSL_SYNCHRONIZATION_MUTEX_H_
|
||||
|
||||
@@ -5030,6 +5031,42 @@ public:
|
||||
|
||||
#endif
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Microsoft SRWLOCK support (read and write lock support)
|
||||
// use: `phmap::srwlock` instead of `std::mutex`
|
||||
// --------------------------------------------------------------------------
|
||||
#if defined(_MSVC_LANG) && defined(SRWLOCK_INIT)
|
||||
|
||||
class srwlock {
|
||||
SRWLOCK _lock;
|
||||
public:
|
||||
srwlock() { InitializeSRWLock(&_lock); }
|
||||
void lock() { AcquireSRWLockExclusive(&_lock); }
|
||||
void unlock() { ReleaseSRWLockExclusive(&_lock); }
|
||||
bool try_lock() { return !!TryAcquireSRWLockExclusive(&_lock); }
|
||||
void lock_shared() { AcquireSRWLockShared(&_lock); }
|
||||
void unlock_shared() { ReleaseSRWLockShared(&_lock); }
|
||||
bool try_lock_shared() { return !!TryAcquireSRWLockShared(&_lock); }
|
||||
};
|
||||
|
||||
|
||||
template<>
|
||||
class LockableImpl<srwlock> : public srwlock
|
||||
{
|
||||
public:
|
||||
using mutex_type = srwlock;
|
||||
using Base = LockableBaseImpl<srwlock>;
|
||||
using SharedLock = typename Base::ReadLock;
|
||||
using ReadWriteLock = typename Base::ReadWriteLock;
|
||||
using UpgradeLock = typename Base::WriteLock;
|
||||
using UniqueLock = typename Base::WriteLock;
|
||||
using SharedLocks = typename Base::ReadLocks;
|
||||
using UniqueLocks = typename Base::WriteLocks;
|
||||
using UpgradeToUnique = typename Base::DoNothing; // we already have unique ownership
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Boost shared_mutex support (read and write lock support)
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user