implement a platform neutral usleep() using C++11
This commit is contained in:
@ -61,7 +61,9 @@
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <thread>
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
@ -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
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
@ -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 */
|
||||
|
||||
@ -39,7 +39,6 @@
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <unistd.h>
|
||||
#include <unordered_map>
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user