2 Copyright 1999-2014 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 #include "MagickCore/cache.h"
22 #include "MagickCore/resource_.h"
23 #include "MagickCore/thread_.h"
25 #if defined(__cplusplus) || defined(c_plusplus)
30 Single threaded unless workload justifies the threading overhead.
32 #define magick_threads(source,destination,chunk,expression) \
33 num_threads((expression) == 0 ? 1 : \
34 ((chunk) > (32*GetMagickResourceLimit(ThreadResource))) && \
35 ((GetImagePixelCacheType(source) == MemoryCache) || \
36 (GetImagePixelCacheType(source) == MapCache)) && \
37 ((GetImagePixelCacheType(destination) == MemoryCache) || \
38 (GetImagePixelCacheType(destination) == MapCache)) ? \
39 GetMagickResourceLimit(ThreadResource) : \
40 GetMagickResourceLimit(ThreadResource) < 2 ? 1 : 2)
42 #if defined(__clang__) || (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ > 10))
43 #define MagickCachePrefetch(address,mode,locality) \
44 __builtin_prefetch(address,mode,locality)
46 #define MagickCachePrefetch(address,mode,locality)
49 #if defined(MAGICKCORE_THREAD_SUPPORT)
50 typedef pthread_mutex_t MagickMutexType;
51 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
52 typedef CRITICAL_SECTION MagickMutexType;
54 typedef size_t MagickMutexType;
57 static inline MagickThreadType GetMagickThreadId(void)
59 #if defined(MAGICKCORE_THREAD_SUPPORT)
60 return(pthread_self());
61 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
62 return(GetCurrentThreadId());
68 static inline size_t GetMagickThreadSignature(void)
70 #if defined(MAGICKCORE_THREAD_SUPPORT)
81 magick_thread.signature=0UL;
82 magick_thread.id=pthread_self();
83 return(magick_thread.signature);
85 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
86 return((size_t) GetCurrentThreadId());
88 return((size_t) getpid());
92 static inline MagickBooleanType IsMagickThreadEqual(const MagickThreadType id)
94 #if defined(MAGICKCORE_THREAD_SUPPORT)
95 if (pthread_equal(id,pthread_self()) != 0)
97 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
98 if (id == GetCurrentThreadId())
108 Lightweight OpenMP methods.
110 static inline size_t GetOpenMPMaximumThreads(void)
112 #if defined(MAGICKCORE_OPENMP_SUPPORT)
113 return(omp_get_max_threads());
119 static inline int GetOpenMPThreadId(void)
121 #if defined(MAGICKCORE_OPENMP_SUPPORT)
122 return(omp_get_thread_num());
128 static inline void SetOpenMPMaximumThreads(const int threads)
130 #if defined(MAGICKCORE_OPENMP_SUPPORT)
131 omp_set_num_threads(threads);
137 static inline void SetOpenMPNested(const int value)
139 #if defined(MAGICKCORE_OPENMP_SUPPORT)
140 omp_set_nested(value);
146 #if defined(__cplusplus) || defined(c_plusplus)