LSSTApplications  20.0.0
LSSTDataManagementBasePackage
lwpID.cc
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2016 LSST Corporation.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 
24 // System Headers
25 #include <iostream>
26 #include <string>
27 #if defined(__linux__)
28 #include <sys/syscall.h>
29 #include <unistd.h>
30 #elif defined(__APPLE__)
31 #include <pthread.h>
32 #else
33 #include <atomic>
34 #endif
35 
36 namespace lsst {
37 namespace log {
38 namespace detail {
39 
40 unsigned lwpID() {
41 
42 #if defined(__linux__)
43 
44  // On Linux have to do syscall
45  auto lwp = syscall(SYS_gettid);
46 
47 #elif defined(__APPLE__)
48 
49  // OSX has a special Pthreads function to find out PID
50  auto lwp = pthread_mach_thread_np(pthread_self());
51 
52 #else
53 
54  // On all other system just generate incremental number and call it LWP
55  static std::atomic<unsigned> threadNum(0);
56  thread_local static auto lwp = ++threadNum;
57 
58 #endif
59 
60  return static_cast<unsigned>(lwp);
61 }
62 
63 }}} // namespace lsst::log::detail
lsst::log::detail::lwpID
unsigned lwpID()
Definition: lwpID.cc:40
std::atomic
STL class.
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
base.packages.log
log
Definition: packages.py:35