diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2019-12-01 11:33:23 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-01 11:33:23 +0000 |
| commit | 3fd5c3cd851d8f4dfd441141ca7e96889f069933 (patch) | |
| tree | 67f47e79f5c5bb80a3ed1b1e9d79a61c08c0a29d /core/mem/alloc.odin | |
| parent | 0c0c83ee295fe8787a4bdc8b826a5432abba2ca9 (diff) | |
| parent | 99121d6ff2b02f3d16b791eb103bb9f9e8b96475 (diff) | |
Merge pull request #458 from Tetralux/linux-threads
Implement core:thread and core:sync on Unix using pthreads
Diffstat (limited to 'core/mem/alloc.odin')
| -rw-r--r-- | core/mem/alloc.odin | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/core/mem/alloc.odin b/core/mem/alloc.odin index 4c60ef4a1..38eda7a11 100644 --- a/core/mem/alloc.odin +++ b/core/mem/alloc.odin @@ -84,7 +84,10 @@ delete :: proc{ new :: inline proc($T: typeid, allocator := context.allocator, loc := #caller_location) -> ^T { - ptr := (^T)(alloc(size_of(T), align_of(T), allocator, loc)); + return new_aligned(T, align_of(T), allocator, loc); +} +new_aligned :: inline proc($T: typeid, alignment: int, allocator := context.allocator, loc := #caller_location) -> ^T { + ptr := (^T)(alloc(size_of(T), alignment, allocator, loc)); if ptr != nil do ptr^ = T{}; return ptr; } @@ -95,9 +98,12 @@ new_clone :: inline proc(data: $T, allocator := context.allocator, loc := #calle } -make_slice :: proc($T: typeid/[]$E, auto_cast len: int, allocator := context.allocator, loc := #caller_location) -> T { +make_slice :: inline proc($T: typeid/[]$E, auto_cast len: int, allocator := context.allocator, loc := #caller_location) -> T { + return make_aligned(T, len, align_of(E), allocator, loc); +} +make_aligned :: proc($T: typeid/[]$E, auto_cast len: int, alignment: int, allocator := context.allocator, loc := #caller_location) -> T { runtime.make_slice_error_loc(loc, len); - data := alloc(size_of(E)*len, align_of(E), allocator, loc); + data := alloc(size_of(E)*len, alignment, allocator, loc); s := Raw_Slice{data, len}; return transmute(T)s; } |