aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--stdlib/mutexeddata.c38
-rw-r--r--stdlib/mutexeddata.h17
2 files changed, 55 insertions, 0 deletions
diff --git a/stdlib/mutexeddata.c b/stdlib/mutexeddata.c
new file mode 100644
index 00000000..f47adfc1
--- /dev/null
+++ b/stdlib/mutexeddata.c
@@ -0,0 +1,38 @@
+// Mutexed data methods/type info
+#include <ctype.h>
+#include <err.h>
+#include <gc.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <sys/param.h>
+
+#include "bools.h"
+#include "metamethods.h"
+#include "optionals.h"
+#include "text.h"
+#include "util.h"
+
+static Text_t MutexedData$as_text(const void *m, bool colorize, const TypeInfo_t *type)
+{
+ auto mutexed = type->MutexedDataInfo;
+ Text_t typename = generic_as_text(NULL, false, mutexed.type);
+ if (!m) {
+ return Texts(colorize ? Text("\x1b[34;1mmutexed\x1b[m(") : Text("mutexed("), typename, Text(")"));
+ }
+ return Text$format(colorize ? "\x1b[34;1mmutexed %k<%p>\x1b[m" : "mutexed %k<%p>", &typename, *((MutexedData_t*)m));
+}
+
+static bool MutexedData$is_none(const void *m, const TypeInfo_t *)
+{
+ return *((MutexedData_t*)m) == NULL;
+}
+
+public const metamethods_t MutexedData$metamethods = {
+ .as_text=MutexedData$as_text,
+ .is_none=MutexedData$is_none,
+ .serialize=cannot_serialize,
+ .deserialize=cannot_deserialize,
+};
+
+// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/stdlib/mutexeddata.h b/stdlib/mutexeddata.h
new file mode 100644
index 00000000..47686195
--- /dev/null
+++ b/stdlib/mutexeddata.h
@@ -0,0 +1,17 @@
+#pragma once
+
+// Metamethods and type info for mutexed data
+
+#include "types.h"
+#include "optionals.h"
+#include "util.h"
+
+#define NONE_MUTEXED_DATA ((MutexedData_t)NULL)
+
+extern const metamethods_t MutexedData$metamethods;
+
+#define MutexedData$info(t) &((TypeInfo_t){.size=sizeof(MutexedData_t), .align=__alignof(MutexedData_t), \
+ .tag=MutexedDataInfo, .MutexedDataInfo.type=t, \
+ .metamethods=MutexedData$metamethods})
+
+// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0