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)
53 #define WorkLoadFactor (64UL << factor)
56 destination_type = (CacheType) GetImagePixelCacheType(destination),
57 source_type = (CacheType) GetImagePixelCacheType(source);
65 number_threads=(int) MagickMax(MagickMin(chunk/WorkLoadFactor,
66 GetMagickResourceLimit(ThreadResource)),1);
67 if (((source_type != MemoryCache) && (source_type != MapCache)) ||
68 ((destination_type != MemoryCache) && (destination_type != MapCache)))
69 number_threads=MagickMin(number_threads,2);
70 return(number_threads);
73 static inline MagickThreadType GetMagickThreadId(
void)
75 #if defined(MAGICKCORE_THREAD_SUPPORT)
76 return(pthread_self());
77 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
78 return(GetCurrentThreadId());
84 static inline size_t GetMagickThreadSignature(
void)
86 #if defined(MAGICKCORE_THREAD_SUPPORT)
97 magick_thread.signature=0UL;
98 magick_thread.id=pthread_self();
99 return(magick_thread.signature);
101 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
102 return((
size_t) GetCurrentThreadId());
104 return((
size_t) getpid());
108 static inline MagickBooleanType IsMagickThreadEqual(
const MagickThreadType
id)
110 #if defined(MAGICKCORE_THREAD_SUPPORT)
111 if (pthread_equal(
id,pthread_self()) != 0)
113 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
114 if (
id == GetCurrentThreadId())
126 static inline size_t GetOpenMPMaximumThreads(
void)
128 #if defined(MAGICKCORE_OPENMP_SUPPORT)
129 return((
size_t) omp_get_max_threads());
135 static inline int GetOpenMPThreadId(
void)
137 #if defined(MAGICKCORE_OPENMP_SUPPORT)
138 return(omp_get_thread_num());
144 #if defined(MAGICKCORE_OPENMP_SUPPORT)
145 static inline void SetOpenMPMaximumThreads(
const int threads)
147 omp_set_num_threads(threads);
149 static inline void SetOpenMPMaximumThreads(
const int magick_unused(threads))
151 magick_unreferenced(threads);
155 #if defined(MAGICKCORE_OPENMP_SUPPORT)
156 static inline void SetOpenMPNested(
const int value)
158 omp_set_nested(value);
160 static inline void SetOpenMPNested(
const int magick_unused(value))
162 magick_unreferenced(value);
166 #if defined(__cplusplus) || defined(c_plusplus)