2 Copyright 1999-2010 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 #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 #if defined(MAGICKCORE_HAVE_PTHREAD)
35 typedef pthread_mutex_t MagickMutexType;
36 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
37 typedef CRITICAL_SECTION MagickMutexType;
39 typedef unsigned long MagickMutexType;
42 static inline MagickThreadType GetMagickThreadId(void)
44 #if defined(MAGICKCORE_HAVE_PTHREAD)
45 return(pthread_self());
46 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
47 return(GetCurrentThreadId());
53 static inline unsigned long GetMagickThreadSignature(void)
55 #if defined(MAGICKCORE_HAVE_PTHREAD)
66 magick_thread.signature=0UL;
67 magick_thread.id=pthread_self();
68 return(magick_thread.signature);
70 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
71 return((unsigned long) GetCurrentThreadId());
73 return((unsigned long) getpid());
77 static inline MagickBooleanType IsMagickThreadEqual(const MagickThreadType id)
79 #if defined(MAGICKCORE_HAVE_PTHREAD)
80 if (pthread_equal(id,pthread_self()) != 0)
82 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
83 if (id == GetCurrentThreadId())
93 Lightweight OpenMP methods.
95 static inline unsigned long GetOpenMPMaximumThreads(void)
97 #if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP >= 200203)
100 maximum_threads = 1UL;
102 if (omp_get_max_threads() > (long) maximum_threads)
103 maximum_threads=omp_get_max_threads();
104 return(maximum_threads);
111 static inline long GetOpenMPThreadId(void)
113 #if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP >= 200203)
114 return(omp_get_thread_num());
120 static inline void SetOpenMPMaximumThreads(const unsigned long threads)
122 #if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP >= 200203)
123 omp_set_num_threads(threads);
129 static inline void SetOpenMPNested(const int value)
131 #if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP >= 200203)
132 omp_set_nested(value);
138 #if defined(__cplusplus) || defined(c_plusplus)