OW_ThreadImpl.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2001-2004 Vintela, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
00029 *******************************************************************************/
00030 
00036 #ifndef OW_THREADIMPL_HPP_INCLUDE_GUARD_
00037 #define OW_THREADIMPL_HPP_INCLUDE_GUARD_
00038 #include "OW_config.h"
00039 #include "OW_Types.hpp"
00040 #include "OW_ThreadTypes.hpp"
00041 
00042 // The classes and functions defined in this file are not meant for general
00043 // use, they are internal implementation details.  They may change at any time.
00044 
00045 namespace OW_NAMESPACE
00046 {
00047 
00048 /*----------------------------------
00049  * Definitions to support threading.
00050  -----------------------------------*/
00051 #define OW_THREAD_FLG_JOINABLE 0x000000001
00052 typedef Int32 (*ThreadFunction)(void*);
00059 namespace ThreadImpl
00060 {
00072    OW_COMMON_API int createThread(Thread_t& handle, ThreadFunction func,
00073       void* funcParm, UInt32 threadFlags);
00079    OW_COMMON_API void destroyThread(Thread_t& handle);
00086    inline bool sameThreads(const volatile Thread_t& handle1,
00087       const volatile Thread_t& handle2)
00088    {
00089    #if defined(OW_WIN32)
00090       return handle1 == handle2;
00091    #elif OW_HAVE_PTHREAD_H
00092       return pthread_equal(handle1, handle2);
00093    #endif
00094    }
00102    OW_COMMON_API void exitThread(Thread_t& handle, Int32 rval);
00106    inline Thread_t currentThread()
00107    {
00108 #if defined(OW_WIN32)
00109       return GetCurrentThreadId();
00110 #else
00111       return pthread_self();
00112 #endif
00113    }
00114 
00115 
00124    OW_COMMON_API UInt64 thread_t_ToUInt64(Thread_t thr);
00125 
00134    OW_COMMON_API int setThreadDetached(Thread_t& handle);
00143    OW_COMMON_API int joinThread(Thread_t& handle, Int32& rval);
00148    OW_COMMON_API void yield();
00154    OW_COMMON_API void sleep(UInt32 milliSeconds);
00158    inline OW_DEPRECATED void memoryBarrier()
00159    {
00160       // DEC/COMPAQ/HP Alpha
00161       #if defined(__alpha)
00162       __asm__ __volatile__("mb");
00163       #endif
00164       
00165       // Intel Itanium
00166       #if defined(__ia64__) || defined(__ia64)
00167       __asm__ __volatile__("mf");
00168       #endif
00169    }
00197    OW_COMMON_API void testCancel();
00198    OW_COMMON_API void saveThreadInTLS(void* pTheThread);
00199    OW_COMMON_API void sendSignalToThread(Thread_t threadID, int signo);
00200    OW_COMMON_API void cancel(Thread_t threadID);
00201 };
00202 
00203 } // end namespace OW_NAMESPACE
00204 
00205 #endif

Generated on Thu Feb 9 08:48:17 2006 for openwbem by  doxygen 1.4.6