|
The Berkeley DB locking protocol is described by a conflict matrix. A conflict matrix is an n x n array where n is the number of different lock modes supported, and the (i, j)th entry of the array indicates whether a lock of mode i conflicts with a lock of mode j.
The Berkeley DB include files declare two commonly used conflict arrays:
The number of modes associated with each matrix are DB_LOCK_RW_N and DB_LOCK_RIW_N, respectively.
In addition, the Berkeley DB include file defines the type db_lockmode_t, which is the type of the lock modes used with the standard tables above:
As an example, consider the basic multiple-reader/single writer conflict matrix described by db_rw_conflicts. In the following example (and in the appropriate file), a 1 represents a conflict (i.e., do not grant the lock if the indicated lock is held) and a 0 indicates that it is OK to grant the lock.
The rows indicate the lock that is held and the columns indicate the lock that is requested.
Notheld Read Write Notheld 0 0 0 Read* 0 0 1 Write** 0 1 1