Merge remote-tracking branch 'offical/master'

This commit is contained in:
ed
2024-03-18 11:46:03 -04:00
19 changed files with 169 additions and 63 deletions
+4 -4
View File
@@ -3,19 +3,19 @@ package mem
import "core:sync"
Mutex_allocator :: struct {
Mutex_Allocator :: struct {
backing: Allocator,
mutex: sync.Mutex,
}
mutex_allocator_init :: proc(m: ^Mutex_allocator, backing_allocator: Allocator) {
mutex_allocator_init :: proc(m: ^Mutex_Allocator, backing_allocator: Allocator) {
m.backing = backing_allocator
m.mutex = {}
}
@(require_results)
mutex_allocator :: proc(m: ^Mutex_allocator) -> Allocator {
mutex_allocator :: proc(m: ^Mutex_Allocator) -> Allocator {
return Allocator{
procedure = mutex_allocator_proc,
data = m,
@@ -25,7 +25,7 @@ mutex_allocator :: proc(m: ^Mutex_allocator) -> Allocator {
mutex_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
size, alignment: int,
old_memory: rawptr, old_size: int, loc := #caller_location) -> (result: []byte, err: Allocator_Error) {
m := (^Mutex_allocator)(allocator_data)
m := (^Mutex_Allocator)(allocator_data)
sync.mutex_guard(&m.mutex)
return m.backing.procedure(m.backing.data, mode, size, alignment, old_memory, old_size, loc)
+9 -8
View File
@@ -6,6 +6,7 @@ import "base:runtime"
File :: struct {
impl: _File,
stream: io.Stream,
}
File_Mode :: distinct u32
@@ -72,56 +73,56 @@ name :: proc(f: ^File) -> string {
close :: proc(f: ^File) -> Error {
if f != nil {
return io.close(f.impl.stream)
return io.close(f.stream)
}
return nil
}
seek :: proc(f: ^File, offset: i64, whence: io.Seek_From) -> (ret: i64, err: Error) {
if f != nil {
return io.seek(f.impl.stream, offset, whence)
return io.seek(f.stream, offset, whence)
}
return 0, .Invalid_File
}
read :: proc(f: ^File, p: []byte) -> (n: int, err: Error) {
if f != nil {
return io.read(f.impl.stream, p)
return io.read(f.stream, p)
}
return 0, .Invalid_File
}
read_at :: proc(f: ^File, p: []byte, offset: i64) -> (n: int, err: Error) {
if f != nil {
return io.read_at(f.impl.stream, p, offset)
return io.read_at(f.stream, p, offset)
}
return 0, .Invalid_File
}
write :: proc(f: ^File, p: []byte) -> (n: int, err: Error) {
if f != nil {
return io.write(f.impl.stream, p)
return io.write(f.stream, p)
}
return 0, .Invalid_File
}
write_at :: proc(f: ^File, p: []byte, offset: i64) -> (n: int, err: Error) {
if f != nil {
return io.write_at(f.impl.stream, p, offset)
return io.write_at(f.stream, p, offset)
}
return 0, .Invalid_File
}
file_size :: proc(f: ^File) -> (n: i64, err: Error) {
if f != nil {
return io.size(f.impl.stream)
return io.size(f.stream)
}
return 0, .Invalid_File
}
flush :: proc(f: ^File) -> Error {
if f != nil {
return io.flush(f.impl.stream)
return io.flush(f.stream)
}
return nil
}
+1 -3
View File
@@ -33,8 +33,6 @@ _File :: struct {
name: string,
fd: int,
allocator: runtime.Allocator,
stream: io.Stream,
}
_file_allocator :: proc() -> runtime.Allocator {
@@ -75,7 +73,7 @@ _new_file :: proc(fd: uintptr, _: string) -> ^File {
file.impl.fd = int(fd)
file.impl.allocator = _file_allocator()
file.impl.name = _get_full_path(file.impl.fd, file.impl.allocator)
file.impl.stream = {
file.stream = {
data = file,
procedure = _file_stream_proc,
}
+2 -2
View File
@@ -4,8 +4,8 @@ import "core:io"
to_stream :: proc(f: ^File) -> (s: io.Stream) {
if f != nil {
assert(f.impl.stream.procedure != nil)
s = f.impl.stream
assert(f.stream.procedure != nil)
s = f.stream
}
return
}
+1 -3
View File
@@ -73,8 +73,6 @@ _File :: struct {
wname: win32.wstring,
kind: _File_Kind,
stream: io.Stream,
allocator: runtime.Allocator,
rw_mutex: sync.RW_Mutex, // read write calls
@@ -181,7 +179,7 @@ _new_file :: proc(handle: uintptr, name: string) -> ^File {
}
f.impl.kind = kind
f.impl.stream = {
f.stream = {
data = f,
procedure = _file_stream_proc,
}
+2 -2
View File
@@ -497,8 +497,8 @@ unique :: proc(s: $S/[]$T) -> S where intrinsics.type_is_comparable(T) #no_bound
for j in 1..<len(s) {
if s[j] != s[j-1] && i != j {
s[i] = s[j]
i += 1
}
i += 1
}
return s[:i]
@@ -515,8 +515,8 @@ unique_proc :: proc(s: $S/[]$T, eq: proc(T, T) -> bool) -> S #no_bounds_check {
for j in 1..<len(s) {
if !eq(s[j], s[j-1]) && i != j {
s[i] = s[j]
i += 1
}
i += 1
}
return s[:i]
+22
View File
@@ -1,4 +1,26 @@
//+build darwin
package darwin
import "core:c"
Bool :: b8
RUsage :: struct {
ru_utime: timeval,
ru_stime: timeval,
ru_maxrss: c.long,
ru_ixrss: c.long,
ru_idrss: c.long,
ru_isrss: c.long,
ru_minflt: c.long,
ru_majflt: c.long,
ru_nswap: c.long,
ru_inblock: c.long,
ru_oublock: c.long,
ru_msgsnd: c.long,
ru_msgrcv: c.long,
ru_nsignals: c.long,
ru_nvcsw: c.long,
ru_nivcsw: c.long,
}
@@ -125,7 +125,7 @@ DARWIN_MAXCOMLEN :: 16
/*--==========================================================================--*/
__darwin_ino64_t :: u64
__darwin_time_t :: u32
__darwin_time_t :: c.long
__darwin_dev_t :: i32
__darwin_mode_t :: u16
__darwin_off_t :: i64
@@ -367,7 +367,7 @@ syscall_execve :: #force_inline proc "contextless" (path: cstring, argv: [^]cstr
}
syscall_munmap :: #force_inline proc "contextless" (addr: rawptr, len: u64) -> c.int {
return cast(c.int)intrinsics.syscall(unix_offset_syscall(.mmap), uintptr(addr), uintptr(len))
return cast(c.int)intrinsics.syscall(unix_offset_syscall(.munmap), uintptr(addr), uintptr(len))
}
syscall_mmap :: #force_inline proc "contextless" (addr: ^u8, len: u64, port: c.int, flags: c.int, fd: int, offset: off_t) -> ^u8 {
@@ -417,3 +417,7 @@ syscall_chdir :: #force_inline proc "contextless" (path: cstring) -> c.int {
syscall_fchdir :: #force_inline proc "contextless" (fd: c.int, path: cstring) -> c.int {
return cast(c.int)intrinsics.syscall(unix_offset_syscall(.getentropy), uintptr(fd), transmute(uintptr)path)
}
syscall_getrusage :: #force_inline proc "contextless" (who: c.int, rusage: ^RUsage) -> c.int {
return cast(c.int) intrinsics.syscall(unix_offset_syscall(.getrusage), uintptr(who), uintptr(rusage))
}