2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8 % W W W AAAAA N N N D D %
13 % MagickWand Support Methods %
20 % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
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. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "MagickWand/studio.h"
43 #include "MagickWand/MagickWand.h"
44 #include "MagickWand/magick-wand-private.h"
45 #include "MagickWand/wand.h"
48 *wand_ids = (SplayTreeInfo *) NULL;
50 static MagickBooleanType
51 instantiate_wand = MagickFalse;
54 *wand_semaphore = (SemaphoreInfo *) NULL;
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 % A c q u i r e W a n d I d %
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 % AcquireWandId() returns a unique wand id.
69 % The format of the AcquireWandId() method is:
71 % size_t AcquireWandId()
74 WandExport size_t AcquireWandId(void)
79 if (wand_semaphore == (SemaphoreInfo *) NULL)
80 AcquireSemaphoreInfo(&wand_semaphore);
81 LockSemaphoreInfo(wand_semaphore);
82 if ((wand_ids == (SplayTreeInfo *) NULL) && (instantiate_wand == MagickFalse))
84 wand_ids=NewSplayTree((int (*)(const void *,const void *)) NULL,
85 (void *(*)(void *)) NULL,(void *(*)(void *)) NULL);
86 instantiate_wand=MagickTrue;
89 (void) AddValueToSplayTree(wand_ids,(const void *) id,(const void *) id);
90 UnlockSemaphoreInfo(wand_semaphore);
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99 % D e s t r o y W a n d I d s %
103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 % DestroyWandIds() deallocates memory associated with the wand id's.
107 % The format of the DestroyWandIds() method is:
109 % void DestroyWandIds(void)
111 % A description of each parameter follows:
114 WandExport void DestroyWandIds(void)
116 if (wand_semaphore == (SemaphoreInfo *) NULL)
117 AcquireSemaphoreInfo(&wand_semaphore);
118 LockSemaphoreInfo(wand_semaphore);
119 if (wand_ids != (SplayTreeInfo *) NULL)
120 wand_ids=DestroySplayTree(wand_ids);
121 instantiate_wand=MagickFalse;
122 UnlockSemaphoreInfo(wand_semaphore);
123 DestroySemaphoreInfo(&wand_semaphore);
127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 % R e l i n q u i s h W a n d I d %
135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137 % RelinquishWandId() relinquishes a unique wand id.
139 % The format of the RelinquishWandId() method is:
141 % void RelinquishWandId(const size_t *id)
143 % A description of each parameter follows:
145 % o id: a unique wand id.
148 WandExport void RelinquishWandId(const size_t id)
150 LockSemaphoreInfo(wand_semaphore);
151 if (wand_ids != (SplayTreeInfo *) NULL)
152 (void) DeleteNodeByValueFromSplayTree(wand_ids,(const void *) id);
153 UnlockSemaphoreInfo(wand_semaphore);