00001 /*************************************************************************** 00002 LOW_thread_Factory.h - description 00003 ------------------- 00004 begin : Thu Oct 2 2003 00005 copyright : (C) 2003 by Harald Roelle 00006 email : roelle@informatik.uni-muenchen.de 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef LOW_THREAD_FACTORY_H 00019 #define LOW_THREAD_FACTORY_H 00020 00021 00022 #include "LOW_thread_mutex.h" 00023 #include "LOW_thread_rwlock.h" 00024 00025 00026 #ifdef __linux__ 00027 00028 #include <pthread.h> 00029 00030 #endif 00031 00032 00033 class LOW_thread_thread; 00034 class LOW_thread_runable; 00035 00036 00037 /** Factory class for platform specific objects related to threads. 00038 00039 This class also contains platform specific type definitions. 00040 00041 This class is thread-safe. 00042 00043 @see LOW_thread_mutex 00044 @see LOW_thread_thread 00045 00046 @author Harald Roelle 00047 */ 00048 class LOW_thread_Factory { 00049 00050 //======================================================================================= 00051 public: 00052 00053 //===================================================================================== 00054 // 00055 // type definitions 00056 // 00057 00058 #ifdef __linux__ 00059 00060 /** Type for thread detach state. */ 00061 typedef enum { detachState_joinable = PTHREAD_CREATE_JOINABLE, /**< Thread can be joined. */ 00062 detachState_detached = PTHREAD_CREATE_DETACHED, /**< Thread is not joinable. */ 00063 detachState_default = -1 /**< System default state (only for setting). */ 00064 } detachState_t; 00065 00066 /** Type for thread scheduling policies. */ 00067 typedef enum { schedPolicy_regular = SCHED_OTHER, /**< Non realtime scheduling. */ 00068 schedPolicy_roundRobin = SCHED_RR, /**< Realtime scheduling, round robin variant. */ 00069 schedPolicy_fifo = SCHED_FIFO, /**< Realtime scheduling, fifo variant. */ 00070 schedPolicy_default = -1 /**< System default scheduling (only for setting). */ 00071 } schedPolicy_t; 00072 00073 typedef int schedPrio_t; /**< Type for scheduling priority. */ 00074 00075 /** Type for thread cancellation attributes. */ 00076 typedef enum { cancelAttrib_disable = 0, /**< Canceling disabled */ 00077 cancelAttrib_defered, /**< Canceling enabled, canceling is deferred until a cancellation point is reached. */ 00078 cancelAttrib_async /**< Canceling enabled, thread is immediately canceled */ 00079 } cancelAttrib_t; 00080 00081 #endif 00082 00083 00084 //===================================================================================== 00085 // 00086 // static factory 00087 // 00088 00089 /** Platform aware replacement for creating dynamic instances of LOW_thread_mutex. 00090 00091 @param inMutexKind Kind of the new mutex. 00092 00093 @return Pointer to new instance of LOW_thread_mutex. 00094 00095 @see LOW_thread_mutex 00096 */ 00097 static LOW_thread_mutex* new_mutex( const LOW_thread_mutex::mutexKind_t inMutexKind); 00098 00099 00100 /** Platform aware replacement for creating dynamic instances of LOW_thread_rwlock. 00101 00102 @return Pointer to new instance of LOW_thread_rwlock. 00103 00104 @see LOW_thread_rwlock 00105 */ 00106 static LOW_thread_rwlock* new_rwlock(); 00107 00108 00109 /** Platform aware replacement for creating dynamic instances of LOW_thread_thread. 00110 00111 @param inRunable Object to be executed in the new thread. 00112 00113 @return Pointer to new instance of LOW_thread_thread. 00114 00115 @see LOW_thread_thread 00116 */ 00117 static LOW_thread_thread* new_thread( LOW_thread_runable *inRunable); 00118 00119 00120 //======================================================================================= 00121 private: 00122 00123 //===================================================================================== 00124 // 00125 // constructors 00126 // 00127 00128 /** Constructor. 00129 Private to prevent instaciation as this is a static factory. 00130 */ 00131 LOW_thread_Factory(); 00132 00133 /** Destructor. 00134 Private to prevent instaciation as this is a static factory. 00135 */ 00136 ~LOW_thread_Factory(); 00137 00138 }; 00139 00140 #endif