-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEVENT77.CPP
More file actions
85 lines (73 loc) · 1.55 KB
/
Copy pathEVENT77.CPP
File metadata and controls
85 lines (73 loc) · 1.55 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**************************************************************/
/* A Small Real Time System for the Real-Time laboratory */
/* built by: A.Teitelbaum on an idea of H.G.Mendelbaum */
/* Jerusalem College of Technology, 5759-64 (1999) */
/* update Tishrey 5777 */
/* EVENT77.CPP, events handling */
/**************************************************************/
#include "smarts77.h"
Event::Event()
{
reset();
}
void Event::send(char name, void *param, int synch)
{
int i;
while(testAndSet( ))
SMARTS.callScheduler( );
source = SMARTS.getCurrentName( );
data = param;
for (i=SMARTS.getTotalTasks()-1; i>=0; --i)
if (SMARTS.getName(i) == name)
break;
if (i>=0)
{
if (SMARTS.getStatus(i)==SUSPENDED && SMARTS.getExpectedEvent(i)==this)
SMARTS.resume(i);
if (synch)
{
senderWait = SMARTS.getCurrentTask( );
dest = name;
SMARTS.suspended();
}
else
dest = name;
}
}
void *Event::wait(char &sourceP)
{
void *param;
if (!flag || dest!=SMARTS.getCurrentName())
{
SMARTS.setCurrentExpectedEvent(this);
SMARTS.suspended();
}
sourceP = source;
param = data;
if (senderWait >= 0)
SMARTS.resume(senderWait);
reset();
return (param);
}
int Event::arrived(char &sourceP)
{
if (flag)
sourceP = source;
return flag;
}
void Event::reset()
{
flag=false;
data = NULL;
source = dest = ' ';
senderWait = -1;
}
int Event::testAndSet()
{
int tmp;
SMARTS.contextSwitchOff( );
tmp = flag;
flag = true;
SMARTS.contextSwitchOn( );
return tmp;
}