Skip to content

Commit

Permalink
Remove usage of usleep in generic code
Browse files Browse the repository at this point in the history
This function is not portable, and there are only a handful of usages of
it anyway. Replacing it with std::this_thread::sleep_for enables us to
get rid of the compatibility code in PosixApi.h.

llvm-svn: 367814
  • Loading branch information
labath committed Aug 5, 2019
1 parent 801d330 commit 3d4f765
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 13 deletions.
1 change: 0 additions & 1 deletion lldb/include/lldb/Host/windows/PosixApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ int vasprintf(char **ret, const char *fmt, va_list ap);
char *strcasestr(const char *s, const char *find);
char *realpath(const char *name, char *resolved);

int usleep(uint32_t useconds);
char *basename(char *path);
char *dirname(char *path);

Expand Down
5 changes: 0 additions & 5 deletions lldb/source/Host/windows/Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,6 @@ int strncasecmp(const char *s1, const char *s2, size_t n) {
return strnicmp(s1, s2, n);
}

int usleep(uint32_t useconds) {
Sleep(useconds / 1000);
return 0;
}

#if _MSC_VER < 1900
namespace lldb_private {
int vsnprintf(char *buffer, size_t count, const char *format, va_list argptr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <cstring>
#include <mutex>
#include <sstream>
#include <thread>

#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Threading.h"
Expand Down Expand Up @@ -280,10 +281,9 @@ bool GDBRemoteCommunicationServerPlatform::KillSpawnedProcess(lldb::pid_t pid) {
return true;
}
}
usleep(10000);
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}

// check one more time after the final usleep
{
std::lock_guard<std::recursive_mutex> guard(m_spawned_pids_mutex);
if (m_spawned_pids.find(pid) == m_spawned_pids.end())
Expand All @@ -302,10 +302,10 @@ bool GDBRemoteCommunicationServerPlatform::KillSpawnedProcess(lldb::pid_t pid) {
return true;
}
}
usleep(10000);
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}

// check one more time after the final usleep Scope for locker
// check one more time after the final sleep
{
std::lock_guard<std::recursive_mutex> guard(m_spawned_pids_mutex);
if (m_spawned_pids.find(pid) == m_spawned_pids.end())
Expand Down
5 changes: 3 additions & 2 deletions lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ Status ProcessGDBRemote::ConnectToDebugserver(llvm::StringRef connect_url) {
if (retry_count >= max_retry_count)
break;

usleep(100000);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
}
Expand Down Expand Up @@ -3591,7 +3591,8 @@ bool ProcessGDBRemote::MonitorDebugserverProcess(
// Sleep for a half a second to make sure our inferior process has time to
// set its exit status before we set it incorrectly when both the debugserver
// and the inferior process shut down.
usleep(500000);
std::this_thread::sleep_for(std::chrono::milliseconds(500));

// If our process hasn't yet exited, debugserver might have died. If the
// process did exit, then we are reaping it.
const StateType state = process_sp->GetState();
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Target/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4954,7 +4954,7 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx,
#ifdef LLDB_RUN_THREAD_HALT_WITH_EVENT
// See comment above...
if (miss_first_event) {
usleep(1000);
std::this_thread::sleep_for(std::chrono::milliseconds(1));
miss_first_event = false;
got_event = false;
} else
Expand Down

0 comments on commit 3d4f765

Please sign in to comment.