Project Lucy has retired. For details please refer to its Attic page.
Lucy::Store::Lock – C API Documentation
Apache Lucy™

Lucy::Store::Lock

parcel Lucy
class variable LUCY_LOCK
struct symbol lucy_Lock
class nickname lucy_Lock
header file Lucy/Store/Lock.h

Name

Lucy::Store::Lock – Abstract class representing an interprocess mutex lock.

Description

The Lock class produces an interprocess mutex lock. The default subclass uses dot-lock files, but alternative implementations are possible.

Each lock must have a name which is unique per resource to be locked. Each lock also has a “host” id which should be unique per machine; it is used to help clear away stale locks.

Functions

init
lucy_Lock*
lucy_Lock_init(
    lucy_Lock *self,
    lucy_Folder *folder,
    cfish_String *name,
    cfish_String *host,
    int32_t timeout,
    int32_t interval
);

Abstract initializer.

folder

A Folder.

name

String identifying the resource to be locked, which must consist solely of characters matching [-_.A-Za-z0-9].

host

A unique per-machine identifier.

timeout

Time in milliseconds to keep retrying before abandoning the attempt to Obtain() a lock.

interval

Time in milliseconds between retries.

Methods

Shared (abstract)
bool
lucy_Lock_Shared(
    lucy_Lock *self
);

Returns true if the Lock is shared, false if the Lock is exclusive.

Obtain
bool
lucy_Lock_Obtain(
    lucy_Lock *self
);

Call Request() once per interval until Request() returns success or the timeout has been reached.

Returns: true on success, false on failure (sets the global error object returned by get_error()).

Request (abstract)
bool
lucy_Lock_Request(
    lucy_Lock *self
);

Make one attempt to acquire the lock.

The semantics of Request() differ depending on whether Shared() returns true. If the Lock is Shared(), then Request() should not fail if another lock is held against the resource identified by name (though it might fail for other reasons). If it is not Shared() – i.e. it’s an exclusive (write) lock – then other locks should cause Request() to fail.

Returns: true on success, false on failure (sets the global error object returned by get_error()).

Release (abstract)
void
lucy_Lock_Release(
    lucy_Lock *self
);

Release the lock.

Is_Locked (abstract)
bool
lucy_Lock_Is_Locked(
    lucy_Lock *self
);

Indicate whether the resource identified by this lock’s name is currently locked.

Returns: true if the resource is locked, false otherwise.

Clear_Stale (abstract)
void
lucy_Lock_Clear_Stale(
    lucy_Lock *self
);

Release all locks that meet the following three conditions: the lock name matches, the host id matches, and the process id that the lock was created under no longer identifies an active process.

Inheritance

Lucy::Store::Lock is a Clownfish::Obj.