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) \
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;
50static inline int GetMagickNumberThreads(
const Image *source,
51 const Image *destination,
const size_t chunk,
int multithreaded)
54 destination_type = (CacheType) GetImagePixelCacheType(destination),
55 source_type = (CacheType) GetImagePixelCacheType(source);
63 if (multithreaded == 0)
65 if (((source_type != MemoryCache) && (source_type != MapCache)) ||
66 ((destination_type != MemoryCache) && (destination_type != MapCache)))
67 number_threads=(int) MagickMin(GetMagickResourceLimit(ThreadResource),2);
69 number_threads=(int) MagickMin((ssize_t)
70 GetMagickResourceLimit(ThreadResource),(ssize_t) (chunk)/64);
71 return(MagickMax(number_threads,1));
74static inline MagickThreadType GetMagickThreadId(
void)
76#if defined(MAGICKCORE_THREAD_SUPPORT)
77 return(pthread_self());
78#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
79 return(GetCurrentThreadId());
85static inline size_t GetMagickThreadSignature(
void)
87#if defined(MAGICKCORE_THREAD_SUPPORT)
98 magick_thread.signature=0UL;
99 magick_thread.id=pthread_self();
100 return(magick_thread.signature);
102#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
103 return((
size_t) GetCurrentThreadId());
105 return((
size_t) getpid());
109static inline MagickBooleanType IsMagickThreadEqual(
const MagickThreadType
id)
111#if defined(MAGICKCORE_THREAD_SUPPORT)
112 if (pthread_equal(
id,pthread_self()) != 0)
114#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
115 if (
id == GetCurrentThreadId())
127static inline size_t GetOpenMPMaximumThreads(
void)
129#if defined(MAGICKCORE_OPENMP_SUPPORT)
130 return((
size_t) omp_get_max_threads());
136static inline int GetOpenMPThreadId(
void)
138#if defined(MAGICKCORE_OPENMP_SUPPORT)
139 return(omp_get_thread_num());
145#if defined(MAGICKCORE_OPENMP_SUPPORT)
146static inline void SetOpenMPMaximumThreads(
const int threads)
148 omp_set_num_threads(threads);
150static inline void SetOpenMPMaximumThreads(
const int magick_unused(threads))
152 magick_unreferenced(threads);
156#if defined(MAGICKCORE_OPENMP_SUPPORT)
157static inline void SetOpenMPNested(
const int value)
159 omp_set_nested(value);
161static inline void SetOpenMPNested(
const int magick_unused(value))
163 magick_unreferenced(value);
167#if defined(__cplusplus) || defined(c_plusplus)