MagickCore  7.1.0
Convert, Edit, Or Compose Bitmap Images
random-private.h
1 /*
2  Copyright @ 2001 ImageMagick Studio LLC, a non-profit organization
3  dedicated to making software imaging solutions freely available.
4 
5  You may not use this file except in compliance with the License. You may
6  obtain a copy of the License at
7 
8  https://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 
21 #include "MagickCore/thread-private.h"
22 
23 #if defined(__cplusplus) || defined(c_plusplus)
24 extern "C" {
25 #endif
26 
27 extern MagickPrivate double
28  GetRandomInfoNormalize(const RandomInfo *);
29 
30 extern MagickPrivate MagickBooleanType
31  RandomComponentGenesis(void);
32 
33 extern MagickPrivate unsigned long
34  *GetRandomInfoSeed(RandomInfo *);
35 
36 extern MagickPrivate void
37  RandomComponentTerminus(void);
38 
39 static inline RandomInfo **DestroyRandomInfoTLS(RandomInfo **random_info)
40 {
41  ssize_t
42  i;
43 
44  assert(random_info != (RandomInfo **) NULL);
45  for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++)
46  if (random_info[i] != (RandomInfo *) NULL)
47  random_info[i]=DestroyRandomInfo(random_info[i]);
48  return((RandomInfo **) RelinquishMagickMemory(random_info));
49 }
50 
51 static inline RandomInfo **AcquireRandomInfoTLS(void)
52 {
53  ssize_t
54  i;
55 
57  **random_info;
58 
59  size_t
60  number_threads;
61 
62  number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
63  random_info=(RandomInfo **) AcquireQuantumMemory(number_threads,
64  sizeof(*random_info));
65  if (random_info == (RandomInfo **) NULL)
66  ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
67  (void) memset(random_info,0,number_threads*sizeof(*random_info));
68  for (i=0; i < (ssize_t) number_threads; i++)
69  random_info[i]=AcquireRandomInfo();
70  return(random_info);
71 }
72 
73 #if defined(__cplusplus) || defined(c_plusplus)
74 }
75 #endif
76 
77 #endif