2 Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization
3 dedicated to making software imaging solutions freely available.
5 You may not use this file except in compliance with the License.
6 obtain a copy of the License at
8 http://www.imagemagick.org/script/license.php
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
16 MagickCore private methods for internal threading.
18 #ifndef _MAGICKCORE_THREAD_PRIVATE_H
19 #define _MAGICKCORE_THREAD_PRIVATE_H
21 #if defined(__cplusplus) || defined(c_plusplus)
25 #include <MagickCore/thread_.h>
27 #if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR > 10))
28 #define MagickCachePrefetch(address,mode,locality) \
29 __builtin_prefetch(address,mode,locality)
31 #define MagickCachePrefetch(address,mode,locality)
34 #define omp_throttle(factor) num_threads(omp_get_max_threads() >> \
35 (factor) == 0 ? 1 : omp_get_max_threads() >> (factor))
37 #if defined(MAGICKCORE_THREAD_SUPPORT)
38 typedef pthread_mutex_t MagickMutexType;
39 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
40 typedef CRITICAL_SECTION MagickMutexType;
42 typedef size_t MagickMutexType;
45 static inline MagickThreadType GetMagickThreadId(void)
47 #if defined(MAGICKCORE_THREAD_SUPPORT)
48 return(pthread_self());
49 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
50 return(GetCurrentThreadId());
56 static inline size_t GetMagickThreadSignature(void)
58 #if defined(MAGICKCORE_THREAD_SUPPORT)
69 magick_thread.signature=0UL;
70 magick_thread.id=pthread_self();
71 return(magick_thread.signature);
73 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
74 return((size_t) GetCurrentThreadId());
76 return((size_t) getpid());
80 static inline MagickBooleanType IsMagickThreadEqual(const MagickThreadType id)
82 #if defined(MAGICKCORE_THREAD_SUPPORT)
83 if (pthread_equal(id,pthread_self()) != 0)
85 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
86 if (id == GetCurrentThreadId())
96 Lightweight OpenMP methods.
98 static inline size_t GetOpenMPMaximumThreads(void)
103 #if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP >= 200203)
108 threads=omp_get_max_threads();
109 if (threads > (ssize_t) maximum_threads)
110 maximum_threads=threads;
113 return(maximum_threads);
116 static inline int GetOpenMPThreadId(void)
118 #if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP >= 200203)
119 return(omp_get_thread_num());
125 static inline void SetOpenMPMaximumThreads(const int threads)
127 #if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP >= 200203)
128 omp_set_num_threads(threads);
134 static inline void SetOpenMPNested(const int value)
136 #if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP >= 200203)
137 omp_set_nested(value);
143 #if defined(__cplusplus) || defined(c_plusplus)