Move locking specific functions into their own source file

This commit is contained in:
jsteube
2016-09-06 19:08:46 +02:00
parent e4bf86dcbe
commit b8e47c2ba2
6 changed files with 78 additions and 40 deletions

View File

@@ -16,6 +16,7 @@
#include "ext_nvml.h"
#include "ext_xnvctrl.h"
#include "convert.h"
#include "locking.h"
#include "thread.h"
#include "timer.h"
#include "types.h"
@@ -33,35 +34,7 @@ extern hc_global_data_t data;
* system
*/
#ifdef F_SETLKW
void lock_file (FILE *fp)
{
struct flock lock;
memset (&lock, 0, sizeof (struct flock));
lock.l_type = F_WRLCK;
while (fcntl(fileno(fp), F_SETLKW, &lock))
{
if (errno != EINTR)
{
log_error ("ERROR: Failed acquiring write lock: %s", strerror (errno));
exit (-1);
}
}
}
void unlock_file (FILE *fp)
{
struct flock lock;
memset (&lock, 0, sizeof (struct flock));
lock.l_type = F_UNLCK;
fcntl(fileno(fp), F_SETLK, &lock);
}
#endif // F_SETLKW
#ifdef WIN
void fsync (int fd)