Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions stl/inc/chrono
Original file line number Diff line number Diff line change
Expand Up @@ -2209,6 +2209,7 @@ namespace chrono {
auto [_Icu_version, _Zones, _Links] = _Tzdb_generate_time_zones();
auto [_Leap_sec, _All_ls_positive] = _Tzdb_generate_leap_seconds(0);
auto _Version = _Icu_version + "." + _STD to_string(_Leap_sec.size());
// TRANSITION, VSO-2228186, should call emplace_front with construction arguments
_Tzdb_list.emplace_front(tzdb{
_STD move(_Version), _STD move(_Zones), _STD move(_Links), _STD move(_Leap_sec), _All_ls_positive});
}
Expand Down Expand Up @@ -2241,12 +2242,6 @@ namespace chrono {
return _Tzdb_list.cend(); // no lock necessary for forward_list::cend()
}

template <class... _ArgsTy>
void _Emplace_front(_ArgsTy&&... _Args) {
_Unique_lock _Lk(_Tzdb_mutex);
_Tzdb_list.emplace_front(_STD forward<_ArgsTy>(_Args)...);
}

const tzdb& _Reload() {
_Unique_lock _Lk(_Tzdb_mutex);
auto [_Leap_sec, _All_ls_positive] = _Tzdb_generate_leap_seconds(_Tzdb_list.front().leap_seconds.size());
Expand All @@ -2266,6 +2261,7 @@ namespace chrono {
}

auto _Version = _Tzdb_update_version(_Tzdb.version, _Leap_sec.size());
// TRANSITION, VSO-2228186, should call emplace_front with construction arguments
_Tzdb_list.emplace_front(tzdb{
_STD move(_Version), _STD move(_Zones), _STD move(_Links), _STD move(_Leap_sec), _All_ls_positive});
}
Expand Down
51 changes: 51 additions & 0 deletions tests/std/include/timezone_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,54 @@ void run_tz_test(TestFunction test_function) {
assert(false);
}
}

namespace tzdb_list_hack { // non-portable hack into tzdb_list
template <auto>
struct member_hacker;

template <auto Val>
consteval auto get_hacked_memptr(member_hacker<Val>) noexcept {
return Val;
}

template <>
struct member_hacker<&tzdb_list::_Tzdb_list> {
friend consteval auto get_tzdb_list_inner_forward_list() noexcept {
return get_hacked_memptr(member_hacker{});
}
};

template <>
struct member_hacker<&tzdb_list::_Tzdb_mutex> {
friend consteval auto get_tzdb_list_inner_smtx() noexcept {
return get_hacked_memptr(member_hacker{});
}
};

consteval auto get_tzdb_list_inner_forward_list() noexcept;
consteval auto get_tzdb_list_inner_smtx() noexcept;

template <class... ArgsTypes>
void emplace_front(tzdb_list& tl, ArgsTypes&&... args) {
struct [[nodiscard]] unique_smtx_lock {
explicit unique_smtx_lock(_Smtx_t& mtx) : mtx_{&mtx} {
_Smtx_lock_exclusive(mtx_);
}

unique_smtx_lock(const unique_smtx_lock&) = delete;
unique_smtx_lock& operator=(const unique_smtx_lock&) = delete;

~unique_smtx_lock() {
_Smtx_unlock_exclusive(mtx_);
}

_Smtx_t* mtx_;
};

constexpr auto memptr_fwdlist = get_tzdb_list_inner_forward_list();
constexpr auto memptr_smtx = get_tzdb_list_inner_smtx();

unique_smtx_lock guard_{tl.*memptr_smtx};
(tl.*memptr_fwdlist).emplace_front(forward<ArgsTypes>(args)...);
}
} // namespace tzdb_list_hack
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ void test() {
leap_vec.emplace_back(sys_days{1d / January / 2020y}, false, leap_vec.back()._Elapsed());
leap_vec.emplace_back(sys_days{1d / January / 2021y}, true, leap_vec.back()._Elapsed());
my_tzdb._All_ls_positive = false;
get_tzdb_list()._Emplace_front(move(my_tzdb));
tzdb_list_hack::emplace_front(get_tzdb_list(), move(my_tzdb));
}

offset = 0s;
Expand All @@ -458,7 +458,7 @@ void test() {
leap_vec.emplace_back(sys_days{1d / January / year{i + 2020}}, false, leap_vec.back()._Elapsed());
}
leap_vec.emplace_back(sys_days{1d / January / 2060y}, true, leap_vec.back()._Elapsed());
get_tzdb_list()._Emplace_front(move(my_tzdb));
tzdb_list_hack::emplace_front(get_tzdb_list(), move(my_tzdb));
}

offset = 0s;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ void parse_timepoints() {
leap_vec.emplace_back(sys_days{1d / January / 2020y}, false, leap_vec.back()._Elapsed());
leap_vec.emplace_back(sys_days{1d / January / 2022y}, true, leap_vec.back()._Elapsed());
my_tzdb._All_ls_positive = false;
get_tzdb_list()._Emplace_front(move(my_tzdb));
tzdb_list_hack::emplace_front(get_tzdb_list(), move(my_tzdb));
}

utc_seconds ut_ref = utc_clock::from_sys(sys_days{1d / July / 1972y}) - 1s; // leap second insertion
Expand Down