1 /* 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 % % 4 % % 5 % % 6 % W W AAA N N DDDD % 7 % W W A A NN N D D % 8 % W W W AAAAA N N N D D % 9 % WW WW A A N NN D D % 10 % W W A A N N DDDD % 11 % % 12 % % 13 % MagickWand Support Methods % 14 % % 15 % Software Design % 16 % Cristy % 17 % May 2004 % 18 % % 19 % % 20 % Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization % 21 % dedicated to making software imaging solutions freely available. % 22 % % 23 % You may not use this file except in compliance with the License. You may % 24 % obtain a copy of the License at % 25 % % 26 % http://www.imagemagick.org/script/license.php % 27 % % 28 % Unless required by applicable law or agreed to in writing, software % 29 % distributed under the License is distributed on an "AS IS" BASIS, % 30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % 31 % See the License for the specific language governing permissions and % 32 % limitations under the License. % 33 % % 34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 35 % 36 % 37 */ 38 39 /* 41 Include declarations. 42 */ 43 #include "MagickWand/studio.h" 44 #include "MagickWand/MagickWand.h" 45 #include "MagickWand/magick-wand-private.h" 46 #include "MagickWand/wand.h" 47 48 static SplayTreeInfo 50 *wand_ids = (SplayTreeInfo *) NULL; 51 52 static MagickBooleanType 53 instantiate_wand = MagickFalse; 54 55 static SemaphoreInfo 56 *wand_semaphore = (SemaphoreInfo *) NULL; 57 58 /* 60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 61 % % 62 % % 63 % % 64 % A c q u i r e W a n d I d % 65 % % 66 % % 67 % % 68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 69 % 70 % AcquireWandId() returns a unique wand id. 71 % 72 % The format of the AcquireWandId() method is: 73 % 74 % size_t AcquireWandId() 75 % 76 */ 77 WandExport size_t AcquireWandId(void) 78 { 79 static size_t 80 id = 0; 81 82 if (wand_semaphore == (SemaphoreInfo *) NULL) 83 ActivateSemaphoreInfo(&wand_semaphore); 84 LockSemaphoreInfo(wand_semaphore); 85 if (wand_ids == (SplayTreeInfo *) NULL) 86 wand_ids=NewSplayTree((int (*)(const void *,const void *)) NULL, 87 (void *(*)(void *)) NULL,(void *(*)(void *)) NULL); 88 id++; 89 (void) AddValueToSplayTree(wand_ids,(const void *) id,(const void *) id); 90 instantiate_wand=MagickTrue; 91 UnlockSemaphoreInfo(wand_semaphore); 92 return(id); 93 } 94 95 /* 97 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 98 % % 99 % % 100 % % 101 % D e s t r o y W a n d I d s % 102 % % 103 % % 104 % % 105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 106 % 107 % DestroyWandIds() deallocates memory associated with the wand id's. 108 % 109 % The format of the DestroyWandIds() method is: 110 % 111 % void DestroyWandIds(void) 112 % 113 % A description of each parameter follows: 114 % 115 */ 116 WandExport void DestroyWandIds(void) 117 { 118 if (wand_semaphore == (SemaphoreInfo *) NULL) 119 ActivateSemaphoreInfo(&wand_semaphore); 120 LockSemaphoreInfo(wand_semaphore); 121 if (wand_ids != (SplayTreeInfo *) NULL) 122 wand_ids=DestroySplayTree(wand_ids); 123 instantiate_wand=MagickFalse; 124 UnlockSemaphoreInfo(wand_semaphore); 125 RelinquishSemaphoreInfo(&wand_semaphore); 126 } 127 128 /* 130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 131 % % 132 % % 133 % % 134 % R e l i n q u i s h W a n d I d % 135 % % 136 % % 137 % % 138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 139 % 140 % RelinquishWandId() relinquishes a unique wand id. 141 % 142 % The format of the RelinquishWandId() method is: 143 % 144 % void RelinquishWandId(const size_t *id) 145 % 146 % A description of each parameter follows: 147 % 148 % o id: a unique wand id. 149 % 150 */ 151 WandExport void RelinquishWandId(const size_t id) 152 { 153 LockSemaphoreInfo(wand_semaphore); 154 if (wand_ids != (SplayTreeInfo *) NULL) 155 (void) DeleteNodeByValueFromSplayTree(wand_ids,(const void *) id); 156 UnlockSemaphoreInfo(wand_semaphore); 157 } 158