Skip to content

Commit 87e4e90

Browse files
author
yuyangzi
committed
block_object syscall的超时时间都改为steady_clock
1 parent b142f2c commit 87e4e90

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

libgo/block_object.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ void BlockObject::CoBlockWait()
5454

5555
bool BlockObject::CoBlockWaitTimed(MininumTimeDurationType timeo)
5656
{
57-
auto begin = std::chrono::high_resolution_clock::now();
57+
auto begin = std::chrono::steady_clock::now();
5858
if (!g_Scheduler.IsCoroutine()) {
5959
while (!TryBlockWait() &&
6060
std::chrono::duration_cast<MininumTimeDurationType>
61-
(std::chrono::high_resolution_clock::now() - begin) < timeo)
61+
(std::chrono::steady_clock::now() - begin) < timeo)
6262
usleep(10 * 1000);
6363
return false;
6464
}

libgo/block_object.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ class BlockObject
3434
return CoBlockWaitTimed(std::chrono::duration_cast<MininumTimeDurationType>(duration));
3535
}
3636

37-
template <typename DeadlineType>
38-
bool CoBlockWaitTimed(DeadlineType deadline)
37+
template <typename Clock, typename Dur>
38+
bool CoBlockWaitTimed(std::chrono::time_point<Clock, Dur> const& deadline)
3939
{
40-
auto now = std::chrono::system_clock::now();
40+
auto now = Clock::now();
4141
if (deadline < now)
4242
return CoBlockWaitTimed(MininumTimeDurationType(0));
4343

4444
return CoBlockWaitTimed(std::chrono::duration_cast<MininumTimeDurationType>
45-
(deadline - std::chrono::system_clock::now()));
45+
(deadline - Clock::now()));
4646
}
4747

4848
bool TryBlockWait();

libgo/linux/linux_glibc_hook.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static ssize_t read_write_mode(int fd, OriginF fn, const char* hook_fn_name, uin
4444
timeval tv;
4545
fd_ctx->get_time_o(timeout_so, &tv);
4646
int timeout_ms = tv.tv_sec * 1000 + tv.tv_usec / 1000;
47-
auto start = std::chrono::system_clock::now();
47+
auto start = std::chrono::steady_clock::now();
4848

4949
retry:
5050
ssize_t n = fn(fd, std::forward<Args>(args)...);
@@ -54,7 +54,7 @@ static ssize_t read_write_mode(int fd, OriginF fn, const char* hook_fn_name, uin
5454
poll_timeout = -1;
5555
else {
5656
int expired = std::chrono::duration_cast<std::chrono::milliseconds>(
57-
std::chrono::system_clock::now() - start).count();
57+
std::chrono::steady_clock::now() - start).count();
5858
if (expired > timeout_ms) {
5959
errno = EAGAIN;
6060
return -1; // 已超时

0 commit comments

Comments
 (0)