146 lines
3.8 KiB
Zig
146 lines
3.8 KiB
Zig
const std = @import("std");
|
|
pub const c = @import("c.zig").c;
|
|
|
|
pub const ThreadID = u64;
|
|
|
|
pub const AtomicInt = extern struct {
|
|
};
|
|
|
|
pub const Mutex = opaque {
|
|
pub inline fn lockMutex(mutex: *Mutex) void {
|
|
return c.SDL_LockMutex(mutex);
|
|
}
|
|
|
|
pub inline fn unlockMutex(mutex: *Mutex) void {
|
|
return c.SDL_UnlockMutex(mutex);
|
|
}
|
|
|
|
pub inline fn destroyMutex(mutex: *Mutex) void {
|
|
return c.SDL_DestroyMutex(mutex);
|
|
}
|
|
|
|
};
|
|
|
|
pub inline fn createMutex() ?*Mutex {
|
|
return c.SDL_CreateMutex();
|
|
}
|
|
|
|
pub inline fn tryLockMutex(SDL_TRY_ACQUIRE(0: Mutex *mutex), mutex) bool {
|
|
return c.SDL_TryLockMutex(SDL_TRY_ACQUIRE(0, );
|
|
}
|
|
|
|
pub const RWLock = opaque {
|
|
pub inline fn lockRWLockForReading(rwlock: *RWLock) void {
|
|
return c.SDL_LockRWLockForReading(rwlock);
|
|
}
|
|
|
|
pub inline fn lockRWLockForWriting(rwlock: *RWLock) void {
|
|
return c.SDL_LockRWLockForWriting(rwlock);
|
|
}
|
|
|
|
pub inline fn unlockRWLock(rwlock: *RWLock) void {
|
|
return c.SDL_UnlockRWLock(rwlock);
|
|
}
|
|
|
|
pub inline fn destroyRWLock(rwlock: *RWLock) void {
|
|
return c.SDL_DestroyRWLock(rwlock);
|
|
}
|
|
|
|
};
|
|
|
|
pub inline fn createRWLock() ?*RWLock {
|
|
return c.SDL_CreateRWLock();
|
|
}
|
|
|
|
pub inline fn tryLockRWLockForReading(SDL_TRY_ACQUIRE_SHARED(0: RWLock *rwlock), rwlock) bool {
|
|
return c.SDL_TryLockRWLockForReading(SDL_TRY_ACQUIRE_SHARED(0, );
|
|
}
|
|
|
|
pub inline fn tryLockRWLockForWriting(SDL_TRY_ACQUIRE(0: RWLock *rwlock), rwlock) bool {
|
|
return c.SDL_TryLockRWLockForWriting(SDL_TRY_ACQUIRE(0, );
|
|
}
|
|
|
|
pub const Semaphore = opaque {
|
|
pub inline fn destroySemaphore(semaphore: *Semaphore) void {
|
|
return c.SDL_DestroySemaphore(semaphore);
|
|
}
|
|
|
|
pub inline fn waitSemaphore(semaphore: *Semaphore) void {
|
|
return c.SDL_WaitSemaphore(semaphore);
|
|
}
|
|
|
|
pub inline fn tryWaitSemaphore(semaphore: *Semaphore) bool {
|
|
return c.SDL_TryWaitSemaphore(semaphore);
|
|
}
|
|
|
|
pub inline fn waitSemaphoreTimeout(semaphore: *Semaphore, timeoutMS: i32) bool {
|
|
return c.SDL_WaitSemaphoreTimeout(semaphore, timeoutMS);
|
|
}
|
|
|
|
pub inline fn signalSemaphore(semaphore: *Semaphore) void {
|
|
return c.SDL_SignalSemaphore(semaphore);
|
|
}
|
|
|
|
pub inline fn getSemaphoreValue(semaphore: *Semaphore) u32 {
|
|
return c.SDL_GetSemaphoreValue(semaphore);
|
|
}
|
|
|
|
};
|
|
|
|
pub inline fn createSemaphore(initial_value: u32) ?*Semaphore {
|
|
return c.SDL_CreateSemaphore(initial_value);
|
|
}
|
|
|
|
pub const Condition = opaque {
|
|
pub inline fn destroyCondition(condition: *Condition) void {
|
|
return c.SDL_DestroyCondition(condition);
|
|
}
|
|
|
|
pub inline fn signalCondition(condition: *Condition) void {
|
|
return c.SDL_SignalCondition(condition);
|
|
}
|
|
|
|
pub inline fn broadcastCondition(condition: *Condition) void {
|
|
return c.SDL_BroadcastCondition(condition);
|
|
}
|
|
|
|
pub inline fn waitCondition(condition: *Condition, mutex: ?*Mutex) void {
|
|
return c.SDL_WaitCondition(condition, mutex);
|
|
}
|
|
|
|
pub inline fn waitConditionTimeout(condition: *Condition, mutex: ?*Mutex, timeoutMS: i32) bool {
|
|
return c.SDL_WaitConditionTimeout(condition, mutex, timeoutMS);
|
|
}
|
|
|
|
};
|
|
|
|
pub inline fn createCondition() ?*Condition {
|
|
return c.SDL_CreateCondition();
|
|
}
|
|
|
|
pub const InitStatus = enum(c_int) {
|
|
initStatusUninitialized,
|
|
initStatusInitializing,
|
|
initStatusInitialized,
|
|
initStatusUninitializing,
|
|
};
|
|
|
|
pub const InitState = extern struct {
|
|
status: AtomicInt,
|
|
thread: ThreadID,
|
|
reserved: ?*anyopaque,
|
|
};
|
|
|
|
pub inline fn shouldInit(state: ?*InitState) bool {
|
|
return c.SDL_ShouldInit(state);
|
|
}
|
|
|
|
pub inline fn shouldQuit(state: ?*InitState) bool {
|
|
return c.SDL_ShouldQuit(state);
|
|
}
|
|
|
|
pub inline fn setInitialized(state: ?*InitState, initialized: bool) void {
|
|
return c.SDL_SetInitialized(state, initialized);
|
|
}
|
|
|