|
activemq-cpp-3.4.0
|
00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one or more 00003 * contributor license agreements. See the NOTICE file distributed with 00004 * this work for additional information regarding copyright ownership. 00005 * The ASF licenses this file to You under the Apache License, Version 2.0 00006 * (the "License"); you may not use this file except in compliance with 00007 * the License. You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 #ifndef _DECAF_LANG_THREAD_H_ 00018 #define _DECAF_LANG_THREAD_H_ 00019 00020 #include <decaf/lang/exceptions/IllegalThreadStateException.h> 00021 #include <decaf/lang/exceptions/IllegalArgumentException.h> 00022 #include <decaf/lang/exceptions/InterruptedException.h> 00023 #include <decaf/lang/exceptions/RuntimeException.h> 00024 #include <decaf/lang/Exception.h> 00025 #include <decaf/lang/Runnable.h> 00026 #include <decaf/util/Config.h> 00027 00028 namespace decaf{ 00029 namespace util{ 00030 namespace concurrent{ 00031 namespace locks{ 00032 class LockSupport; 00033 }}} 00034 namespace lang{ 00035 00036 class Runtime; 00037 class ThreadGroup; 00038 class ThreadProperties; 00039 00066 class DECAF_API Thread : public Runnable { 00067 private: 00068 00072 ThreadProperties* properties; 00073 00074 public: 00075 00077 static const int MIN_PRIORITY = 1; 00078 00080 static const int NORM_PRIORITY = 5; 00081 00083 static const int MAX_PRIORITY = 10; 00084 00086 enum State{ 00087 00089 NEW = 0, 00090 00092 RUNNABLE = 1, 00093 00095 BLOCKED = 2, 00096 00098 WAITING = 3, 00099 00104 TIMED_WAITING = 4, 00105 00107 SLEEPING = 5, 00108 00110 TERMINATED = 6 00111 00112 }; 00113 00114 public: 00115 00120 class UncaughtExceptionHandler { 00121 public: 00122 00123 virtual ~UncaughtExceptionHandler() {} 00124 00131 virtual void uncaughtException( const Thread* thread, const Throwable& error ) throw() = 0; 00132 00133 }; 00134 00135 private: 00136 00137 Thread( const Thread& ); 00138 Thread& operator= ( const Thread& ); 00139 00140 public: 00141 00148 Thread(); 00149 00159 Thread( Runnable* task ); 00160 00169 Thread( const std::string& name ); 00170 00181 Thread( Runnable* task, const std::string& name ); 00182 00183 virtual ~Thread(); 00184 00193 virtual void start(); 00194 00202 virtual void join(); 00203 00214 virtual void join( long long millisecs ); 00215 00228 virtual void join( long long millisecs, unsigned int nanos ); 00229 00233 virtual void run(); 00234 00239 std::string getName() const; 00240 00246 void setName( const std::string& name ); 00247 00253 int getPriority() const; 00254 00263 void setPriority( int value ); 00264 00274 void setDaemon(bool value); 00275 00282 bool isDaemon() const; 00283 00289 const UncaughtExceptionHandler* getUncaughtExceptionHandler() const; 00290 00297 void setUncaughtExceptionHandler( UncaughtExceptionHandler* handler ); 00298 00304 std::string toString() const; 00305 00312 bool isAlive() const; 00313 00319 Thread::State getState() const; 00320 00321 public: 00322 00335 static void sleep( long long millisecs ); 00336 00352 static void sleep( long long millisecs, unsigned int nanos ); 00353 00358 static void yield(); 00359 00364 static long long getId(); 00365 00371 static Thread* currentThread(); 00372 00373 private: 00374 00375 // Initialize the Threads internal state 00376 void initialize( Runnable* task, const std::string& name ); 00377 00378 // Create a Thread Facade for threads not created by the Decaf Library. 00379 static Thread* createForeignThreadInstance( const std::string& name ); 00380 00381 // Called by the Decaf Runtime at startup to allow the Platform Threading 00382 // code to initialize any necessary Threading constructs needed to support 00383 // the features of this class. 00384 static void initThreading(); 00385 00386 // Called by the Decf Runtime at Shutdown to allow the Platform Threading 00387 // code to return any resources that were allocated at startup for the 00388 // Threading library. 00389 static void shutdownThreading(); 00390 00391 // Called from LockSupport to Park a Thread (suspend it from execution) 00392 static void park( Thread* thread ); 00393 00394 // Called from LockSupport to Park a Thread (suspend it from execution) 00395 static void park( Thread* thread, long long mills, long long nanos ); 00396 00397 // Called from LockSupport to UnPark a Thread (resume its execution status). 00398 static void unpark( Thread* thread ); 00399 00400 // Allow some Decaf Classes greater access to the Threading model. 00401 friend class decaf::util::concurrent::locks::LockSupport; 00402 friend class decaf::lang::Runtime; 00403 00404 }; 00405 00406 }} 00407 00408 #endif /*_DECAF_LANG_THREAD_H_*/