From e6c3a80b01ffb52079783cddd9be6d392d0f7039 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Mon, 29 Jul 2024 19:59:52 -0400 Subject: redesign compositor protocol, start widget library --- euler/include/cassert | 12 ++++++++ euler/include/condition_variable | 3 ++ euler/include/mutex | 2 +- euler/include/std/condition-variable.hpp | 13 ++++++++ euler/include/std/list.hpp | 19 +++++++----- euler/include/std/unique-lock.hpp | 53 ++++++++++++++++++++++++++++++++ euler/include/std/unique_lock.hpp | 53 -------------------------------- euler/include/std/vector.hpp | 18 +++++++++++ 8 files changed, 111 insertions(+), 62 deletions(-) create mode 100644 euler/include/cassert create mode 100644 euler/include/condition_variable create mode 100644 euler/include/std/condition-variable.hpp create mode 100644 euler/include/std/unique-lock.hpp delete mode 100644 euler/include/std/unique_lock.hpp (limited to 'euler/include') diff --git a/euler/include/cassert b/euler/include/cassert new file mode 100644 index 0000000..415790d --- /dev/null +++ b/euler/include/cassert @@ -0,0 +1,12 @@ +#pragma once + +namespace euler { + + [[noreturn]] inline void assert_failed() { + //TODO: log error and abort + while (1) ; + } + +} + +#define assert(cond) ((cond) ? (void)0 : ::euler::assert_failed()); diff --git a/euler/include/condition_variable b/euler/include/condition_variable new file mode 100644 index 0000000..ec327eb --- /dev/null +++ b/euler/include/condition_variable @@ -0,0 +1,3 @@ +#pragma once + +#include diff --git a/euler/include/mutex b/euler/include/mutex index 7a03381..7eefb3e 100644 --- a/euler/include/mutex +++ b/euler/include/mutex @@ -1,4 +1,4 @@ #pragma once -#include +#include #include diff --git a/euler/include/std/condition-variable.hpp b/euler/include/std/condition-variable.hpp new file mode 100644 index 0000000..0568373 --- /dev/null +++ b/euler/include/std/condition-variable.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include + +namespace std { + + class condition_variable { + + //TODO + + }; + +} diff --git a/euler/include/std/list.hpp b/euler/include/std/list.hpp index 77eaaec..c0d6e21 100644 --- a/euler/include/std/list.hpp +++ b/euler/include/std/list.hpp @@ -19,11 +19,11 @@ namespace std { node *the_node; - bool operator ==(const generic_iterator &other) { + bool operator ==(const generic_iterator &other) const { return the_node == other.the_node; } - bool operator !=(const generic_iterator &other) { + bool operator !=(const generic_iterator &other) const { return the_node != other.the_node; } @@ -82,13 +82,14 @@ namespace std { return iterator { .the_node = r }; } - iterator begin() const noexcept { - return iterator { .the_node = first_node }; - } + iterator begin() noexcept { return iterator { .the_node = first_node }; } + iterator end() noexcept { return iterator { .the_node = 0 }; } - iterator end() const noexcept { - return iterator { .the_node = 0 }; - } + const_iterator begin() const noexcept { return iterator { .the_node = first_node }; } + const_iterator end() const noexcept { return iterator { .the_node = 0 }; } + + const_iterator cbegin() const noexcept { return iterator { .the_node = first_node }; } + const_iterator cend() const noexcept { return iterator { .the_node = 0 }; } size_t remove(const T &value) { size_t removed = 0; @@ -140,6 +141,7 @@ namespace std { clear(); for (node *n = other.first_node; n; n = n->next) push_back(n->value); + return *this; } list &operator =(list &&other) { @@ -150,6 +152,7 @@ namespace std { other.first_node = 0; other.last_node = 0; other.count = 0; + return *this; } }; diff --git a/euler/include/std/unique-lock.hpp b/euler/include/std/unique-lock.hpp new file mode 100644 index 0000000..14b3645 --- /dev/null +++ b/euler/include/std/unique-lock.hpp @@ -0,0 +1,53 @@ +#pragma once + +namespace std { + + template + class unique_lock { + + Mutex *the_mutex; + bool has_locked; + + public: + inline unique_lock() noexcept : the_mutex(0) {} + + unique_lock(const unique_lock &other) = delete; + + inline unique_lock(unique_lock &&other) noexcept + : the_mutex(other.the_mutex), has_locked(other.has_locked) { + other.the_mutex = 0; + } + + inline explicit unique_lock(Mutex &m) + : the_mutex(&m), has_locked(true) { + the_mutex->lock(); + } + + inline ~unique_lock() { + if (the_mutex && has_locked) + the_mutex->unlock(); + } + + unique_lock &operator =(const unique_lock &other) = delete; + + inline unique_lock &operator =(unique_lock &&other) { + if (the_mutex && has_locked) + the_mutex->unlock(); + the_mutex = other.the_mutex; + has_locked = other.has_locked; + other.the_mutex = 0; + } + + inline void lock() { + the_mutex->lock(); + has_locked = true; + } + + inline void unlock() { + the_mutex->unlock(); + has_locked = false; + } + + }; + +} diff --git a/euler/include/std/unique_lock.hpp b/euler/include/std/unique_lock.hpp deleted file mode 100644 index 14b3645..0000000 --- a/euler/include/std/unique_lock.hpp +++ /dev/null @@ -1,53 +0,0 @@ -#pragma once - -namespace std { - - template - class unique_lock { - - Mutex *the_mutex; - bool has_locked; - - public: - inline unique_lock() noexcept : the_mutex(0) {} - - unique_lock(const unique_lock &other) = delete; - - inline unique_lock(unique_lock &&other) noexcept - : the_mutex(other.the_mutex), has_locked(other.has_locked) { - other.the_mutex = 0; - } - - inline explicit unique_lock(Mutex &m) - : the_mutex(&m), has_locked(true) { - the_mutex->lock(); - } - - inline ~unique_lock() { - if (the_mutex && has_locked) - the_mutex->unlock(); - } - - unique_lock &operator =(const unique_lock &other) = delete; - - inline unique_lock &operator =(unique_lock &&other) { - if (the_mutex && has_locked) - the_mutex->unlock(); - the_mutex = other.the_mutex; - has_locked = other.has_locked; - other.the_mutex = 0; - } - - inline void lock() { - the_mutex->lock(); - has_locked = true; - } - - inline void unlock() { - the_mutex->unlock(); - has_locked = false; - } - - }; - -} diff --git a/euler/include/std/vector.hpp b/euler/include/std/vector.hpp index 1c35d9d..8cd02b4 100644 --- a/euler/include/std/vector.hpp +++ b/euler/include/std/vector.hpp @@ -131,6 +131,12 @@ namespace std { } + void clear() { + for (size_type i = 0; i < _size; ++i) + std::destroy_at(_data + i); + _size = 0; + } + constexpr size_type size() const noexcept { return _size; } @@ -188,6 +194,18 @@ namespace std { ++_size; } + using iterator = T *; + using const_iterator = const T *; + + iterator begin() noexcept { return _data; } + iterator end() noexcept { return _data + _size; } + + const_iterator begin() const noexcept { return _data; } + const_iterator end() const noexcept { return _data + _size; } + + const_iterator cbegin() const noexcept { return _data; } + const_iterator cend() const noexcept { return _data + _size; } + }; } -- cgit v1.2.3