Skip to content

Commit 545a8f4

Browse files
committed
Add more sched.h content
1 parent f7cfe03 commit 545a8f4

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

libc/calls/struct/cpuset.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ void CPU_AND(cpu_set_t *, cpu_set_t *, cpu_set_t *);
2424
void CPU_OR(cpu_set_t *, cpu_set_t *, cpu_set_t *);
2525
void CPU_XOR(cpu_set_t *, cpu_set_t *, cpu_set_t *);
2626

27+
#define CPU_ALLOC_SIZE(n) \
28+
((((n) + (8 * sizeof(long) - 1)) & -(8 * sizeof(long))) / sizeof(long))
29+
#define CPU_ALLOC(n) ((cpu_set_t *)calloc(1, CPU_ALLOC_SIZE(n)))
30+
#define CPU_FREE(set) free(set)
31+
#define CPU_ZERO_S(size, set) memset(set, 0, size)
32+
#define CPU_EQUAL_S(size, set1, set2) (!memcmp(set1, set2, size))
33+
#define _CPU_S(i, size, set, op) \
34+
((i) / 8U >= (size) ? 0 \
35+
: (((unsigned long *)(set))[(i) / 8 / sizeof(long)] op( \
36+
1UL << ((i) % (8 * sizeof(long))))))
37+
#define CPU_SET_S(i, size, set) _CPU_S(i, size, set, |=)
38+
#define CPU_CLR_S(i, size, set) _CPU_S(i, size, set, &= ~)
39+
#define CPU_ISSET_S(i, size, set) _CPU_S(i, size, set, &)
40+
2741
COSMOPOLITAN_C_END_
2842
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
2943
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_CPUSET_H_ */

libc/dlopen/dlopen.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,9 @@ static dontinline bool foreign_compile(char exe[hasatleast PATH_MAX]) {
632632
return false;
633633
}
634634
int pid, ws;
635-
char *args[] = {"cc", "-pie", "-fPIC", src, "-o", tmp, 0};
635+
char *args[] = {
636+
"cc", "-pie", "-fPIC", src, "-o", tmp, IsNetbsd() ? 0 : "-ldl", 0,
637+
};
636638
errno_t err = posix_spawnp(&pid, args[0], NULL, NULL, args, environ);
637639
if (err) {
638640
unlink(tmp);

libc/thread/pthread_setaffinity_np.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "libc/nt/enum/threadaccess.h"
2828
#include "libc/nt/runtime.h"
2929
#include "libc/nt/thread.h"
30+
#include "libc/str/str.h"
3031
#include "libc/sysv/errfuns.h"
3132
#include "libc/thread/posixthread.internal.h"
3233

@@ -51,8 +52,14 @@ static dontinline textwindows int sys_pthread_setaffinity_nt(
5152
errno_t pthread_setaffinity_np(pthread_t thread, size_t size,
5253
const cpu_set_t *bitset) {
5354
int e, rc, tid;
55+
cpu_set_t bs = {0};
5456
struct PosixThread *pt;
5557
e = errno;
58+
if (size < sizeof(cpu_set_t)) {
59+
memcpy(&bs, bitset, size);
60+
bitset = &bs;
61+
size = sizeof(cpu_set_t);
62+
}
5663
pt = (struct PosixThread *)thread;
5764
tid = _pthread_tid(pt);
5865
if (size != sizeof(cpu_set_t)) {

0 commit comments

Comments
 (0)