00001 /* 00002 Copyright 1999-2020 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. You may 00006 obtain a copy of the License at 00007 00008 https://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 #include "magick/thread-private.h" 00022 00023 #if defined(__cplusplus) || defined(c_plusplus) 00024 extern "C" { 00025 #endif 00026 00027 static inline RandomInfo **DestroyRandomInfoThreadSet( 00028 RandomInfo **random_info) 00029 { 00030 register ssize_t 00031 i; 00032 00033 assert(random_info != (RandomInfo **) NULL); 00034 for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++) 00035 if (random_info[i] != (RandomInfo *) NULL) 00036 random_info[i]=DestroyRandomInfo(random_info[i]); 00037 return((RandomInfo **) RelinquishAlignedMemory(random_info)); 00038 } 00039 00040 static inline RandomInfo **AcquireRandomInfoThreadSet(void) 00041 { 00042 register ssize_t 00043 i; 00044 00045 RandomInfo 00046 **random_info; 00047 00048 size_t 00049 number_threads; 00050 00051 number_threads=(size_t) GetMagickResourceLimit(ThreadResource); 00052 random_info=(RandomInfo **) AcquireAlignedMemory(number_threads, 00053 sizeof(*random_info)); 00054 if (random_info == (RandomInfo **) NULL) 00055 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); 00056 (void) memset(random_info,0,number_threads*sizeof(*random_info)); 00057 for (i=0; i < (ssize_t) number_threads; i++) 00058 random_info[i]=AcquireRandomInfo(); 00059 return(random_info); 00060 } 00061 00062 extern MagickExport unsigned long 00063 *GetRandomInfoSeed(RandomInfo *); 00064 00065 extern MagickExport double 00066 GetRandomInfoNormalize(const RandomInfo *); 00067 00068 #if defined(__cplusplus) || defined(c_plusplus) 00069 } 00070 #endif 00071 00072 #endif