blob: b5845b4ea7221860e93871dc5842a800296fcbd7 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
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% John Cristy %
17% May 2004 %
18% %
19% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% 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/*
40 Include declarations.
41*/
cristy4c08aed2011-07-01 19:47:50 +000042#include "MagickWand/studio.h"
43#include "MagickWand/MagickWand.h"
44#include "MagickWand/magick-wand-private.h"
45#include "MagickWand/wand.h"
cristy3ed852e2009-09-05 21:47:34 +000046
47static SplayTreeInfo
48 *wand_ids = (SplayTreeInfo *) NULL;
49
50static MagickBooleanType
51 instantiate_wand = MagickFalse;
52
53static SemaphoreInfo
54 *wand_semaphore = (SemaphoreInfo *) NULL;
55
56/*
57%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58% %
59% %
60% %
61% A c q u i r e W a n d I d %
62% %
63% %
64% %
65%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66%
67% AcquireWandId() returns a unique wand id.
68%
69% The format of the AcquireWandId() method is:
70%
cristybb503372010-05-27 20:51:26 +000071% size_t AcquireWandId()
cristy3ed852e2009-09-05 21:47:34 +000072%
73*/
cristybb503372010-05-27 20:51:26 +000074WandExport size_t AcquireWandId(void)
cristy3ed852e2009-09-05 21:47:34 +000075{
cristybb503372010-05-27 20:51:26 +000076 static size_t
cristy3ed852e2009-09-05 21:47:34 +000077 id = 0;
78
cristy18b17442009-10-25 18:36:48 +000079 if (wand_semaphore == (SemaphoreInfo *) NULL)
80 AcquireSemaphoreInfo(&wand_semaphore);
cristyf84a1932010-01-03 18:00:18 +000081 LockSemaphoreInfo(wand_semaphore);
cristy3ed852e2009-09-05 21:47:34 +000082 if ((wand_ids == (SplayTreeInfo *) NULL) && (instantiate_wand == MagickFalse))
83 {
84 wand_ids=NewSplayTree((int (*)(const void *,const void *)) NULL,
85 (void *(*)(void *)) NULL,(void *(*)(void *)) NULL);
86 instantiate_wand=MagickTrue;
87 }
88 id++;
89 (void) AddValueToSplayTree(wand_ids,(const void *) id,(const void *) id);
cristyf84a1932010-01-03 18:00:18 +000090 UnlockSemaphoreInfo(wand_semaphore);
cristy3ed852e2009-09-05 21:47:34 +000091 return(id);
92}
93
94/*
95%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96% %
97% %
98% %
99% D e s t r o y W a n d I d s %
100% %
101% %
102% %
103%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104%
105% DestroyWandIds() deallocates memory associated with the wand id's.
106%
107% The format of the DestroyWandIds() method is:
108%
109% void DestroyWandIds(void)
110%
111% A description of each parameter follows:
112%
113*/
114WandExport void DestroyWandIds(void)
115{
cristy9ffa3ae2009-11-02 17:34:36 +0000116 if (wand_semaphore == (SemaphoreInfo *) NULL)
117 AcquireSemaphoreInfo(&wand_semaphore);
cristyf84a1932010-01-03 18:00:18 +0000118 LockSemaphoreInfo(wand_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000119 if (wand_ids != (SplayTreeInfo *) NULL)
120 wand_ids=DestroySplayTree(wand_ids);
121 instantiate_wand=MagickFalse;
cristyf84a1932010-01-03 18:00:18 +0000122 UnlockSemaphoreInfo(wand_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000123 DestroySemaphoreInfo(&wand_semaphore);
124}
125
126/*
127%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128% %
129% %
130% %
131% R e l i n q u i s h W a n d I d %
132% %
133% %
134% %
135%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136%
137% RelinquishWandId() relinquishes a unique wand id.
138%
139% The format of the RelinquishWandId() method is:
140%
cristybb503372010-05-27 20:51:26 +0000141% void RelinquishWandId(const size_t *id)
cristy3ed852e2009-09-05 21:47:34 +0000142%
143% A description of each parameter follows:
144%
145% o id: a unique wand id.
146%
147*/
cristybb503372010-05-27 20:51:26 +0000148WandExport void RelinquishWandId(const size_t id)
cristy3ed852e2009-09-05 21:47:34 +0000149{
cristyf84a1932010-01-03 18:00:18 +0000150 LockSemaphoreInfo(wand_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000151 if (wand_ids != (SplayTreeInfo *) NULL)
152 (void) DeleteNodeByValueFromSplayTree(wand_ids,(const void *) id);
cristyf84a1932010-01-03 18:00:18 +0000153 UnlockSemaphoreInfo(wand_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000154}