修复事件等待指定时间BUG
This commit is contained in:
parent
d401f76669
commit
3c8cb3d382
|
@ -120,9 +120,29 @@ bool platform_event::wait(unsigned timeout)
|
|||
sem_wait(&sem_);
|
||||
else
|
||||
{
|
||||
struct timespec to;
|
||||
to.tv_sec = timeout / 1000;
|
||||
to.tv_nsec = (long)((timeout % 1000) * 1000 * 1000);
|
||||
struct timespec to = { 0 };
|
||||
//to.tv_sec = timeout / 1000;
|
||||
//to.tv_nsec = (long)((timeout % 1000) * 1000 * 1000);
|
||||
#if !(defined(WIN32) || defined(_WIN64))
|
||||
if (clock_gettime(CLOCK_REALTIME, &to) == -1)
|
||||
{
|
||||
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "clock_gettime failed: %d - %s\n", errno, strerror(errno));
|
||||
to.tv_sec = time(nullptr);
|
||||
}
|
||||
#endif
|
||||
/*/
|
||||
to.tv_nsec += (uint64_t)timeout * 1000 * 1000;
|
||||
to.tv_sec += to.tv_nsec / (uint64_t)1 * 1000 * 1000 * 1000;
|
||||
to.tv_nsec %= (uint64_t)1 * 1000 * 1000 * 1000;
|
||||
/*/
|
||||
to.tv_sec += timeout / 1000;
|
||||
to.tv_nsec += (uint64_t)(timeout % 1000) * 1000 * 1000;
|
||||
if(to.tv_nsec >= (uint64_t)1 * 1000 * 1000 * 1000)
|
||||
{
|
||||
to.tv_sec++;
|
||||
to.tv_nsec -= (uint64_t)1 * 1000 * 1000 * 1000;
|
||||
}
|
||||
////////*//////////////////
|
||||
waited = sem_timedwait(&sem_, &to) == 0;
|
||||
}
|
||||
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "platform_event(%s - %s) --> %s.\n", hg_log::format_ptr(this).c_str(), dbg_info_.c_str(), waited ? "waited" : "wait timeout");
|
||||
|
|
Loading…
Reference in New Issue