18 #ifndef MAGICKCORE_THREAD_PRIVATE_H
19 #define MAGICKCORE_THREAD_PRIVATE_H
21 #include "magick/cache.h"
22 #include "magick/image-private.h"
23 #include "magick/resource_.h"
24 #include "magick/thread_.h"
26 #if defined(__cplusplus) || defined(c_plusplus)
30 #define magick_number_threads(source,destination,chunk,factor) \
31 num_threads(GetMagickNumberThreads(source,destination,chunk,factor))
32 #if defined(__clang__) || (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ > 10))
33 #define MagickCachePrefetch(address,mode,locality) \
34 __builtin_prefetch(address,mode,locality)
36 #define MagickCachePrefetch(address,mode,locality) \
37 magick_unreferenced(address); \
38 magick_unreferenced(mode); \
39 magick_unreferenced(locality);
42 #if defined(MAGICKCORE_THREAD_SUPPORT)
43 typedef pthread_mutex_t MagickMutexType;
44 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
45 typedef CRITICAL_SECTION MagickMutexType;
47 typedef size_t MagickMutexType;
50 static inline int GetMagickNumberThreads(
const Image *source,
51 const Image *destination,
const size_t chunk,
const int factor)
54 destination_type = (CacheType) GetImagePixelCacheType(destination),
55 source_type = (CacheType) GetImagePixelCacheType(source);
58 max_threads = (size_t) GetMagickResourceLimit(ThreadResource),
60 workload_factor = 64UL << factor;
65 number_threads=(chunk <= workload_factor) ? 1 :
66 (chunk >= (workload_factor << 6)) ? max_threads :
67 1+(chunk-workload_factor)*(max_threads-1)/(((workload_factor << 6))-1);
71 if (((source_type != MemoryCache) && (source_type != MapCache)) ||
72 ((destination_type != MemoryCache) && (destination_type != MapCache)))
73 number_threads=MagickMin(number_threads,4);
74 return((
int) number_threads);
77 static inline MagickThreadType GetMagickThreadId(
void)
79 #if defined(MAGICKCORE_THREAD_SUPPORT)
80 return(pthread_self());
81 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
82 return(GetCurrentThreadId());
88 static inline size_t GetMagickThreadSignature(
void)
90 #if defined(MAGICKCORE_THREAD_SUPPORT)
101 magick_thread.signature=0UL;
102 magick_thread.id=pthread_self();
103 return(magick_thread.signature);
105 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
106 return((
size_t) GetCurrentThreadId());
108 return((
size_t) getpid());
112 static inline MagickBooleanType IsMagickThreadEqual(
const MagickThreadType
id)
114 #if defined(MAGICKCORE_THREAD_SUPPORT)
115 if (pthread_equal(
id,pthread_self()) != 0)
117 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
118 if (
id == GetCurrentThreadId())
130 static inline size_t GetOpenMPMaximumThreads(
void)
132 #if defined(MAGICKCORE_OPENMP_SUPPORT)
133 return((
size_t) omp_get_max_threads());
139 static inline int GetOpenMPThreadId(
void)
141 #if defined(MAGICKCORE_OPENMP_SUPPORT)
142 return(omp_get_thread_num());
148 #if defined(MAGICKCORE_OPENMP_SUPPORT)
149 static inline void SetOpenMPMaximumThreads(
const int threads)
151 omp_set_num_threads(threads);
153 static inline void SetOpenMPMaximumThreads(
const int magick_unused(threads))
155 magick_unreferenced(threads);
159 #if defined(MAGICKCORE_OPENMP_SUPPORT)
160 static inline void SetOpenMPNested(
const int value)
162 omp_set_nested(value);
164 static inline void SetOpenMPNested(
const int magick_unused(value))
166 magick_unreferenced(value);
170 #if defined(__cplusplus) || defined(c_plusplus)