projects
/
fio.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'delete-instead-of-unlink' of https://github.com/edigaryev/fio
[fio.git]
/
filelock.c
diff --git
a/filelock.c
b/filelock.c
index 6e84970fc0064cafaeb0945befd5f4355fd9cf7b..fd3a6b29e422830f62d35234715b290d57713908 100644
(file)
--- a/
filelock.c
+++ b/
filelock.c
@@
-11,22
+11,22
@@
#include "flist.h"
#include "filelock.h"
#include "smalloc.h"
#include "flist.h"
#include "filelock.h"
#include "smalloc.h"
-#include "
mutex
.h"
+#include "
fio_sem
.h"
#include "hash.h"
#include "log.h"
struct fio_filelock {
uint32_t hash;
#include "hash.h"
#include "log.h"
struct fio_filelock {
uint32_t hash;
- struct fio_
mutex
lock;
+ struct fio_
sem
lock;
struct flist_head list;
unsigned int references;
};
struct flist_head list;
unsigned int references;
};
-#define MAX_FILELOCKS 1
28
+#define MAX_FILELOCKS 1
024
static struct filelock_data {
struct flist_head list;
static struct filelock_data {
struct flist_head list;
- struct fio_
mutex
lock;
+ struct fio_
sem
lock;
struct flist_head free_list;
struct fio_filelock ffs[MAX_FILELOCKS];
struct flist_head free_list;
struct fio_filelock ffs[MAX_FILELOCKS];
@@
-58,9
+58,9
@@
static struct fio_filelock *get_filelock(int trylock, int *retry)
if (ff || trylock)
break;
if (ff || trylock)
break;
- fio_
mutex
_up(&fld->lock);
+ fio_
sem
_up(&fld->lock);
usleep(1000);
usleep(1000);
- fio_
mutex
_down(&fld->lock);
+ fio_
sem
_down(&fld->lock);
*retry = 1;
} while (1);
*retry = 1;
} while (1);
@@
-78,13
+78,13
@@
int fio_filelock_init(void)
INIT_FLIST_HEAD(&fld->list);
INIT_FLIST_HEAD(&fld->free_list);
INIT_FLIST_HEAD(&fld->list);
INIT_FLIST_HEAD(&fld->free_list);
- if (__fio_
mutex_init(&fld->lock, FIO_MUTEX
_UNLOCKED))
+ if (__fio_
sem_init(&fld->lock, FIO_SEM
_UNLOCKED))
goto err;
for (i = 0; i < MAX_FILELOCKS; i++) {
struct fio_filelock *ff = &fld->ffs[i];
goto err;
for (i = 0; i < MAX_FILELOCKS; i++) {
struct fio_filelock *ff = &fld->ffs[i];
- if (__fio_
mutex_init(&ff->lock, FIO_MUTEX
_UNLOCKED))
+ if (__fio_
sem_init(&ff->lock, FIO_SEM
_UNLOCKED))
goto err;
flist_add_tail(&ff->list, &fld->free_list);
}
goto err;
flist_add_tail(&ff->list, &fld->free_list);
}
@@
-101,7
+101,7
@@
void fio_filelock_exit(void)
return;
assert(flist_empty(&fld->list));
return;
assert(flist_empty(&fld->list));
- __fio_
mutex
_remove(&fld->lock);
+ __fio_
sem
_remove(&fld->lock);
while (!flist_empty(&fld->free_list)) {
struct fio_filelock *ff;
while (!flist_empty(&fld->free_list)) {
struct fio_filelock *ff;
@@
-109,7
+109,7
@@
void fio_filelock_exit(void)
ff = flist_first_entry(&fld->free_list, struct fio_filelock, list);
flist_del_init(&ff->list);
ff = flist_first_entry(&fld->free_list, struct fio_filelock, list);
flist_del_init(&ff->list);
- __fio_
mutex
_remove(&ff->lock);
+ __fio_
sem
_remove(&ff->lock);
}
sfree(fld);
}
sfree(fld);
@@
-172,26
+172,26
@@
static bool __fio_lock_file(const char *fname, int trylock)
hash = jhash(fname, strlen(fname), 0);
hash = jhash(fname, strlen(fname), 0);
- fio_
mutex
_down(&fld->lock);
+ fio_
sem
_down(&fld->lock);
ff = fio_hash_get(hash, trylock);
if (ff)
ff->references++;
ff = fio_hash_get(hash, trylock);
if (ff)
ff->references++;
- fio_
mutex
_up(&fld->lock);
+ fio_
sem
_up(&fld->lock);
if (!ff) {
if (!ff) {
- assert(
!
trylock);
+ assert(trylock);
return true;
}
if (!trylock) {
return true;
}
if (!trylock) {
- fio_
mutex
_down(&ff->lock);
+ fio_
sem
_down(&ff->lock);
return false;
}
return false;
}
- if (!fio_
mutex
_down_trylock(&ff->lock))
+ if (!fio_
sem
_down_trylock(&ff->lock))
return false;
return false;
- fio_
mutex
_down(&fld->lock);
+ fio_
sem
_down(&fld->lock);
/*
* If we raced and the only reference to the lock is us, we can
/*
* If we raced and the only reference to the lock is us, we can
@@
-202,10
+202,10
@@
static bool __fio_lock_file(const char *fname, int trylock)
ff = NULL;
}
ff = NULL;
}
- fio_
mutex
_up(&fld->lock);
+ fio_
sem
_up(&fld->lock);
if (ff) {
if (ff) {
- fio_
mutex
_down(&ff->lock);
+ fio_
sem
_down(&ff->lock);
return false;
}
return false;
}
@@
-229,12
+229,12
@@
void fio_unlock_file(const char *fname)
hash = jhash(fname, strlen(fname), 0);
hash = jhash(fname, strlen(fname), 0);
- fio_
mutex
_down(&fld->lock);
+ fio_
sem
_down(&fld->lock);
ff = fio_hash_find(hash);
if (ff) {
int refs = --ff->references;
ff = fio_hash_find(hash);
if (ff) {
int refs = --ff->references;
- fio_
mutex
_up(&ff->lock);
+ fio_
sem
_up(&ff->lock);
if (!refs) {
flist_del_init(&ff->list);
put_filelock(ff);
if (!refs) {
flist_del_init(&ff->list);
put_filelock(ff);
@@
-242,5
+242,5
@@
void fio_unlock_file(const char *fname)
} else
log_err("fio: file not found for unlocking\n");
} else
log_err("fio: file not found for unlocking\n");
- fio_
mutex
_up(&fld->lock);
+ fio_
sem
_up(&fld->lock);
}
}