Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! src: make BuiltinLoader threadsafe and no…
Browse files Browse the repository at this point in the history
…n-global
  • Loading branch information
addaleax committed Jan 17, 2023
1 parent d015622 commit 93e411a
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/node_threadsafe_cow.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ class CopyOnWrite final {
// Write helpers to access the target data structure.
template <typename T>
class ThreadsafeCopyOnWrite final {
private:
// Define this early since some of the public members depend on it
// and some compilers need it to be defined first in that case.
struct Impl {
explicit Impl(const T& data) : data(data) {}
explicit Impl(T&& data) : data(std::move(data)) {}

Impl(const Impl& other);
Impl& operator=(const Impl& other) = delete;
Impl(Impl&& other) = delete;
Impl& operator=(Impl&& other) = delete;

RwLock mutex;
T data;
};

public:
template <typename... Args>
ThreadsafeCopyOnWrite(Args&&... args)
Expand Down Expand Up @@ -79,19 +95,6 @@ class ThreadsafeCopyOnWrite final {
Write write() { return Write(this); }

private:
struct Impl {
explicit Impl(const T& data) : data(data) {}
explicit Impl(T&& data) : data(std::move(data)) {}

Impl(const Impl& other);
Impl& operator=(const Impl& other) = delete;
Impl(Impl&& other) = delete;
Impl& operator=(Impl&& other) = delete;

RwLock mutex;
T data;
};

CopyOnWrite<Impl> impl_;
};

Expand Down

0 comments on commit 93e411a

Please sign in to comment.