• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Third-Party Library Changelog
2
3## libc++ condition_variable::wait_for Changed
4
5**Access Level**
6
7Public API
8
9**Reason for Change**
10
11Before the change, the **condition_variable::wait_for** API of the libc++ library uses the system wall clock time, which is affected by changes to the system time and does not meet expectations.
12
13```
14template <class _Rep, class _Period>
15cv_status
16condition_variable::wait_for(unique_lock<mutex>& __lk,
17                             const chrono::duration<_Rep, _Period>& __d)
18{
19    ...
20
21#if defined(_LIBCPP_HAS_COND_CLOCKWAIT)
22    using __clock_tp_ns = time_point<steady_clock, nanoseconds>;
23    __ns_rep __now_count_ns = _VSTD::__safe_nanosecond_cast(__c_now.time_since_epoch()).count();
24#else
25    using __clock_tp_ns = time_point<system_clock, nanoseconds>;
26    __ns_rep __now_count_ns = _VSTD::__safe_nanosecond_cast(system_clock::now().time_since_epoch()).count();
27#endif
28
29    ...
30    __do_timed_wait(...);
31    ...
32}
33```
34
35```
36void
37condition_variable::__do_timed_wait(unique_lock<mutex>& lk,
38     chrono::time_point<chrono::system_clock, chrono::nanoseconds> tp) noexcept
39{
40    ...
41    nanoseconds d = tp.time_since_epoch();
42    if (d > nanoseconds(0x59682F000000E941))
43        d = nanoseconds(0x59682F000000E941);
44    ...
45    int ec = __libcpp_condvar_timedwait(&__cv_, lk.mutex()->native_handle(), &ts);
46    ...
47}
48```
49
50Here, 0x59682F000000E941 ns = 6442450944s = 2174-02-25 17:42:24. When the current system time plus the wait time specified in the **wait_for** API exceeds this value, it gets truncated, and **__libcpp_condvar_timedwait** returns immediately.
51
52**Impact of the Change**
53
54This change requires application adaptation.
55
56- Before the change, the **condition_variable::wait_for** API of the libc++ library uses the system wall clock time and is affected by changes to the system time. When the current system time plus the wait time specified in the API exceeded a specific value (0x59682F000000E941), the **condition_variable::wait_for** API returns immediately.
57
58- After the change, the **condition_variable::wait_for** API of the libc++ library uses a monotonically increasing time and is not affected by changes to the system time.
59
60**Start API Level**
61
629
63
64**Change Since**
65
66OpenHarmony SDK 6.0.0.39
67
68**Adaptation Guide**
69
70The libc++ library is released in binary form in the NDK (**libc++_shared.so**). The prototype of the **condition_variable::wait_for** API remains unchanged. Only the implementation has been aligned with the C++ standard and platforms like Android, iOS, and Windows. You can simply recompile your applications after updating the NDK.
71