Synesis Software STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ...

pantheios/internal/threading.h

Go to the documentation of this file.
00001 /* /////////////////////////////////////////////////////////////////////////
00002  * File:        pantheios/internal/threading.h
00003  *
00004  * Purpose:     Detects whether the library is being built single- or
00005  *              multi-threaded.
00006  *
00007  * Created:     20th November 2007
00008  * Updated:     18th March 2012
00009  *
00010  * Home:        http://www.pantheios.org/
00011  *
00012  * Copyright (c) 2007-2012, Matthew Wilson and Synesis Software
00013  * All rights reserved.
00014  *
00015  * Redistribution and use in source and binary forms, with or without
00016  * modification, are permitted provided that the following conditions are
00017  * met:
00018  *
00019  * - Redistributions of source code must retain the above copyright notice,
00020  *   this list of conditions and the following disclaimer.
00021  * - Redistributions in binary form must reproduce the above copyright
00022  *   notice, this list of conditions and the following disclaimer in the
00023  *   documentation and/or other materials provided with the distribution.
00024  * - Neither the names of Matthew Wilson and Synesis Software nor the names
00025  *   of any contributors may be used to endorse or promote products derived
00026  *   from this software without specific prior written permission.
00027  *
00028  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00029  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
00030  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00031  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00032  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00033  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00034  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00035  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00036  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00037  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00038  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039  *
00040  * ////////////////////////////////////////////////////////////////////// */
00041 
00042 
00049 #ifndef PANTHEIOS_INCL_PANTHEIOS_INTERNAL_H_THREADING
00050 #define PANTHEIOS_INCL_PANTHEIOS_INTERNAL_H_THREADING
00051 
00052 /* /////////////////////////////////////////////////////////////////////////
00053  * Includes
00054  */
00055 
00056 #ifndef PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS
00057 # include <pantheios/pantheios.h>
00058 #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS */
00059 
00060 #ifndef PLATFORMSTL_INCL_PLATFORMSTL_H_PLATFORMSTL
00061 # include <platformstl/platformstl.h>
00062 #endif /* !PLATFORMSTL_INCL_PLATFORMSTL_H_PLATFORMSTL */
00063 #ifndef PLATFORMSTL_INCL_PLATFORMSTL_SYNCH_UTIL_H_FEATURES
00064 # include <platformstl/synch/util/features.h>
00065 #endif /* !PLATFORMSTL_INCL_PLATFORMSTL_SYNCH_UTIL_H_FEATURES */
00066 
00067 /* /////////////////////////////////////////////////////////////////////////
00068  * Feature discrimination
00069  */
00070 
00071 #ifdef PANTHEIOS_MT
00072 # undef PANTHEIOS_MT
00073 #endif /* PANTHEIOS_MT */
00074 #ifdef PANTHEIOS_MT_HAS_ATOMIC_INTEGER_OPERATIONS
00075 # undef PANTHEIOS_MT_HAS_ATOMIC_INTEGER_OPERATIONS
00076 #endif /* PANTHEIOS_MT_HAS_ATOMIC_INTEGER_OPERATIONS */
00077 
00078 /* Detect whether we're multithreaded */
00079 
00080 #if defined(PANTHEIOS_FORCE_MT)
00081 # define PANTHEIOS_MT
00082 #elif !defined(PANTHEIOS_NO_MT)
00083 # if defined(PLATFORMSTL_OS_IS_UNIX)
00084 #  if defined(UNIXSTL_USING_PTHREADS)
00085 #   define PANTHEIOS_MT
00086 #  endif /* UNIXSTL_USING_PTHREADS */
00087 # elif defined(PLATFORMSTL_OS_IS_WINDOWS)
00088 #  if defined(__MT__) || \
00089       defined(_REENTRANT) || \
00090       defined(_MT)
00091 #   define PANTHEIOS_MT
00092 #  endif /* ?? mt ?? */
00093 # else /* ? OS */
00094 #  error Platform is not yet discriminated
00095 # endif /* OS */
00096 #endif /* PANTHEIOS_FORCE_MT || PANTHEIOS_NO_MT */
00097 
00098 /* Detect whether, if we're multithreaded, we're using atomic integer ops */
00099 
00100 #ifdef PANTHEIOS_MT
00101 # if defined(PLATFORMSTL_HAS_ATOMIC_INTEGER_OPERATIONS) && \
00102      !defined(PANTHEIOS_FORCE_NO_ATOMIC_INTEGER_OPERATIONS)
00103 #  define PANTHEIOS_MT_HAS_ATOMIC_INTEGER_OPERATIONS
00104 # endif
00105 #endif /* PANTHEIOS_MT */
00106 
00107 /* ////////////////////////////////////////////////////////////////////// */
00108 
00109 #endif /* PANTHEIOS_INCL_PANTHEIOS_INTERNAL_H_THREADING */
00110 
00111 /* ///////////////////////////// end of file //////////////////////////// */

pantheios Library documentation © Matthew Wilson & Synesis Software, 2006-2011 SourceForge.net Logo