Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-74953: _PyThread_cond_after() uses _PyTime_t#94056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
vstinner merged 2 commits intopython:mainfromvstinner:lock_abs_timeout
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from1 commit
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
NextNext commit
gh-74953: _PyThread_cond_after() uses _PyTime_t
pthread _PyThread_cond_after() implementation now uses the _PyTime_ttype to handle properly overflow: clamp to the maximum value.
  • Loading branch information
@vstinner
vstinner committedJun 21, 2022
commitbcc9696314d90f882be0579ceb6cdb252372b9f0
6 changes: 3 additions & 3 deletionsPython/condvar.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,9 +68,9 @@ void _PyThread_cond_after(long long us, struct timespec *abs);
Py_LOCAL_INLINE(int)
PyCOND_TIMEDWAIT(PyCOND_T *cond, PyMUTEX_T *mut, long long us)
{
struct timespecabs;
_PyThread_cond_after(us, &abs);
int ret = pthread_cond_timedwait(cond, mut, &abs);
struct timespecabs_timeout;
_PyThread_cond_after(us, &abs_timeout);
int ret = pthread_cond_timedwait(cond, mut, &abs_timeout);
if (ret == ETIMEDOUT) {
return 1;
}
Expand Down
26 changes: 13 additions & 13 deletionsPython/thread_pthread.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -156,23 +156,23 @@ _PyThread_cond_init(PyCOND_T *cond)
return pthread_cond_init(cond, condattr_monotonic);
}


void
_PyThread_cond_after(long long us, struct timespec *abs)
{
_PyTime_t timeout = _PyTime_FromMicrosecondsClamp(us);
_PyTime_t t;
#ifdef CONDATTR_MONOTONIC
if (condattr_monotonic) {
clock_gettime(CLOCK_MONOTONIC, abs);
abs->tv_sec += us / 1000000;
abs->tv_nsec += (us % 1000000) * 1000;
abs->tv_sec += abs->tv_nsec / 1000000000;
abs->tv_nsec %= 1000000000;
return;
t = _PyTime_GetMonotonicClock();
}
else
#endif

struct timespec ts;
MICROSECONDS_TO_TIMESPEC(us, ts);
*abs = ts;
{
t = _PyTime_GetSystemClock();
}
t = _PyTime_Add(t, timeout);
_PyTime_AsTimespec_clamp(t, abs);
}


Expand DownExpand Up@@ -639,17 +639,17 @@ PyThread_acquire_lock_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds,
goto unlock;
}

struct timespecabs;
struct timespecabs_timeout;
if (microseconds > 0) {
_PyThread_cond_after(microseconds, &abs);
_PyThread_cond_after(microseconds, &abs_timeout);
}
// Continue trying until we get the lock

// mut must be locked by me -- part of the condition protocol
while (1) {
if (microseconds > 0) {
status = pthread_cond_timedwait(&thelock->lock_released,
&thelock->mut, &abs);
&thelock->mut, &abs_timeout);
if (status == 1) {
break;
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp