-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCMacSystemRunnable.cpp
132 lines (102 loc) · 4.48 KB
/
SCMacSystemRunnable.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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*-----------------------------------------------------------------------------+
| |
| SCL - Simulation Class Library |
| |
| (c) 1995 Marc Diefenbruch, Wolfgang Textor |
| University of Essen, Germany |
| |
+---------------+-------------------+---------------+-------------------+------+
| Module | File | Created | Project | |
+---------------+-------------------+---------------+-------------------+------+
| SCPosixThread | SCPosixThread.cc | 7. Mai 1995 | SCL | |
+---------------+-------------------+---------------+-------------------+------+
| |
| Change Log |
| |
| Nr. Date Description |
| ----- -------- ------------------------------------------------------ |
| 001 |
| 000 07.05.95 Neu angelegt |
| |
+-----------------------------------------------------------------------------*/
/* Lineal
00000000001111111111222222222233333333334444444444555555555566666666667777777777
01234567890123456789012345678901234567890123456789012345678901234567890123456789
*/
#include "SCRunnableTypes.h"
#if (_SC_THREAD_TYPE == SCMacintoshThreads)
#include <Threads.h>
#include "SCScheduler.h"
#if _SC_DMALLOC
#include <dmalloc.h>
#endif
#if _SC_THREAD_DEBUG
#include "SCDebug.h"
#endif
SCThread * SCSystemRunnable::interactionThread = NULL;
/*----- Konstruktoren / Destruktoren -----*/
SCSystemRunnable::SCSystemRunnable (const SCObjectType newType,
const SCObject* pParent):
SCSystemThread(newType, pParent)
{
// Do nothing
}
SCSystemRunnable::~SCSystemRunnable (void)
{
// Do nothing
}
/*----- Member-Funktionen -----*/
void SCSystemRunnable::Suspend (void)
{
OSErr error;
#if _SC_THREAD_DEBUG
scThreadDebugLog << "ThreadID #" << ExecutingThreadID() << " enters "
<< "SCSystemRunnable::Suspend"
<< " (" << Identity() << ")" << endl;
#endif
assert(SCSystemThread::ExecutingThreadID() == Identity()); // Only the owner thread
// may run in this code!
assert(interactionThread); // Wake up scheduler or main thread
interactionThread->Resume(); // to prevent deadlock!
error = SetThreadState (threadID, kStoppedThreadState, kNoThreadID);
assert (error == noErr);
#if _SC_THREAD_DEBUG
scThreadDebugLog << "ThreadID #" << ExecutingThreadID() << " exits "
<< "SCSystemRunnable::Suspend"
<< " (" << Identity() << ")" << endl;
#endif
}
void SCSystemRunnable::Resume (void)
{
OSErr error;
#if _SC_THREAD_DEBUG
scThreadDebugLog << "ThreadID #" << ExecutingThreadID() << " enters "
<< "SCSystemRunnable::Resume"
<< " (" << Identity() << ")" << endl;
#endif
assert(SCSystemThread::ExecutingThreadID() != Identity());
// Owner thread must NEVER
// run in this code!
error = SetThreadState (threadID, kReadyThreadState, kNoThreadID);
assert (error == noErr);
assert(interactionThread);
interactionThread->Suspend(); // Set scheduler or
// main thread to sleep if its
// not already resumed
#if _SC_THREAD_DEBUG
scThreadDebugLog << "ThreadID #" << ExecutingThreadID() << " exits "
<< "SCSystemRunnable::Resume"
<< " (" << Identity() << ")" << endl;
#endif
}
/* static members */
_SCINLINE_ SCThread *SCSystemRunnable::GetInteractionThread(void)
{
return interactionThread;
}
_SCINLINE_ void SCSystemRunnable::SetInteractionThread(SCThread *iThread)
{
assert(iThread);
interactionThread = iThread;
}
#endif