blob: 2c101e8a7fdfa7ec760c0ab2d80dc41f991b387f [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
cristyb56bb242014-11-25 17:12:48 +00002 Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization
cristy3ed852e2009-09-05 21:47:34 +00003 dedicated to making software imaging solutions freely available.
4
5 You may not use this file except in compliance with the License.
6 obtain a copy of the License at
7
8 http://www.imagemagick.org/script/license.php
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 MagickCore random generation private methods.
17*/
18#ifndef _MAGICKCORE_RANDOM_PRIVATE_H
19#define _MAGICKCORE_RANDOM_PRIVATE_H
20
cristy6398ec72013-11-28 02:00:27 +000021#include "MagickCore/thread-private.h"
22
cristy3ed852e2009-09-05 21:47:34 +000023#if defined(__cplusplus) || defined(c_plusplus)
24extern "C" {
25#endif
26
cristye85d0f72013-11-27 02:25:43 +000027extern MagickPrivate double
cristy6062ead2015-05-20 11:38:51 +000028 GetRandomInfoNormalize(const RandomInfo *);
cristye85d0f72013-11-27 02:25:43 +000029
cristy5ff4eaf2011-09-03 01:38:02 +000030extern MagickPrivate MagickBooleanType
31 RandomComponentGenesis(void);
32
cristye85d0f72013-11-27 02:25:43 +000033extern MagickPrivate unsigned long
34 *GetRandomInfoSeed(RandomInfo *);
35
cristy5ff4eaf2011-09-03 01:38:02 +000036extern MagickPrivate void
37 RandomComponentTerminus(void);
38
cristy3ed852e2009-09-05 21:47:34 +000039static inline RandomInfo **DestroyRandomInfoThreadSet(
40 RandomInfo **random_info)
41{
cristybb503372010-05-27 20:51:26 +000042 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +000043 i;
44
45 assert(random_info != (RandomInfo **) NULL);
cristy92923f12012-07-30 22:09:44 +000046 for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++)
cristy3ed852e2009-09-05 21:47:34 +000047 if (random_info[i] != (RandomInfo *) NULL)
48 random_info[i]=DestroyRandomInfo(random_info[i]);
cristya64b85d2011-09-14 01:02:31 +000049 return((RandomInfo **) RelinquishMagickMemory(random_info));
cristy3ed852e2009-09-05 21:47:34 +000050}
51
52static inline RandomInfo **AcquireRandomInfoThreadSet(void)
53{
cristybb503372010-05-27 20:51:26 +000054 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +000055 i;
56
57 RandomInfo
58 **random_info;
59
cristybb503372010-05-27 20:51:26 +000060 size_t
cristy3ed852e2009-09-05 21:47:34 +000061 number_threads;
62
cristy92923f12012-07-30 22:09:44 +000063 number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
cristya64b85d2011-09-14 01:02:31 +000064 random_info=(RandomInfo **) AcquireQuantumMemory(number_threads,
cristy3ed852e2009-09-05 21:47:34 +000065 sizeof(*random_info));
66 if (random_info == (RandomInfo **) NULL)
67 return((RandomInfo **) NULL);
68 (void) ResetMagickMemory(random_info,0,number_threads*sizeof(*random_info));
cristybb503372010-05-27 20:51:26 +000069 for (i=0; i < (ssize_t) number_threads; i++)
cristy3ed852e2009-09-05 21:47:34 +000070 {
71 random_info[i]=AcquireRandomInfo();
72 if (random_info[i] == (RandomInfo *) NULL)
73 return(DestroyRandomInfoThreadSet(random_info));
74 }
75 return(random_info);
76}
77
78#if defined(__cplusplus) || defined(c_plusplus)
79}
80#endif
81
82#endif