summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2025-01-03 01:49:42 +0100
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2025-01-03 01:49:42 +0100
commitc2d4216695b48dfe6bf7083c11e0a7fcbb671e2e (patch)
tree600719b0f7d7d491eb70ca416b8af3b47bbc28eb
parenteb58edf811a328ddcc5e671a258be208da212630 (diff)
Add atomic & is_integer
-rw-r--r--asl/BUILD.bazel4
-rw-r--r--asl/atomic.hpp51
-rw-r--r--asl/meta.hpp12
-rw-r--r--asl/status.cpp0
-rw-r--r--asl/status.hpp13
-rw-r--r--asl/tests/status_tests.cpp0
-rw-r--r--todo.txt1
7 files changed, 81 insertions, 0 deletions
diff --git a/asl/BUILD.bazel b/asl/BUILD.bazel
index 54db8c7..da1018e 100644
--- a/asl/BUILD.bazel
+++ b/asl/BUILD.bazel
@@ -4,6 +4,7 @@ cc_library(
"allocator.hpp",
"annotations.hpp",
"assert.hpp",
+ "atomic.hpp",
"box.hpp",
"buffer.hpp",
"config.hpp",
@@ -19,6 +20,7 @@ cc_library(
"option.hpp",
"print.hpp",
"span.hpp",
+ "status.hpp",
"string.hpp",
"string_view.hpp",
"utility.hpp",
@@ -29,6 +31,7 @@ cc_library(
"format.cpp",
"format_float.cpp",
"print.cpp",
+ "status.cpp",
],
deps = [
"//vendor/dragonbox",
@@ -57,6 +60,7 @@ cc_library(
"meta",
"option",
"span",
+ "status",
"string",
"string_view",
"utility",
diff --git a/asl/atomic.hpp b/asl/atomic.hpp
new file mode 100644
index 0000000..cf6968c
--- /dev/null
+++ b/asl/atomic.hpp
@@ -0,0 +1,51 @@
+#pragma once
+
+#include "asl/meta.hpp"
+
+namespace asl
+{
+
+enum class memory_order : int // NOLINT(*-enum-size)
+{
+ relaxed = __ATOMIC_RELAXED,
+ acquire = __ATOMIC_ACQUIRE,
+ release = __ATOMIC_RELEASE,
+ acq_rel = __ATOMIC_ACQ_REL,
+ seq_cst = __ATOMIC_SEQ_CST,
+};
+
+template<typename T> struct atomic { T m_value{}; };
+
+inline void atomic_fence(memory_order order)
+{
+ __atomic_thread_fence((int)order);
+}
+
+template<is_integer T>
+inline void atomic_store(atomic<T>* a, T value, memory_order order = memory_order::relaxed)
+{
+ __atomic_store(&a->m_value, &value, (int)order);
+}
+
+template<is_integer T>
+inline T atomic_load(atomic<T>* a, memory_order order = memory_order::relaxed)
+{
+ T value;
+ __atomic_load(&a->m_value, &value, (int)order);
+ return value;
+}
+
+template<typename T>
+inline T atomic_fetch_increment(atomic<T>* a, memory_order order = memory_order::relaxed)
+{
+ return __atomic_fetch_add(&a->m_value, 1, (int)order);
+}
+
+template<typename T>
+inline T atomic_fetch_decrement(atomic<T>* a, memory_order order = memory_order::relaxed)
+{
+ return __atomic_fetch_sub(&a->m_value, 1, (int)order);
+}
+
+} // namespace asl
+
diff --git a/asl/meta.hpp b/asl/meta.hpp
index f69a4a3..959201e 100644
--- a/asl/meta.hpp
+++ b/asl/meta.hpp
@@ -177,6 +177,18 @@ template<> struct _is_floating_point_helper<double> : true_type {};
template<typename T> concept is_floating_point = _is_floating_point_helper<un_cv_t<T>>::value;
+template<typename T> struct _is_integer_helper : false_type {};
+template<> struct _is_integer_helper<int8_t> : true_type {};
+template<> struct _is_integer_helper<int16_t> : true_type {};
+template<> struct _is_integer_helper<int32_t> : true_type {};
+template<> struct _is_integer_helper<int64_t> : true_type {};
+template<> struct _is_integer_helper<uint8_t> : true_type {};
+template<> struct _is_integer_helper<uint16_t> : true_type {};
+template<> struct _is_integer_helper<uint32_t> : true_type {};
+template<> struct _is_integer_helper<uint64_t> : true_type {};
+
+template<typename T> concept is_integer = _is_integer_helper<un_cv_t<T>>::value;
+
template<typename T, typename U>
concept equality_comparable_with = requires (const un_cvref_t<T>& a, const un_cvref_t<T>& b)
{
diff --git a/asl/status.cpp b/asl/status.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asl/status.cpp
diff --git a/asl/status.hpp b/asl/status.hpp
new file mode 100644
index 0000000..2e4bae5
--- /dev/null
+++ b/asl/status.hpp
@@ -0,0 +1,13 @@
+#pragma once
+
+#include "asl/integers.hpp"
+#include "asl/string_view.hpp"
+
+namespace asl
+{
+
+class status
+{
+};
+
+} // namespace asl
diff --git a/asl/tests/status_tests.cpp b/asl/tests/status_tests.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asl/tests/status_tests.cpp
diff --git a/todo.txt b/todo.txt
index 60d1751..f172e86 100644
--- a/todo.txt
+++ b/todo.txt
@@ -2,6 +2,7 @@ hashing
hash_set
hash_map
logging
+atomic
status
status_or
dynlib