Move locking specific functions into their own source file
This commit is contained in:
29
src/shared.c
29
src/shared.c
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user