Resolved timer/duration variable name TODO.

This commit is contained in:
Pietro Gagliardi 2019-04-30 09:32:48 -04:00
parent 69000cda46
commit 25d4021269
2 changed files with 15 additions and 16 deletions

View File

@ -24,17 +24,17 @@ void testingprivRunWithTimeout(testingT *t, const char *file, long line, int64_t
{ {
char *timeoutstr; char *timeoutstr;
void (*prevsig)(int); void (*prevsig)(int);
struct itimerval timer, prevtimer; struct itimerval duration, prevDuration;
int setitimerError = 0; int setitimerError = 0;
timeoutstr = testingNsecString(timeout); timeoutstr = testingNsecString(timeout);
prevsig = signal(SIGALRM, onTimeout); prevsig = signal(SIGALRM, onTimeout);
timer.it_interval.tv_sec = 0; duration.it_interval.tv_sec = 0;
timer.it_interval.tv_usec = 0; duration.it_interval.tv_usec = 0;
timer.it_value.tv_sec = timeout / testingNsecPerSec; duration.it_value.tv_sec = timeout / testingNsecPerSec;
timer.it_value.tv_usec = (timeout % testingNsecPerSec) / testingNsecPerUsec; duration.it_value.tv_usec = (timeout % testingNsecPerSec) / testingNsecPerUsec;
if (setitimer(ITIMER_REAL, &timer, &prevtimer) != 0) { if (setitimer(ITIMER_REAL, &duration, &prevDuration) != 0) {
setitimerError = errno; setitimerError = errno;
testingprivTLogfFull(t, file, line, "error applying %s timeout: %s", comment, strerror(setitimerError)); testingprivTLogfFull(t, file, line, "error applying %s timeout: %s", comment, strerror(setitimerError));
testingTFail(t); testingTFail(t);
@ -51,7 +51,7 @@ void testingprivRunWithTimeout(testingT *t, const char *file, long line, int64_t
out: out:
if (setitimerError == 0) if (setitimerError == 0)
setitimer(ITIMER_REAL, &prevtimer, NULL); setitimer(ITIMER_REAL, &prevDuration, NULL);
signal(SIGALRM, prevsig); signal(SIGALRM, prevsig);
testingFreeNsecString(timeoutstr); testingFreeNsecString(timeoutstr);
if (failNowOnError) if (failNowOnError)
@ -60,12 +60,12 @@ out:
void testingSleep(int64_t nsec) void testingSleep(int64_t nsec)
{ {
struct timespec rqtp; struct timespec duration;
// TODO check errors, possibly falling back to usleep, setitimer/pause, or even sleep // TODO check errors, possibly falling back to usleep, setitimer/pause, or even sleep
rqtp.tv_sec = nsec / testingNsecPerSec; duration.tv_sec = nsec / testingNsecPerSec;
rqtp.tv_nsec = nsec % testingNsecPerSec; duration.tv_nsec = nsec % testingNsecPerSec;
nanosleep(&rqtp, NULL); nanosleep(&duration, NULL);
} }
struct testingThread { struct testingThread {

View File

@ -300,7 +300,7 @@ void testingprivRunWithTimeout(testingT *t, const char *file, long line, int64_t
MSG msg; MSG msg;
int closeTargetThread = 0; int closeTargetThread = 0;
uintptr_t timerThread = 0; uintptr_t timerThread = 0;
LARGE_INTEGER timer; LARGE_INTEGER duration;
int waitForTimerThread = 0; int waitForTimerThread = 0;
HRESULT hr; HRESULT hr;
@ -334,9 +334,9 @@ void testingprivRunWithTimeout(testingT *t, const char *file, long line, int64_t
goto out; goto out;
} }
timer.QuadPart = timeout / 100; duration.QuadPart = timeout / 100;
timer.QuadPart = -timer.QuadPart; duration.QuadPart = -duration.QuadPart;
hr = hrSetWaitableTimer(timeout_timer, &timer, 0, NULL, NULL, FALSE); hr = hrSetWaitableTimer(timeout_timer, &duration, 0, NULL, NULL, FALSE);
if (hr != S_OK) { if (hr != S_OK) {
testingprivTLogfFull(t, file, line, "error applying %s timeout: 0x%08I32X", comment, hr); testingprivTLogfFull(t, file, line, "error applying %s timeout: 0x%08I32X", comment, hr);
testingTFail(t); testingTFail(t);
@ -404,7 +404,6 @@ void testingSleep(int64_t nsec)
LARGE_INTEGER duration; LARGE_INTEGER duration;
HRESULT hr; HRESULT hr;
// TODO rename all the other durations that are timeout or timer to duration or nsec, both here and in the Unix/Darwin code
duration.QuadPart = nsec / 100; duration.QuadPart = nsec / 100;
duration.QuadPart = -duration.QuadPart; duration.QuadPart = -duration.QuadPart;
hr = hrCreateWaitableTimerW(NULL, TRUE, NULL, &timer); hr = hrCreateWaitableTimerW(NULL, TRUE, NULL, &timer);