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-2008 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 "wand/studio.h"
00043 #include "wand/MagickWand.h"
00044 #include "wand/magick-wand-private.h"
00045 #include "wand/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 %      unsigned long AcquireWandId()
00072 %
00073 */
00074 WandExport unsigned long AcquireWandId(void)
00075 {
00076   static unsigned long
00077     id = 0;
00078 
00079   if ((wand_ids == (SplayTreeInfo *) NULL) &&
00080       (instantiate_wand == MagickFalse))
00081     {
00082       AcquireSemaphoreInfo(&wand_semaphore);
00083       if ((wand_ids == (SplayTreeInfo *) NULL) &&
00084           (instantiate_wand == MagickFalse))
00085         {
00086           wand_ids=NewSplayTree((int (*)(const void *,const void *)) NULL,
00087             (void *(*)(void *)) NULL,(void *(*)(void *)) NULL);
00088           instantiate_wand=MagickTrue;
00089         }
00090       RelinquishSemaphoreInfo(wand_semaphore);
00091     }
00092   AcquireSemaphoreInfo(&wand_semaphore);
00093   id++;
00094   (void) AddValueToSplayTree(wand_ids,(const void *) id,(const void *) id);
00095   RelinquishSemaphoreInfo(wand_semaphore);
00096   return(id);
00097 }
00098 
00099 /*
00100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00101 %                                                                             %
00102 %                                                                             %
00103 %                                                                             %
00104 %    R e l i n q u i s h W a n d I d                                          %
00105 %                                                                             %
00106 %                                                                             %
00107 %                                                                             %
00108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00109 %
00110 %  RelinquishWandId() relinquishes a unique wand id.
00111 %
00112 %  The format of the RelinquishWandId() method is:
00113 %
00114 %      void RelinquishWandId(const unsigned long *id)
00115 %
00116 %  A description of each parameter follows:
00117 %
00118 %    o id: a unique wand id.
00119 %
00120 */
00121 WandExport void RelinquishWandId(const unsigned long id)
00122 {
00123   (void) LogMagickEvent(WandEvent,GetMagickModule(),"...");
00124   if (wand_ids == (SplayTreeInfo *) NULL)
00125     return;
00126   AcquireSemaphoreInfo(&wand_semaphore);
00127   (void) DeleteNodeByValueFromSplayTree(wand_ids,(const void *) id);
00128   if ((instantiate_wand == MagickFalse) ||
00129       (GetNumberOfNodesInSplayTree(wand_ids) != 0))
00130     {
00131       RelinquishSemaphoreInfo(wand_semaphore);
00132       return;
00133     }
00134   wand_ids=DestroySplayTree(wand_ids);
00135   instantiate_wand=MagickFalse;
00136   RelinquishSemaphoreInfo(wand_semaphore);
00137   DestroySemaphoreInfo(&wand_semaphore);
00138 }

Generated on Sat Nov 22 23:45:26 2008 for MagickWand by  doxygen 1.5.7.1