aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdlib')
-rw-r--r--src/stdlib/README.md1
-rw-r--r--src/stdlib/datatypes.h6
-rw-r--r--src/stdlib/mutexeddata.c39
-rw-r--r--src/stdlib/mutexeddata.h17
-rw-r--r--src/stdlib/optionals.c3
-rw-r--r--src/stdlib/threads.c92
-rw-r--r--src/stdlib/threads.h22
-rw-r--r--src/stdlib/tomo.h2
-rw-r--r--src/stdlib/types.h4
9 files changed, 2 insertions, 184 deletions
diff --git a/src/stdlib/README.md b/src/stdlib/README.md
index 1583c168..6591ead6 100644
--- a/src/stdlib/README.md
+++ b/src/stdlib/README.md
@@ -31,5 +31,4 @@ some common functionality.
- Pointers: [pointers.h](pointers.h), [pointers.c](pointers.c)
- Tables: [tables.h](tables.h), [tables.c](tables.c)
- Text: [text.h](text.h), [text.c](text.c)
-- Threads: [threads.h](threads.h), [threads.c](threads.c)
- Type Infos (for representing types as values): [types.h](types.h), [types.c](types.c)
diff --git a/src/stdlib/datatypes.h b/src/stdlib/datatypes.h
index 22cee673..b1265fc3 100644
--- a/src/stdlib/datatypes.h
+++ b/src/stdlib/datatypes.h
@@ -3,7 +3,6 @@
// Common datastructures (arrays, tables, closures)
#include <gmp.h>
-#include <pthread.h>
#include <stdbool.h>
#include <stdint.h>
#include <time.h>
@@ -111,11 +110,6 @@ typedef struct {
typedef struct RNGState_t* RNG_t;
-typedef struct MutexedData_s {
- pthread_mutex_t mutex;
- void *data;
-} *MutexedData_t;
-
#define OptionalBool_t uint8_t
#define OptionalArray_t Array_t
#define OptionalTable_t Table_t
diff --git a/src/stdlib/mutexeddata.c b/src/stdlib/mutexeddata.c
deleted file mode 100644
index ead154e7..00000000
--- a/src/stdlib/mutexeddata.c
+++ /dev/null
@@ -1,39 +0,0 @@
-// 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 Texts(colorize ? Text("\x1b[34;1mmutexed ") : Text("mutexed "), typename,
- Text$format(colorize ? "<%p>\x1b[m" : "<%p>", *((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/src/stdlib/mutexeddata.h b/src/stdlib/mutexeddata.h
deleted file mode 100644
index 47686195..00000000
--- a/src/stdlib/mutexeddata.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#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
diff --git a/src/stdlib/optionals.c b/src/stdlib/optionals.c
index db2c477f..797cb111 100644
--- a/src/stdlib/optionals.c
+++ b/src/stdlib/optionals.c
@@ -1,7 +1,5 @@
// Optional types
-#include <pthread.h>
-
#include "bools.h"
#include "bytes.h"
#include "datatypes.h"
@@ -10,7 +8,6 @@
#include "nums.h"
#include "patterns.h"
#include "text.h"
-#include "threads.h"
#include "util.h"
public PUREFUNC bool is_none(const void *obj, const TypeInfo_t *non_optional_type)
diff --git a/src/stdlib/threads.c b/src/stdlib/threads.c
deleted file mode 100644
index 05f5a941..00000000
--- a/src/stdlib/threads.c
+++ /dev/null
@@ -1,92 +0,0 @@
-// Logic for the Thread type, representing a pthread
-
-#include <ctype.h>
-#include <err.h>
-#include <fcntl.h>
-#include <gc.h>
-#include <math.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <pthread.h>
-#include <sys/param.h>
-
-#include "arrays.h"
-#include "datatypes.h"
-#include "metamethods.h"
-#include "rng.h"
-#include "text.h"
-#include "threads.h"
-#include "types.h"
-#include "util.h"
-
-#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
-static ssize_t getrandom(void *buf, size_t buflen, unsigned int flags) {
- (void)flags;
- arc4random_buf(buf, buflen);
- return buflen;
-}
-#elif defined(__linux__)
-// Use getrandom()
-# include <sys/random.h>
-#else
- #error "Unsupported platform for secure random number generation"
-#endif
-
-static void *run_thread(Closure_t *closure)
-{
- uint8_t *random_bytes = GC_MALLOC_ATOMIC(40);
- getrandom(random_bytes, 40, 0);
- Array_t rng_seed = {.length=40, .data=random_bytes, .stride=1, .atomic=1};
- default_rng = RNG$new(rng_seed);
- ((void(*)(void*))closure->fn)(closure->userdata);
- return NULL;
-}
-
-public Thread_t Thread$new(Closure_t fn)
-{
- Thread_t thread = GC_MALLOC(sizeof(pthread_t));
- Closure_t *closure = new(Closure_t, .fn=fn.fn, .userdata=fn.userdata);
- pthread_create(thread, NULL, (void*)run_thread, closure);
- return thread;
-}
-
-public void Thread$join(Thread_t thread)
-{
- pthread_join(*thread, NULL);
-}
-
-public void Thread$cancel(Thread_t thread)
-{
- pthread_cancel(*thread);
-}
-
-public void Thread$detach(Thread_t thread)
-{
- pthread_detach(*thread);
-}
-
-Text_t Thread$as_text(const void *thread, bool colorize, const TypeInfo_t*)
-{
- if (!thread) {
- return colorize ? Text("\x1b[34;1mThread\x1b[m") : Text("Thread");
- }
- return Text$format(colorize ? "\x1b[34;1mThread(%p)\x1b[m" : "Thread(%p)", *(Thread_t**)thread);
-}
-
-static bool Thread$is_none(const void *obj, const TypeInfo_t*)
-{
- return *(Thread_t*)obj == NULL;
-}
-
-public const TypeInfo_t Thread$info = {
- .size=sizeof(Thread_t), .align=__alignof(Thread_t),
- .metamethods={
- .as_text=Thread$as_text,
- .is_none=Thread$is_none,
- .serialize=cannot_serialize,
- .deserialize=cannot_deserialize,
- },
-};
-
-// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/src/stdlib/threads.h b/src/stdlib/threads.h
deleted file mode 100644
index 9f1c3d33..00000000
--- a/src/stdlib/threads.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#pragma once
-
-// Logic for the Thread type, representing a pthread
-
-#include <pthread.h>
-#include <stdbool.h>
-
-#include "datatypes.h"
-#include "types.h"
-#include "util.h"
-
-#define Thread_t pthread_t*
-
-Thread_t Thread$new(Closure_t fn);
-void Thread$cancel(Thread_t thread);
-void Thread$join(Thread_t thread);
-void Thread$detach(Thread_t thread);
-Text_t Thread$as_text(const void *thread, bool colorize, const TypeInfo_t *type);
-
-extern const TypeInfo_t Thread$info;
-
-// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/src/stdlib/tomo.h b/src/stdlib/tomo.h
index 16e5ec57..4aa1253d 100644
--- a/src/stdlib/tomo.h
+++ b/src/stdlib/tomo.h
@@ -17,7 +17,6 @@
#include "integers.h"
#include "memory.h"
#include "metamethods.h"
-#include "mutexeddata.h"
#include "nums.h"
#include "optionals.h"
#include "paths.h"
@@ -29,7 +28,6 @@
#include "structs.h"
#include "tables.h"
#include "text.h"
-#include "threads.h"
#include "types.h"
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/src/stdlib/types.h b/src/stdlib/types.h
index c7b938a0..786e92d4 100644
--- a/src/stdlib/types.h
+++ b/src/stdlib/types.h
@@ -30,7 +30,7 @@ struct TypeInfo_s {
metamethods_t metamethods;
struct { // Anonymous tagged union for convenience
enum { OpaqueInfo, StructInfo, EnumInfo, PointerInfo, TextInfo, ArrayInfo, TableInfo, FunctionInfo,
- OptionalInfo, MutexedDataInfo, TypeInfoInfo } tag;
+ OptionalInfo, TypeInfoInfo } tag;
union {
struct {} OpaqueInfo;
struct {
@@ -54,7 +54,7 @@ struct TypeInfo_s {
} TypeInfoInfo;
struct {
const TypeInfo_t *type;
- } OptionalInfo, MutexedDataInfo;
+ } OptionalInfo;
struct {
const char *name;
int num_tags;