aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2022-07-18 15:20:28 +0100
committergingerBill <bill@gingerbill.org>2022-07-18 15:20:28 +0100
commit9eb3da0474c7e00d0c246dc60409cf86f7db4e51 (patch)
tree03b97eaf32382e79411ead79425c613c90b30f2e
parente91f8feedfec3316c93e32172d4c0ae989776b32 (diff)
Remove import cycle on FreeBSD
-rw-r--r--core/os/dir_freebsd.odin8
-rw-r--r--core/os/os_freebsd.odin16
-rw-r--r--core/sync/futex_freebsd.odin20
-rw-r--r--core/sync/primitives_freebsd.odin10
4 files changed, 29 insertions, 25 deletions
diff --git a/core/os/dir_freebsd.odin b/core/os/dir_freebsd.odin
index 74c410a51..c664ffb34 100644
--- a/core/os/dir_freebsd.odin
+++ b/core/os/dir_freebsd.odin
@@ -1,6 +1,5 @@
package os
-import "core:strings"
import "core:mem"
read_dir :: proc(fd: Handle, n: int, allocator := context.allocator) -> (fi: []File_Info, err: Errno) {
@@ -51,10 +50,13 @@ read_dir :: proc(fd: Handle, n: int, allocator := context.allocator) -> (fi: []F
continue
}
- fullpath := strings.join( []string{ dirpath, filename }, "/", context.temp_allocator)
+ fullpath := make([]byte, len(dirpath)+1+len(filename))
+ copy(fullpath, dirpath)
+ copy(fullpath[len(dirpath):], "/")
+ copy(fullpath[len(dirpath)+1:], filename)
defer delete(fullpath, context.temp_allocator)
- fi_, err = stat(fullpath, allocator)
+ fi_, err = stat(string(fullpath), allocator)
if err != ERROR_NONE {
for fi__ in dfi {
file_info_delete(fi__, allocator)
diff --git a/core/os/os_freebsd.odin b/core/os/os_freebsd.odin
index a991caafc..adf4f246f 100644
--- a/core/os/os_freebsd.odin
+++ b/core/os/os_freebsd.odin
@@ -241,13 +241,13 @@ S_ISGID :: 0o2000 // Set group id on execution
S_ISVTX :: 0o1000 // Directory restrcted delete
-S_ISLNK :: #force_inline proc(m: mode_t) -> bool do return (m & S_IFMT) == S_IFLNK
-S_ISREG :: #force_inline proc(m: mode_t) -> bool do return (m & S_IFMT) == S_IFREG
-S_ISDIR :: #force_inline proc(m: mode_t) -> bool do return (m & S_IFMT) == S_IFDIR
-S_ISCHR :: #force_inline proc(m: mode_t) -> bool do return (m & S_IFMT) == S_IFCHR
-S_ISBLK :: #force_inline proc(m: mode_t) -> bool do return (m & S_IFMT) == S_IFBLK
-S_ISFIFO :: #force_inline proc(m: mode_t) -> bool do return (m & S_IFMT) == S_IFIFO
-S_ISSOCK :: #force_inline proc(m: mode_t) -> bool do return (m & S_IFMT) == S_IFSOCK
+S_ISLNK :: #force_inline proc(m: mode_t) -> bool { return (m & S_IFMT) == S_IFLNK }
+S_ISREG :: #force_inline proc(m: mode_t) -> bool { return (m & S_IFMT) == S_IFREG }
+S_ISDIR :: #force_inline proc(m: mode_t) -> bool { return (m & S_IFMT) == S_IFDIR }
+S_ISCHR :: #force_inline proc(m: mode_t) -> bool { return (m & S_IFMT) == S_IFCHR }
+S_ISBLK :: #force_inline proc(m: mode_t) -> bool { return (m & S_IFMT) == S_IFBLK }
+S_ISFIFO :: #force_inline proc(m: mode_t) -> bool { return (m & S_IFMT) == S_IFIFO }
+S_ISSOCK :: #force_inline proc(m: mode_t) -> bool { return (m & S_IFMT) == S_IFSOCK }
F_OK :: 0 // Test for file existance
X_OK :: 1 // Test for execute permission
@@ -257,7 +257,7 @@ R_OK :: 4 // Test for read permission
foreign libc {
@(link_name="__error") __errno_location :: proc() -> ^int ---
- @(link_name="open") _unix_open :: proc(path: cstring, flags: c.int, mode: c.int) -> Handle ---
+ @(link_name="open") _unix_open :: proc(path: cstring, flags: c.int, mode: c.int) -> Handle ---
@(link_name="close") _unix_close :: proc(fd: Handle) -> c.int ---
@(link_name="read") _unix_read :: proc(fd: Handle, buf: rawptr, size: c.size_t) -> c.ssize_t ---
@(link_name="write") _unix_write :: proc(fd: Handle, buf: rawptr, size: c.size_t) -> c.ssize_t ---
diff --git a/core/sync/futex_freebsd.odin b/core/sync/futex_freebsd.odin
index 2e1d065bc..07fba82a8 100644
--- a/core/sync/futex_freebsd.odin
+++ b/core/sync/futex_freebsd.odin
@@ -3,24 +3,22 @@
package sync
import "core:c"
-import "core:os"
import "core:time"
UMTX_OP_WAIT :: 2
UMTX_OP_WAKE :: 3
+ETIMEDOUT :: 60
+
foreign import libc "system:c"
foreign libc {
_umtx_op :: proc "c" (obj: rawptr, op: c.int, val: c.ulong, uaddr: rawptr, uaddr2: rawptr) -> c.int ---
+ __error :: proc "c" () -> ^c.int ---
}
_futex_wait :: proc(f: ^Futex, expected: u32) -> bool {
- timeout := os.Unix_File_Time{
- seconds = 5,
- nanoseconds = 0,
- }
-
+ timeout := [2]i64{14400, 0} // 4 hours
for {
res := _umtx_op(f, UMTX_OP_WAIT, c.ulong(expected), nil, &timeout)
@@ -28,7 +26,7 @@ _futex_wait :: proc(f: ^Futex, expected: u32) -> bool {
return true
}
- if os.Errno(os.get_last_error()) == os.ETIMEDOUT {
+ if __error()^ == ETIMEDOUT {
continue
}
@@ -42,16 +40,14 @@ _futex_wait_with_timeout :: proc(f: ^Futex, expected: u32, duration: time.Durati
return false
}
- res := _umtx_op(f, UMTX_OP_WAIT, c.ulong(expected), nil, &os.Unix_File_Time{
- seconds = (os.time_t)(duration/1e9),
- nanoseconds = (c.long)(duration%1e9),
- })
+ timeout := [2]i64{i64(duration/1e9), i64(duration%1e9)}
+ res := _umtx_op(f, UMTX_OP_WAIT, c.ulong(expected), nil, &timeout)
if res != -1 {
return true
}
- if os.Errno(os.get_last_error()) == os.ETIMEDOUT {
+ if __error()^ == ETIMEDOUT {
return false
}
diff --git a/core/sync/primitives_freebsd.odin b/core/sync/primitives_freebsd.odin
index e6219acf1..2d7cbf18d 100644
--- a/core/sync/primitives_freebsd.odin
+++ b/core/sync/primitives_freebsd.odin
@@ -2,8 +2,14 @@
//+private
package sync
-import "core:os"
+import "core:c"
+
+foreign import dl "system:dl"
+
+foreign dl {
+ pthread_getthreadid_np :: proc "c" () -> c.int ---
+}
_current_thread_id :: proc "contextless" () -> int {
- return os.current_thread_id()
+ return int(pthread_getthreadid_np())
}