This source file includes following definitions.
- MagickCreateThreadKey
- MagickDeleteThreadKey
- MagickGetThreadValue
- MagickSetThreadValue
- CreateMagickThreadKey
- DeleteMagickThreadKey
- GetMagickThreadValue
- SetMagickThreadValue
#include "magick/studio.h"
#include "magick/memory_.h"
#include "magick/thread_.h"
#include "magick/thread-private.h"
typedef struct _MagickThreadValue
{
size_t
number_threads;
void
**values,
(*destructor)(void *);
} MagickThreadValue;
MagickExport MagickBooleanType MagickCreateThreadKey(MagickThreadKey *key)
{
#if defined(MAGICKCORE_THREAD_SUPPORT)
return(pthread_key_create(key,NULL) == 0 ? MagickTrue : MagickFalse);
#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
*key=TlsAlloc();
return(*key != TLS_OUT_OF_INDEXES ? MagickTrue : MagickFalse);
#else
*key=AcquireMagickMemory(sizeof(key));
return(*key != (void *) NULL ? MagickTrue : MagickFalse);
#endif
}
MagickExport MagickBooleanType MagickDeleteThreadKey(MagickThreadKey key)
{
#if defined(MAGICKCORE_THREAD_SUPPORT)
return(pthread_key_delete(key) == 0 ? MagickTrue : MagickFalse);
#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
return(TlsFree(key) != 0 ? MagickTrue : MagickFalse);
#else
key=(MagickThreadKey) RelinquishMagickMemory(key);
return(MagickTrue);
#endif
}
MagickExport void *MagickGetThreadValue(MagickThreadKey key)
{
#if defined(MAGICKCORE_THREAD_SUPPORT)
return(pthread_getspecific(key));
#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
return(TlsGetValue(key));
#else
return((void *) key);
#endif
}
MagickExport MagickBooleanType MagickSetThreadValue(MagickThreadKey key,
const void *value)
{
#if defined(MAGICKCORE_THREAD_SUPPORT)
return(pthread_setspecific(key,value) == 0 ? MagickTrue : MagickFalse);
#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
return(TlsSetValue(key,(void *) value) != 0 ? MagickTrue : MagickFalse);
#else
key=(void *) value;
return(MagickTrue);
#endif
}
MagickExport MagickBooleanType CreateMagickThreadKey(MagickThreadKey *key,
void (*destructor)(void *))
{
#if defined(MAGICKCORE_THREAD_SUPPORT)
return(pthread_key_create(key,destructor) == 0 ? MagickTrue : MagickFalse);
#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
*key=TlsAlloc();
return(*key != TLS_OUT_OF_INDEXES ? MagickTrue : MagickFalse);
#else
{
MagickThreadValue
**keys;
keys=(MagickThreadValue **) key;
*keys=(MagickThreadValue *) AcquireQuantumMemory(1,sizeof(*keys));
if (*keys != (MagickThreadValue *) NULL)
{
(*keys)->number_threads=GetOpenMPMaximumThreads();
(*keys)->values=AcquireQuantumMemory((*keys)->number_threads,
sizeof(void *));
if ((*keys)->values == (void *) NULL)
*keys=RelinquishMagickMemory(*keys);
else
(void) memset((*keys)->values,0,(*keys)->number_threads*
sizeof(void *));
(*keys)->destructor=destructor;
}
return((*keys != (MagickThreadValue *) NULL) ? MagickTrue : MagickFalse);
}
#endif
}
MagickExport MagickBooleanType DeleteMagickThreadKey(MagickThreadKey key)
{
#if defined(MAGICKCORE_THREAD_SUPPORT)
return(pthread_key_delete(key) == 0 ? MagickTrue : MagickFalse);
#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
return(TlsFree(key) != 0 ? MagickTrue : MagickFalse);
#else
{
MagickThreadValue
*keys;
register ssize_t
i;
keys=(MagickThreadValue *) key;
for (i=0; i < (ssize_t) keys->number_threads; i++)
if ((keys->destructor != (void *) NULL) &&
(keys->values[i] != (void *) NULL))
{
keys->destructor(keys->values[i]);
keys->values[i]=(void *) NULL;
}
keys=(MagickThreadValue *) RelinquishMagickMemory(keys);
}
return(MagickTrue);
#endif
}
MagickExport void *GetMagickThreadValue(MagickThreadKey key)
{
#if defined(MAGICKCORE_THREAD_SUPPORT)
return(pthread_getspecific(key));
#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
return(TlsGetValue(key));
#else
{
MagickThreadValue
*keys;
keys=(MagickThreadValue *) key;
return(keys->values[GetOpenMPThreadId()]);
}
#endif
}
MagickExport MagickBooleanType SetMagickThreadValue(MagickThreadKey key,
const void *value)
{
#if defined(MAGICKCORE_THREAD_SUPPORT)
return(pthread_setspecific(key,value) == 0 ? MagickTrue : MagickFalse);
#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
return(TlsSetValue(key,(void *) value) != 0 ? MagickTrue : MagickFalse);
#else
{
MagickThreadValue
*keys;
keys=(MagickThreadValue *) key;
keys->values[GetOpenMPThreadId()]=(void *) value;
}
return(MagickTrue);
#endif
}