lock_record_pool_t *lock_global_pool;
+
+/*============================================================================*/
+/* INITIALIZATION OF DATA STRUCTURES */
+/*============================================================================*/
+
+
/* lock_init *******************************************************************
Initialize global data for locking.
}
-/* lock_init_thread_lock_record_pool *******************************************
+/* lock_init_execution_env *****************************************************
- Initialize the lock record pool(s) for a thread.
+ Initialize the execution environment for a thread.
IN:
thread.......the thread
*******************************************************************************/
-void lock_init_thread_lock_record_pool(threadobject *thread)
+void lock_init_execution_env(threadobject *thread)
{
thread->ee.firstLR = NULL;
thread->ee.lrpool = NULL;
}
+
+/*============================================================================*/
+/* LOCK RECORD MANAGEMENT */
+/*============================================================================*/
+
+
/* lock_record_alloc_new_pool **************************************************
Get a new lock record pool from the memory allocator.
static lock_record_pool_t *lock_record_alloc_new_pool(threadobject *thread, int size)
{
- lock_record_pool_t *p = mem_alloc(sizeof(lock_record_pool_header_t)
+ lock_record_pool_t *p = mem_alloc(sizeof(lock_record_pool_header_t)
+ sizeof(lock_record_t) * size);
int i;
static lock_record_pool_t *lock_record_alloc_pool(threadobject *t, int size)
{
pthread_mutex_lock(&lock_global_pool_lock);
+
if (lock_global_pool) {
int i;
lock_record_pool_t *pool = lock_global_pool;
lock_global_pool = pool->header.next;
+
pthread_mutex_unlock(&lock_global_pool_lock);
for (i=0; i < pool->header.size; i++) {
return pool;
}
+
pthread_mutex_unlock(&lock_global_pool_lock);
return lock_record_alloc_new_pool(t, size);
void lock_record_free_pools(lock_record_pool_t *pool)
{
lock_record_pool_header_t *last;
+
pthread_mutex_lock(&lock_global_pool_lock);
+
last = &pool->header;
while (last->next)
last = &last->next->header;
last->next = lock_global_pool;
lock_global_pool = pool;
+
pthread_mutex_unlock(&lock_global_pool_lock);
}
}
+
+/*============================================================================*/
+/* OBJECT LOCK INITIALIZATION */
+/*============================================================================*/
+
+
/* lock_init_object_lock *******************************************************
Initialize the monitor pointer of the given object. The monitor gets
}
+
+/*============================================================================*/
+/* LOCKING ALGORITHM */
+/*============================================================================*/
+
+
/* lock_queue_on_lock_record ***************************************************
Suspend the current thread and queue it on the given lock record.
/* the lock record does not lock this object */
lock_record_t *nlr;
lock_record_t *mlr;
-
+
/* allocate a new lock record for this object */
mlr = lock_record_alloc(t);
mlr->o = o;
lock_handle_waiter(mlr, lr, o);
return mlr;
}
- }
+ }
else {
/* no, it's another lock record */
/* if we don't own the old record, set incharge XXX */
lock_record_release(mlr);
lock_record_recycle(t, mlr);
lock_queue_on_lock_record(nlr, o);
- }
+ }
else {
/* the lock record is for the object we want */
*******************************************************************************/
static void lock_record_remove_waiter(lock_record_t *lr,
- lock_record_t *toremove)
+ lock_record_t *toremove)
{
do {
if (lr->waiter == toremove) {
}
+
+/*============================================================================*/
+/* INQUIRY FUNCIONS */
+/*============================================================================*/
+
+
/* lock_does_thread_hold_lock **************************************************
Return true if the given thread owns the monitor of the given object.
}
+
+/*============================================================================*/
+/* WRAPPERS FOR OPERATIONS ON THE CURRENT THREAD */
+/*============================================================================*/
+
+
/* lock_wait_for_object ********************************************************
Wait for the given object.