MagickWand  6.7.5
wand.c
Go to the documentation of this file.
00001 /*
00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00003 %                                                                             %
00004 %                                                                             %
00005 %                                                                             %
00006 %                         W   W   AAA   N   N  DDDD                           %
00007 %                         W   W  A   A  NN  N  D   D                          %
00008 %                         W W W  AAAAA  N N N  D   D                          %
00009 %                         WW WW  A   A  N  NN  D   D                          %
00010 %                         W   W  A   A  N   N  DDDD                           %
00011 %                                                                             %
00012 %                                                                             %
00013 %                         MagickWand Support Methods                          %
00014 %                                                                             %
00015 %                              Software Design                                %
00016 %                                John Cristy                                  %
00017 %                                 May  2004                                   %
00018 %                                                                             %
00019 %                                                                             %
00020 %  Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization      %
00021 %  dedicated to making software imaging solutions freely available.           %
00022 %                                                                             %
00023 %  You may not use this file except in compliance with the License.  You may  %
00024 %  obtain a copy of the License at                                            %
00025 %                                                                             %
00026 %    http://www.imagemagick.org/script/license.php                            %
00027 %                                                                             %
00028 %  Unless required by applicable law or agreed to in writing, software        %
00029 %  distributed under the License is distributed on an "AS IS" BASIS,          %
00030 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
00031 %  See the License for the specific language governing permissions and        %
00032 %  limitations under the License.                                             %
00033 %                                                                             %
00034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00035 %
00036 %
00037 */
00038 
00039 /*
00040   Include declarations.
00041 */
00042 #include "MagickWand/studio.h"
00043 #include "MagickWand/MagickWand.h"
00044 #include "MagickWand/magick-wand-private.h"
00045 #include "MagickWand/wand.h"
00046 
00047 static SplayTreeInfo
00048   *wand_ids = (SplayTreeInfo *) NULL;
00049 
00050 static MagickBooleanType
00051   instantiate_wand = MagickFalse;
00052 
00053 static SemaphoreInfo
00054   *wand_semaphore = (SemaphoreInfo *) NULL;
00055 
00056 /*
00057 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00058 %                                                                             %
00059 %                                                                             %
00060 %                                                                             %
00061 %   A c q u i r e W a n d I d                                                 %
00062 %                                                                             %
00063 %                                                                             %
00064 %                                                                             %
00065 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00066 %
00067 %  AcquireWandId() returns a unique wand id.
00068 %
00069 %  The format of the AcquireWandId() method is:
00070 %
00071 %      size_t AcquireWandId()
00072 %
00073 */
00074 WandExport size_t AcquireWandId(void)
00075 {
00076   static size_t
00077     id = 0;
00078 
00079   if (wand_semaphore == (SemaphoreInfo *) NULL)
00080     AcquireSemaphoreInfo(&wand_semaphore);
00081   LockSemaphoreInfo(wand_semaphore);
00082   if ((wand_ids == (SplayTreeInfo *) NULL) && (instantiate_wand == MagickFalse))
00083     {
00084       wand_ids=NewSplayTree((int (*)(const void *,const void *)) NULL,
00085         (void *(*)(void *)) NULL,(void *(*)(void *)) NULL);
00086       instantiate_wand=MagickTrue;
00087     }
00088   id++;
00089   (void) AddValueToSplayTree(wand_ids,(const void *) id,(const void *) id);
00090   UnlockSemaphoreInfo(wand_semaphore);
00091   return(id);
00092 }
00093 
00094 /*
00095 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00096 %                                                                             %
00097 %                                                                             %
00098 %                                                                             %
00099 %    D e s t r o y W a n d I d s                                              %
00100 %                                                                             %
00101 %                                                                             %
00102 %                                                                             %
00103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00104 %
00105 %  DestroyWandIds() deallocates memory associated with the wand id's.
00106 %
00107 %  The format of the DestroyWandIds() method is:
00108 %
00109 %      void DestroyWandIds(void)
00110 %
00111 %  A description of each parameter follows:
00112 %
00113 */
00114 WandExport void DestroyWandIds(void)
00115 {
00116   if (wand_semaphore == (SemaphoreInfo *) NULL)
00117     AcquireSemaphoreInfo(&wand_semaphore);
00118   LockSemaphoreInfo(wand_semaphore);
00119   if (wand_ids != (SplayTreeInfo *) NULL)
00120     wand_ids=DestroySplayTree(wand_ids);
00121   instantiate_wand=MagickFalse;
00122   UnlockSemaphoreInfo(wand_semaphore);
00123   DestroySemaphoreInfo(&wand_semaphore);
00124 }
00125 
00126 /*
00127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00128 %                                                                             %
00129 %                                                                             %
00130 %                                                                             %
00131 %    R e l i n q u i s h W a n d I d                                          %
00132 %                                                                             %
00133 %                                                                             %
00134 %                                                                             %
00135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00136 %
00137 %  RelinquishWandId() relinquishes a unique wand id.
00138 %
00139 %  The format of the RelinquishWandId() method is:
00140 %
00141 %      void RelinquishWandId(const size_t *id)
00142 %
00143 %  A description of each parameter follows:
00144 %
00145 %    o id: a unique wand id.
00146 %
00147 */
00148 WandExport void RelinquishWandId(const size_t id)
00149 {
00150   LockSemaphoreInfo(wand_semaphore);
00151   if (wand_ids != (SplayTreeInfo *) NULL)
00152     (void) DeleteNodeByValueFromSplayTree(wand_ids,(const void *) id);
00153   UnlockSemaphoreInfo(wand_semaphore);
00154 }