Files
slsDetectorPackage/slsSupportLib/include/sls/thread_utils.h
T
Erik Fröjdh c87cc7e515
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
Mac compatible version of gettid() (#1585)
* added getThreadId
2026-10-13 08:23:56 +02:00

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