cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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 % |
cristy | de984cd | 2013-12-01 14:49:27 +0000 | [diff] [blame] | 16 | % Cristy % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 17 | % May 2004 % |
| 18 | % % |
| 19 | % % |
Cristy | 7ce65e7 | 2015-12-12 18:03:16 -0500 | [diff] [blame] | 20 | % Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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 | /* |
| 40 | Include declarations. |
| 41 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 42 | #include "MagickWand/studio.h" |
| 43 | #include "MagickWand/MagickWand.h" |
| 44 | #include "MagickWand/magick-wand-private.h" |
| 45 | #include "MagickWand/wand.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 46 | |
| 47 | static SplayTreeInfo |
| 48 | *wand_ids = (SplayTreeInfo *) NULL; |
| 49 | |
| 50 | static MagickBooleanType |
| 51 | instantiate_wand = MagickFalse; |
| 52 | |
| 53 | static 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 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 71 | % size_t AcquireWandId() |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 72 | % |
| 73 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 74 | WandExport size_t AcquireWandId(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 75 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 76 | static size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 77 | id = 0; |
| 78 | |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 79 | if (wand_semaphore == (SemaphoreInfo *) NULL) |
cristy | 04b11db | 2014-02-16 15:10:39 +0000 | [diff] [blame] | 80 | ActivateSemaphoreInfo(&wand_semaphore); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 81 | LockSemaphoreInfo(wand_semaphore); |
cristy | 9c5171c | 2014-05-25 21:26:39 +0000 | [diff] [blame] | 82 | if (wand_ids == (SplayTreeInfo *) NULL) |
| 83 | wand_ids=NewSplayTree((int (*)(const void *,const void *)) NULL, |
| 84 | (void *(*)(void *)) NULL,(void *(*)(void *)) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 85 | id++; |
| 86 | (void) AddValueToSplayTree(wand_ids,(const void *) id,(const void *) id); |
cristy | 9c5171c | 2014-05-25 21:26:39 +0000 | [diff] [blame] | 87 | instantiate_wand=MagickTrue; |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 88 | UnlockSemaphoreInfo(wand_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 89 | return(id); |
| 90 | } |
| 91 | |
| 92 | /* |
| 93 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 94 | % % |
| 95 | % % |
| 96 | % % |
| 97 | % D e s t r o y W a n d I d s % |
| 98 | % % |
| 99 | % % |
| 100 | % % |
| 101 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 102 | % |
| 103 | % DestroyWandIds() deallocates memory associated with the wand id's. |
| 104 | % |
| 105 | % The format of the DestroyWandIds() method is: |
| 106 | % |
| 107 | % void DestroyWandIds(void) |
| 108 | % |
| 109 | % A description of each parameter follows: |
| 110 | % |
| 111 | */ |
| 112 | WandExport void DestroyWandIds(void) |
| 113 | { |
cristy | 9ffa3ae | 2009-11-02 17:34:36 +0000 | [diff] [blame] | 114 | if (wand_semaphore == (SemaphoreInfo *) NULL) |
cristy | 04b11db | 2014-02-16 15:10:39 +0000 | [diff] [blame] | 115 | ActivateSemaphoreInfo(&wand_semaphore); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 116 | LockSemaphoreInfo(wand_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 117 | if (wand_ids != (SplayTreeInfo *) NULL) |
| 118 | wand_ids=DestroySplayTree(wand_ids); |
| 119 | instantiate_wand=MagickFalse; |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 120 | UnlockSemaphoreInfo(wand_semaphore); |
cristy | 3d162a9 | 2014-02-16 14:05:06 +0000 | [diff] [blame] | 121 | RelinquishSemaphoreInfo(&wand_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | /* |
| 125 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 126 | % % |
| 127 | % % |
| 128 | % % |
| 129 | % R e l i n q u i s h W a n d I d % |
| 130 | % % |
| 131 | % % |
| 132 | % % |
| 133 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 134 | % |
| 135 | % RelinquishWandId() relinquishes a unique wand id. |
| 136 | % |
| 137 | % The format of the RelinquishWandId() method is: |
| 138 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 139 | % void RelinquishWandId(const size_t *id) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 140 | % |
| 141 | % A description of each parameter follows: |
| 142 | % |
| 143 | % o id: a unique wand id. |
| 144 | % |
| 145 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 146 | WandExport void RelinquishWandId(const size_t id) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 147 | { |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 148 | LockSemaphoreInfo(wand_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 149 | if (wand_ids != (SplayTreeInfo *) NULL) |
| 150 | (void) DeleteNodeByValueFromSplayTree(wand_ids,(const void *) id); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 151 | UnlockSemaphoreInfo(wand_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 152 | } |