SharedResource is now using an RWLock.

This commit is contained in:
Relintai 2022-02-04 13:53:30 +01:00
parent f434d1ff6c
commit a05ca2e261
2 changed files with 26 additions and 9 deletions

View File

@ -1,10 +1,23 @@
#include "shared_resource.h"
void SharedResource::lock() {
_mutex.lock();
void SharedResource::read_lock() {
_lock.read_lock();
}
void SharedResource::unlock() {
_mutex.unlock();
void SharedResource::read_unlock() {
_lock.read_unlock();
}
Error SharedResource::read_try_lock() {
return _lock.read_try_lock();
}
void SharedResource::write_lock() {
_lock.write_lock();
}
void SharedResource::write_unlock() {
_lock.write_unlock();
}
Error SharedResource::write_try_lock() {
return _lock.write_try_lock();
}
SharedResource::SharedResource() :

View File

@ -4,21 +4,25 @@
#include "core/string.h"
#include "resource.h"
#include "core/threading/mutex.h"
#include "core/threading/rw_lock.h"
class SharedResource : public Resource {
RCPP_OBJECT(SharedResource, Resource);
public:
void lock();
void unlock();
void read_lock();
void read_unlock();
Error read_try_lock();
void write_lock();
void write_unlock();
Error write_try_lock();
SharedResource();
~SharedResource();
private:
//todo add read write lock instead of this
Mutex _mutex;
RWLock _lock;
};
#endif