MagickCore  6.7.5
random-private.h
Go to the documentation of this file.
00001 /*
00002   Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization
00003   dedicated to making software imaging solutions freely available.
00004   
00005   You may not use this file except in compliance with the License.
00006   obtain a copy of the License at
00007   
00008     http://www.imagemagick.org/script/license.php
00009   
00010   Unless required by applicable law or agreed to in writing, software
00011   distributed under the License is distributed on an "AS IS" BASIS,
00012   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013   See the License for the specific language governing permissions and
00014   limitations under the License.
00015 
00016   MagickCore random generation private methods.
00017 */
00018 #ifndef _MAGICKCORE_RANDOM_PRIVATE_H
00019 #define _MAGICKCORE_RANDOM_PRIVATE_H
00020 
00021 #if defined(__cplusplus) || defined(c_plusplus)
00022 extern "C" {
00023 #endif
00024 
00025 #include "MagickCore/thread-private.h"
00026 
00027 extern MagickPrivate MagickBooleanType
00028   RandomComponentGenesis(void);
00029 
00030 extern MagickPrivate void
00031   RandomComponentTerminus(void);
00032 
00033 static inline RandomInfo **DestroyRandomInfoThreadSet(
00034   RandomInfo **random_info)
00035 {
00036   register ssize_t
00037     i;
00038 
00039   assert(random_info != (RandomInfo **) NULL);
00040   for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
00041     if (random_info[i] != (RandomInfo *) NULL)
00042       random_info[i]=DestroyRandomInfo(random_info[i]);
00043   return((RandomInfo **) RelinquishMagickMemory(random_info));
00044 }
00045 
00046 static inline RandomInfo **AcquireRandomInfoThreadSet(void)
00047 {
00048   register ssize_t
00049     i;
00050 
00051   RandomInfo
00052     **random_info;
00053 
00054   size_t
00055     number_threads;
00056 
00057   number_threads=GetOpenMPMaximumThreads();
00058   random_info=(RandomInfo **) AcquireQuantumMemory(number_threads,
00059     sizeof(*random_info));
00060   if (random_info == (RandomInfo **) NULL)
00061     return((RandomInfo **) NULL);
00062   (void) ResetMagickMemory(random_info,0,number_threads*sizeof(*random_info));
00063   for (i=0; i < (ssize_t) number_threads; i++)
00064   {
00065     random_info[i]=AcquireRandomInfo();
00066     if (random_info[i] == (RandomInfo *) NULL)
00067       return(DestroyRandomInfoThreadSet(random_info));
00068   }
00069   return(random_info);
00070 }
00071 
00072 #if defined(__cplusplus) || defined(c_plusplus)
00073 }
00074 #endif
00075 
00076 #endif