| ... | ... | @@ -2162,10 +2162,63 @@ pub const libc = struct { |
| 2162 | 2162 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/powl.html |
| 2163 | 2163 | pub extern fn powl(x: c_longdouble, y: c_longdouble) c_longdouble; |
| 2164 | 2164 | |
| 2165 | /// int pthread_attr_destroy(pthread_attr_t *attr); |
| 2166 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_attr_destroy.html |
| 2167 | pub extern fn pthread_attr_destroy(attr: *pthread_attr_t) c_int; |
| 2168 | |
| 2169 | /// int pthread_attr_init(pthread_attr_t *attr); |
| 2170 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_attr_init.html |
| 2171 | pub extern fn pthread_attr_init(attr: *pthread_attr_t) c_int; |
| 2172 | |
| 2173 | /// int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize); |
| 2174 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_attr_setguardsize.html |
| 2175 | pub extern fn pthread_attr_setguardsize(attr: *pthread_attr_t, guardsize: usize) c_int; |
| 2176 | |
| 2177 | /// int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize); |
| 2178 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_attr_setstacksize.html |
| 2179 | pub extern fn pthread_attr_setstacksize(attr: *pthread_attr_t, stacksize: usize) c_int; |
| 2180 | |
| 2165 | 2181 | /// int pthread_cancel(pthread_t thread); |
| 2166 | 2182 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_cancel.html |
| 2167 | 2183 | pub extern fn pthread_cancel(thread: pthread_t) c_int; |
| 2168 | 2184 | |
| 2185 | /// int pthread_cond_broadcast(pthread_cond_t *cond); |
| 2186 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_cond_broadcast.html |
| 2187 | pub extern fn pthread_cond_broadcast(cond: *pthread_cond_t) c_int; |
| 2188 | |
| 2189 | /// int pthread_cond_destroy(pthread_cond_t *cond); |
| 2190 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_cond_destroy.html |
| 2191 | pub extern fn pthread_cond_destroy(cond: *pthread_cond_t) c_int; |
| 2192 | |
| 2193 | /// int pthread_cond_init(pthread_cond_t *restrict cond, const pthread_condattr_t *restrict attr); |
| 2194 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_cond_init.html |
| 2195 | pub extern fn pthread_cond_init(noalias cond: *pthread_cond_t, noalias attr: ?*const pthread_condattr_t) c_int; |
| 2196 | |
| 2197 | /// int pthread_cond_signal(pthread_cond_t *cond); |
| 2198 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_cond_signal.html |
| 2199 | pub extern fn pthread_cond_signal(cond: *pthread_cond_t) c_int; |
| 2200 | |
| 2201 | /// int pthread_cond_timedwait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex, const struct timespec *restrict abstime); |
| 2202 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_cond_timedwait.html |
| 2203 | pub extern fn pthread_cond_timedwait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t, noalias abstime: *const struct_timespec) c_int; |
| 2204 | |
| 2205 | /// int pthread_cond_wait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex); |
| 2206 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_cond_wait.html |
| 2207 | pub extern fn pthread_cond_wait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t) c_int; |
| 2208 | |
| 2209 | /// int pthread_condattr_destroy(pthread_condattr_t *attr); |
| 2210 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_condattr_destroy.html |
| 2211 | pub extern fn pthread_condattr_destroy(attr: *pthread_condattr_t) c_int; |
| 2212 | |
| 2213 | |
| 2214 | /// int pthread_condattr_init(pthread_condattr_t *attr); |
| 2215 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_condattr_init.html |
| 2216 | pub extern fn pthread_condattr_init(attr: *pthread_condattr_t) c_int; |
| 2217 | |
| 2218 | /// int pthread_create(pthread_t *restrict thread, const pthread_attr_t *restrict attr, void *(*start_routine)(void*), void *restrict arg); |
| 2219 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_create.html |
| 2220 | pub extern fn pthread_create(noalias newthread: *pthread_t, noalias attr: *const pthread_attr_t, start_routine: *const fn (*anyopaque) callconv(.C) ?*anyopaque, noalias arg: *anyopaque) c_int; |
| 2221 | |
| 2169 | 2222 | /// int pthread_detach(pthread_t thread); |
| 2170 | 2223 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_detach.html |
| 2171 | 2224 | pub extern fn pthread_detach(thread: pthread_t) c_int; |
| ... | ... | @@ -2178,10 +2231,42 @@ pub const libc = struct { |
| 2178 | 2231 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_getconcurrency.html |
| 2179 | 2232 | pub extern fn pthread_getconcurrency() c_int; |
| 2180 | 2233 | |
| 2234 | /// int pthread_join(pthread_t thread, void **value_ptr); |
| 2235 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_join.html |
| 2236 | pub extern fn pthread_join(thread: pthread_t, retval: ?*?*anyopaque) c_int; |
| 2237 | |
| 2181 | 2238 | /// int pthread_kill(pthread_t thread, int sig); |
| 2182 | 2239 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_kill.html |
| 2183 | 2240 | pub extern fn pthread_kill(thread: pthread_t, sig: c_int) c_int; |
| 2184 | 2241 | |
| 2242 | /// int pthread_mutex_destroy(pthread_mutex_t *mutex); |
| 2243 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_mutex_destroy.html |
| 2244 | pub extern fn pthread_mutex_destroy(mutex: *pthread_mutex_t) c_int; |
| 2245 | |
| 2246 | /// int pthread_mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr); |
| 2247 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_mutex_init.html |
| 2248 | pub extern fn pthread_mutex_init(mutex: *pthread_mutex_t, attr: ?*const pthread_mutexattr_t) c_int; |
| 2249 | |
| 2250 | /// int pthread_mutex_lock(pthread_mutex_t *mutex); |
| 2251 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_mutex_lock.html |
| 2252 | pub extern fn pthread_mutex_lock(mutex: *pthread_mutex_t) c_int; |
| 2253 | |
| 2254 | /// int pthread_mutex_trylock(pthread_mutex_t *mutex); |
| 2255 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_mutex_trylock.html |
| 2256 | pub extern fn pthread_mutex_trylock(mutex: *pthread_mutex_t) c_int; |
| 2257 | |
| 2258 | /// int pthread_mutex_unlock(pthread_mutex_t *mutex); |
| 2259 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_mutex_unlock.html |
| 2260 | pub extern fn pthread_mutex_unlock(mutex: *pthread_mutex_t) c_int; |
| 2261 | |
| 2262 | /// int pthread_mutexattr_destroy(pthread_mutexattr_t *attr); |
| 2263 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_mutexattr_destroy.html |
| 2264 | pub extern fn pthread_mutexattr_destroy(attr: *pthread_mutexattr_t) c_int; |
| 2265 | |
| 2266 | /// int pthread_mutexattr_init(pthread_mutexattr_t *attr); |
| 2267 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_mutexattr_init.html |
| 2268 | pub extern fn pthread_mutexattr_init(attr: *pthread_mutexattr_t) c_int; |
| 2269 | |
| 2185 | 2270 | /// pthread_t pthread_self(void); |
| 2186 | 2271 | /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_self.html |
| 2187 | 2272 | pub extern fn pthread_self() pthread_t; |
| ... | ... | @@ -2663,6 +2748,7 @@ pub const libc = struct { |
| 2663 | 2748 | pub extern fn memfd_create(name: [*:0]const u8, flags: c_uint) c_int; |
| 2664 | 2749 | pub extern fn sendfile(out_fd: c_int, in_fd: c_int, offset: ?*const off_t, count: usize) isize; |
| 2665 | 2750 | pub extern fn getdents(dirfd: c_int, buf: [*]u8, nbytes: usize) c_int; |
| 2751 | pub extern fn sched_getaffinity(pid: pid_t, cpusetsize: usize, mask: *cpu_set_t) c_int; |
| 2666 | 2752 | }; |
| 2667 | 2753 | |
| 2668 | 2754 | pub const clock_t = c_long; |
| ... | ... | @@ -2679,7 +2765,7 @@ pub const struct_utmpx = opaque {}; |
| 2679 | 2765 | pub const wint_t = c_uint; |
| 2680 | 2766 | pub const struct_if_nameindex = opaque {}; |
| 2681 | 2767 | pub const struct_lconv = opaque {}; |
| 2682 | | pub const pthread_t = c_ulong; |
| 2768 | pub const pthread_t = *opaque {}; |
| 2683 | 2769 | pub const FILE = opaque {}; |
| 2684 | 2770 | pub const locale_t = *const opaque {}; |
| 2685 | 2771 | pub const nl_catd = *const opaque {}; |
| ... | ... | @@ -2708,6 +2794,16 @@ pub const struct_sockaddr_in6 = extern struct { family: AF = .INET6, port: in_po |
| 2708 | 2794 | pub const struct_sockaddr_un = extern struct { family: AF = .UNIX, path: [108]u8 }; |
| 2709 | 2795 | pub const struct_addrinfo = extern struct { flags: c_int, family: c_int, socktype: c_int, protocol: c_int, addrlen: socklen_t, addr: ?*struct_sockaddr, canonname: ?[*:0]u8, next: ?*struct_addrinfo }; |
| 2710 | 2796 | pub const struct_dirent = extern struct { ino: ino_t, off: off_t, reclen: c_ushort, type: DT, name: [NAME_MAX + 1]u8 }; |
| 2797 | pub const cpu_set_t = [1024 / 8 / @sizeOf(c_ulong)]c_ulong; |
| 2798 | |
| 2799 | const impdef = @cImport({ |
| 2800 | @cInclude("pthread.h"); |
| 2801 | }); |
| 2802 | pub const pthread_attr_t = impdef.pthread_attr_t; |
| 2803 | pub const pthread_mutexattr_t = impdef.pthread_mutexattr_t; |
| 2804 | pub const pthread_mutex_t = impdef.pthread_mutex_t; |
| 2805 | pub const pthread_condattr_t = impdef.pthread_condattr_t; |
| 2806 | pub const pthread_cond_t = impdef.pthread_cond_t; |
| 2711 | 2807 | |
| 2712 | 2808 | pub const AT = struct { |
| 2713 | 2809 | pub const FDCWD = -100; |
| ... | ... | @@ -3290,3 +3386,98 @@ pub fn munmap(addr: *const anyopaque, len: usize) errno.Error!void { |
| 3290 | 3386 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 3291 | 3387 | std.debug.assert(rc == 0); |
| 3292 | 3388 | } |
| 3389 | pub fn pthread_attr_init(attr: *pthread_attr_t) void { |
| 3390 | const rc = libc.pthread_attr_init(attr); |
| 3391 | std.debug.assert(rc == 0); |
| 3392 | } |
| 3393 | pub fn pthread_attr_destroy(attr: *pthread_attr_t) void { |
| 3394 | const rc = libc.pthread_attr_destroy(attr); |
| 3395 | std.debug.assert(rc == 0); |
| 3396 | } |
| 3397 | pub fn pthread_attr_setstacksize(attr: *pthread_attr_t, size: usize) !void { |
| 3398 | const rc = libc.pthread_attr_setstacksize(attr, size); |
| 3399 | if (rc != 0) return errno.fromInt(rc); |
| 3400 | std.debug.assert(rc == 0); |
| 3401 | } |
| 3402 | pub fn pthread_attr_setguardsize(attr: *pthread_attr_t, size: usize) !void { |
| 3403 | const rc = libc.pthread_attr_setguardsize(attr, size); |
| 3404 | if (rc != 0) return errno.fromInt(rc); |
| 3405 | std.debug.assert(rc == 0); |
| 3406 | } |
| 3407 | pub fn pthread_create(noalias newthread: *pthread_t, noalias attr: *const pthread_attr_t, start_routine: *const fn (*anyopaque) callconv(.C) ?*anyopaque, noalias arg: *anyopaque) !void { |
| 3408 | const rc = libc.pthread_create(newthread, attr, start_routine, arg); |
| 3409 | if (rc != 0) return errno.fromInt(rc); |
| 3410 | std.debug.assert(rc == 0); |
| 3411 | } |
| 3412 | pub fn pthread_detach(thread: pthread_t) !void { |
| 3413 | const rc = libc.pthread_detach(thread); |
| 3414 | if (rc != 0) return errno.fromInt(rc); |
| 3415 | std.debug.assert(rc == 0); |
| 3416 | } |
| 3417 | pub fn pthread_join(thread: pthread_t, retval: ?*?*anyopaque) !void { |
| 3418 | const rc = libc.pthread_join(thread, retval); |
| 3419 | if (rc != 0) return errno.fromInt(rc); |
| 3420 | std.debug.assert(rc == 0); |
| 3421 | } |
| 3422 | pub fn sched_getaffinity(pid: pid_t) !cpu_set_t { |
| 3423 | var cpuset: cpu_set_t = undefined; |
| 3424 | const rc = libc.sched_getaffinity(pid, @sizeOf(cpu_set_t), &cpuset); |
| 3425 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 3426 | std.debug.assert(rc == 0); |
| 3427 | return cpuset; |
| 3428 | } |
| 3429 | pub fn pthread_mutex_init(mutex: *pthread_mutex_t, attr: ?*const pthread_mutexattr_t) !void { |
| 3430 | const rc = libc.pthread_mutex_init(mutex, attr); |
| 3431 | if (rc != 0) return errno.fromInt(rc); |
| 3432 | std.debug.assert(rc == 0); |
| 3433 | } |
| 3434 | pub fn pthread_mutex_destroy(mutex: *pthread_mutex_t) !void { |
| 3435 | const rc = libc.pthread_mutex_destroy(mutex); |
| 3436 | if (rc != 0) return errno.fromInt(rc); |
| 3437 | std.debug.assert(rc == 0); |
| 3438 | } |
| 3439 | pub fn pthread_mutex_trylock(mutex: *pthread_mutex_t) !void { |
| 3440 | const rc = libc.pthread_mutex_trylock(mutex); |
| 3441 | if (rc != 0) return errno.fromInt(rc); |
| 3442 | std.debug.assert(rc == 0); |
| 3443 | } |
| 3444 | pub fn pthread_mutex_lock(mutex: *pthread_mutex_t) !void { |
| 3445 | const rc = libc.pthread_mutex_lock(mutex); |
| 3446 | if (rc != 0) return errno.fromInt(rc); |
| 3447 | std.debug.assert(rc == 0); |
| 3448 | } |
| 3449 | pub fn pthread_mutex_unlock(mutex: *pthread_mutex_t) !void { |
| 3450 | const rc = libc.pthread_mutex_unlock(mutex); |
| 3451 | if (rc != 0) return errno.fromInt(rc); |
| 3452 | std.debug.assert(rc == 0); |
| 3453 | } |
| 3454 | pub fn pthread_cond_init(noalias cond: *pthread_cond_t, noalias attr: ?*const pthread_condattr_t) !void { |
| 3455 | const rc = libc.pthread_cond_init(cond, attr); |
| 3456 | if (rc != 0) return errno.fromInt(rc); |
| 3457 | std.debug.assert(rc == 0); |
| 3458 | } |
| 3459 | pub fn pthread_cond_destroy(cond: *pthread_cond_t) !void { |
| 3460 | const rc = libc.pthread_cond_destroy(cond); |
| 3461 | if (rc != 0) return errno.fromInt(rc); |
| 3462 | std.debug.assert(rc == 0); |
| 3463 | } |
| 3464 | pub fn pthread_cond_wait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t) !void { |
| 3465 | const rc = libc.pthread_cond_wait(cond, mutex); |
| 3466 | if (rc != 0) return errno.fromInt(rc); |
| 3467 | std.debug.assert(rc == 0); |
| 3468 | } |
| 3469 | pub fn pthread_cond_timedwait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t, noalias abstime: *const struct_timespec) !void { |
| 3470 | const rc = libc.pthread_cond_timedwait(cond, mutex, abstime); |
| 3471 | if (rc != 0) return errno.fromInt(rc); |
| 3472 | std.debug.assert(rc == 0); |
| 3473 | } |
| 3474 | pub fn pthread_cond_signal(cond: *pthread_cond_t) !void { |
| 3475 | const rc = libc.pthread_cond_signal(cond); |
| 3476 | if (rc != 0) return errno.fromInt(rc); |
| 3477 | std.debug.assert(rc == 0); |
| 3478 | } |
| 3479 | pub fn pthread_cond_broadcast(cond: *pthread_cond_t) !void { |
| 3480 | const rc = libc.pthread_cond_broadcast(cond); |
| 3481 | if (rc != 0) return errno.fromInt(rc); |
| 3482 | std.debug.assert(rc == 0); |
| 3483 | } |