Skip to content

Commit 2db69de

Browse files
mhaggergitster
authored andcommitted
lockfile: move documentation to lockfile.h and lockfile.c
Rearrange/rewrite it somewhat to fit its new environment. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7974889 commit 2db69de

File tree

3 files changed

+283
-280
lines changed

3 files changed

+283
-280
lines changed

Documentation/technical/api-lockfile.txt

Lines changed: 0 additions & 220 deletions
This file was deleted.

lockfile.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,59 @@
11
/*
22
* Copyright (c) 2005, Junio C Hamano
33
*/
4+
5+
/*
6+
* State diagram and cleanup
7+
* -------------------------
8+
*
9+
* This module keeps track of all locked files in `lock_file_list` for
10+
* use at cleanup. This list and the `lock_file` objects that comprise
11+
* it must be kept in self-consistent states at all time, because the
12+
* program can be interrupted any time by a signal, in which case the
13+
* signal handler will walk through the list attempting to clean up
14+
* any open lock files.
15+
*
16+
* The possible states of a `lock_file` object are as follows:
17+
*
18+
* - Uninitialized. In this state the object's `on_list` field must be
19+
* zero but the rest of its contents need not be initialized. As
20+
* soon as the object is used in any way, it is irrevocably
21+
* registered in `lock_file_list`, and `on_list` is set.
22+
*
23+
* - Locked, lockfile open (after `hold_lock_file_for_update()`,
24+
* `hold_lock_file_for_append()`, or `reopen_lock_file()`). In this
25+
* state:
26+
*
27+
* - the lockfile exists
28+
* - `active` is set
29+
* - `filename` holds the filename of the lockfile
30+
* - `fd` holds a file descriptor open for writing to the lockfile
31+
* - `fp` holds a pointer to an open `FILE` object if and only if
32+
* `fdopen_lock_file()` has been called on the object
33+
* - `owner` holds the PID of the process that locked the file
34+
*
35+
* - Locked, lockfile closed (after successful `close_lock_file()`).
36+
* Same as the previous state, except that the lockfile is closed
37+
* and `fd` is -1.
38+
*
39+
* - Unlocked (after `commit_lock_file()`, `commit_lock_file_to()`,
40+
* `rollback_lock_file()`, a failed attempt to lock, or a failed
41+
* `close_lock_file()`). In this state:
42+
*
43+
* - `active` is unset
44+
* - `filename` is empty (usually, though there are transitory
45+
* states in which this condition doesn't hold). Client code should
46+
* *not* rely on the filename being empty in this state.
47+
* - `fd` is -1
48+
* - the object is left registered in the `lock_file_list`, and
49+
* `on_list` is set.
50+
*
51+
* A lockfile is owned by the process that created it. The `lock_file`
52+
* has an `owner` field that records the owner's PID. This field is
53+
* used to prevent a forked process from closing a lockfile created by
54+
* its parent.
55+
*/
56+
457
#include "cache.h"
558
#include "lockfile.h"
659
#include "sigchain.h"

0 commit comments

Comments
 (0)