1
/* Copyright (c) 2009 PrimeBase Technologies GmbH
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
* 2009-01-20 Vladimir Kolesnikov
24
#include "xt_config.h"
25
#include "locklist_xt.h"
27
#ifdef XT_THREAD_LOCK_INFO
28
#include "pthread_xt.h"
29
#include "thread_xt.h"
32
void xt_thread_lock_info_init(XTThreadLockInfoPtr ptr, XTSpinLock *lock)
34
ptr->li_spin_lock = lock;
35
ptr->li_lock_type = XTThreadLockInfo::SPIN_LOCK;
38
void xt_thread_lock_info_init(XTThreadLockInfoPtr ptr, xt_mutex_struct *lock)
41
ptr->li_lock_type = XTThreadLockInfo::MUTEX;
44
void xt_thread_lock_info_init(XTThreadLockInfoPtr ptr, xt_rwlock_struct *lock)
46
ptr->li_rwlock = lock;
47
ptr->li_lock_type = XTThreadLockInfo::RW_LOCK;
50
void xt_thread_lock_info_init(XTThreadLockInfoPtr ptr, XTMutexXSLock *lock)
52
ptr->li_fast_rwlock = lock;
53
ptr->li_lock_type = XTThreadLockInfo::FAST_RW_LOCK;
56
void xt_thread_lock_info_init(XTThreadLockInfoPtr ptr, XTSpinXSLock *lock)
58
ptr->li_spin_rwlock = lock;
59
ptr->li_lock_type = XTThreadLockInfo::SPIN_RW_LOCK;
62
void xt_thread_lock_info_free(XTThreadLockInfoPtr ptr)
64
/* TODO: check to see if it's present in a thread's list */
67
void xt_thread_lock_info_add_owner (XTThreadLockInfoPtr ptr)
69
XTThread *self = xt_get_self();
74
if (self->st_thread_lock_count < XT_THREAD_LOCK_INFO_MAX_COUNT) {
75
self->st_thread_lock_list[self->st_thread_lock_count] = ptr;
76
self->st_thread_lock_count++;
80
void xt_thread_lock_info_release_owner (XTThreadLockInfoPtr ptr)
82
XTThread *self = xt_get_self();
87
for (int i = self->st_thread_lock_count - 1; i >= 0; i--) {
88
if (self->st_thread_lock_list[i] == ptr) {
89
self->st_thread_lock_count--;
90
memcpy(self->st_thread_lock_list + i,
91
self->st_thread_lock_list + i + 1,
92
(self->st_thread_lock_count - i)*sizeof(XTThreadLockInfoPtr));
93
self->st_thread_lock_list[self->st_thread_lock_count] = NULL;
99
void xt_trace_thread_locks(XTThread *self)
104
xt_ttracef(self, "thread lock list (first in list added first): ");
106
if (!self->st_thread_lock_count) {
107
xt_trace(" <empty>\n");
113
int count = min(self->st_thread_lock_count, XT_THREAD_LOCK_INFO_MAX_COUNT);
115
for(int i = 0; i < count; i++) {
117
const char *lock_type = NULL;
118
const char *lock_name = NULL;
120
XTThreadLockInfoPtr li = self->st_thread_lock_list[i];
122
switch(li->li_lock_type) {
123
case XTThreadLockInfo::SPIN_LOCK:
124
lock_type = "XTSpinLock";
125
lock_name = li->li_spin_lock->spl_name;
127
case XTThreadLockInfo::MUTEX:
128
lock_type = "xt_mutex_struct";
130
lock_name = li->li_mutex->mt_name;
132
lock_name = li->li_mutex->mu_name;
135
case XTThreadLockInfo::RW_LOCK:
136
lock_type = "xt_rwlock_struct";
137
lock_name = li->li_rwlock->rw_name;
139
case XTThreadLockInfo::FAST_RW_LOCK:
140
lock_type = "XTMutexXSLock";
141
lock_name = li->li_fast_rwlock->xsm_name;
143
case XTThreadLockInfo::SPIN_RW_LOCK:
144
lock_type = "XTSpinRWLock";
145
lock_name = li->li_spin_rwlock->sxs_name;
149
xt_ttracef(self, " #lock#%d: type: %s name: %s \n", count, lock_type, lock_name);