5 * Created by damian on 25/5/08.
6 * Copyright 2008 frey damian@frey.co.nz. All rights reserved.
17 /** base class for threads */
22 FThread( ) { thread_running
= false; }
23 virtual ~FThread() { if ( thread_running
) StopThread(); }
25 /// start running the ThreadedFunction. thread_priority only takes effect if running as root.
26 void StartThread( int thread_priority
= 0 ) ;
27 /// stop running ThreadedFunction
32 /// override this to do what you want on this object
33 /// called repeatedly until the thread should die
34 virtual void ThreadedFunction() { printf("FThread::ThreadedFunction running.. override me!\n"); }
38 static void * run_function(void * objPtr
){
39 FThread
* the_fthread
= (FThread
*)objPtr
;
41 while( !the_fthread
->thread_should_stop
)
42 the_fthread
->ThreadedFunction();
44 the_fthread
->thread_running
= false;
52 bool thread_should_stop
;
59 FThreadContext() { Set(); }
61 /// set to the current thread context
62 void Set() { context
= pthread_self(); }
65 bool operator == ( const FThreadContext
& other
) const { return pthread_equal( context
, other
.context
); }