Skip to content

Commit 77ee03c

Browse files
majnemercopybara-github
authored andcommitted
Use int64_t for thread ids instead of int32_t
Apple's XNU kernel uses 64-bit thread ids. It is imprudent to assume that the top 32 bits are clear. PiperOrigin-RevId: 706972768
1 parent 936ef9e commit 77ee03c

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

tsl/platform/env.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ limitations under the License.
1717

1818
#include <sys/stat.h>
1919

20+
#include <cstdint>
2021
#include <deque>
2122
#include <utility>
2223
#include <vector>
2324

25+
#include "absl/strings/str_format.h"
2426
#include "tsl/platform/env_time.h"
2527
#include "tsl/platform/errors.h"
2628
#include "tsl/platform/host_info.h"
@@ -445,12 +447,12 @@ bool Env::LocalTempFilename(string* filename) {
445447
}
446448

447449
bool Env::CreateUniqueFileName(string* prefix, const string& suffix) {
448-
int32_t tid = GetCurrentThreadId();
450+
int64_t tid = GetCurrentThreadId();
449451
int32_t pid = GetProcessId();
450452
long long now_microsec = NowMicros(); // NOLINT
451453

452-
*prefix += strings::Printf("%s-%x-%d-%llx", port::Hostname().c_str(), tid,
453-
pid, now_microsec);
454+
absl::StrAppendFormat(prefix, "%s-%x-%d-%llx", port::Hostname(), tid, pid,
455+
now_microsec);
454456

455457
if (!suffix.empty()) {
456458
*prefix += suffix;

tsl/platform/env.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ class Env {
461461
// Posix: Returns pthread id which is only guaranteed to be unique within a
462462
// process.
463463
// Windows: Returns thread id which is unique.
464-
virtual int32 GetCurrentThreadId() = 0;
464+
virtual int64_t GetCurrentThreadId() = 0;
465465

466466
// Copies current thread name to "name". Returns true if success.
467467
virtual bool GetCurrentThreadName(std::string* name) = 0;
@@ -559,7 +559,9 @@ class EnvWrapper : public Env {
559559
absl::AnyInvocable<void()> fn) override {
560560
return target_->StartThread(thread_options, name, std::move(fn));
561561
}
562-
int32 GetCurrentThreadId() override { return target_->GetCurrentThreadId(); }
562+
int64_t GetCurrentThreadId() override {
563+
return target_->GetCurrentThreadId();
564+
}
563565
bool GetCurrentThreadName(std::string* name) override {
564566
return target_->GetCurrentThreadName(name);
565567
}

0 commit comments

Comments
 (0)