mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 08:12:28 +00:00
Improve the affinity system calls
This commit is contained in:
parent
60b68d7152
commit
59ac141e49
19 changed files with 231 additions and 123 deletions
|
@ -23,9 +23,11 @@
|
|||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/sysconf.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "libc/thread/thread2.h"
|
||||
|
||||
void SetUp(void) {
|
||||
if (!IsLinux()) {
|
||||
if (!IsLinux() && !IsFreebsd() && !IsWindows()) {
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
@ -52,3 +54,26 @@ TEST(sched_getaffinity, secondOnly) {
|
|||
EXPECT_FALSE(CPU_ISSET(0, &y));
|
||||
EXPECT_TRUE(CPU_ISSET(1, &y));
|
||||
}
|
||||
|
||||
TEST(sched_getaffinity, getpid) {
|
||||
cpu_set_t x, y;
|
||||
CPU_ZERO(&x);
|
||||
CPU_SET(0, &x);
|
||||
ASSERT_SYS(0, 0, sched_setaffinity(getpid(), sizeof(x), &x));
|
||||
ASSERT_SYS(0, 0, sched_getaffinity(getpid(), sizeof(y), &y));
|
||||
EXPECT_EQ(1, CPU_COUNT(&y));
|
||||
EXPECT_TRUE(CPU_ISSET(0, &y));
|
||||
EXPECT_FALSE(CPU_ISSET(1, &y));
|
||||
}
|
||||
|
||||
TEST(pthread_getaffinity, getpid) {
|
||||
cpu_set_t x, y;
|
||||
CPU_ZERO(&x);
|
||||
CPU_SET(0, &x);
|
||||
ASSERT_SYS(0, 0, pthread_setaffinity_np(pthread_self(), sizeof(x), &x));
|
||||
if (IsWindows()) return; // win32 doesn't define GetThreadAffinityMask ;_;
|
||||
ASSERT_SYS(0, 0, pthread_getaffinity_np(pthread_self(), sizeof(y), &y));
|
||||
EXPECT_EQ(1, CPU_COUNT(&y));
|
||||
EXPECT_TRUE(CPU_ISSET(0, &y));
|
||||
EXPECT_FALSE(CPU_ISSET(1, &y));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue