DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Package Functions | Properties | Private Member Functions | Private Attributes | List of all members
Deveel.Data.Transactions.Lock Class Reference

Package Functions

 Lock (LockingQueue queue, LockingMode mode, AccessType accessType)
 
void Acquire ()
 
void Release ()
 
void CheckAccess (AccessType accessType)
 

Properties

LockingQueue Queue [get, set]
 
AccessType AccessType [get, private set]
 
LockingMode Mode [get, private set]
 
bool WasChecked [get, set]
 
ILockable Lockable [get]
 

Private Member Functions

void StartMode ()
 
void EndMode ()
 

Private Attributes

bool exclusiveMode
 
int sharedAccess
 

Detailed Description

Definition at line 21 of file Lock.cs.

Constructor & Destructor Documentation

Deveel.Data.Transactions.Lock.Lock ( LockingQueue  queue,
LockingMode  mode,
AccessType  accessType 
)
inlinepackage

Definition at line 25 of file Lock.cs.

25  {
26  Queue = queue;
27  AccessType = accessType;
28  Mode = mode;
29  Queue.Acquire(this);
30  }
LockingQueue Queue
Definition: Lock.cs:32

Member Function Documentation

void Deveel.Data.Transactions.Lock.Acquire ( )
inlinepackage

Definition at line 90 of file Lock.cs.

90  {
91  StartMode();
92  }
void Deveel.Data.Transactions.Lock.CheckAccess ( AccessType  accessType)
inlinepackage

Definition at line 101 of file Lock.cs.

101  {
102  if (AccessType == AccessType.Write &&
103  accessType != AccessType.Write)
104  throw new InvalidOperationException("Access error on Lock: Tried to Write to a non Write Lock.");
105 
106  if (!WasChecked) {
107  Queue.CheckAccess(this);
108  WasChecked = true;
109  }
110  }
LockingQueue Queue
Definition: Lock.cs:32
void Deveel.Data.Transactions.Lock.EndMode ( )
inlineprivate

Definition at line 70 of file Lock.cs.

70  {
71  lock (this) {
72  if (Mode == LockingMode.Exclusive) {
73  exclusiveMode = false;
74  Monitor.PulseAll(this);
75  } else if (Mode == LockingMode.Shared) {
76  --sharedAccess;
77  if (sharedAccess == 0 && exclusiveMode) {
78  Monitor.PulseAll(this);
79  } else if (sharedAccess < 0) {
80  sharedAccess = 0;
81  Monitor.PulseAll(this);
82  throw new Exception("Too many 'Sahred Locks Release' calls");
83  }
84  } else {
85  throw new InvalidOperationException("Invalid mode");
86  }
87  }
88  }
LockingMode
The mode applied to a lock over a resource during a transaction.
Definition: LockingMode.cs:24
void Deveel.Data.Transactions.Lock.Release ( )
inlinepackage

Definition at line 94 of file Lock.cs.

94  {
95  EndMode();
96  Queue.Release(this);
97 
98  // TODO: if the lock was not check, silently report the error to the system
99  }
LockingQueue Queue
Definition: Lock.cs:32
void Deveel.Data.Transactions.Lock.StartMode ( )
inlineprivate

Definition at line 44 of file Lock.cs.

44  {
45  lock (this) {
46  // If currently in exclusive mode, block until not.
47 
48  while (exclusiveMode) {
49  Monitor.Wait(this);
50  }
51 
52  if (Mode == LockingMode.Exclusive) {
53  // Set this thread to exclusive mode, and wait until all shared modes
54  // have completed.
55 
56  exclusiveMode = true;
57  while (sharedAccess > 0) {
58  Monitor.Wait(this);
59  }
60  } else if (Mode == LockingMode.Shared) {
61  // Increase the threads counter that are in shared mode.
62 
63  ++sharedAccess;
64  } else {
65  throw new InvalidOperationException("Invalid mode");
66  }
67  }
68  }
LockingMode
The mode applied to a lock over a resource during a transaction.
Definition: LockingMode.cs:24

Member Data Documentation

bool Deveel.Data.Transactions.Lock.exclusiveMode
private

Definition at line 22 of file Lock.cs.

int Deveel.Data.Transactions.Lock.sharedAccess
private

Definition at line 23 of file Lock.cs.

Property Documentation

AccessType Deveel.Data.Transactions.Lock.AccessType
getprivate set

Definition at line 34 of file Lock.cs.

ILockable Deveel.Data.Transactions.Lock.Lockable
getpackage

Definition at line 40 of file Lock.cs.

LockingMode Deveel.Data.Transactions.Lock.Mode
getprivate set

Definition at line 36 of file Lock.cs.

LockingQueue Deveel.Data.Transactions.Lock.Queue
getsetprivate

Definition at line 32 of file Lock.cs.

bool Deveel.Data.Transactions.Lock.WasChecked
getsetprivate

Definition at line 38 of file Lock.cs.


The documentation for this class was generated from the following file: