Compare commits

...

4 Commits

Author SHA1 Message Date
071f9e22be add core::Mutex inheriting data::Wrap<nf7::Mutex> 2023-08-20 11:30:17 +09:00
c274f35265 add data::Wrap 2023-08-20 11:29:51 +09:00
b732d73eb9 allow Mutex to be moved and copied 2023-08-20 11:20:56 +09:00
7362dc3503 Revert "add mtx() property to File interface"
This reverts commit 01236d4aef783b68e34de95558b3e1a398b3a1fb.
2023-08-20 11:11:35 +09:00
6 changed files with 45 additions and 19 deletions

View File

@ -25,6 +25,7 @@ target_sources(nf7_core
uv/parallelism.hh
clock.hh
logger.hh
mutex.hh
version.hh
)

17
core/mutex.hh Normal file
View File

@ -0,0 +1,17 @@
// No copyright
#pragma once
#include "iface/common/mutex.hh"
#include "iface/data/wrap.hh"
namespace nf7::core {
class Mutex : public data::Wrap<nf7::Mutex> {
public:
Mutex() : Wrap("nf7::core::Mutex", mtx_) { }
private:
nf7::Mutex mtx_;
};
} // namespace nf7::core

View File

@ -21,6 +21,7 @@ target_sources(nf7_iface
common/task_context.hh
common/value.hh
data/interface.hh
data/wrap.hh
subsys/concurrency.hh
subsys/interface.hh
subsys/logger.hh

View File

@ -20,10 +20,10 @@ class Mutex final {
Mutex();
~Mutex() noexcept;
Mutex(const Mutex&) = delete;
Mutex(Mutex&&) = delete;
Mutex& operator=(const Mutex&) = delete;
Mutex& operator=(Mutex&&) = delete;
Mutex(const Mutex&) = default;
Mutex(Mutex&&) = default;
Mutex& operator=(const Mutex&) = default;
Mutex& operator=(Mutex&&) = default;
public:
Future<SharedToken> Lock() noexcept;

21
iface/data/wrap.hh Normal file
View File

@ -0,0 +1,21 @@
// No copyright
#pragma once
#include "iface/data/interface.hh"
namespace nf7::data {
template <typename T>
class Wrap : public Interface {
protected:
Wrap(const char* name, T& data) noexcept
: Interface(name), data_(data) { }
public:
T& data() const noexcept { return data_; }
private:
T& data_;
};
} // namespace nf7::data

View File

@ -6,20 +6,6 @@
namespace nf7 {
class File : public Container<data::Interface> {
public:
File() = default;
public:
Mutex& mtx() const noexcept { return mtx_; }
public:
using Container<data::Interface>::Get;
using Container<data::Interface>::GetOr;
using Container<data::Interface>::installed;
private:
mutable Mutex mtx_;
};
using File = Container<data::Interface>;
} // namespace nf7