cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 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 % |
| 15 | % John Cristy % |
| 16 | % March 2003 % |
| 17 | % % |
| 18 | % % |
cristy | 1454be7 | 2011-12-19 01:52:48 +0000 | [diff] [blame] | 19 | % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 20 | % 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 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 41 | #include "MagickCore/studio.h" |
| 42 | #include "MagickCore/memory_.h" |
| 43 | #include "MagickCore/thread_.h" |
| 44 | #include "MagickCore/thread-private.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 45 | |
| 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 | */ |
| 64 | MagickExport MagickBooleanType MagickCreateThreadKey(MagickThreadKey *key) |
| 65 | { |
cristy | 55bf91c | 2010-09-24 00:29:41 +0000 | [diff] [blame] | 66 | #if defined(MAGICKCORE_THREAD_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 67 | return(pthread_key_create(key,NULL) == 0 ? MagickTrue : MagickFalse); |
cristy | fe092d8 | 2009-10-11 04:00:45 +0000 | [diff] [blame] | 68 | #elif defined(MAGICKCORE_HAVE_WINTHREADS) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 69 | *key=TlsAlloc(); |
| 70 | return(*key != TLS_OUT_OF_INDEXES ? MagickTrue : MagickFalse); |
| 71 | #else |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 72 | *key=AcquireMagickMemory(sizeof(key)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 73 | 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 | */ |
| 99 | MagickExport MagickBooleanType MagickDeleteThreadKey(MagickThreadKey key) |
| 100 | { |
cristy | 55bf91c | 2010-09-24 00:29:41 +0000 | [diff] [blame] | 101 | #if defined(MAGICKCORE_THREAD_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 102 | return(pthread_key_delete(key) == 0 ? MagickTrue : MagickFalse); |
cristy | fe092d8 | 2009-10-11 04:00:45 +0000 | [diff] [blame] | 103 | #elif defined(MAGICKCORE_HAVE_WINTHREADS) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 104 | return(TlsFree(key) != 0 ? MagickTrue : MagickFalse); |
| 105 | #else |
| 106 | key=(MagickThreadKey) RelinquishMagickMemory(key); |
| 107 | return(MagickTrue); |
| 108 | #endif |
| 109 | |
| 110 | } |
| 111 | |
| 112 | /* |
| 113 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 114 | % % |
| 115 | % % |
| 116 | % % |
| 117 | % M a g i c k G e t T h r e a d V a l u e % |
| 118 | % % |
| 119 | % % |
| 120 | % % |
| 121 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 122 | % |
| 123 | % MagickGetThreadValue() returns a value associated with the thread key. |
| 124 | % |
| 125 | % The format of the MagickGetThreadValue method is: |
| 126 | % |
| 127 | % void *MagickGetThreadValue(MagickThreadKey key) |
| 128 | % |
| 129 | % A description of each parameter follows: |
| 130 | % |
| 131 | % o key: the thread key. |
| 132 | % |
| 133 | */ |
| 134 | MagickExport void *MagickGetThreadValue(MagickThreadKey key) |
| 135 | { |
cristy | 55bf91c | 2010-09-24 00:29:41 +0000 | [diff] [blame] | 136 | #if defined(MAGICKCORE_THREAD_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 137 | return(pthread_getspecific(key)); |
cristy | fe092d8 | 2009-10-11 04:00:45 +0000 | [diff] [blame] | 138 | #elif defined(MAGICKCORE_HAVE_WINTHREADS) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 139 | return(TlsGetValue(key)); |
| 140 | #else |
| 141 | return((void *) (*key)); |
| 142 | #endif |
| 143 | } |
| 144 | |
| 145 | /* |
| 146 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 147 | % % |
| 148 | % % |
| 149 | % % |
| 150 | % M a g i c k S e t T h r e a d V a l u e % |
| 151 | % % |
| 152 | % % |
| 153 | % % |
| 154 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 155 | % |
| 156 | % MagickSetThreadValue() associates a value with the thread key. |
| 157 | % |
| 158 | % The format of the MagickSetThreadValue method is: |
| 159 | % |
| 160 | % MagickBooleanType MagickSetThreadValue(MagickThreadKey key, |
| 161 | % const void *value) |
| 162 | % |
| 163 | % A description of each parameter follows: |
| 164 | % |
| 165 | % o key: the thread key. |
| 166 | % |
| 167 | % o value: the value |
| 168 | % |
| 169 | */ |
| 170 | MagickExport MagickBooleanType MagickSetThreadValue(MagickThreadKey key, |
| 171 | const void *value) |
| 172 | { |
cristy | 55bf91c | 2010-09-24 00:29:41 +0000 | [diff] [blame] | 173 | #if defined(MAGICKCORE_THREAD_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 174 | return(pthread_setspecific(key,value) == 0 ? MagickTrue : MagickFalse); |
cristy | fe092d8 | 2009-10-11 04:00:45 +0000 | [diff] [blame] | 175 | #elif defined(MAGICKCORE_HAVE_WINTHREADS) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 176 | return(TlsSetValue(key,(void *) value) != 0 ? MagickTrue : MagickFalse); |
| 177 | #else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 178 | *key=(size_t) value; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 179 | return(MagickTrue); |
| 180 | #endif |
| 181 | } |