Skip to content

Commit

Permalink
win32: move usleep definition to unistd.h (#765)
Browse files Browse the repository at this point in the history
  • Loading branch information
slyshykO authored and xor-gate committed Feb 9, 2019
1 parent 8186d85 commit b9c315d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/gdbserver/gdb-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ int main(int argc, char** argv) {

do {
if (serve(sl, &state)) {
sleep (1); // don't go bezurk if serve returns with error
}
usleep (1 * 1000); // don't go bezurk if serve returns with error
}

/* in case serve() changed the connection */
sl = connected_stlink;
Expand Down
6 changes: 4 additions & 2 deletions src/mingw/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ char *win32_strsep (char **stringp, const char *delim)
}

#ifndef STLINK_HAVE_UNISTD_H
void usleep(DWORD waitTime)
int usleep(unsigned int waitTime)
{
if (waitTime >= 1000)
{
Expand All @@ -288,7 +288,7 @@ void usleep(DWORD waitTime)
SetWaitableTimer(timer, &dueTime, 0, NULL, NULL, 0);
WaitForSingleObject(timer, INFINITE);
CloseHandle(timer);
return;
return 0;
}
LARGE_INTEGER perf_cnt, start, now;

Expand All @@ -298,6 +298,8 @@ void usleep(DWORD waitTime)
do {
QueryPerformanceCounter((LARGE_INTEGER*) &now);
} while ((now.QuadPart - start.QuadPart) / (float)perf_cnt.QuadPart * 1000 * 1000 < waitTime);

return 0;
}
#endif

Expand Down
5 changes: 0 additions & 5 deletions src/mingw/mingw.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,4 @@ char *win32_strsep(char **stringp, const char *delim);
ssize_t win32_read_socket(SOCKET fd, void *buf, int n);
ssize_t win32_write_socket(SOCKET fd, void *buf, int n);

#ifndef STLINK_HAVE_UNISTD_H
static inline void sleep(unsigned ms) { Sleep(ms); }
void usleep(DWORD waitTime);
#endif

#endif //defined(__MINGW32__) || defined(_MSC_VER)
4 changes: 4 additions & 0 deletions src/win32/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;

#ifndef STLINK_HAVE_UNISTD_H
int usleep(unsigned int waitTime);
#endif

#endif /* unistd.h */

0 comments on commit b9c315d

Please sign in to comment.