Skeleton of application, at least compiles
This commit is contained in:
+48
@@ -0,0 +1,48 @@
|
||||
#include "Thread.h"
|
||||
|
||||
void * ftc::Thread::DoRun(void * arg)
|
||||
{
|
||||
try {
|
||||
((Thread*)arg)->is_running = true;
|
||||
((Thread*)arg)->Run();
|
||||
}
|
||||
catch (...) {
|
||||
|
||||
}
|
||||
((Thread*)arg)->is_running = false;
|
||||
if (((Thread*)arg)->delete_after_finish)
|
||||
{
|
||||
delete ((Thread*)arg);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ftc::Thread::Run()
|
||||
{
|
||||
}
|
||||
|
||||
bool ftc::Thread::Start()
|
||||
{
|
||||
pthread_attr_t attr;
|
||||
if (pthread_attr_init(&attr) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
is_running = true;
|
||||
if (pthread_create(&thread, &attr, &Thread::DoRun, this) != 0)
|
||||
{
|
||||
is_running = false;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ftc::Thread::Perform(Thread *work)
|
||||
{
|
||||
work->delete_after_finish = true;
|
||||
work->Start();
|
||||
}
|
||||
Reference in New Issue
Block a user