|
@@ -12,7 +12,7 @@ typedef struct {
|
|
|
|
|
|
static int incrementMutexCounter(void* p) {
|
|
|
MutexCounter* mcp = (MutexCounter*)p;
|
|
|
- for(int i = 0; i < 10000; i++) {
|
|
|
+ for(int i = 0; i < 20000; i++) {
|
|
|
mtx_lock(&mcp->m);
|
|
|
mcp->counter++;
|
|
|
mtx_unlock(&mcp->m);
|
|
@@ -21,7 +21,7 @@ static int incrementMutexCounter(void* p) {
|
|
|
}
|
|
|
|
|
|
static void testMutex() {
|
|
|
- i64 n = -coreGetNanos();
|
|
|
+ i64 n = -getNanos();
|
|
|
|
|
|
MutexCounter mc = {.counter = 0};
|
|
|
mtx_init(&mc.m, mtx_plain);
|
|
@@ -30,40 +30,40 @@ static void testMutex() {
|
|
|
thrd_create(t + 1, incrementMutexCounter, &mc);
|
|
|
thrd_join(t[0], nullptr);
|
|
|
thrd_join(t[1], nullptr);
|
|
|
- CORE_TEST_INT(20000, mc.counter);
|
|
|
+ TEST_INT(40000, mc.counter);
|
|
|
|
|
|
- n += coreGetNanos();
|
|
|
+ n += getNanos();
|
|
|
printf("%ldns Mutex\n", n);
|
|
|
}
|
|
|
|
|
|
typedef struct {
|
|
|
- CoreSpinLock s;
|
|
|
+ SpinLock s;
|
|
|
int counter;
|
|
|
} SpinLockCounter;
|
|
|
|
|
|
static int incrementSpinLockCounter(void* p) {
|
|
|
SpinLockCounter* mcp = (SpinLockCounter*)p;
|
|
|
for(int i = 0; i < 20000; i++) {
|
|
|
- coreLockSpinLock(&mcp->s);
|
|
|
+ lockSpinLock(&mcp->s);
|
|
|
mcp->counter++;
|
|
|
- coreUnlockSpinLock(&mcp->s);
|
|
|
+ unlockSpinLock(&mcp->s);
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
static void testSpinLockLoop() {
|
|
|
- i64 n = -coreGetNanos();
|
|
|
+ i64 n = -getNanos();
|
|
|
|
|
|
SpinLockCounter sc = {.counter = 0};
|
|
|
- coreInitSpinLock(&sc.s);
|
|
|
+ initSpinLock(&sc.s);
|
|
|
thrd_t t[2];
|
|
|
thrd_create(t + 0, incrementSpinLockCounter, &sc);
|
|
|
thrd_create(t + 1, incrementSpinLockCounter, &sc);
|
|
|
thrd_join(t[0], nullptr);
|
|
|
thrd_join(t[1], nullptr);
|
|
|
- CORE_TEST_INT(40000, sc.counter);
|
|
|
+ TEST_INT(40000, sc.counter);
|
|
|
|
|
|
- n += coreGetNanos();
|
|
|
+ n += getNanos();
|
|
|
printf("%ldns SpinLock\n", n);
|
|
|
}
|
|
|
|