[Lldb-commits] [lldb] r367814 - Remove usage of usleep in generic code

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Mon Aug 5 01:23:25 PDT 2019


Author: labath
Date: Mon Aug  5 01:23:25 2019
New Revision: 367814

URL: http://llvm.org/viewvc/llvm-project?rev=367814&view=rev
Log:
Remove usage of usleep in generic code

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.

Modified:
    lldb/trunk/include/lldb/Host/windows/PosixApi.h
    lldb/trunk/source/Host/windows/Windows.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
    lldb/trunk/source/Target/Process.cpp

Modified: lldb/trunk/include/lldb/Host/windows/PosixApi.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/windows/PosixApi.h?rev=367814&r1=367813&r2=367814&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/windows/PosixApi.h (original)
+++ lldb/trunk/include/lldb/Host/windows/PosixApi.h Mon Aug  5 01:23:25 2019
@@ -80,7 +80,6 @@ int vasprintf(char **ret, const char *fm
 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);
 

Modified: lldb/trunk/source/Host/windows/Windows.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/Windows.cpp?rev=367814&r1=367813&r2=367814&view=diff
==============================================================================
--- lldb/trunk/source/Host/windows/Windows.cpp (original)
+++ lldb/trunk/source/Host/windows/Windows.cpp Mon Aug  5 01:23:25 2019
@@ -199,11 +199,6 @@ int strncasecmp(const char *s1, const ch
   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) {

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp?rev=367814&r1=367813&r2=367814&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp Mon Aug  5 01:23:25 2019
@@ -15,6 +15,7 @@
 #include <cstring>
 #include <mutex>
 #include <sstream>
+#include <thread>
 
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Threading.h"
@@ -280,10 +281,9 @@ bool GDBRemoteCommunicationServerPlatfor
         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())
@@ -302,10 +302,10 @@ bool GDBRemoteCommunicationServerPlatfor
         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())

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=367814&r1=367813&r2=367814&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Mon Aug  5 01:23:25 2019
@@ -1032,7 +1032,7 @@ Status ProcessGDBRemote::ConnectToDebugs
         if (retry_count >= max_retry_count)
           break;
 
-        usleep(100000);
+        std::this_thread::sleep_for(std::chrono::milliseconds(100));
       }
     }
   }
@@ -3591,7 +3591,8 @@ bool ProcessGDBRemote::MonitorDebugserve
   // 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();

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=367814&r1=367813&r2=367814&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Mon Aug  5 01:23:25 2019
@@ -4954,7 +4954,7 @@ Process::RunThreadPlan(ExecutionContext
 #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




More information about the lldb-commits mailing list