Skip to content

Commit

Permalink
Merge pull request #420 from ennova/ruby-2-wait-cpu
Browse files Browse the repository at this point in the history
Fix high CPU usage when waiting with a timeout on Ruby < 3.0
  • Loading branch information
larskanis authored Jan 31, 2022
2 parents 28a3bf7 + 20bab5e commit 300e94e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ext/pg_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -2241,7 +2241,7 @@ pg_rb_thread_io_wait(VALUE io, VALUE events, VALUE timeout) {
GetOpenFile((io), fptr);
if( !NIL_P(timeout) ){
ptimeout.tv_sec = (time_t)(NUM2DBL(timeout));
ptimeout.tv_usec = (time_t)(NUM2DBL(timeout) - (double)ptimeout.tv_sec);
ptimeout.tv_usec = (time_t)((NUM2DBL(timeout) - (double)ptimeout.tv_sec) * 1e6);

gettimeofday(&currtime, NULL);
timeradd(&currtime, &ptimeout, &aborttime);
Expand Down Expand Up @@ -2332,7 +2332,7 @@ pg_rb_io_wait(VALUE io, VALUE events, VALUE timeout) {
GetOpenFile((io), fptr);
if( !NIL_P(timeout) ){
waittime.tv_sec = (time_t)(NUM2DBL(timeout));
waittime.tv_usec = (time_t)(NUM2DBL(timeout) - (double)waittime.tv_sec);
waittime.tv_usec = (time_t)((NUM2DBL(timeout) - (double)waittime.tv_sec) * 1e6);
}
res = rb_wait_for_single_fd(fptr->fd, NUM2UINT(events), NIL_P(timeout) ? NULL : &waittime);

Expand Down

0 comments on commit 300e94e

Please sign in to comment.