blob: 0faf96dad2b6577916c5c7ce8211e3ed30c7ceeb [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
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 %
10% %
11% %
12% MagickCore Thread Methods %
13% %
14% Software Design %
cristyde984cd2013-12-01 14:49:27 +000015% Cristy %
cristy3ed852e2009-09-05 21:47:34 +000016% March 2003 %
17% %
18% %
cristyfe676ee2013-11-18 13:03:38 +000019% Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000020% dedicated to making software imaging solutions freely available. %
21% %
22% You may not use this file except in compliance with the License. You may %
23% obtain a copy of the License at %
24% %
25% http://www.imagemagick.org/script/license.php %
26% %
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. %
32% %
33%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34%
35%
36*/
37
38/*
39 Include declarations.
40*/
cristy4c08aed2011-07-01 19:47:50 +000041#include "MagickCore/studio.h"
42#include "MagickCore/memory_.h"
43#include "MagickCore/thread_.h"
44#include "MagickCore/thread-private.h"
cristy3ed852e2009-09-05 21:47:34 +000045
46/*
47%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48% %
49% %
50% %
51% M a g i c k C r e a t e T h r e a d K e y %
52% %
53% %
54% %
55%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56%
57% MagickCreateThreadKey() creates a thread key and returns it.
58%
59% The format of the MagickCreateThreadKey method is:
60%
61% MagickThreadKey MagickCreateThreadKey(MagickThreadKey *key)
62%
63*/
64MagickExport MagickBooleanType MagickCreateThreadKey(MagickThreadKey *key)
65{
cristy55bf91c2010-09-24 00:29:41 +000066#if defined(MAGICKCORE_THREAD_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +000067 return(pthread_key_create(key,NULL) == 0 ? MagickTrue : MagickFalse);
cristyfe092d82009-10-11 04:00:45 +000068#elif defined(MAGICKCORE_HAVE_WINTHREADS)
cristy3ed852e2009-09-05 21:47:34 +000069 *key=TlsAlloc();
70 return(*key != TLS_OUT_OF_INDEXES ? MagickTrue : MagickFalse);
71#else
cristy73bd4a52010-10-05 11:24:23 +000072 *key=AcquireMagickMemory(sizeof(key));
cristy3ed852e2009-09-05 21:47:34 +000073 return(*key != (void *) NULL ? MagickTrue : MagickFalse);
74#endif
75}
76
77/*
78%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79% %
80% %
81% %
82% M a g i c k D e l e t e T h r e a d K e y %
83% %
84% %
85% %
86%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87%
88% MagickDeleteThreadKey() deletes a thread key.
89%
90% The format of the AcquireAESInfo method is:
91%
92% MagickBooleanType MagickDeleteThreadKey(MagickThreadKey key)
93%
94% A description of each parameter follows:
95%
96% o key: the thread key.
97%
98*/
99MagickExport MagickBooleanType MagickDeleteThreadKey(MagickThreadKey key)
100{
cristy55bf91c2010-09-24 00:29:41 +0000101#if defined(MAGICKCORE_THREAD_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +0000102 return(pthread_key_delete(key) == 0 ? MagickTrue : MagickFalse);
cristyfe092d82009-10-11 04:00:45 +0000103#elif defined(MAGICKCORE_HAVE_WINTHREADS)
cristy3ed852e2009-09-05 21:47:34 +0000104 return(TlsFree(key) != 0 ? MagickTrue : MagickFalse);
105#else
106 key=(MagickThreadKey) RelinquishMagickMemory(key);
107 return(MagickTrue);
108#endif
cristy3ed852e2009-09-05 21:47:34 +0000109}
110
111/*
112%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113% %
114% %
115% %
116% M a g i c k G e t T h r e a d V a l u e %
117% %
118% %
119% %
120%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121%
122% MagickGetThreadValue() returns a value associated with the thread key.
123%
124% The format of the MagickGetThreadValue method is:
125%
126% void *MagickGetThreadValue(MagickThreadKey key)
127%
128% A description of each parameter follows:
129%
130% o key: the thread key.
131%
132*/
133MagickExport void *MagickGetThreadValue(MagickThreadKey key)
134{
cristy55bf91c2010-09-24 00:29:41 +0000135#if defined(MAGICKCORE_THREAD_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +0000136 return(pthread_getspecific(key));
cristyfe092d82009-10-11 04:00:45 +0000137#elif defined(MAGICKCORE_HAVE_WINTHREADS)
cristy3ed852e2009-09-05 21:47:34 +0000138 return(TlsGetValue(key));
139#else
140 return((void *) (*key));
141#endif
142}
143
144/*
145%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146% %
147% %
148% %
149% M a g i c k S e t T h r e a d V a l u e %
150% %
151% %
152% %
153%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154%
155% MagickSetThreadValue() associates a value with the thread key.
156%
157% The format of the MagickSetThreadValue method is:
158%
159% MagickBooleanType MagickSetThreadValue(MagickThreadKey key,
160% const void *value)
161%
162% A description of each parameter follows:
163%
164% o key: the thread key.
165%
166% o value: the value
167%
168*/
169MagickExport MagickBooleanType MagickSetThreadValue(MagickThreadKey key,
170 const void *value)
171{
cristy55bf91c2010-09-24 00:29:41 +0000172#if defined(MAGICKCORE_THREAD_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +0000173 return(pthread_setspecific(key,value) == 0 ? MagickTrue : MagickFalse);
cristyfe092d82009-10-11 04:00:45 +0000174#elif defined(MAGICKCORE_HAVE_WINTHREADS)
cristy3ed852e2009-09-05 21:47:34 +0000175 return(TlsSetValue(key,(void *) value) != 0 ? MagickTrue : MagickFalse);
176#else
cristybb503372010-05-27 20:51:26 +0000177 *key=(size_t) value;
cristy3ed852e2009-09-05 21:47:34 +0000178 return(MagickTrue);
179#endif
180}