| 1 | const builtin = @import("builtin"); |
| 2 | const std = @import("std"); |
| 3 | |
| 4 | const c = std.c; |
| 5 | const math = std.math; |
| 6 | const testing = std.testing; |
| 7 | |
| 8 | test "pthread_spinlock_t" { |
| 9 | if (builtin.target.os.tag.isDarwin()) return; // Darwin doesn't have `pthread_spin_*` |
| 10 | if (builtin.target.os.tag == .windows and builtin.target.abi != .gnu) return; // winpthreads-only |
| 11 | |
| 12 | var spin: c.pthread_spinlock_t = undefined; |
| 13 | _ = c.pthread_spin_init(&spin, c.PTHREAD_PROCESS_PRIVATE); |
| 14 | defer _ = c.pthread_spin_destroy(&spin); |
| 15 | |
| 16 | try std.testing.expectEqual(@backingInt(c.E.SUCCESS), c.pthread_spin_trylock(&spin)); |
| 17 | try std.testing.expectEqual(@backingInt(c.E.SUCCESS), c.pthread_spin_unlock(&spin)); |
| 18 | |
| 19 | try std.testing.expectEqual(@backingInt(c.E.SUCCESS), c.pthread_spin_lock(&spin)); |
| 20 | try std.testing.expectEqual(@backingInt(c.E.SUCCESS), c.pthread_spin_unlock(&spin)); |
| 21 | } |