Skip to content

Commit

Permalink
Fix photon_std::thread::id default constructor (#573)
Browse files Browse the repository at this point in the history
  • Loading branch information
beef9999 authored Sep 26, 2024
1 parent 0ed102e commit a9e38cc
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions thread/std-compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ inline uint64_t __duration_to_microseconds(const ::std::chrono::duration<Rep, Pe

class thread {
public:
using id = photon::thread*;

thread() = default;

~thread() {
Expand Down Expand Up @@ -93,6 +91,17 @@ class thread {
return m_th != nullptr;
}

class id {
public:
id() = default;
id(photon::thread* th_id) : th_id_(th_id) {}
bool operator==(const id& rhs) const { return th_id_ == rhs.th_id_; }
bool operator!=(const id& rhs) const { return !(rhs == *this); }
uint64_t value() const { return uint64_t(th_id_); }
private:
photon::thread* th_id_ = nullptr;
};

id get_id() const noexcept {
return m_th;
}
Expand Down Expand Up @@ -424,4 +433,12 @@ inline void swap(photon_std::unique_lock<Mutex>& lhs, photon_std::unique_lock<Mu
lhs.swap(rhs);
}

template<>
struct hash<photon_std::thread::id> {
size_t operator()(const photon_std::thread::id& x) const {
hash<uint64_t> hasher;
return hasher(x.value());
}
};

}

0 comments on commit a9e38cc

Please sign in to comment.