10
struct thread *create_thread(void)
12
static unsigned int num;
14
struct thread *new_thread = (struct thread *)malloc(sizeof(struct thread));
16
new_thread->right = 0;
17
new_thread->num = ++num;
23
struct thread *find_thread(pthread_t thread)
25
static struct thread *root;
29
root = create_thread();
30
root->thread = thread;
34
struct thread *current = root;
38
if(current->thread == thread)
41
if(current->thread > thread)
45
current->left = create_thread();
46
current->left->thread = thread;
48
current = current->left;
54
current->right = create_thread();
55
current->right->thread = thread;
57
current = current->right;
62
struct mutex *create_mutex(void)
64
static unsigned int num;
66
struct mutex *new_mutex = (struct mutex *)malloc(sizeof(struct mutex));
69
real_mutex_init(&new_mutex->lock, 0);
70
real_cond_init(&new_mutex->cond, 0);
71
new_mutex->num = ++num;
72
new_mutex->state = uninitialized;
74
new_mutex->owns_next = 0;
79
struct mutex *find_mutex(pthread_mutex_t *mutex)
81
static struct mutex *root;
85
root = create_mutex();
90
struct mutex *current = root;
94
if(current->mutex == mutex)
97
if(current->mutex > mutex)
101
current->left = create_mutex();
102
current->left->mutex = mutex;
104
current = current->left;
110
current->right = create_mutex();
111
current->right->mutex = mutex;
113
current = current->right;