thread-private.h

Go to the documentation of this file.
00001 /*
00002   Copyright 1999-2009 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 private methods for internal threading.
00017 */
00018 #ifndef _MAGICKCORE_THREAD_PRIVATE_H
00019 #define _MAGICKCORE_THREAD_PRIVATE_H
00020 
00021 #if defined(__cplusplus) || defined(c_plusplus)
00022 extern "C" {
00023 #endif
00024 
00025 #include <magick/thread_.h>
00026 
00027 #if defined(MAGICKCORE_HAVE_PTHREAD)
00028   typedef pthread_mutex_t MagickMutexType;
00029 #elif defined(__WINDOWS__)
00030   typedef CRITICAL_SECTION MagickMutexType;
00031 #else
00032   typedef unsigned long MagickMutexType;
00033 #endif
00034 
00035 static inline MagickThreadType GetMagickThreadId(void)
00036 {
00037 #if defined(MAGICKCORE_HAVE_PTHREAD)
00038   return(pthread_self());
00039 #elif defined(__WINDOWS__)
00040   return(GetCurrentThreadId());
00041 #else
00042   return(getpid());
00043 #endif
00044 }
00045 
00046 static inline unsigned long GetMagickThreadSignature(void)
00047 {
00048 #if defined(MAGICKCORE_HAVE_PTHREAD)
00049   {
00050     union
00051     {
00052       pthread_t
00053         id;
00054 
00055       unsigned long
00056         signature;
00057     } magick_thread;
00058 
00059     magick_thread.signature=0UL;
00060     magick_thread.id=pthread_self();
00061     return(magick_thread.signature);
00062   }
00063 #elif defined(__WINDOWS__)
00064   return((unsigned long) GetCurrentThreadId());
00065 #else
00066   return((unsigned long) getpid());
00067 #endif
00068 }
00069 
00070 static inline MagickBooleanType IsMagickThreadEqual(const MagickThreadType id)
00071 {
00072 #if defined(MAGICKCORE_HAVE_PTHREAD)
00073   if (pthread_equal(id,pthread_self()) != 0)
00074     return(MagickTrue);
00075 #elif defined(__WINDOWS__)
00076   if (id == GetCurrentThreadId())
00077     return(MagickTrue);
00078 #else
00079   if (id == getpid())
00080     return(MagickTrue);
00081 #endif
00082   return(MagickFalse);
00083 }
00084 
00085 /*
00086   Lightweight OpenMP methods.
00087 */
00088 static inline unsigned long GetOpenMPMaximumThreads(void)
00089 {
00090 #if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP >= 200203)
00091   {
00092     static unsigned long
00093       maximum_threads = 1UL;
00094 
00095     if (omp_get_max_threads() > (long) maximum_threads)
00096       maximum_threads=omp_get_max_threads();
00097     return(maximum_threads);
00098   }
00099 #endif
00100   return(1UL);
00101 }
00102 
00103 static inline long GetOpenMPThreadId(void)
00104 {
00105 #if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP >= 200203)
00106   return(omp_get_thread_num());
00107 #else
00108   return(0);
00109 #endif
00110 }
00111 
00112 static inline void SetOpenMPMaximumThreads(const unsigned long threads)
00113 {
00114 #if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP >= 200203)
00115   omp_set_num_threads(threads);
00116 #else
00117   (void) threads;
00118 #endif
00119 }
00120 
00121 static inline void SetOpenMPNested(const int value)
00122 {
00123 #if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP >= 200203)
00124   omp_set_nested(value);
00125 #else
00126   (void) value;
00127 #endif
00128 }
00129 
00130 #if defined(__cplusplus) || defined(c_plusplus)
00131 }
00132 #endif
00133 
00134 #endif

Generated on 19 Nov 2009 for MagickCore by  doxygen 1.6.1