Skip to content

Commit b68d37f

Browse files
committed
mac 兼容
1 parent 0e862c8 commit b68d37f

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

log4z.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -950,10 +950,34 @@ bool CSem::Wait(int timeout)
950950
}
951951
else
952952
{
953-
timespec ts;
954-
ts.tv_sec = time(NULL) + timeout/1000;
955-
ts.tv_nsec = (timeout%1000)*1000000;
956-
return (sem_timedwait(&m_semid, &ts) == 0);
953+
struct timeval tm;
954+
gettimeofday(&tm, NULL);
955+
long long endtime = tm.tv_sec *1000 + tm.tv_usec/1000 + timeout;
956+
do
957+
{
958+
SleepMillisecond(50);
959+
int ret = sem_trywait(&m_semid);
960+
if (ret == 0)
961+
{
962+
return true;
963+
}
964+
struct timeval tv_cur;
965+
gettimeofday(&tv_cur, NULL);
966+
if (tv_cur.tv_sec*1000 + tv_cur.tv_usec/1000 > endtime)
967+
{
968+
return false;
969+
}
970+
971+
if (ret == -1 && errno == EAGAIN)
972+
{
973+
continue;
974+
}
975+
else
976+
{
977+
return false;
978+
}
979+
} while (true);
980+
return false;
957981
}
958982
#endif
959983
return true;

0 commit comments

Comments
 (0)