mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-19 21:56:13 +00:00
Added: Some sort of implementation for CPThread::isRunning()
This commit is contained in:
parent
88b65f0e5b
commit
a31836c6e0
2 changed files with 23 additions and 17 deletions
|
@ -59,8 +59,9 @@ public:
|
||||||
/// Internal use
|
/// Internal use
|
||||||
IRunnable *Runnable;
|
IRunnable *Runnable;
|
||||||
|
|
||||||
|
uint8 _StateV2; // 0=not created, 1=started, 2=ended, 3=finished
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8 _State; // 0=not created, 1=started, 2=finished
|
|
||||||
uint32 _StackSize;
|
uint32 _StackSize;
|
||||||
pthread_t _ThreadHandle;
|
pthread_t _ThreadHandle;
|
||||||
};
|
};
|
||||||
|
|
|
@ -84,6 +84,8 @@ static void *ProxyFunc( void *arg )
|
||||||
// Run the code of the thread
|
// Run the code of the thread
|
||||||
parent->Runnable->run();
|
parent->Runnable->run();
|
||||||
|
|
||||||
|
parent->_StateV2 = 2;
|
||||||
|
|
||||||
// Allow some clean
|
// Allow some clean
|
||||||
// pthread_exit(0);
|
// pthread_exit(0);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -96,7 +98,7 @@ static void *ProxyFunc( void *arg )
|
||||||
*/
|
*/
|
||||||
CPThread::CPThread(IRunnable *runnable, uint32 stackSize)
|
CPThread::CPThread(IRunnable *runnable, uint32 stackSize)
|
||||||
: Runnable(runnable),
|
: Runnable(runnable),
|
||||||
_State(0),
|
_StateV2(0),
|
||||||
_StackSize(stackSize)
|
_StackSize(stackSize)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -106,10 +108,10 @@ CPThread::CPThread(IRunnable *runnable, uint32 stackSize)
|
||||||
*/
|
*/
|
||||||
CPThread::~CPThread()
|
CPThread::~CPThread()
|
||||||
{
|
{
|
||||||
if(_State == 1)
|
if(_StateV2 == 1 || _StateV2 == 2)
|
||||||
terminate(); // force the end of the thread if not already ended
|
terminate(); // force the end of the thread if not already ended
|
||||||
|
|
||||||
if(_State > 0)
|
if(_StateV2 > 0)
|
||||||
pthread_detach(_ThreadHandle); // free allocated resources only if it was created
|
pthread_detach(_ThreadHandle); // free allocated resources only if it was created
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,13 +134,14 @@ void CPThread::start()
|
||||||
{
|
{
|
||||||
throw EThread("Cannot start new thread");
|
throw EThread("Cannot start new thread");
|
||||||
}
|
}
|
||||||
_State = 1;
|
_StateV2 = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CPThread::isRunning()
|
bool CPThread::isRunning()
|
||||||
{
|
{
|
||||||
// TODO : need a real implementation here that check thread status
|
// ExTODO : need a real implementation here that check thread status
|
||||||
return _State == 1;
|
// DONE : some sort of implementation
|
||||||
|
return _StateV2 == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -146,11 +149,11 @@ bool CPThread::isRunning()
|
||||||
*/
|
*/
|
||||||
void CPThread::terminate()
|
void CPThread::terminate()
|
||||||
{
|
{
|
||||||
if(_State == 1)
|
if (_StateV2 == 1 || _StateV2 == 2)
|
||||||
{
|
{
|
||||||
// cancel only if started
|
// cancel only if started
|
||||||
pthread_cancel(_ThreadHandle);
|
pthread_cancel(_ThreadHandle);
|
||||||
_State = 2; // set to finished
|
_StateV2 = 3; // set to finished
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,13 +162,13 @@ void CPThread::terminate()
|
||||||
*/
|
*/
|
||||||
void CPThread::wait ()
|
void CPThread::wait ()
|
||||||
{
|
{
|
||||||
if(_State == 1)
|
if (_StateV2 == 1 || _StateV2 == 2)
|
||||||
{
|
{
|
||||||
if(pthread_join(_ThreadHandle, 0) != 0)
|
if(pthread_join(_ThreadHandle, 0) != 0)
|
||||||
{
|
{
|
||||||
throw EThread( "Cannot join with thread" );
|
throw EThread( "Cannot join with thread" );
|
||||||
}
|
}
|
||||||
_State = 2; // set to finished
|
_StateV2 = 3; // set to finished
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,27 +212,29 @@ uint64 CPThread::getCPUMask()
|
||||||
|
|
||||||
void CPThread::setPriority(TThreadPriority priority)
|
void CPThread::setPriority(TThreadPriority priority)
|
||||||
{
|
{
|
||||||
// TODO: Verify and test this
|
// TODO: Test this
|
||||||
|
sched_param sp;
|
||||||
switch (priority)
|
switch (priority)
|
||||||
{
|
{
|
||||||
case ThreadPriorityHigh:
|
case ThreadPriorityHigh:
|
||||||
{
|
{
|
||||||
int minPrio = sched_get_priority_min(SCHED_FIFO);
|
int minPrio = sched_get_priority_min(SCHED_FIFO);
|
||||||
int maxPrio = sched_get_priority_max(SCHED_FIFO);
|
int maxPrio = sched_get_priority_max(SCHED_FIFO);
|
||||||
int prio = ((maxPrio - minPrio) / 4) + minPrio;
|
sp.sched_priority = ((maxPrio - minPrio) / 4) + minPrio;
|
||||||
pthread_setschedparam(_ThreadHandle, SCHED_FIFO, prio);
|
pthread_setschedparam(_ThreadHandle, SCHED_FIFO, &sp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ThreadPriorityHighest:
|
case ThreadPriorityHighest:
|
||||||
{
|
{
|
||||||
int minPrio = sched_get_priority_min(SCHED_FIFO);
|
int minPrio = sched_get_priority_min(SCHED_FIFO);
|
||||||
int maxPrio = sched_get_priority_max(SCHED_FIFO);
|
int maxPrio = sched_get_priority_max(SCHED_FIFO);
|
||||||
int prio = ((maxPrio - minPrio) / 2) + minPrio;
|
sp.sched_priority = ((maxPrio - minPrio) / 2) + minPrio;
|
||||||
pthread_setschedparam(_ThreadHandle, SCHED_FIFO, prio);
|
pthread_setschedparam(_ThreadHandle, SCHED_FIFO, &sp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
pthread_setschedparam(_ThreadHandle, SCHED_OTHER, 0);
|
sp.sched_priority = 0;
|
||||||
|
pthread_setschedparam(_ThreadHandle, SCHED_OTHER, &sp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue