update code to support compilation with zig 0.8.0

This commit is contained in:
Emil Lerch 2021-06-09 16:26:42 -07:00
parent c6dbbf33af
commit e5f5f0e8cd
Signed by: lobo
GPG Key ID: A7B62D657EF764F8
2 changed files with 3 additions and 59 deletions

View File

@ -27,7 +27,6 @@ const c = @cImport({
@cInclude("aws/io/socket.h");
@cInclude("aws/io/stream.h");
});
const std_atomic_bool = @import("bool.zig"); // This is in std in 0.8.0
const CN_NORTH_1_HASH = std.hash_map.hashString("cn-north-1");
const CN_NORTHWEST_1_HASH = std.hash_map.hashString("cn-northwest-1");
@ -816,7 +815,7 @@ fn AsyncResult(comptime T: type) type {
return struct {
result: *T,
requiredCount: u32 = 1,
sync: std_atomic_bool.Bool = std_atomic_bool.Bool.init(false), // This is a 0.8.0 feature... :(
sync: std.atomic.Atomic(bool) = std.atomic.Atomic(bool).init(false),
count: u8 = 0,
};
}
@ -912,8 +911,8 @@ fn endPointFromUri(allocator: *std.mem.Allocator, uri: []const u8) !EndPoint {
const RequestContext = struct {
connection: ?*c.aws_http_connection = null,
connection_complete: std_atomic_bool.Bool = std_atomic_bool.Bool.init(false), // This is a 0.8.0 feature... :(
request_complete: std_atomic_bool.Bool = std_atomic_bool.Bool.init(false), // This is a 0.8.0 feature... :(
connection_complete: std.atomic.Atomic(bool) = std.atomic.Atomic(bool).init(false),
request_complete: std.atomic.Atomic(bool) = std.atomic.Atomic(bool).init(false),
return_error: ?AwsError = null,
allocator: *std.mem.Allocator,
body: ?[]const u8 = null,

View File

@ -1,55 +0,0 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2015-2021 Zig Contributors
// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
// The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software.
const std = @import("std");
const builtin = std.builtin;
const testing = std.testing;
/// Thread-safe, lock-free boolean
pub const Bool = extern struct {
unprotected_value: bool,
pub const Self = @This();
pub fn init(init_val: bool) Self {
return Self{ .unprotected_value = init_val };
}
// xchg is only valid rmw operation for a bool
/// Atomically modifies memory and then returns the previous value.
pub fn xchg(self: *Self, operand: bool, comptime ordering: std.builtin.AtomicOrder) bool {
switch (ordering) {
.Monotonic, .Acquire, .Release, .AcqRel, .SeqCst => {},
else => @compileError("Invalid ordering '" ++ @tagName(ordering) ++ "' for a RMW operation"),
}
return @atomicRmw(bool, &self.unprotected_value, .Xchg, operand, ordering);
}
pub fn load(self: *Self, comptime ordering: std.builtin.AtomicOrder) bool {
switch (ordering) {
.Unordered, .Monotonic, .Acquire, .SeqCst => {},
else => @compileError("Invalid ordering '" ++ @tagName(ordering) ++ "' for a load operation"),
}
return @atomicLoad(bool, &self.unprotected_value, ordering);
}
pub fn store(self: *Self, value: bool, comptime ordering: std.builtin.AtomicOrder) void {
switch (ordering) {
.Unordered, .Monotonic, .Release, .SeqCst => {},
else => @compileError("Invalid ordering '" ++ @tagName(ordering) ++ "' for a store operation"),
}
@atomicStore(bool, &self.unprotected_value, value, ordering);
}
};
test "std.atomic.Bool" {
var a = Bool.init(false);
testing.expectEqual(false, a.xchg(false, .SeqCst));
testing.expectEqual(false, a.load(.SeqCst));
a.store(true, .SeqCst);
testing.expectEqual(true, a.xchg(false, .SeqCst));
testing.expectEqual(false, a.load(.SeqCst));
}