blocxx
ThreadImpl.hpp
Go to the documentation of this file.
1/*******************************************************************************
2* Copyright (C) 2005, Vintela, Inc. All rights reserved.
3* Copyright (C) 2006, Novell, Inc. All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7*
8* * Redistributions of source code must retain the above copyright notice,
9* this list of conditions and the following disclaimer.
10* * Redistributions in binary form must reproduce the above copyright
11* notice, this list of conditions and the following disclaimer in the
12* documentation and/or other materials provided with the distribution.
13* * Neither the name of
14* Vintela, Inc.,
15* nor Novell, Inc.,
16* nor the names of its contributors or employees may be used to
17* endorse or promote products derived from this software without
18* specific prior written permission.
19*
20* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30* POSSIBILITY OF SUCH DAMAGE.
31*******************************************************************************/
32
33
39#ifndef BLOCXX_THREADIMPL_HPP_INCLUDE_GUARD_
40#define BLOCXX_THREADIMPL_HPP_INCLUDE_GUARD_
41#include "blocxx/BLOCXX_config.h"
42#include "blocxx/Types.hpp"
44#include "blocxx/Timeout.hpp"
45
46#ifdef BLOCXX_NCR
47#ifndef PTHREAD_ONCE_INIT
48#define PTHREAD_ONCE_INIT pthread_once_init
49#endif
50#endif
51
52
53// The classes and functions defined in this file are not meant for general
54// use, they are internal implementation details. They may change at any time.
55
56namespace BLOCXX_NAMESPACE
57{
58
59/*----------------------------------
60 * Definitions to support threading.
61 -----------------------------------*/
62#define BLOCXX_THREAD_FLG_JOINABLE 0x000000001
63typedef Int32 (*ThreadFunction)(void*);
70namespace ThreadImpl
71{
83 BLOCXX_COMMON_API int createThread(Thread_t& handle, ThreadFunction func,
84 void* funcParm, UInt32 threadFlags);
90 BLOCXX_COMMON_API void destroyThread(Thread_t& handle);
97 inline bool sameThreads(const volatile Thread_t& handle1,
98 const volatile Thread_t& handle2)
99 {
100 #if defined(BLOCXX_WIN32)
101 return handle1 == handle2;
102 #elif BLOCXX_USE_PTHREAD
103 return pthread_equal(handle1, handle2);
104 #endif
105 }
113 BLOCXX_COMMON_API void exitThread(Thread_t& handle, Int32 rval);
117 inline Thread_t currentThread()
118 {
119#if defined(BLOCXX_WIN32)
120 return GetCurrentThreadId();
121#else
122 return pthread_self();
123#endif
124 }
125
126
135 BLOCXX_COMMON_API UInt64 thread_t_ToUInt64(Thread_t thr);
136
145 BLOCXX_COMMON_API int setThreadDetached(Thread_t& handle);
154 BLOCXX_COMMON_API int joinThread(Thread_t& handle, Int32& rval);
159 BLOCXX_COMMON_API void yield();
165 BLOCXX_COMMON_API void sleep(UInt32 milliSeconds);
171 BLOCXX_COMMON_API void sleep(const Timeout& timeout);
199 BLOCXX_COMMON_API void testCancel();
200 BLOCXX_COMMON_API void saveThreadInTLS(void* pTheThread);
201 BLOCXX_COMMON_API void sendSignalToThread(Thread_t threadID, int signo);
202 BLOCXX_COMMON_API void cancel(Thread_t threadID);
203};
204
205} // end namespace BLOCXX_NAMESPACE
206
207#endif
A timeout can be absolute, which means that it will happen at the specified DateTime.
Definition Timeout.hpp:56
BLOCXX_COMMON_API void testCancel()
Test if this thread has been cancelled.
BLOCXX_COMMON_API void destroyThread(Thread_t &handle)
Destroy any resources associated with a thread that was created with the createThread method.
BLOCXX_COMMON_API int joinThread(Thread_t &handle, Int32 &rval)
Join a thread that has been previously set to joinable.
bool sameThreads(const volatile Thread_t &handle1, const volatile Thread_t &handle2)
Check two platform dependant thread types for equality.
BLOCXX_COMMON_API UInt64 thread_t_ToUInt64(Thread_t thr)
Convert a Thread_t to an UInt64.
BLOCXX_COMMON_API int createThread(Thread_t &handle, ThreadFunction func, void *funcParm, UInt32 threadFlags)
Starts a thread running the given function.
BLOCXX_COMMON_API int setThreadDetached(Thread_t &handle)
Set a thread that was previously in the joinable state to a detached state.
BLOCXX_COMMON_API void cancel(Thread_t threadID)
void yield()
Voluntarily yield to the processor giving the next thread in the chain the opportunity to run.
void sleep(UInt32 milliSeconds)
Suspend execution of the current thread until the given number of milliSeconds have elapsed.
BLOCXX_COMMON_API void exitThread(Thread_t &handle, Int32 rval)
Exit thread method.
BLOCXX_COMMON_API void saveThreadInTLS(void *pTheThread)
BLOCXX_COMMON_API void sendSignalToThread(Thread_t threadID, int signo)
Taken from RFC 1321.
Int32(* ThreadFunction)(void *)