Tor  0.4.7.0-alpha-dev
Functions
lockfile.h File Reference

Header for lockfile.c. More...

Go to the source code of this file.

Functions

tor_lockfile_ttor_lockfile_lock (const char *filename, int blocking, int *locked_out)
 
void tor_lockfile_unlock (tor_lockfile_t *lockfile)
 

Detailed Description

Header for lockfile.c.

Definition in file lockfile.h.

Function Documentation

◆ tor_lockfile_lock()

tor_lockfile_t* tor_lockfile_lock ( const char *  filename,
int  blocking,
int *  locked_out 
)

Try to get a lock on the lockfile filename, creating it as necessary. If someone else has the lock and blocking is true, wait until the lock is available. Otherwise return immediately whether we succeeded or not.

Set *locked_out to true if somebody else had the lock, and to false otherwise.

Return a tor_lockfile_t on success, NULL on failure.

(Implementation note: because we need to fall back to fcntl on some platforms, these locks are per-process, not per-thread. If you want to do in-process locking, use tor_mutex_t like a normal person. On Windows, when blocking is true, the maximum time that is actually waited is 10 seconds, after which NULL is returned and locked_out is set to 1.)

Definition at line 63 of file lockfile.c.

◆ tor_lockfile_unlock()

void tor_lockfile_unlock ( tor_lockfile_t lockfile)

Release the lock held as lockfile.

Definition at line 121 of file lockfile.c.

Referenced by release_lockfile().