Class CriticalI_RepositoryLock

Description

Interface for acquiring locks for accessing or modifying the repository.

The locking mechanism makes use of flock(). This is simple, very widely available, and unlikely to leave the system in an inconsistent state. However, it availability and reliability are not universal. It will not work on NFS, some other networked file systems, and old FAT filesystems (which are really outdated at this point), so install your repository accordingly.

A read lock of the repository can be upgraded by obtaining a write lock, but calling read lock once a write lock has been obtained will not downgrade the lock to a read lock. This is different than the behavior of flock itself. While this may not seem intuitive at first, it allows for greater modularity and reuse of code. In this way locking can actually be declarative. Underlying routines which need to access files in the repository can declare the type of lock they need (shared or exclusive) and know that a lock of that level or higher has been obtained. That way, if a read operation occurs inside of a large exclusive operation, the read operation can call for a read lock without affecting the locking needs of the larger transaction. Similarly, because locks are freed automatically at the end of the script, code should generally rely on this behavior to release the lock instead of releasing it explicitly which could adversely affect locking if used within a larger transaction.

Located in /Core/lib/CriticalI/RepositoryLock.php (line 32)


	
			
Class Constant Summary
Variable Summary
 static mixed $fileHandle
 static mixed $lockState
Method Summary
 static void cleanup ()
 static void create_lock_file ()
 static void read_lock ()
 static void release ()
 static void write_lock ()
Variables
static mixed $fileHandle = false (line 38)
  • access: protected
static mixed $lockState = self::UNLOCKED (line 37)
  • access: protected
Methods
static cleanup (line 112)

Called automatically on shutdown to clean up after the lock file.

Generally this shouldn't be necessary, but some Windows systems have much stricter requirements when it comes to locks. This should provide the cleanest shutdown in all cases.

  • access: public
void cleanup ()
static create_lock_file (line 50)

Called internally to create the lock file

  • access: protected
void create_lock_file ()
static read_lock (line 68)

Acquire a read lock of the repository

  • access: public
void read_lock ()
static release (line 96)

Release any acquired lock

  • access: public
void release ()
static write_lock (line 82)

Acquire a write lock of the repository

  • access: public
void write_lock ()
Class Constants
READ_LOCKED = 1 (line 34)
UNLOCKED = 0 (line 33)
WRITE_LOCKED = 2 (line 35)

Documentation generated on Wed, 25 Apr 2012 09:46:45 -0700 by phpDocumentor 1.4.3