GitLab will be upgraded on 30 Jan 2023 from 2.00 pm (AEDT) to 3.00 pm (AEDT). During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to us at N110 (b) CSIT building.

dacapolock.c 1.02 KB
Newer Older
john's avatar
john committed
1
2
#include "dacapolock.h"

john's avatar
john committed
3
4
5
6
7
8
9
10
11
12
13
14
jboolean rawMonitorInit(jvmtiEnv* baseEnv, const char* name, MonitorLockType* lock) {
	pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
	/* pthread_mutex_t m = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; */

    lock->lock       = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
    lock->cond       = (pthread_cond_t)PTHREAD_COND_INITIALIZER;
    
    lock->wait_count = 0;
    return !FALSE;
}


john's avatar
john committed
15
/* Enter a critical section by doing a JVMTI Raw Monitor Enter */
john's avatar
john committed
16
void rawMonitorEnter(MonitorLockType* lock)
john's avatar
john committed
17
{
john's avatar
john committed
18
	pthread_mutex_lock(&(lock->lock));
john's avatar
john committed
19
20
21
}

/* Exit a critical section by doing a JVMTI Raw Monitor Exit */
john's avatar
john committed
22
void rawMonitorExit(MonitorLockType* lock)
john's avatar
john committed
23
{
john's avatar
john committed
24
	pthread_mutex_unlock(&(lock->lock));
john's avatar
john committed
25
26
}

john's avatar
john committed
27
jboolean rawMonitorWait(MonitorLockType* lock,jlong timeout)
28
{
john's avatar
john committed
29
30
31
32
	lock->wait_count++;
	pthread_cond_wait(&(lock->cond),&(lock->lock));
	lock->wait_count--;
	return !FALSE;
33
34
}

john's avatar
john committed
35
void rawMonitorNotify(MonitorLockType* lock)
36
{
john's avatar
john committed
37
38
39
	/* do not signal if nothing is waiting */
	if (0<lock->wait_count)
		pthread_cond_signal(&(lock->cond));
40
}