Skip to content

Commit

Permalink
Merge pull request #5 from delaneyj/zig-master-fixes
Browse files Browse the repository at this point in the history
fixes to work with zig master branch
  • Loading branch information
kprotty committed Nov 25, 2021
2 parents 498cdf8 + 548559b commit 926480a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion benchmarks/zig/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Zig implementations

```
zig build run -Drelease-fast // -Dc if on posix systems
zig build run -Drelease-fast // add -Dc flag if on posix systems
```
Runs the quick sort benchmark using the thread pool in this repo which is written in [Ziglang](https://ziglang.org/). `async.zig` wraps the thread pool api which similar `async/await` syntax as the other languages in the benchmark. Also, I wrote two thread pools for curiousity. You can switch which one is used by changing the path to the zig file in `build.zig`.
5 changes: 3 additions & 2 deletions benchmarks/zig/async.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const std = @import("std");
const builtin = @import("builtin");
const ThreadPool = @import("thread_pool");

/// Global thread pool which mimics other async runtimes
Expand Down Expand Up @@ -53,13 +54,13 @@ pub fn run(comptime asyncFn: anytype, args: anytype) ReturnTypeOf(asyncFn) {

// On windows, use the process heap allocator.
// On posix systems, use the libc allocator.
const is_windows = std.builtin.target.os.tag == .windows;
const is_windows = builtin.target.os.tag == .windows;
var win_heap: if (is_windows) std.heap.HeapAllocator else void = undefined;
if (is_windows) {
win_heap = @TypeOf(win_heap).init();
win_heap.heap_handle = std.os.windows.kernel32.GetProcessHeap() orelse unreachable;
allocator = &win_heap.allocator;
} else if (std.builtin.link_libc) {
} else if (builtin.link_libc) {
allocator = std.heap.c_allocator;
} else {
@compileError("link to libc with '-Dc' as zig stdlib doesn't provide a fast, libc-less, general purpose allocator (yet)");
Expand Down

0 comments on commit 926480a

Please sign in to comment.