blob: 2bec78466b7bca0daea6cb0f1a9957b3ec70d4b5 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2 Copyright 1999-2009 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.
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 private methods for internal threading.
17*/
18#ifndef _MAGICKCORE_THREAD_PRIVATE_H
19#define _MAGICKCORE_THREAD_PRIVATE_H
20
21#if defined(__cplusplus) || defined(c_plusplus)
22extern "C" {
23#endif
24
25#include <magick/thread_.h>
26
27#if defined(MAGICKCORE_HAVE_PTHREAD)
28 typedef pthread_mutex_t MagickMutexType;
29#elif defined(__WINDOWS__)
30 typedef CRITICAL_SECTION MagickMutexType;
31#else
32 typedef unsigned long MagickMutexType;
33#endif
34
35static inline MagickThreadType GetMagickThreadId(void)
36{
37#if defined(MAGICKCORE_HAVE_PTHREAD)
38 return(pthread_self());
39#elif defined(__WINDOWS__)
40 return(GetCurrentThreadId());
41#else
42 return(getpid());
43#endif
44}
45
46static inline unsigned long GetMagickThreadSignature(void)
47{
48#if defined(MAGICKCORE_HAVE_PTHREAD)
49 {
50 union
51 {
52 pthread_t
53 id;
54
55 unsigned long
56 signature;
57 } magick_thread;
58
59 magick_thread.signature=0UL;
60 magick_thread.id=pthread_self();
61 return(magick_thread.signature);
62 }
63#elif defined(__WINDOWS__)
64 return((unsigned long) GetCurrentThreadId());
65#else
66 return((unsigned long) getpid());
67#endif
68}
69
70static inline MagickBooleanType IsMagickThreadEqual(const MagickThreadType id)
71{
72#if defined(MAGICKCORE_HAVE_PTHREAD)
73 if (pthread_equal(id,pthread_self()) != 0)
74 return(MagickTrue);
75#elif defined(__WINDOWS__)
76 if (id == GetCurrentThreadId())
77 return(MagickTrue);
78#else
79 if (id == getpid())
80 return(MagickTrue);
81#endif
82 return(MagickFalse);
83}
84
85/*
86 Lightweight OpenMP methods.
87*/
88static inline unsigned long GetOpenMPMaximumThreads(void)
89{
90#if defined(MAGICKCORE_OPENMP_SUPPORT)
91 return((unsigned long) omp_get_max_threads());
92#endif
93 return(1UL);
94}
95
96static inline long GetOpenMPThreadId(void)
97{
98#if defined(MAGICKCORE_OPENMP_SUPPORT)
99 return(omp_get_thread_num());
100#else
101 return(0);
102#endif
103}
104
105static inline void SetOpenMPMaximumThreads(const unsigned long threads)
106{
107#if defined(MAGICKCORE_OPENMP_SUPPORT)
108 omp_set_num_threads(threads);
109#else
110 (void) threads;
111#endif
112}
113
114#if defined(__cplusplus) || defined(c_plusplus)
115}
116#endif
117
118#endif