2 Copyright 1999-2011 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 <magick/thread_.h>
27 #define omp_throttle(factor) num_threads(omp_get_max_threads() >> (factor))
29 #if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR > 10))
30 #define MagickCachePrefetch(address,mode,locality) \
31 __builtin_prefetch(address,mode,locality)
33 #define MagickCachePrefetch(address,mode,locality)
36 #if defined(MAGICKCORE_THREAD_SUPPORT)
37 typedef pthread_mutex_t MagickMutexType;
38 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
39 typedef CRITICAL_SECTION MagickMutexType;
41 typedef size_t MagickMutexType;
44 static inline MagickThreadType GetMagickThreadId(void)
46 #if defined(MAGICKCORE_THREAD_SUPPORT)
47 return(pthread_self());
48 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
49 return(GetCurrentThreadId());
55 static inline size_t GetMagickThreadSignature(void)
57 #if defined(MAGICKCORE_THREAD_SUPPORT)
68 magick_thread.signature=0UL;
69 magick_thread.id=pthread_self();
70 return(magick_thread.signature);
72 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
73 return((size_t) GetCurrentThreadId());
75 return((size_t) getpid());
79 static inline MagickBooleanType IsMagickThreadEqual(const MagickThreadType id)
81 #if defined(MAGICKCORE_THREAD_SUPPORT)
82 if (pthread_equal(id,pthread_self()) != 0)
84 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
85 if (id == GetCurrentThreadId())
95 Lightweight OpenMP methods.
97 static inline size_t GetOpenMPMaximumThreads(void)
102 #if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP >= 200203)
107 threads=omp_get_max_threads();
108 if (threads > (ssize_t) maximum_threads)
109 maximum_threads=threads;
112 return(maximum_threads);
115 static inline int GetOpenMPThreadId(void)
117 #if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP >= 200203)
118 return(omp_get_thread_num());
124 static inline void SetOpenMPMaximumThreads(const int threads)
126 #if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP >= 200203)
127 omp_set_num_threads(threads);
133 static inline void SetOpenMPNested(const int value)
135 #if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP >= 200203)
136 omp_set_nested(value);
142 #if defined(__cplusplus) || defined(c_plusplus)