22 |
|
|
23 |
#include "Thread.h" |
#include "Thread.h" |
24 |
|
|
25 |
Thread::Thread(bool RealTime, int PriorityMax, int PriorityDelta) { |
Thread::Thread(bool LockMemory, bool RealTime, int PriorityMax, int PriorityDelta) { |
26 |
|
this->bLockedMemory = LockMemory; |
27 |
this->isRealTime = RealTime; |
this->isRealTime = RealTime; |
28 |
this->Running = false; |
this->Running = false; |
29 |
this->PriorityDelta = PriorityDelta; |
this->PriorityDelta = PriorityDelta; |
130 |
|
|
131 |
if (!isRealTime) return 0; |
if (!isRealTime) return 0; |
132 |
|
|
|
if (mlockall(MCL_CURRENT | MCL_FUTURE) < 0) { |
|
|
perror("WARNING, can't mlockall() memory!"); |
|
|
} |
|
|
|
|
133 |
/* |
/* |
134 |
* set the process to realtime privs |
* set the process to realtime privs |
135 |
*/ |
*/ |
142 |
} |
} |
143 |
|
|
144 |
if (sched_setscheduler(0, SCHED_FIFO, &schp) != 0) { |
if (sched_setscheduler(0, SCHED_FIFO, &schp) != 0) { |
145 |
perror("sched_setscheduler"); |
perror("Thread: WARNING, can't assign realtime scheduling to thread!"); |
146 |
return -1; |
return -1; |
147 |
} |
} |
148 |
#endif |
#endif |
150 |
} |
} |
151 |
|
|
152 |
/** |
/** |
153 |
|
* Locks the memory so it will not be swapped out by the operating system. |
154 |
|
*/ |
155 |
|
int Thread::LockMemory() { |
156 |
|
if (!bLockedMemory) return 0; |
157 |
|
if (mlockall(MCL_CURRENT | MCL_FUTURE) < 0) { |
158 |
|
perror("Thread: WARNING, can't mlockall() memory!"); |
159 |
|
return -1; |
160 |
|
} |
161 |
|
return 0; |
162 |
|
} |
163 |
|
|
164 |
|
/** |
165 |
* Registers thread destructor callback function which will be executed when |
* Registers thread destructor callback function which will be executed when |
166 |
* the thread stops it's execution and sets the 'Running' flag to true. This |
* the thread stops it's execution and sets the 'Running' flag to true. This |
167 |
* method will be called by the __pthread_launcher callback function, DO NOT |
* method will be called by the __pthread_launcher callback function, DO NOT |
193 |
Thread* t; |
Thread* t; |
194 |
t = (Thread*) thread; |
t = (Thread*) thread; |
195 |
t->SetSchedulingPriority(); |
t->SetSchedulingPriority(); |
196 |
|
t->LockMemory(); |
197 |
t->EnableDestructor(); |
t->EnableDestructor(); |
198 |
t->Main(); |
t->Main(); |
199 |
} |
} |