forked from xcore/tool_axe
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLock.cpp
36 lines (33 loc) · 814 Bytes
/
Lock.cpp
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
36
// Copyright (c) 2011, Richard Osborne, All rights reserved
// This software is freely distributable under a derivative of the
// University of Illinois/NCSA Open Source License posted in
// LICENSE.txt and at <http://github.xcore.com/>
#include "Lock.h"
#include "Thread.h"
Resource::ResOpResult Lock::
out(Thread &thread, uint32_t value, ticks_t time)
{
// Unpause a thread.
if (!threads.empty()) {
Thread *next = threads.front();
threads.pop();
if (time > next->time)
next->time = time;
next->pc++;
next->schedule();
} else {
held = false;
}
return CONTINUE;
}
Resource::ResOpResult Lock::
in(Thread &thread, ticks_t time, uint32_t &value)
{
if (!held) {
held = true;
value = getID();
return CONTINUE;
}
threads.push(&thread);
return DESCHEDULE;
}