fix doc example typo
[boost.git] / boost / interprocess / detail / os_thread_functions.hpp
blob4d2e3dd00d095d06ee1da037bb8360533b7db113
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2005-2008. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // See http://www.boost.org/libs/interprocess for documentation.
8 //
9 //////////////////////////////////////////////////////////////////////////////
11 #ifndef BOOST_INTERPROCESS_DETAIL_OS_THREAD_FUNCTIONS_HPP
12 #define BOOST_INTERPROCESS_DETAIL_OS_THREAD_FUNCTIONS_HPP
14 #include <boost/interprocess/detail/config_begin.hpp>
15 #include <boost/interprocess/detail/workaround.hpp>
17 #if (defined BOOST_INTERPROCESS_WINDOWS)
18 # include <boost/interprocess/detail/win32_api.hpp>
19 #else
20 # ifdef BOOST_HAS_UNISTD_H
21 # include <pthread.h>
22 # include <unistd.h>
23 # include <sched.h>
24 # else
25 # error Unknown platform
26 # endif
27 #endif
29 namespace boost {
30 namespace interprocess {
31 namespace detail{
33 #if (defined BOOST_INTERPROCESS_WINDOWS)
35 typedef unsigned long OS_process_id_t;
36 typedef unsigned long OS_thread_id_t;
37 typedef OS_thread_id_t OS_systemwide_thread_id_t;
39 //process
40 inline OS_process_id_t get_current_process_id()
41 { return winapi::get_current_process_id(); }
43 inline OS_process_id_t get_invalid_process_id()
44 { return OS_process_id_t(0); }
46 //thread
47 inline OS_thread_id_t get_current_thread_id()
48 { return winapi::get_current_thread_id(); }
50 inline OS_thread_id_t get_invalid_thread_id()
51 { return OS_thread_id_t(0xffffffff); }
53 inline bool equal_thread_id(OS_thread_id_t id1, OS_thread_id_t id2)
54 { return id1 == id2; }
56 inline void thread_yield()
57 { winapi::sched_yield(); }
59 //systemwide thread
60 inline OS_systemwide_thread_id_t get_current_systemwide_thread_id()
62 return get_current_thread_id();
65 inline void systemwide_thread_id_copy
66 (const volatile OS_systemwide_thread_id_t &from, volatile OS_systemwide_thread_id_t &to)
68 to = from;
71 inline bool equal_systemwide_thread_id(const OS_systemwide_thread_id_t &id1, const OS_systemwide_thread_id_t &id2)
73 return equal_thread_id(id1, id2);
76 inline OS_systemwide_thread_id_t get_invalid_systemwide_thread_id()
78 return get_invalid_thread_id();
81 #else //#if (defined BOOST_INTERPROCESS_WINDOWS)
83 typedef pthread_t OS_thread_id_t;
84 typedef pid_t OS_process_id_t;
86 struct OS_systemwide_thread_id_t
88 OS_systemwide_thread_id_t()
89 : pid(), tid()
92 OS_systemwide_thread_id_t(pid_t p, pthread_t t)
93 : pid(p), tid(t)
96 OS_systemwide_thread_id_t(const OS_systemwide_thread_id_t &x)
97 : pid(x.pid), tid(x.tid)
100 OS_systemwide_thread_id_t(const volatile OS_systemwide_thread_id_t &x)
101 : pid(x.pid), tid(x.tid)
104 OS_systemwide_thread_id_t & operator=(const OS_systemwide_thread_id_t &x)
105 { pid = x.pid; tid = x.tid; return *this; }
107 OS_systemwide_thread_id_t & operator=(const volatile OS_systemwide_thread_id_t &x)
108 { pid = x.pid; tid = x.tid; return *this; }
110 void operator=(const OS_systemwide_thread_id_t &x) volatile
111 { pid = x.pid; tid = x.tid; }
113 pid_t pid;
114 pthread_t tid;
117 inline void systemwide_thread_id_copy
118 (const volatile OS_systemwide_thread_id_t &from, volatile OS_systemwide_thread_id_t &to)
120 to.pid = from.pid;
121 to.tid = from.tid;
124 //process
125 inline OS_process_id_t get_current_process_id()
126 { return ::getpid(); }
128 inline OS_process_id_t get_invalid_process_id()
129 { return pid_t(0); }
131 //thread
132 inline OS_thread_id_t get_current_thread_id()
133 { return ::pthread_self(); }
135 inline OS_thread_id_t get_invalid_thread_id()
137 static pthread_t invalid_id;
138 return invalid_id;
141 inline bool equal_thread_id(OS_thread_id_t id1, OS_thread_id_t id2)
142 { return 0 != ::pthread_equal(id1, id2); }
144 inline void thread_yield()
145 { ::sched_yield(); }
147 //systemwide thread
148 inline OS_systemwide_thread_id_t get_current_systemwide_thread_id()
150 return OS_systemwide_thread_id_t(::getpid(), ::pthread_self());
153 inline bool equal_systemwide_thread_id(const OS_systemwide_thread_id_t &id1, const OS_systemwide_thread_id_t &id2)
155 return (0 != ::pthread_equal(id1.tid, id2.tid)) && (id1.pid == id2.pid);
158 inline OS_systemwide_thread_id_t get_invalid_systemwide_thread_id()
160 return OS_systemwide_thread_id_t(get_invalid_process_id(), get_invalid_thread_id());
163 #endif //#if (defined BOOST_INTERPROCESS_WINDOWS)
165 } //namespace detail{
166 } //namespace interprocess {
167 } //namespace boost {
169 #include <boost/interprocess/detail/config_end.hpp>
171 #endif //BOOST_INTERPROCESS_DETAIL_OS_THREAD_FUNCTIONS_HPP