Skip to content

Commit

Permalink
Use timeradd|sub() macros instead of functions (patch alus).
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Ford committed Jan 20, 2011
1 parent 8aaeba0 commit 95febb8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
22 changes: 0 additions & 22 deletions vm/missing/windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,4 @@ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp) {
return 0;
}

#define RBX_USEC_PER_SEC 1000000

void timeradd(struct timeval *a, struct timeval *b, struct timeval *res) {
res->tv_sec = a->tv_sec + b->tv_sec;
res->tv_usec = a->tv_usec + b->tv_usec;

if(res->tv_usec >= RBX_USEC_PER_SEC) {
res->tv_sec++;
res->tv_usec -= RBX_USEC_PER_SEC;
}
}

void timersub(struct timeval *a, struct timeval *b, struct timeval *res) {
res->tv_sec = a->tv_sec - b->tv_sec;
res->tv_usec = a->tv_usec - b->tv_usec;

if(res->tv_usec < 0) {
res->tv_sec--;
res->tv_usec += RBX_USEC_PER_SEC;
}
}

#endif
22 changes: 20 additions & 2 deletions vm/windows_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,26 @@ char* realpath(const char* file_name, char* resolved_name);
#define timezone _timezone

int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
void timeradd(struct timeval *a, struct timeval *b, struct timeval *res);
void timersub(struct timeval *a, struct timeval *b, struct timeval *res);

#define RBX_USEC_PER_SEC 1000000
#define timeradd(tvp, uvp, vvp) \
do { \
(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
if ((vvp)->tv_usec >= RBX_USEC_PER_SEC) { \
(vvp)->tv_sec++; \
(vvp)->tv_usec -= RBX_USEC_PER_SEC; \
} \
} while (0)
#define timersub(tvp, uvp, vvp) \
do { \
(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
if ((vvp)->tv_usec < 0) { \
(vvp)->tv_sec--; \
(vvp)->tv_usec += RBX_USEC_PER_SEC; \
} \
} while (0)

#endif // RBX_WINDOWS

Expand Down

0 comments on commit 95febb8

Please sign in to comment.