mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-10-14 11:50:28 +02:00
Build on RHEL9 docker image / build (push) Successful in 4m47s
Build on RHEL8 docker image / build (push) Successful in 5m3s
Build and Deploy on local RHEL9 / build (push) Successful in 2m5s
Build and Deploy on local RHEL8 / build (push) Successful in 5m0s
Run Simulator Tests on local RHEL9 / build (push) Successful in 20m42s
Run Simulator Tests on local RHEL8 / build (push) Successful in 24m10s
* added getThreadId
37 lines
795 B
C++
37 lines
795 B
C++
// SPDX-License-Identifier: LGPL-3.0-or-other
|
|
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
|
#pragma once
|
|
|
|
/**
|
|
* @file thread_utils.h
|
|
* @short id of the calling thread
|
|
*/
|
|
|
|
#include <sys/types.h> // pid_t
|
|
|
|
#if defined(__APPLE__)
|
|
#include <cstdint>
|
|
#include <pthread.h>
|
|
#elif defined(__linux__)
|
|
#include <sys/syscall.h>
|
|
#include <unistd.h>
|
|
#else
|
|
#error "getThreadId is not implemented for this platform"
|
|
#endif
|
|
|
|
namespace sls {
|
|
|
|
/** Kernel thread id of the calling thread. On macOS the 64-bit id is
|
|
* truncated to pid_t. */
|
|
inline pid_t getThreadId() noexcept {
|
|
#if defined(__APPLE__)
|
|
std::uint64_t tid = 0;
|
|
pthread_threadid_np(nullptr, &tid);
|
|
return static_cast<pid_t>(tid);
|
|
#else
|
|
return static_cast<pid_t>(::syscall(SYS_gettid));
|
|
#endif
|
|
}
|
|
|
|
} // namespace sls
|