## camel-lock

camel-lock

## Functions

gint | camel_lock_dot ()
gint | camel_lock_fcntl ()
gint | camel_lock_flock ()
void | camel_unlock_dot ()
void | camel_unlock_fcntl ()
void | camel_unlock_flock ()
gint | camel_lock_folder ()
void | camel_unlock_folder ()

## Types and Values

#define | CAMEL_LOCK_DOT_RETRY
#define | CAMEL_LOCK_DOT_DELAY
#define | CAMEL_LOCK_DOT_STALE
#define | CAMEL_LOCK_RETRY
#define | CAMEL_LOCK_DELAY
enum | CamelLockType

## Description

## Functions

### camel_lock_dot ()

    gint
    camel_lock_dot (const gchar *path,
                    GError **error);

Create an exclusive lock using .lock semantics. All locks are equivalent to write locks (exclusive).

The function does nothing and returns success (zero), when dot locking had not been compiled.

#### Parameters

path | a path to lock |
error | return location for a GError, or `NULL` |

#### Returns

-1 on error, sets `ex` appropriately.

### camel_lock_fcntl ()

    gint
    camel_lock_fcntl (gint fd,
                      CamelLockType type,
                      GError **error);

Create a lock using fcntl(2).

`type` is CAMEL_LOCK_WRITE or CAMEL_LOCK_READ, to create exclusive or shared read locks

The function does nothing and returns success (zero), when fcntl locking had not been compiled.

#### Parameters

fd | a file descriptor |
type | a CamelLockType |
error | return location for a GError, or `NULL` |

#### Returns

-1 on error.

### camel_lock_flock ()

    gint
    camel_lock_flock (gint fd,
                      CamelLockType type,
                      GError **error);

Create a lock using flock(2).

`type` is CAMEL_LOCK_WRITE or CAMEL_LOCK_READ, to create exclusive or shared read locks

The function does nothing and returns success (zero), when flock locking had not been compiled.

#### Parameters

fd | a file descriptor |
type | a CamelLockType |
error | return location for a GError, or `NULL` |

#### Returns

-1 on error.

### camel_unlock_dot ()

    void
    camel_unlock_dot (const gchar *path);

Attempt to unlock a .lock lock.

The function does nothing, when dot locking had not been compiled.

#### Parameters

path | a path to unlock |

### camel_unlock_fcntl ()

    void
    camel_unlock_fcntl (gint fd);

Unlock an fcntl lock.

The function does nothing, when fcntl locking had not been compiled.

#### Parameters

fd | a file descriptor |

### camel_unlock_flock ()

    void
    camel_unlock_flock (gint fd);

Unlock an flock lock.

The function does nothing, when flock locking had not been compiled.

#### Parameters

fd | a file descriptor |

### camel_lock_folder ()

    gint
    camel_lock_folder (const gchar *path,
                       gint fd,
                       CamelLockType type,
                       GError **error);

Attempt to lock a folder, multiple attempts will be made using all locking strategies available.

#### Parameters

path | Path to the file to lock (used for .locking only). |
fd | Open file descriptor of the right type to lock. |
type | Type of lock, CAMEL_LOCK_READ or CAMEL_LOCK_WRITE. |
error | return location for a GError, or `NULL` |

#### Returns

-1 on error, `ex` will describe the locking system that failed.

### camel_unlock_folder ()

    void
    camel_unlock_folder (const gchar *path,
                         gint fd);

Free a lock on a folder.

#### Parameters

path | Filename of folder. |
fd | Open descrptor on which locks were placed. |

## Types and Values

### CAMEL_LOCK_DOT_RETRY

    #define CAMEL_LOCK_DOT_RETRY (5) /* number of times to retry lock */

### CAMEL_LOCK_DOT_DELAY

    #define CAMEL_LOCK_DOT_DELAY (2) /* delay between locking retries */

### CAMEL_LOCK_DOT_STALE

    #define CAMEL_LOCK_DOT_STALE (60) /* seconds before a lock becomes stale */

### CAMEL_LOCK_RETRY

    #define CAMEL_LOCK_RETRY (5) /* number of times to retry lock */

### CAMEL_LOCK_DELAY

    #define CAMEL_LOCK_DELAY (2) /* delay between locking retries */

### enum CamelLockType

#### Members

CAMEL_LOCK_READ |  |
CAMEL_LOCK_WRITE |  |