summaryrefslogtreecommitdiff
path: root/src/platform
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform')
-rw-r--r--src/platform/mutex.c9
-rw-r--r--src/platform/mutex.h28
-rw-r--r--src/platform/path.c35
-rw-r--r--src/platform/path.h16
-rw-r--r--src/platform/platform.h37
-rw-r--r--src/platform/platform_unix.c16
-rw-r--r--src/platform/platform_windows.c22
-rw-r--r--src/platform/thread.c0
-rw-r--r--src/platform/thread.h17
9 files changed, 75 insertions, 105 deletions
diff --git a/src/platform/mutex.c b/src/platform/mutex.c
deleted file mode 100644
index 2aeb825..0000000
--- a/src/platform/mutex.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "mutex.h"
-
-#if defined(CEL_PLATFORM_LINUX) || defined(CEL_PLATFORM_MAC)
-// TODO: implement in terms of pthreads
-#endif
-
-#if defined(CEL_PLATFORM_WINDOWS)
-// TODO: implement using win32 api
-#endif \ No newline at end of file
diff --git a/src/platform/mutex.h b/src/platform/mutex.h
deleted file mode 100644
index a0a4208..0000000
--- a/src/platform/mutex.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * @file mutex.h
- * @author your name (you@domain.com)
- * @brief
- * @version 0.1
- * @date 2024-04-27
- *
- * @copyright Copyright (c) 2024
- *
- */
-#include <stdbool.h>
-
-typedef struct cel_mutex cel_mutex;
-
-cel_mutex mutex_create();
-
-void mutex_destroy(cel_mutex* mutex);
-
-/** @brief Blocks until the mutex can be acquired. if returns false then an error occurred and can
- * be checked (TODO) */
-bool mutex_lock(cel_mutex* mutex);
-
-/** @brief Tries to acquire the mutex like `mutex_lock` but returns immediately if the mutex has
- * already been locked */
-bool mutex_try_lock(cel_mutex* mutex);
-
-/** @brief Releases a mutex. If it is already unlocked then does nothing */
-void mutex_unlock(cel_mutex* mutex); \ No newline at end of file
diff --git a/src/platform/path.c b/src/platform/path.c
deleted file mode 100644
index f43d954..0000000
--- a/src/platform/path.c
+++ /dev/null
@@ -1,35 +0,0 @@
-#include "path.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include "mem.h"
-#include "str.h"
-
-#if defined(CEL_PLATFORM_LINUX) || defined(CEL_PLATFORM_MAC)
-#include <libgen.h>
-path_opt path_parent(arena* a, const char* path) {
- // Duplicate the string because dirname doesnt like const literals
- char* path_copy = arena_alloc(a, strlen(path) + 1);
- strcpy(path_copy, path);
- char* path_dirname = dirname(path_copy);
- return (path_opt){ .path = Str8_cstr_view(path_dirname), .has_value = true };
-}
-#endif
-#ifdef CEL_PLATFORM_WINDOWS
-#include <shlwapi.h>
-#include <windows.h>
-#pragma comment(lib, "Shlwapi.lib")
-
-path_opt path_parent(arena* a, const char* path) {
- // Duplicate the string because PathRemoveFileSpec mutates in-place
- size_t len = strlen(path) + 1;
- char* path_copy = arena_alloc(a, len);
- strcpy_s(path_copy, len, path);
-
- if (PathRemoveFileSpecA(path_copy)) {
- return (path_opt){ .path = Str8_cstr_view(path_copy), .has_value = true };
- } else {
- return (path_opt){ .has_value = false };
- }
-}
-#endif
diff --git a/src/platform/path.h b/src/platform/path.h
deleted file mode 100644
index ce53339..0000000
--- a/src/platform/path.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/**
- * @file path.h
- * @brief
- * @date 2024-03-11
- * @copyright Copyright (c) 2024
- */
-#pragma once
-
-#include "str.h"
-
-typedef struct path_opt {
- Str8 path;
- bool has_value;
-} path_opt;
-
-path_opt path_parent(arena* a, const char* path); // TODO: convert to using str8
diff --git a/src/platform/platform.h b/src/platform/platform.h
new file mode 100644
index 0000000..c2be630
--- /dev/null
+++ b/src/platform/platform.h
@@ -0,0 +1,37 @@
+#pragma once
+
+#include "defines.h"
+#include "str.h"
+
+// -- Paths
+typedef struct path_opt {
+ Str8 path;
+ bool has_value;
+} path_opt;
+
+// TODO: convert to using str8
+// TODO: use uppercase code style
+path_opt path_parent(arena* a, const char* path);
+
+// --- Threads
+typedef struct CelThread CelThread;
+
+CelThread Thread_Create();
+void Thread_Destroy(CelThread* thread);
+
+// --- Mutexes
+typedef struct CelMutex CelMutex;
+
+CelMutex Mutex_Create();
+void Mutex_Destroy(CelMutex* mutex);
+
+/** @brief Blocks until the mutex can be acquired. if returns false then an error occurred and can
+ * be checked (TODO) */
+bool Mutex_Lock(CelMutex* mutex);
+
+/** @brief Tries to acquire the mutex like `mutex_lock` but returns immediately if the mutex has
+ * already been locked */
+bool Mutex_TryLock(CelMutex* mutex);
+
+/** @brief Releases a mutex. If it is already unlocked then does nothing */
+void Mutex_Unlock(CelMutex* mutex);
diff --git a/src/platform/platform_unix.c b/src/platform/platform_unix.c
new file mode 100644
index 0000000..86ac170
--- /dev/null
+++ b/src/platform/platform_unix.c
@@ -0,0 +1,16 @@
+#include "platform.h"
+
+#if defined(CEL_PLATFORM_LINUX) || defined(CEL_PLATFORM_MAC)
+
+#include <libgen.h>
+#include <string.h>
+
+path_opt path_parent(arena* a, const char* path) {
+ // Duplicate the string because dirname doesnt like const literals
+ char* path_copy = arena_alloc(a, strlen(path) + 1);
+ strcpy(path_copy, path);
+ char* path_dirname = dirname(path_copy);
+ return (path_opt){ .path = Str8_cstr_view(path_dirname), .has_value = true };
+}
+
+#endif
diff --git a/src/platform/platform_windows.c b/src/platform/platform_windows.c
new file mode 100644
index 0000000..21ef359
--- /dev/null
+++ b/src/platform/platform_windows.c
@@ -0,0 +1,22 @@
+#include "platform.h"
+
+#if defined(CEL_PLATFORM_WINDOWS)
+
+#include <shlwapi.h>
+#include <windows.h>
+#pragma comment(lib, "Shlwapi.lib")
+
+path_opt path_parent(arena* a, const char* path) {
+ // Duplicate the string because PathRemoveFileSpec mutates in-place
+ size_t len = strlen(path) + 1;
+ char* path_copy = arena_alloc(a, len);
+ strcpy_s(path_copy, len, path);
+
+ if (PathRemoveFileSpecA(path_copy)) {
+ return (path_opt){ .path = Str8_cstr_view(path_copy), .has_value = true };
+ } else {
+ return (path_opt){ .has_value = false };
+ }
+}
+
+#endif
diff --git a/src/platform/thread.c b/src/platform/thread.c
deleted file mode 100644
index e69de29..0000000
--- a/src/platform/thread.c
+++ /dev/null
diff --git a/src/platform/thread.h b/src/platform/thread.h
deleted file mode 100644
index af07d3f..0000000
--- a/src/platform/thread.h
+++ /dev/null
@@ -1,17 +0,0 @@
-/**
- * @file thread.h
- * @author your name (you@domain.com)
- * @brief
- * @version 0.1
- * @date 2024-04-27
- *
- * @copyright Copyright (c) 2024
- *
- */
-
-typedef struct cel_thread cel_thread;
-
-cel_thread thread_create();
-void thread_destroy(cel_thread* thread);
-
-// join \ No newline at end of file