summaryrefslogtreecommitdiffstats
path: root/src/kernel/spinlock.C
blob: ab86e481e23d4da132dd12817ba9efa8dbb58936 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <kernel/spinlock.H>
#include <arch/ppc.H>

void Spinlock::lock()
{
    uint64_t reservation = __sync_fetch_and_add(&iv_reserve, 1);
    if (iv_ready != reservation)
    {
	do
	{
	    setThreadPriorityLow();
	}
	while(iv_ready != reservation);
	setThreadPriorityHigh();
    }
    isync();
}

void Spinlock::unlock()
{
    __sync_add_and_fetch(&iv_ready, 1);
}
OpenPOWER on IntegriCloud