diff --git a/src/platform.cpp b/src/platform.cpp index 866e34b4cc..9039816f12 100644 --- a/src/platform.cpp +++ b/src/platform.cpp @@ -61,7 +61,9 @@ #endif //////////////////////////////////////////////////////////////////////// +#include #include +#include /* ------------------------------------------------------------------ */ @@ -172,6 +174,14 @@ double platform::walltime() return wtime; } +/* ---------------------------------------------------------------------- + sleep with microsecond resolution +------------------------------------------------------------------------ */ +void platform::usleep(int usec) +{ + return std::this_thread::sleep_for(std::chrono::microseconds(usec)); +} + /* ---------------------------------------------------------------------- get Operating system and version info ------------------------------------------------------------------------- */ diff --git a/src/platform.h b/src/platform.h index 97057006ad..31710caf2e 100644 --- a/src/platform.h +++ b/src/platform.h @@ -42,6 +42,15 @@ namespace platform { double walltime(); + + /*! Suspend execution for a microsecond interval + * + * This emulates the usleep(3) BSD function call also mentioned in POSIX.1-2001. + * + * \param usec length of delay in microseconds */ + + void usleep(int usec); + /*! Return string with the operating system version and architecture info * * \return string with info about the OS and the platform is is running on */ diff --git a/src/variable.cpp b/src/variable.cpp index 1981d000c3..22f792b5ec 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -39,7 +39,6 @@ #include #include #include -#include #include using namespace LAMMPS_NS; @@ -692,11 +691,11 @@ int Variable::next(int narg, char **arg) int seed = 12345 + universe->me + which[find(arg[0])]; if (!random) random = new RanMars(lmp,seed); int delay = (int) (1000000*random->uniform()); - usleep(delay); + platform::usleep(delay); while (1) { if (!rename("tmp.lammps.variable","tmp.lammps.variable.lock")) break; delay = (int) (1000000*random->uniform()); - usleep(delay); + platform::usleep(delay); } // if the file cannot be found, we may have a race with some @@ -719,7 +718,7 @@ int Variable::next(int narg, char **arg) break; } delay = (int) (1000000*random->uniform()); - usleep(delay); + platform::usleep(delay); } delete random; random = nullptr;