aboutsummaryrefslogtreecommitdiff
path: root/src/linda.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/linda.h')
-rw-r--r--src/linda.h14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/linda.h b/src/linda.h
index 4943197..611008e 100644
--- a/src/linda.h
+++ b/src/linda.h
@@ -7,6 +7,7 @@
7 7
8#include <array> 8#include <array>
9#include <condition_variable> 9#include <condition_variable>
10#include <string_view>
10#include <variant> 11#include <variant>
11 12
12struct Keeper; 13struct Keeper;
@@ -26,13 +27,8 @@ class Linda
26 private: 27 private:
27 static constexpr size_t kEmbeddedNameLength = 24; 28 static constexpr size_t kEmbeddedNameLength = 24;
28 using EmbeddedName = std::array<char, kEmbeddedNameLength>; 29 using EmbeddedName = std::array<char, kEmbeddedNameLength>;
29 struct AllocatedName
30 {
31 size_t len{ 0 };
32 char* name{ nullptr };
33 };
34 // depending on the name length, it is either embedded inside the Linda, or allocated separately 30 // depending on the name length, it is either embedded inside the Linda, or allocated separately
35 std::variant<AllocatedName, EmbeddedName> nameVariant; 31 std::variant<std::string_view, EmbeddedName> nameVariant;
36 32
37 public: 33 public:
38 std::condition_variable readHappened; 34 std::condition_variable readHappened;
@@ -51,7 +47,7 @@ class Linda
51 static void operator delete(void* p_) { static_cast<Linda*>(p_)->U->internalAllocator.free(p_, sizeof(Linda)); } 47 static void operator delete(void* p_) { static_cast<Linda*>(p_)->U->internalAllocator.free(p_, sizeof(Linda)); }
52 48
53 ~Linda(); 49 ~Linda();
54 Linda(Universe* U_, LindaGroup group_, char const* name_, size_t len_); 50 Linda(Universe* U_, LindaGroup group_, std::string_view const& name_);
55 Linda() = delete; 51 Linda() = delete;
56 // non-copyable, non-movable 52 // non-copyable, non-movable
57 Linda(Linda const&) = delete; 53 Linda(Linda const&) = delete;
@@ -60,11 +56,11 @@ class Linda
60 Linda& operator=(Linda const&&) = delete; 56 Linda& operator=(Linda const&&) = delete;
61 57
62 private: 58 private:
63 void setName(char const* name_, size_t len_); 59 void setName(std::string_view const& name_);
64 60
65 public: 61 public:
66 [[nodiscard]] Keeper* acquireKeeper() const; 62 [[nodiscard]] Keeper* acquireKeeper() const;
67 [[nodiscard]] char const* getName() const; 63 [[nodiscard]] std::string_view getName() const;
68 void releaseKeeper(Keeper* keeper_) const; 64 void releaseKeeper(Keeper* keeper_) const;
69 [[nodiscard]] static int ProtectedCall(lua_State* L_, lua_CFunction f_); 65 [[nodiscard]] static int ProtectedCall(lua_State* L_, lua_CFunction f_);
70 [[nodiscard]] Keeper* whichKeeper() const { return U->keepers->nb_keepers ? &U->keepers->keeper_array[keeperIndex] : nullptr; } 66 [[nodiscard]] Keeper* whichKeeper() const { return U->keepers->nb_keepers ? &U->keepers->keeper_array[keeperIndex] : nullptr; }