MDAT
1.0
|
Lock manager. More...
Public Member Functions | |
void | addLock (const char *name, pthread_mutex_t *lock) |
Registers a new lock. More... | |
void | acquireLock (int id, pthread_mutex_t *lock) |
Implements the lock operation. More... | |
void | releaseLock (int id, pthread_mutex_t *lock) |
Implements the unlock operation. More... | |
string | getLockTable () const |
Returns the lock table in a string. More... | |
The lock manager is responsible for managing the locks used during the concurrent sections of the program. Each lock must first be registered using addLock. The state of locks are adjusted via the acquireLock and releaseLock methods.
void LockManager::addLock | ( | const char * | name, |
pthread_mutex_t * | lock | ||
) |
Registers a new lock.
[in] | name | name of lock |
[in] | lock | lock variable |
void LockManager::acquireLock | ( | int | id, |
pthread_mutex_t * | lock | ||
) |
Thread takes a lock if available. If the lock is unavailable, the thread will wait until it acquires the lock.
[in] | id | id of thread trying to acquire lock |
[in] | lock | lock variable |
void LockManager::releaseLock | ( | int | id, |
pthread_mutex_t * | lock | ||
) |
Gives up the lock. If one or more threads are waiting, one thread will be woken up and given the lock. If no threads are waiting, the lock is returned to the unlocked state.
[in] | id | id of thread trying to acquire lock |
[in] | lock | lock variable |
string LockManager::getLockTable | ( | ) | const |
Returns the lock table in a string in a trace-friendly format.