|
MagickCore
6.7.5
|
00001 /* 00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00003 % % 00004 % % 00005 % TTTTT H H RRRR EEEEE AAA DDDD % 00006 % T H H R R E A A D D % 00007 % T HHHHH RRRR EEE AAAAA D D % 00008 % T H H R R E A A D D % 00009 % T H H R R EEEEE A A DDDD % 00010 % % 00011 % % 00012 % MagickCore Thread Methods % 00013 % % 00014 % Software Design % 00015 % John Cristy % 00016 % March 2003 % 00017 % % 00018 % % 00019 % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization % 00020 % dedicated to making software imaging solutions freely available. % 00021 % % 00022 % You may not use this file except in compliance with the License. You may % 00023 % obtain a copy of the License at % 00024 % % 00025 % http://www.imagemagick.org/script/license.php % 00026 % % 00027 % Unless required by applicable law or agreed to in writing, software % 00028 % distributed under the License is distributed on an "AS IS" BASIS, % 00029 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % 00030 % See the License for the specific language governing permissions and % 00031 % limitations under the License. % 00032 % % 00033 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00034 % 00035 % 00036 */ 00037 00038 /* 00039 Include declarations. 00040 */ 00041 #include "MagickCore/studio.h" 00042 #include "MagickCore/memory_.h" 00043 #include "MagickCore/thread_.h" 00044 #include "MagickCore/thread-private.h" 00045 00046 /* 00047 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00048 % % 00049 % % 00050 % % 00051 % M a g i c k C r e a t e T h r e a d K e y % 00052 % % 00053 % % 00054 % % 00055 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00056 % 00057 % MagickCreateThreadKey() creates a thread key and returns it. 00058 % 00059 % The format of the MagickCreateThreadKey method is: 00060 % 00061 % MagickThreadKey MagickCreateThreadKey(MagickThreadKey *key) 00062 % 00063 */ 00064 MagickExport MagickBooleanType MagickCreateThreadKey(MagickThreadKey *key) 00065 { 00066 #if defined(MAGICKCORE_THREAD_SUPPORT) 00067 return(pthread_key_create(key,NULL) == 0 ? MagickTrue : MagickFalse); 00068 #elif defined(MAGICKCORE_HAVE_WINTHREADS) 00069 *key=TlsAlloc(); 00070 return(*key != TLS_OUT_OF_INDEXES ? MagickTrue : MagickFalse); 00071 #else 00072 *key=AcquireMagickMemory(sizeof(key)); 00073 return(*key != (void *) NULL ? MagickTrue : MagickFalse); 00074 #endif 00075 } 00076 00077 /* 00078 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00079 % % 00080 % % 00081 % % 00082 % M a g i c k D e l e t e T h r e a d K e y % 00083 % % 00084 % % 00085 % % 00086 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00087 % 00088 % MagickDeleteThreadKey() deletes a thread key. 00089 % 00090 % The format of the AcquireAESInfo method is: 00091 % 00092 % MagickBooleanType MagickDeleteThreadKey(MagickThreadKey key) 00093 % 00094 % A description of each parameter follows: 00095 % 00096 % o key: the thread key. 00097 % 00098 */ 00099 MagickExport MagickBooleanType MagickDeleteThreadKey(MagickThreadKey key) 00100 { 00101 #if defined(MAGICKCORE_THREAD_SUPPORT) 00102 return(pthread_key_delete(key) == 0 ? MagickTrue : MagickFalse); 00103 #elif defined(MAGICKCORE_HAVE_WINTHREADS) 00104 return(TlsFree(key) != 0 ? MagickTrue : MagickFalse); 00105 #else 00106 key=(MagickThreadKey) RelinquishMagickMemory(key); 00107 return(MagickTrue); 00108 #endif 00109 00110 } 00111 00112 /* 00113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00114 % % 00115 % % 00116 % % 00117 % M a g i c k G e t T h r e a d V a l u e % 00118 % % 00119 % % 00120 % % 00121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00122 % 00123 % MagickGetThreadValue() returns a value associated with the thread key. 00124 % 00125 % The format of the MagickGetThreadValue method is: 00126 % 00127 % void *MagickGetThreadValue(MagickThreadKey key) 00128 % 00129 % A description of each parameter follows: 00130 % 00131 % o key: the thread key. 00132 % 00133 */ 00134 MagickExport void *MagickGetThreadValue(MagickThreadKey key) 00135 { 00136 #if defined(MAGICKCORE_THREAD_SUPPORT) 00137 return(pthread_getspecific(key)); 00138 #elif defined(MAGICKCORE_HAVE_WINTHREADS) 00139 return(TlsGetValue(key)); 00140 #else 00141 return((void *) (*key)); 00142 #endif 00143 } 00144 00145 /* 00146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00147 % % 00148 % % 00149 % % 00150 % M a g i c k S e t T h r e a d V a l u e % 00151 % % 00152 % % 00153 % % 00154 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00155 % 00156 % MagickSetThreadValue() associates a value with the thread key. 00157 % 00158 % The format of the MagickSetThreadValue method is: 00159 % 00160 % MagickBooleanType MagickSetThreadValue(MagickThreadKey key, 00161 % const void *value) 00162 % 00163 % A description of each parameter follows: 00164 % 00165 % o key: the thread key. 00166 % 00167 % o value: the value 00168 % 00169 */ 00170 MagickExport MagickBooleanType MagickSetThreadValue(MagickThreadKey key, 00171 const void *value) 00172 { 00173 #if defined(MAGICKCORE_THREAD_SUPPORT) 00174 return(pthread_setspecific(key,value) == 0 ? MagickTrue : MagickFalse); 00175 #elif defined(MAGICKCORE_HAVE_WINTHREADS) 00176 return(TlsSetValue(key,(void *) value) != 0 ? MagickTrue : MagickFalse); 00177 #else 00178 *key=(size_t) value; 00179 return(MagickTrue); 00180 #endif 00181 }