forked from nbauernfeind/deephaven-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cpp-client): Add GetTidAsString as a utility function (deephaven…
…#5843) Add `GetTidAsString()` as a utility function. Note that the previous version of this code was `inline`. However, on the Windows platform, making it inline involves pulling in some windows includes including `windows.h`. The problem with including `windows.h` is that it defines some macros that might conflict. In particular it defines the `min` and `max` macros that definitely conflict. In order to free ourselves and our Windows customers from seeing the conflicts that might arise, we isolate the Windows-specific code in a .cc file rather than including `windows.h` in a .h file. There are other approaches that would work too, such as defining `NOMINMAX` or changing all of our calls that look like `min()` and `max()` to have extra parentheses: `(min)()` and `(max)()`. However in my opinion, isolating this Windows-specific code in one .cc file was simplest for now.
- Loading branch information
Showing
4 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
cpp-client/deephaven/dhcore/src/utility/utility_platform_specific.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending | ||
*/ | ||
#include <string> | ||
#include "deephaven/dhcore/utility/utility.h" | ||
|
||
// for GetTidAsString | ||
#if defined(__linux__) | ||
#include <unistd.h> | ||
#include <sys/syscall.h> | ||
#elif defined(_WIN32) | ||
#include <windows.h> | ||
#endif | ||
|
||
namespace deephaven::dhcore::utility { | ||
[[nodiscard]] std::string GetTidAsString() { | ||
#if defined(__linux__) | ||
const pid_t tid = syscall(__NR_gettid); // this is more portable than gettid(). | ||
return std::to_string(tid); | ||
#elif defined(_WIN32) | ||
auto tid = GetCurrentThreadId(); | ||
return std::to_string(tid); | ||
#else | ||
#error "Don't have a way to getting thread id on your platform" | ||
#endif | ||
} | ||
} // namespace deephaven::dhcore::utility |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters