file-lock.h revision 65f9a90ef5ed4c86fb9e44f22e472509126ae9f5
#ifndef FILE_LOCK_H
#define FILE_LOCK_H
#include <unistd.h>
#include <fcntl.h>
#define DEFAULT_LOCK_TIMEOUT 120
struct file_lock;
enum file_lock_method {
};
/* Parse lock method from given string. Returns TRUE if ok,
FALSE if name is unknown. */
/* Convert lock method to string. */
/* Lock the file. Returns 1 if successful, 0 if file is already locked,
or -1 if error. lock_type is F_WRLCK or F_RDLCK. */
enum file_lock_method lock_method,
/* Like file_try_lock(), but return the error message as a string instead
of logging it. Also when returning 0 an error message is returned. */
enum file_lock_method lock_method,
/* Like lock_try_lock(), but return 0 only after having tried to lock for
timeout_secs. */
enum file_lock_method lock_method,
unsigned int timeout_secs,
/* Like file_wait_lock(), but return the error message as a string instead
of logging it. Also when returning 0 an error message is returned. */
enum file_lock_method lock_method,
unsigned int timeout_secs,
/* Change the lock type. WARNING: This isn't an atomic operation!
The result is the same as file_unlock() + file_try_lock(). */
/* When the lock is freed, unlink() the file automatically. This can be useful
for files that are only created to exist as lock files. */
/* When the lock is freed, close the fd automatically. This can
be useful for files that are only created to exist as lock files. */
/* Unlock and free the lock. */
/* Free the lock without unlocking it (because you're closing the fd anyway). */
/* Returns the path given as parameter to file_*lock*(). */
/* Update lock file's path (after it gets renamed by the caller). This is
useful mainly together with file_lock_set_unlink_on_free(). */
/* Returns human-readable string containing the process that has the file
currently locked. Returns "" if unknown, otherwise " (string)". */
int lock_type);
/* Track the duration of a lock wait. */
void file_lock_wait_start(void);
void file_lock_wait_end(const char *lock_name);
/* Return how many microseconds has been spent on lock waiting. */
#endif