/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2008.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: include/sgx/core/threading/thread.hpp

*/

#ifndef SGX_CORE_THREADING_THREAD_HPP
#define SGX_CORE_THREADING_THREAD_HPP	1

class CThread;
typedef tMEM_SIZE (*cbThreadFunction)(CThread *);

#define SGX_THREAD_STATE_INITIALIZING	0
#define SGX_THREAD_STATE_RUNNING			1
#define SGX_THREAD_STATE_PAUSED			2

/**
You can derive from this class, to eliminate the (rather ugly) hangover
of callback functions from version 8.x. You are obliged to honour the m_State
member, and only process the thread code when it equals SGX_THREAD_STATE_RUNNING.

Every thread is created by CThreadManager::create(pThread)
Once it has been added to the system, the m_State is will be to
SGX_THREAD_STATE_INITIALIZING and its start method will be invoked. 
You must call

  pThread->resume();

To begin processing.

*/
class CThread
{ 
public:
	CThread(const sgxCPU *pOnCPU=NULL);
	virtual tMEM_SIZE start();
	virtual void suspend();
	virtual void resume();
	virtual void end();

	volatile tUINT32	m_State;
	void *				m_pUserData;
	
	// Do not change the values below, unless you know what you're doing!
	const sgxCPU *		m_pCPU;
	cbThreadFunction	m_CallbackToStartThread;
	tMEM_SIZE				m_SystemID;

};

#endif /* SGX_CORE_THREADING_THREAD_HPP */

