implement a platform neutral usleep() using C++11

This commit is contained in:
Axel Kohlmeyer
2021-10-05 17:58:27 -04:00
parent 528050aa08
commit fcdabe0002
3 changed files with 22 additions and 4 deletions

View File

@ -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;