1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-19 16:35:06 +00:00

LibThread: Lockable - add forwarding constructor

This commit is contained in:
Muhammad Zahalqa 2020-08-14 17:06:02 +03:00 committed by Andreas Kling
parent 746f6ea36d
commit 33cb41edcb

View file

@ -28,17 +28,17 @@
#ifdef __serenity__ #ifdef __serenity__
#include <AK/Assertions.h> # include <AK/Assertions.h>
#include <AK/Types.h> # include <AK/Atomic.h>
#include <AK/Atomic.h> # include <AK/Types.h>
#include <unistd.h> # include <unistd.h>
namespace LibThread { namespace LibThread {
class Lock { class Lock {
public: public:
Lock() {} Lock() { }
~Lock() {} ~Lock() { }
void lock(); void lock();
void unlock(); void unlock();
@ -90,12 +90,19 @@ inline void Lock::unlock()
--m_level; --m_level;
} }
#define LOCKER(lock) LibThread::Locker locker(lock) # define LOCKER(lock) LibThread::Locker locker(lock)
template<typename T> template<typename T>
class Lockable { class Lockable {
public: public:
Lockable() {} Lockable() { }
template<typename... Args>
Lockable(Args&&... args)
: m_resource(forward(args)...)
{
}
Lockable(T&& resource) Lockable(T&& resource)
: m_resource(move(resource)) : m_resource(move(resource))
{ {
@ -128,6 +135,6 @@ public:
} }
#define LOCKER(x) # define LOCKER(x)
#endif #endif