~posulliv/drizzle/optimizer-style-cleanup

« back to all changes in this revision

Viewing changes to plugin/pbxt/src/locklist_xt.cc

  • Committer: Padraig O'Sullivan
  • Date: 2010-04-17 01:38:47 UTC
  • mfrom: (1237.9.238 bad-staging)
  • Revision ID: osullivan.padraig@gmail.com-20100417013847-ibjioqsfbmf5yg4g
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2009 PrimeBase Technologies GmbH
 
2
 *
 
3
 * PrimeBase XT
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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
 
18
 *
 
19
 * 2009-01-20   Vladimir Kolesnikov
 
20
 *
 
21
 * H&G2JCtL
 
22
 */
 
23
 
 
24
#include "xt_config.h"
 
25
#include "locklist_xt.h"
 
26
 
 
27
#ifdef XT_THREAD_LOCK_INFO
 
28
#include "pthread_xt.h"
 
29
#include "thread_xt.h"
 
30
#include "trace_xt.h"
 
31
 
 
32
void xt_thread_lock_info_init(XTThreadLockInfoPtr ptr, XTSpinLock *lock)
 
33
{
 
34
        ptr->li_spin_lock = lock;
 
35
        ptr->li_lock_type = XTThreadLockInfo::SPIN_LOCK;
 
36
}
 
37
 
 
38
void xt_thread_lock_info_init(XTThreadLockInfoPtr ptr, xt_mutex_struct *lock)
 
39
{
 
40
        ptr->li_mutex     = lock;
 
41
        ptr->li_lock_type = XTThreadLockInfo::MUTEX;
 
42
}
 
43
 
 
44
void xt_thread_lock_info_init(XTThreadLockInfoPtr ptr, xt_rwlock_struct *lock)
 
45
{
 
46
        ptr->li_rwlock    = lock;
 
47
        ptr->li_lock_type = XTThreadLockInfo::RW_LOCK;
 
48
}
 
49
 
 
50
void xt_thread_lock_info_init(XTThreadLockInfoPtr ptr, XTMutexXSLock *lock)
 
51
{
 
52
        ptr->li_fast_rwlock = lock;
 
53
        ptr->li_lock_type   = XTThreadLockInfo::FAST_RW_LOCK;
 
54
}
 
55
 
 
56
void xt_thread_lock_info_init(XTThreadLockInfoPtr ptr, XTSpinXSLock *lock)
 
57
{
 
58
        ptr->li_spin_rwlock = lock;
 
59
        ptr->li_lock_type   = XTThreadLockInfo::SPIN_RW_LOCK;
 
60
}
 
61
 
 
62
void xt_thread_lock_info_free(XTThreadLockInfoPtr ptr)
 
63
{
 
64
        /* TODO: check to see if it's present in a thread's list */
 
65
}
 
66
 
 
67
void xt_thread_lock_info_add_owner (XTThreadLockInfoPtr ptr)
 
68
{
 
69
        XTThread *self = xt_get_self();
 
70
 
 
71
        if (!self)
 
72
                return;
 
73
 
 
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++;
 
77
        }
 
78
}
 
79
 
 
80
void xt_thread_lock_info_release_owner (XTThreadLockInfoPtr ptr)
 
81
{
 
82
        XTThread *self = xt_get_self();
 
83
 
 
84
        if (!self)
 
85
                return;
 
86
 
 
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;
 
94
                        break;
 
95
                }
 
96
        }
 
97
}
 
98
 
 
99
void xt_trace_thread_locks(XTThread *self)
 
100
{
 
101
        if (!self)
 
102
                return;
 
103
 
 
104
        xt_ttracef(self, "thread lock list (first in list added first): ");
 
105
 
 
106
        if (!self->st_thread_lock_count) {
 
107
                xt_trace(" <empty>\n");
 
108
                return;
 
109
        }
 
110
 
 
111
        xt_trace("\n");
 
112
 
 
113
        int count = min(self->st_thread_lock_count, XT_THREAD_LOCK_INFO_MAX_COUNT);
 
114
 
 
115
        for(int i = 0; i < count; i++) {
 
116
 
 
117
                const char *lock_type = NULL;
 
118
                const char *lock_name = NULL;
 
119
 
 
120
                XTThreadLockInfoPtr li = self->st_thread_lock_list[i];
 
121
 
 
122
                switch(li->li_lock_type) {
 
123
                        case XTThreadLockInfo::SPIN_LOCK:
 
124
                                lock_type = "XTSpinLock";
 
125
                                lock_name = li->li_spin_lock->spl_name;
 
126
                                break;
 
127
                        case XTThreadLockInfo::MUTEX:
 
128
                                lock_type = "xt_mutex_struct";
 
129
#ifdef XT_WIN
 
130
                                lock_name = li->li_mutex->mt_name;
 
131
#else
 
132
                                lock_name = li->li_mutex->mu_name;
 
133
#endif
 
134
                                break;
 
135
                        case XTThreadLockInfo::RW_LOCK:
 
136
                                lock_type = "xt_rwlock_struct";
 
137
                                lock_name = li->li_rwlock->rw_name;
 
138
                                break;
 
139
                        case XTThreadLockInfo::FAST_RW_LOCK:
 
140
                                lock_type = "XTMutexXSLock";
 
141
                                lock_name = li->li_fast_rwlock->xsm_name;
 
142
                                break;
 
143
                        case XTThreadLockInfo::SPIN_RW_LOCK:
 
144
                                lock_type = "XTSpinRWLock";
 
145
                                lock_name = li->li_spin_rwlock->sxs_name;
 
146
                                break;
 
147
                }
 
148
 
 
149
                xt_ttracef(self, "  #lock#%d: type: %s name: %s \n", count, lock_type, lock_name);
 
150
        }
 
151
}
 
152
 
 
153
#endif
 
154