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,multithreaded) \
31 num_threads(GetMagickNumberThreads(source,destination,chunk,multithreaded))
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)
39 #if defined(MAGICKCORE_THREAD_SUPPORT)
40 typedef pthread_mutex_t MagickMutexType;
41 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
42 typedef CRITICAL_SECTION MagickMutexType;
44 typedef size_t MagickMutexType;
47 static inline MagickThreadType GetMagickThreadId(
void)
49 #if defined(MAGICKCORE_THREAD_SUPPORT)
50 return(pthread_self());
51 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
52 return(GetCurrentThreadId());
58 static inline int GetMagickNumberThreads(
const Image *source,
59 const Image *destination,
const size_t chunk,
int multithreaded)
62 destination_type = (CacheType) GetImagePixelCacheType(destination),
63 source_type = (CacheType) GetImagePixelCacheType(source);
71 if (multithreaded == 0)
73 if (((source_type != MemoryCache) && (source_type != MapCache)) ||
74 ((destination_type != MemoryCache) && (destination_type != MapCache)))
75 number_threads=(int) MagickMin(GetMagickResourceLimit(ThreadResource),2);
77 number_threads=(int) MagickMin((ssize_t)
78 GetMagickResourceLimit(ThreadResource),(ssize_t) (chunk)/64);
79 return(MagickMax(number_threads,1));
82 static inline size_t GetMagickThreadSignature(
void)
84 #if defined(MAGICKCORE_THREAD_SUPPORT)
95 magick_thread.signature=0UL;
96 magick_thread.id=pthread_self();
97 return(magick_thread.signature);
99 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
100 return((
size_t) GetCurrentThreadId());
102 return((
size_t) getpid());
106 static inline MagickBooleanType IsMagickThreadEqual(
const MagickThreadType
id)
108 #if defined(MAGICKCORE_THREAD_SUPPORT)
109 if (pthread_equal(
id,pthread_self()) != 0)
111 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
112 if (
id == GetCurrentThreadId())
124 static inline size_t GetOpenMPMaximumThreads(
void)
126 #if defined(MAGICKCORE_OPENMP_SUPPORT)
127 return(omp_get_max_threads());
133 static inline int GetOpenMPThreadId(
void)
135 #if defined(MAGICKCORE_OPENMP_SUPPORT)
136 return(omp_get_thread_num());
142 static inline void SetOpenMPMaximumThreads(
const int threads)
144 #if defined(MAGICKCORE_OPENMP_SUPPORT)
145 omp_set_num_threads(threads);
151 static inline void SetOpenMPNested(
const int value)
153 #if defined(MAGICKCORE_OPENMP_SUPPORT)
154 omp_set_nested(value);
160 #if defined(__cplusplus) || defined(c_plusplus)