Backlog/lib/sdl3/v2/thread.zig

80 lines
2.3 KiB
Zig

const std = @import("std");
pub const c = @import("c.zig").c;
pub const PropertiesID = u32;
pub const Thread = opaque {
pub inline fn getThreadName(thread: *Thread) [*c]const u8 {
return c.SDL_GetThreadName(thread);
}
pub inline fn getThreadID(thread: *Thread) ThreadID {
return c.SDL_GetThreadID(thread);
}
pub inline fn waitThread(thread: *Thread, status: *c_int) void {
return c.SDL_WaitThread(thread, @ptrCast(status));
}
pub inline fn getThreadState(thread: *Thread) ThreadState {
return c.SDL_GetThreadState(thread);
}
pub inline fn detachThread(thread: *Thread) void {
return c.SDL_DetachThread(thread);
}
};
pub const ThreadID = u64;
pub const TLSID = AtomicInt;
pub const ThreadPriority = enum(c_int) {
threadPriorityLow,
threadPriorityNormal,
threadPriorityHigh,
threadPriorityTimeCritical,
};
pub const ThreadFunction = *const fn(data: ?*anyopaque) callconv(.C) c_int;
pub inline fn createThread(fn: ThreadFunction, name: [*c]const u8, data: ?*anyopaque) ?*Thread {
return c.SDL_CreateThread(fn, name, data);
}
pub inline fn createThreadWithProperties(props: PropertiesID) ?*Thread {
return c.SDL_CreateThreadWithProperties(props);
}
pub inline fn createThreadRuntime(fn: ThreadFunction, name: [*c]const u8, data: ?*anyopaque, pfnBeginThread: FunctionPointer, pfnEndThread: FunctionPointer,) ?*Thread {
return c.SDL_CreateThreadRuntime(fn, name, data, pfnBeginThread, pfnEndThread);
}
pub inline fn createThreadWithPropertiesRuntime(props: PropertiesID, pfnBeginThread: FunctionPointer, pfnEndThread: FunctionPointer) ?*Thread {
return c.SDL_CreateThreadWithPropertiesRuntime(props, pfnBeginThread, pfnEndThread);
}
pub inline fn getCurrentThreadID() ThreadID {
return c.SDL_GetCurrentThreadID();
}
pub inline fn setCurrentThreadPriority(priority: ThreadPriority) bool {
return c.SDL_SetCurrentThreadPriority(priority);
}
pub inline fn getTLS(id: ?*TLSID) ?*anyopaque {
return c.SDL_GetTLS(id);
}
pub const TLSDestructorCallback = *const fn(value: ?*anyopaque) callconv(.C) void;
pub inline fn setTLS(id: ?*TLSID, value: ?*const anyopaque, destructor: TLSDestructorCallback) bool {
return c.SDL_SetTLS(id, value, destructor);
}
pub inline fn cleanupTLS() void {
return c.SDL_CleanupTLS();
}