2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 % TTTTT H H RRRR EEEEE AAA DDDD %
6 % T H H R R E A A D D %
7 % T HHHHH RRRR EEE AAAAA D D %
8 % T H H R R E A A D D %
9 % T H H R R EEEEE A A DDDD %
12 % MagickCore Thread Methods %
19 % Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization %
20 % dedicated to making software imaging solutions freely available. %
22 % You may not use this file except in compliance with the License. You may %
23 % obtain a copy of the License at %
25 % http://www.imagemagick.org/script/license.php %
27 % Unless required by applicable law or agreed to in writing, software %
28 % distributed under the License is distributed on an "AS IS" BASIS, %
29 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
30 % See the License for the specific language governing permissions and %
31 % limitations under the License. %
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 #include "MagickCore/studio.h"
42 #include "MagickCore/memory_.h"
43 #include "MagickCore/thread_.h"
44 #include "MagickCore/thread-private.h"
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 % M a g i c k C r e a t e T h r e a d K e y %
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 % MagickCreateThreadKey() creates a thread key and returns it.
59 % The format of the MagickCreateThreadKey method is:
61 % MagickThreadKey MagickCreateThreadKey(MagickThreadKey *key)
64 MagickExport MagickBooleanType MagickCreateThreadKey(MagickThreadKey *key)
66 #if defined(MAGICKCORE_THREAD_SUPPORT)
67 return(pthread_key_create(key,NULL) == 0 ? MagickTrue : MagickFalse);
68 #elif defined(MAGICKCORE_HAVE_WINTHREADS)
70 return(*key != TLS_OUT_OF_INDEXES ? MagickTrue : MagickFalse);
72 *key=AcquireMagickMemory(sizeof(key));
73 return(*key != (void *) NULL ? MagickTrue : MagickFalse);
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 % M a g i c k D e l e t e T h r e a d K e y %
86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 % MagickDeleteThreadKey() deletes a thread key.
90 % The format of the AcquireAESInfo method is:
92 % MagickBooleanType MagickDeleteThreadKey(MagickThreadKey key)
94 % A description of each parameter follows:
96 % o key: the thread key.
99 MagickExport MagickBooleanType MagickDeleteThreadKey(MagickThreadKey key)
101 #if defined(MAGICKCORE_THREAD_SUPPORT)
102 return(pthread_key_delete(key) == 0 ? MagickTrue : MagickFalse);
103 #elif defined(MAGICKCORE_HAVE_WINTHREADS)
104 return(TlsFree(key) != 0 ? MagickTrue : MagickFalse);
106 key=(MagickThreadKey) RelinquishMagickMemory(key);
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116 % M a g i c k G e t T h r e a d V a l u e %
120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122 % MagickGetThreadValue() returns a value associated with the thread key.
124 % The format of the MagickGetThreadValue method is:
126 % void *MagickGetThreadValue(MagickThreadKey key)
128 % A description of each parameter follows:
130 % o key: the thread key.
133 MagickExport void *MagickGetThreadValue(MagickThreadKey key)
135 #if defined(MAGICKCORE_THREAD_SUPPORT)
136 return(pthread_getspecific(key));
137 #elif defined(MAGICKCORE_HAVE_WINTHREADS)
138 return(TlsGetValue(key));
140 return((void *) (*key));
145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149 % M a g i c k S e t T h r e a d V a l u e %
153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155 % MagickSetThreadValue() associates a value with the thread key.
157 % The format of the MagickSetThreadValue method is:
159 % MagickBooleanType MagickSetThreadValue(MagickThreadKey key,
162 % A description of each parameter follows:
164 % o key: the thread key.
169 MagickExport MagickBooleanType MagickSetThreadValue(MagickThreadKey key,
172 #if defined(MAGICKCORE_THREAD_SUPPORT)
173 return(pthread_setspecific(key,value) == 0 ? MagickTrue : MagickFalse);
174 #elif defined(MAGICKCORE_HAVE_WINTHREADS)
175 return(TlsSetValue(key,(void *) value) != 0 ? MagickTrue : MagickFalse);