Line data Source code
1 :
2 : /* Copyright (c) 2010-2013, Stefan Eilemann <eile@eyescale.ch>
3 : *
4 : * This library is free software; you can redistribute it and/or modify it under
5 : * the terms of the GNU Lesser General Public License version 2.1 as published
6 : * by the Free Software Foundation.
7 : *
8 : * This library is distributed in the hope that it will be useful, but WITHOUT
9 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 : * details.
12 : *
13 : * You should have received a copy of the GNU Lesser General Public License
14 : * along with this library; if not, write to the Free Software Foundation, Inc.,
15 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 : */
17 :
18 : #include "threadID.h"
19 :
20 : #include "log.h"
21 :
22 : #include <pthread.h>
23 : #include <cstring> // for memset
24 :
25 : #include "detail/threadID.h"
26 :
27 : namespace lunchbox
28 : {
29 4682189 : ThreadID::ThreadID()
30 4682189 : : _impl( new detail::ThreadID )
31 : {
32 5003696 : memset( &_impl->pthread, 0, sizeof( pthread_t ));
33 5003696 : }
34 :
35 1409 : ThreadID::ThreadID( const ThreadID& from )
36 1409 : : _impl( new detail::ThreadID )
37 : {
38 1409 : _impl->pthread = from._impl->pthread;
39 1409 : }
40 :
41 10726998 : ThreadID::~ThreadID()
42 : {
43 5406146 : delete _impl;
44 5320852 : }
45 :
46 2324481 : ThreadID& ThreadID::operator = ( const ThreadID& from )
47 : {
48 2324481 : _impl->pthread = from._impl->pthread;
49 2324481 : return *this;
50 : }
51 :
52 3425517 : bool ThreadID::operator == ( const ThreadID& rhs ) const
53 : {
54 3425517 : return pthread_equal( _impl->pthread, rhs._impl->pthread );
55 : }
56 :
57 0 : bool ThreadID::operator != ( const ThreadID& rhs ) const
58 : {
59 0 : return !pthread_equal( _impl->pthread, rhs._impl->pthread );
60 : }
61 :
62 9807 : bool ThreadID::operator < ( const ThreadID& rhs ) const
63 : {
64 : #ifdef PTW32_VERSION
65 : return _impl->pthread.p < rhs._impl->pthread.p;
66 : #else
67 9807 : return _impl->pthread < rhs._impl->pthread;
68 : #endif
69 : }
70 :
71 0 : std::ostream& operator << ( std::ostream& os, const ThreadID& threadID )
72 : {
73 : #ifdef PTW32_VERSION
74 : os << threadID._impl->pthread.p;
75 : #else
76 0 : os << threadID._impl->pthread;
77 : #endif
78 0 : return os;
79 : }
80 :
81 72 : }
|