| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| |
| #include "iceberg/util/thread_util_internal.h" |
| |
| #if defined(_WIN32) |
| # include <windows.h> |
| #elif defined(__APPLE__) |
| # include <pthread.h> |
| #else |
| # include <unistd.h> |
| |
| # include <sys/syscall.h> |
| #endif |
| |
| namespace iceberg { |
| |
| uint64_t OsThreadId() noexcept { |
| static thread_local uint64_t tid = []() -> uint64_t { |
| #if defined(_WIN32) |
| return static_cast<uint64_t>(::GetCurrentThreadId()); |
| #elif defined(__APPLE__) |
| uint64_t id = 0; |
| pthread_threadid_np(nullptr, &id); |
| return id; |
| #else |
| return static_cast<uint64_t>(::syscall(SYS_gettid)); |
| #endif |
| }(); |
| return tid; |
| } |
| |
| } // namespace iceberg |