-
Notifications
You must be signed in to change notification settings - Fork 0
/
lock.c
36 lines (30 loc) · 1.61 KB
/
lock.c
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
26
27
28
29
30
31
32
33
34
35
/*****************************************************************************/
/* File: lock.c */
/* */
/* Description: Source file for synchonization primitives. */
/* */
/* Author: Shoily O Rahman <shoily@gmail.com> */
/* */
/* Date: Oct 16, 2020 */
/* Lock order - */
/* spinlock_smp->lock_pgd (kernel) */
/* lock_pgd (user)->spinlock_page_alloc */
/* */
/*****************************************************************************/
#include "lock.h"
void spinlock_lock(spinlock *lock) {
__asm__ __volatile__("movl $1, %%eax;"
"1:;"
"lock xchgl %0, %%eax;"
"testl %%eax, %%eax;"
"jne 1b;"
: "=m" (lock->val)
: "m" (lock->val)
: "%eax", "%ebx", "cc", "memory" );
}
void spinlock_unlock(spinlock *lock) {
__asm__ __volatile__("movl $0, %0;"
: "=m" (lock->val)
:
: "memory" );
}