// Copyright (c) Wojciech Figat. All rights reserved. #pragma once #if PLATFORM_UNIX #include "Engine/Platform/Platform.h" #include /// /// Unix implementation of a read/write lock that allows for shared reading by multiple threads and exclusive writing by a single thread. /// class FLAXENGINE_API UnixReadWriteLock { private: mutable pthread_rwlock_t _lock; private: NON_COPYABLE(UnixReadWriteLock); public: /// /// Initializes a new instance of the class. /// UnixReadWriteLock() { pthread_rwlock_init(&_lock, nullptr); } /// /// Finalizes an instance of the class. /// ~UnixReadWriteLock() { pthread_rwlock_destroy(&_lock); } public: /// /// Locks for shared reading. /// void ReadLock() const { pthread_rwlock_rdlock(&_lock); } /// /// Releases the lock after shared reading. /// void ReadUnlock() const { pthread_rwlock_unlock(&_lock); } /// /// Locks for exclusive writing. /// void WriteLock() const { pthread_rwlock_wrlock(&_lock); } /// /// Releases the lock after exclusive writing. /// void WriteUnlock() const { pthread_rwlock_unlock(&_lock); } }; #endif