41#include "MagickCore/studio.h"
42#include "MagickCore/memory_.h"
43#include "MagickCore/thread_.h"
44#include "MagickCore/thread-private.h"
56 (*destructor)(
void *);
84MagickExport MagickBooleanType CreateMagickThreadKey(MagickThreadKey *key,
85 void (*destructor)(
void *))
87#if defined(MAGICKCORE_THREAD_SUPPORT)
88 return(pthread_key_create(key,destructor) == 0 ? MagickTrue : MagickFalse);
89#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
90 magick_unreferenced(destructor);
92 return(*key != TLS_OUT_OF_INDEXES ? MagickTrue : MagickFalse);
102 (*keys)->number_threads=GetOpenMPMaximumThreads();
103 (*keys)->values=(
void **) AcquireQuantumMemory((*keys)->number_threads,
105 if ((*keys)->values == (
void **) NULL)
108 (
void) memset((*keys)->values,0,(*keys)->number_threads*
110 (*keys)->destructor=destructor;
139MagickExport MagickBooleanType DeleteMagickThreadKey(MagickThreadKey key)
141#if defined(MAGICKCORE_THREAD_SUPPORT)
142 return(pthread_key_delete(key) == 0 ? MagickTrue : MagickFalse);
143#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
144 return(TlsFree(key) != 0 ? MagickTrue : MagickFalse);
154 for (i=0; i < (ssize_t) keys->number_threads; i++)
155 if ((keys->destructor != (
void *) NULL) &&
156 (keys->values[i] != (
void *) NULL))
158 keys->destructor(keys->values[i]);
159 keys->values[i]=(
void *) NULL;
190MagickExport
void *GetMagickThreadValue(MagickThreadKey key)
192#if defined(MAGICKCORE_THREAD_SUPPORT)
193 return(pthread_getspecific(key));
194#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
195 return(TlsGetValue(key));
202 return(keys->values[GetOpenMPThreadId()]);
233MagickExport MagickBooleanType SetMagickThreadValue(MagickThreadKey key,
236#if defined(MAGICKCORE_THREAD_SUPPORT)
237 return(pthread_setspecific(key,value) == 0 ? MagickTrue : MagickFalse);
238#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
239 return(TlsSetValue(key,(
void *) value) != 0 ? MagickTrue : MagickFalse);
246 keys->values[GetOpenMPThreadId()]=(
void *) value;