summary refs log tree commit diff stats
path: root/search/anagrams.go
stat options
Period:
Authors:

Commits per author per week (path 'search/anagrams.go')

AuthorW22 2024W23 2024W24 2024W25 2024Total
Total00000
'blob content' class='blob'>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "spinlock.h"

static inline int32 exchangeAtomic(volatile int32* oldValueAddress, int32 newValue) {
    //no need to use lock instruction on xchg

    asm volatile ("xchgl %0, %1"
                   : "=r"(newValue)
                   : "m"(*oldValueAddress), "0"(newValue)
                   : "memory");
    return newValue;
}

void Spinlock_Init(Spinlock* spinlock) {
    *spinlock = 0;
}

void Spinlock_Lock(Spinlock* spinlock) {
    while (exchangeAtomic((int32*)spinlock, 1)) {
        halt();
    }
}

void Spinlock_Unlock(Spinlock* spinlock) {
    *spinlock = 0;
}