+static struct filelock_data {
+ struct flist_head list;
+ struct fio_mutex lock;
+
+ struct flist_head free_list;
+ struct fio_filelock ffs[MAX_FILELOCKS];
+} *fld;
+
+static void put_filelock(struct fio_filelock *ff)
+{
+ flist_add(&ff->list, &fld->free_list);
+}
+
+static struct fio_filelock *__get_filelock(void)
+{
+ struct fio_filelock *ff;
+
+ if (flist_empty(&fld->free_list))
+ return NULL;
+
+ ff = flist_first_entry(&fld->free_list, struct fio_filelock, list);
+ flist_del_init(&ff->list);
+ return ff;
+}
+
+static struct fio_filelock *get_filelock(int trylock, int *retry)
+{
+ struct fio_filelock *ff;
+
+ do {
+ ff = __get_filelock();
+ if (ff || trylock)
+ break;
+
+ fio_mutex_up(&fld->lock);
+ usleep(1000);
+ fio_mutex_down(&fld->lock);
+ *retry = 1;
+ } while (1);
+
+ return ff;
+}