00001 /******************************************************************************* 00002 * Copyright (C) 2001-2004 Vintela, Inc. All rights reserved. 00003 * 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions are met: 00006 * 00007 * - Redistributions of source code must retain the above copyright notice, 00008 * this list of conditions and the following disclaimer. 00009 * 00010 * - Redistributions in binary form must reproduce the above copyright notice, 00011 * this list of conditions and the following disclaimer in the documentation 00012 * and/or other materials provided with the distribution. 00013 * 00014 * - Neither the name of Vintela, Inc. nor the names of its 00015 * contributors may be used to endorse or promote products derived from this 00016 * software without specific prior written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS 00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00028 * POSSIBILITY OF SUCH DAMAGE. 00029 *******************************************************************************/ 00030 00036 #ifndef OW_THREAD_TYPES_HPP_ 00037 #define OW_THREAD_TYPES_HPP_ 00038 #include "OW_config.h" 00039 00040 // The classes and functions defined in this file are not meant for general 00041 // use, they are internal implementation details. They may change at any time. 00042 00043 #if defined(OW_USE_PTHREAD) 00044 00045 #include <pthread.h> 00046 00047 namespace OW_NAMESPACE 00048 { 00049 00050 // Platform specific thread type 00051 typedef pthread_t Thread_t; 00052 typedef pthread_mutex_t NativeMutex_t; 00053 struct NonRecursiveMutex_t 00054 { 00055 pthread_mutex_t mutex; 00056 }; 00057 00058 #if defined(OW_HAVE_PTHREAD_MUTEXATTR_SETTYPE) 00059 // Platform specific mutex type 00060 // we have native recursive mutexes. 00061 struct Mutex_t 00062 { 00063 pthread_mutex_t mutex; 00064 }; 00065 00066 #else 00067 00068 // we have to emulate recursive mutexes. 00069 struct Mutex_t 00070 { 00071 pthread_mutex_t mutex; 00072 pthread_cond_t unlocked; 00073 bool valid_id; 00074 unsigned count; 00075 pthread_t thread_id; 00076 }; 00077 #endif 00078 00079 // Platform specific conditional variable type 00080 typedef pthread_cond_t ConditionVar_t; 00081 struct NonRecursiveMutexLockState 00082 { 00083 pthread_t thread_id; 00084 NativeMutex_t* pmutex; 00085 }; 00086 00087 } // end namespace OW_NAMESPACE 00088 00089 #elif defined(OW_WIN32) 00090 00091 namespace OW_NAMESPACE 00092 { 00093 // Platform specific thread type 00094 typedef DWORD Thread_t; 00095 typedef HANDLE NativeMutex_t; 00096 typedef HANDLE NonRecursiveMutex_t; 00097 typedef LPCRITICAL_SECTION Mutex_t; 00098 00099 // Platform specific conditional variable type 00100 typedef struct 00101 { 00102 // Number of waiting threads 00103 int waitersCount; 00104 // Serialize access to waitersCount 00105 CRITICAL_SECTION waitersCountLock; 00106 // Semaphore used to queue up threads waiting for the condition to 00107 // become signaled 00108 HANDLE queue; 00109 // An auto-reset event used during broadcasting to wait for all the 00110 // threads to wake up and be released from the queue 00111 HANDLE waitersDone; 00112 // Keeps track of whether we are broadcasting or signaling. This allows 00113 // for optimization if just signaling. 00114 bool wasBroadcast; 00115 } ConditionInfo_t; 00116 00117 typedef ConditionInfo_t* ConditionVar_t; 00118 //typedef void* ConditionVar_t; 00119 struct NonRecursiveMutexLockState 00120 { 00121 DWORD thread_id; 00122 NativeMutex_t* pmutex; 00123 }; 00124 00125 } // end namespace OW_NAMESPACE 00126 00127 #endif 00128 00129 #endif // #ifndef OW_THREAD_TYPES_HPP_ 00130