@@ -1624,14 +1624,27 @@ TEST_F(pthread_CondWakeupTest, signal_clockwait_realtime_realtime) {
1624
1624
#endif // __BIONIC__
1625
1625
}
1626
1626
1627
- static void pthread_cond_timedwait_timeout_helper (clockid_t clock,
1627
+ static void pthread_cond_timedwait_timeout_helper (bool init_monotonic, clockid_t clock,
1628
1628
int (*wait_function)(pthread_cond_t * __cond,
1629
1629
pthread_mutex_t * __mutex,
1630
1630
const timespec* __timeout)) {
1631
1631
pthread_mutex_t mutex;
1632
1632
ASSERT_EQ (0 , pthread_mutex_init (&mutex, nullptr ));
1633
1633
pthread_cond_t cond;
1634
- ASSERT_EQ (0 , pthread_cond_init (&cond, nullptr ));
1634
+
1635
+ if (init_monotonic) {
1636
+ pthread_condattr_t attr;
1637
+ pthread_condattr_init (&attr);
1638
+
1639
+ ASSERT_EQ (0 , pthread_condattr_setclock (&attr, CLOCK_MONOTONIC));
1640
+ clockid_t clock;
1641
+ ASSERT_EQ (0 , pthread_condattr_getclock (&attr, &clock));
1642
+ ASSERT_EQ (CLOCK_MONOTONIC, clock);
1643
+
1644
+ ASSERT_EQ (0 , pthread_cond_init (&cond, &attr));
1645
+ } else {
1646
+ ASSERT_EQ (0 , pthread_cond_init (&cond, nullptr ));
1647
+ }
1635
1648
ASSERT_EQ (0 , pthread_mutex_lock (&mutex));
1636
1649
1637
1650
timespec ts;
@@ -1648,12 +1661,13 @@ static void pthread_cond_timedwait_timeout_helper(clockid_t clock,
1648
1661
}
1649
1662
1650
1663
TEST (pthread, pthread_cond_timedwait_timeout) {
1651
- pthread_cond_timedwait_timeout_helper (CLOCK_REALTIME, pthread_cond_timedwait);
1664
+ pthread_cond_timedwait_timeout_helper (false , CLOCK_REALTIME, pthread_cond_timedwait);
1652
1665
}
1653
1666
1654
1667
TEST (pthread, pthread_cond_timedwait_monotonic_np_timeout) {
1655
1668
#if defined(__BIONIC__)
1656
- pthread_cond_timedwait_timeout_helper (CLOCK_MONOTONIC, pthread_cond_timedwait_monotonic_np);
1669
+ pthread_cond_timedwait_timeout_helper (false , CLOCK_MONOTONIC, pthread_cond_timedwait_monotonic_np);
1670
+ pthread_cond_timedwait_timeout_helper (true , CLOCK_MONOTONIC, pthread_cond_timedwait_monotonic_np);
1657
1671
#else // __BIONIC__
1658
1672
GTEST_SKIP () << " pthread_cond_timedwait_monotonic_np not available" ;
1659
1673
#endif // __BIONIC__
@@ -1662,12 +1676,22 @@ TEST(pthread, pthread_cond_timedwait_monotonic_np_timeout) {
1662
1676
TEST (pthread, pthread_cond_clockwait_timeout) {
1663
1677
#if defined(__BIONIC__)
1664
1678
pthread_cond_timedwait_timeout_helper (
1665
- CLOCK_MONOTONIC,
1679
+ false , CLOCK_MONOTONIC,
1666
1680
[](pthread_cond_t * __cond, pthread_mutex_t * __mutex, const timespec* __timeout) {
1667
1681
return pthread_cond_clockwait (__cond, __mutex, CLOCK_MONOTONIC, __timeout);
1668
1682
});
1669
1683
pthread_cond_timedwait_timeout_helper (
1670
- CLOCK_REALTIME,
1684
+ true , CLOCK_MONOTONIC,
1685
+ [](pthread_cond_t * __cond, pthread_mutex_t * __mutex, const timespec* __timeout) {
1686
+ return pthread_cond_clockwait (__cond, __mutex, CLOCK_MONOTONIC, __timeout);
1687
+ });
1688
+ pthread_cond_timedwait_timeout_helper (
1689
+ false , CLOCK_REALTIME,
1690
+ [](pthread_cond_t * __cond, pthread_mutex_t * __mutex, const timespec* __timeout) {
1691
+ return pthread_cond_clockwait (__cond, __mutex, CLOCK_REALTIME, __timeout);
1692
+ });
1693
+ pthread_cond_timedwait_timeout_helper (
1694
+ true , CLOCK_REALTIME,
1671
1695
[](pthread_cond_t * __cond, pthread_mutex_t * __mutex, const timespec* __timeout) {
1672
1696
return pthread_cond_clockwait (__cond, __mutex, CLOCK_REALTIME, __timeout);
1673
1697
});
0 commit comments