00001 00007 /* Copyright 2000 - 2005 Vijay Mathew Pandyalakal. All rights reserved. 00008 * 00009 * This software may be used or modified for any purpose, personal or 00010 * commercial. Open Source redistributions are permitted. 00011 * 00012 * Redistributions qualify as "Open Source" under one of the following terms: 00013 * 00014 * Redistributions are made at no charge beyond the reasonable cost of 00015 * materials and delivery. 00016 * 00017 * Redistributions are accompanied by a copy of the Source Code or by an 00018 * irrevocable offer to provide a copy of the Source Code for up to three 00019 * years at the cost of materials and delivery. Such redistributions 00020 * must allow further use, modification, and redistribution of the Source 00021 * Code under substantially the same terms as this license. 00022 * 00023 * Redistributions of source code must retain the copyright notices as they 00024 * appear in each source code file, these license terms, and the 00025 * disclaimer/limitation of liability set forth as paragraph 6 below. 00026 * 00027 * Redistributions in binary form must reproduce this Copyright Notice, 00028 * these license terms, and the disclaimer/limitation of liability set 00029 * forth as paragraph 6 below, in the documentation and/or other materials 00030 * provided with the distribution. 00031 * 00032 * The Software is provided on an "AS IS" basis. No warranty is 00033 * provided that the Software is free of defects, or fit for a 00034 * particular purpose. 00035 * 00036 * Limitation of Liability. The Author shall not be liable 00037 * for any damages suffered by the Licensee or any third party resulting 00038 * from use of the Software. 00039 */ 00040 00041 #include <string> 00042 #include <windows.h> 00043 #include <scol.h> 00044 namespace openutils { 00045 class ThreadException; 00046 class Mutex; 00047 00054 class Thread { 00055 00056 private: 00057 // unsigned long* to the low-level thread object 00058 unsigned long* m_hThread; 00059 // a name to identify the thread 00060 std::string m_strName; 00061 00062 public: 00063 Thread(); 00064 Thread(const char* nm); 00065 virtual ~Thread(); 00066 void setName(const char* nm); 00067 std::string getName() const; 00068 void start(); 00069 virtual void run(); 00070 void sleep(long ms); 00071 void suspend(); 00072 void resume(); 00073 void stop(); 00074 00075 void setPriority(int p); 00076 00077 bool wait(const char* m,long ms=5000); 00078 void release(const char* m); 00079 00080 public: 00081 // Thread priorities 00082 static const int P_ABOVE_NORMAL; 00083 static const int P_BELOW_NORMAL; 00084 static const int P_HIGHEST; 00085 static const int P_IDLE; 00086 static const int P_LOWEST; 00087 static const int P_NORMAL; 00088 static const int P_CRITICAL; 00089 private: 00090 };// class Thread 00091 00096 class Mutex { 00097 private: 00098 // unsigned long* to the low-level mutex object 00099 unsigned long* m_hMutex; 00100 // name to identify the mutex 00101 std::string m_strName; 00102 public: 00103 Mutex(); 00104 Mutex(const char* nm); 00105 void create(const char* nm); 00106 unsigned long* getMutexHandle(); 00107 std::string getName(); 00108 void release(); 00109 ~Mutex(); 00110 }; 00111 00116 class ThreadException { 00117 private: 00118 std::string msg; 00119 public: 00120 ThreadException(const char* m); 00121 std::string getMessage() const; 00122 }; 00123 } // namespace openutils 00124 00125 // global function called by the thread object. 00126 // this in turn calls the overridden run() 00127 extern "C" { 00128 unsigned int _ou_thread_proc(void* param); 00129 } 00130 00131 00132
1.6.3