


|
Personal page of Konjengbam |
|
“Bluetooth adopter, technology enabler and innovative thinking” |

|
// UserThread.h: interface for the CUserThread class. // //////////////////////////////////////////////////////////////////////
/************************************ REVISION LOG ENTRY Written By: Jayanta Konjengbam Revision By: Jayanta Konjengbam Revised on 23.10.2002 16:24:30 Comments: Following classes provide a way of operating on Win32 Threads, providing a wrapper C++ class (alternative to CWinThread of MFC) based on Win32 thread APIs.
As of now, only worker threads are supported. It is advised to use CThreadManager to create worker threads. This manager monitors the threads lifetime, and when not required it flushes the threads resources. ************************************/
#if !defined(AFX_USERTHREAD_H__676008A5_77DD_411C_9833_D15779525022__INCLUDED_) #define AFX_USERTHREAD_H__676008A5_77DD_411C_9833_D15779525022__INCLUDED_
#if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000
///////////////////////////////////////////////////////////////////// // CThreadManager class CUserThread; // Forward class declaration
class CThreadManager { public: // Constructor and Desctructor CThreadManager(); // This will start a thread that will monitor other threads // created using CUserThread object
virtual ~CThreadManager(); // This destroys the monitoring thread and all other // monitored threads
public: void StartManager(); void EndManager();
void RegisterThread(CUserThread* pThread); // Register the thread to manager to monitor void UnregisterThreadAll(); // End manager calls this anyway. so, explicit call may not be required
int NoOfThreads() const;
// Global static routines static CUserThread* CreateThread( LPTHREAD_START_ROUTINE lpThreadFunc, LPVOID lpParam, LPSECURITY_ATTRIBUTES lpThreadAttributes = NULL, DWORD dwStackSize = 0L, DWORD dwCreationFlags = 0L );
private: CRITICAL_SECTION m_criticalSection; HANDLE m_hMutexObj; CUserThread* m_pMasterThread;
friend UINT MasterMonitorFunc( LPVOID lParam ); void EndThread( CUserThread* pThread ); };
////////////////////////////////////////////////////////////////////// // CUserThread class CUserThread { public: // Constructor CUserThread( LPTHREAD_START_ROUTINE lpThreadFunc, LPVOID lpParam, LPSECURITY_ATTRIBUTES lpThreadAttributes = NULL, DWORD dwStackSize = 0L, DWORD dwCreationFlags = 0L );
// Destructor virtual ~CUserThread();
// Public methods void EnableWait( BOOL bWaitStat ); // By, default, this is set to FALSE
BOOL ResumeThread(); BOOL SuspendThread();
BOOL SetPriority( int nPriorityLevel ); int GetPriority();
void ExitThread(); // Incorporates clean exit too, if Wait = TRUE // Public Attributes public: DWORD m_dwThreadID; HANDLE m_hThread; BOOL m_bAutoDelete; // When object dies, thread will also be destroyed if set to TRUE
protected: CUserThread(); // No implementation
BOOL m_bWait; // If set to TRUE, then a clean exit of the thread is guaranteed.
// Following methods are strictly forbidden private: CUserThread( const CUserThread& userThread ); // No implementation
CUserThread& operator= ( const CUserThread& rUserThread ); // No implementation const bool operator== ( const CUserThread& rUserThread ); // No implementation };
#endif // !defined(AFX_USERTHREAD_H__676008A5_77DD_411C_9833_D15779525022__INCLUDED_) |