|
WizardsToolkit
1.0.7
|
00001 /* 00002 Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization 00003 dedicated to making software imaging solutions freely available. 00004 00005 You may not use this file except in compliance with the License. 00006 obtain a copy of the License at 00007 00008 http://www.wizards-toolkit.org/script/license.php 00009 00010 Unless required by applicable law or agreed to in writing, software 00011 distributed under the License is distributed on an "AS IS" BASIS, 00012 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 See the License for the specific language governing permissions and 00014 limitations under the License. 00015 00016 WizardCore private methods for internal threading. 00017 */ 00018 #ifndef _WIZARDSTOOLKIT_THREAD_PRIVATE_H 00019 #define _WIZARDSTOOLKIT_THREAD_PRIVATE_H 00020 00021 #if defined(__cplusplus) || defined(c_plusplus) 00022 extern "C" { 00023 #endif 00024 00025 #include <wizard/thread_.h> 00026 00027 #if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR > 10)) 00028 #define WizardCachePrefetch(address,mode,locality) \ 00029 __builtin_prefetch(address,mode,locality) 00030 #else 00031 #define WizardCachePrefetch(address,mode,locality) 00032 #endif 00033 00034 #if defined(WIZARDSTOOLKIT_THREAD_SUPPORT) 00035 typedef pthread_mutex_t WizardMutexType; 00036 #elif defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) 00037 typedef CRITICAL_SECTION WizardMutexType; 00038 #else 00039 typedef size_t WizardMutexType; 00040 #endif 00041 00042 static inline WizardThreadType GetWizardThreadId(void) 00043 { 00044 #if defined(WIZARDSTOOLKIT_THREAD_SUPPORT) 00045 return(pthread_self()); 00046 #elif defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) 00047 return(GetCurrentThreadId()); 00048 #else 00049 return(getpid()); 00050 #endif 00051 } 00052 00053 static inline size_t GetWizardThreadSignature(void) 00054 { 00055 #if defined(WIZARDSTOOLKIT_THREAD_SUPPORT) 00056 { 00057 union 00058 { 00059 pthread_t 00060 id; 00061 00062 size_t 00063 signature; 00064 } wizard_thread; 00065 00066 wizard_thread.signature=0UL; 00067 wizard_thread.id=pthread_self(); 00068 return(wizard_thread.signature); 00069 } 00070 #elif defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) 00071 return((size_t) GetCurrentThreadId()); 00072 #else 00073 return((size_t) getpid()); 00074 #endif 00075 } 00076 00077 static inline WizardBooleanType IsWizardThreadEqual(const WizardThreadType id) 00078 { 00079 #if defined(WIZARDSTOOLKIT_THREAD_SUPPORT) 00080 if (pthread_equal(id,pthread_self()) != 0) 00081 return(WizardTrue); 00082 #elif defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) 00083 if (id == GetCurrentThreadId()) 00084 return(WizardTrue); 00085 #else 00086 if (id == getpid()) 00087 return(WizardTrue); 00088 #endif 00089 return(WizardFalse); 00090 } 00091 00092 /* 00093 Lightweight OpenMP methods. 00094 */ 00095 static inline size_t GetOpenMPMaximumThreads(void) 00096 { 00097 static size_t 00098 maximum_threads = 1; 00099 00100 #if defined(WIZARDSTOOLKIT_OPENMP_SUPPORT) 00101 if (omp_get_max_threads() > (ssize_t) maximum_threads) 00102 maximum_threads=omp_get_max_threads(); 00103 #endif 00104 return(maximum_threads); 00105 } 00106 00107 static inline ssize_t GetOpenMPThreadId(void) 00108 { 00109 #if defined(WIZARDSTOOLKIT_OPENMP_SUPPORT) 00110 return(omp_get_thread_num()); 00111 #else 00112 return(0); 00113 #endif 00114 } 00115 00116 static inline void SetOpenMPMaximumThreads(const size_t threads) 00117 { 00118 #if defined(WIZARDSTOOLKIT_OPENMP_SUPPORT) 00119 omp_set_num_threads(threads); 00120 #else 00121 (void) threads; 00122 #endif 00123 } 00124 00125 static inline void SetOpenMPNested(const int value) 00126 { 00127 #if defined(WIZARDSTOOLKIT_OPENMP_SUPPORT) && (_OPENMP >= 200203) 00128 omp_set_nested(value); 00129 #else 00130 (void) value; 00131 #endif 00132 } 00133 00134 #if defined(__cplusplus) || defined(c_plusplus) 00135 } 00136 #endif 00137 00138 #endif