~ubuntu-branches/ubuntu/trusty/mariadb-5.5/trusty-proposed

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Otto Kekäläinen
  • Date: 2013-12-22 10:27:05 UTC
  • Revision ID: package-import@ubuntu.com-20131222102705-mndw7s12mz0szrcn
Tags: upstream-5.5.32
Import upstream version 5.5.32

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, XTRWMutex *lock)
 
39
{
 
40
        ptr->li_rw_mutex  = lock;
 
41
        ptr->li_lock_type = XTThreadLockInfo::RW_MUTEX;
 
42
}
 
43
 
 
44
void xt_thread_lock_info_init(XTThreadLockInfoPtr ptr, XTFastLock *lock)
 
45
{
 
46
        ptr->li_fast_lock  = lock;
 
47
        ptr->li_lock_type = XTThreadLockInfo::FAST_LOCK;
 
48
}
 
49
 
 
50
void xt_thread_lock_info_init(XTThreadLockInfoPtr ptr, xt_mutex_struct *lock)
 
51
{
 
52
        ptr->li_mutex     = lock;
 
53
        ptr->li_lock_type = XTThreadLockInfo::MUTEX;
 
54
}
 
55
 
 
56
void xt_thread_lock_info_init(XTThreadLockInfoPtr ptr, xt_rwlock_struct *lock)
 
57
{
 
58
        ptr->li_rwlock    = lock;
 
59
        ptr->li_lock_type = XTThreadLockInfo::RW_LOCK;
 
60
}
 
61
 
 
62
void xt_thread_lock_info_init(XTThreadLockInfoPtr ptr, XTXSMutexLock *lock)
 
63
{
 
64
        ptr->li_fast_rwlock = lock;
 
65
        ptr->li_lock_type   = XTThreadLockInfo::FAST_RW_LOCK;
 
66
}
 
67
 
 
68
void xt_thread_lock_info_init(XTThreadLockInfoPtr ptr, XTSpinXSLock *lock)
 
69
{
 
70
        ptr->li_spin_rwlock = lock;
 
71
        ptr->li_lock_type   = XTThreadLockInfo::SPIN_RW_LOCK;
 
72
}
 
73
 
 
74
void xt_thread_lock_info_init(XTThreadLockInfoPtr ptr, XTAtomicRWLock *lock)
 
75
{
 
76
        ptr->li_atomic_rwlock = lock;
 
77
        ptr->li_lock_type   = XTThreadLockInfo::ATOMIC_RW_LOCK;
 
78
}
 
79
 
 
80
void xt_thread_lock_info_init(XTThreadLockInfoPtr ptr, XTSkewRWLock *lock)
 
81
{
 
82
        ptr->li_skew_rwlock = lock;
 
83
        ptr->li_lock_type   = XTThreadLockInfo::SKEW_RW_LOCK;
 
84
}
 
85
 
 
86
void xt_thread_lock_info_free(XTThreadLockInfoPtr ptr)
 
87
{
 
88
        /* TODO: check to see if it's present in a thread's list */
 
89
}
 
90
 
 
91
void xt_thread_lock_info_add_owner (XTThreadLockInfoPtr ptr)
 
92
{
 
93
        XTThread *self = xt_get_self();
 
94
 
 
95
        if (!self)
 
96
                return;
 
97
 
 
98
        if (self->st_thread_lock_count < XT_THREAD_LOCK_INFO_MAX_COUNT) {
 
99
                self->st_thread_lock_list[self->st_thread_lock_count] = ptr;
 
100
                self->st_thread_lock_count++;
 
101
        }
 
102
}
 
103
 
 
104
void xt_thread_lock_info_release_owner (XTThreadLockInfoPtr ptr)
 
105
{
 
106
        XTThread *self = xt_get_self();
 
107
 
 
108
        if (!self)
 
109
                return;
 
110
 
 
111
        for (int i = self->st_thread_lock_count - 1; i >= 0; i--) {
 
112
                if (self->st_thread_lock_list[i] == ptr) {
 
113
                        self->st_thread_lock_count--;
 
114
                        memcpy(self->st_thread_lock_list + i, 
 
115
                                self->st_thread_lock_list + i + 1, 
 
116
                                (self->st_thread_lock_count - i)*sizeof(XTThreadLockInfoPtr));
 
117
                        self->st_thread_lock_list[self->st_thread_lock_count] = NULL;
 
118
                        break;
 
119
                }
 
120
        }
 
121
}
 
122
 
 
123
void xt_trace_thread_locks(XTThread *self)
 
124
{
 
125
        if (!self)
 
126
                return;
 
127
 
 
128
        xt_ttracef(self, "thread lock list (first in list added first): ");
 
129
 
 
130
        if (!self->st_thread_lock_count) {
 
131
                xt_trace(" <empty>\n");
 
132
                return;
 
133
        }
 
134
 
 
135
        xt_trace("\n");
 
136
 
 
137
        int count = min(self->st_thread_lock_count, XT_THREAD_LOCK_INFO_MAX_COUNT);
 
138
 
 
139
        for(int i = 0; i < count; i++) {
 
140
 
 
141
                const char *lock_type = NULL;
 
142
                const char *lock_name = NULL;
 
143
 
 
144
                XTThreadLockInfoPtr li = self->st_thread_lock_list[i];
 
145
 
 
146
                switch(li->li_lock_type) {
 
147
                        case XTThreadLockInfo::SPIN_LOCK:
 
148
                                lock_type = "XTSpinLock";
 
149
                                lock_name = li->li_spin_lock->spl_name;
 
150
                                break;
 
151
                        case XTThreadLockInfo::RW_MUTEX:
 
152
                                lock_type = "XTRWMutex";
 
153
                                lock_name = li->li_rw_mutex->xs_name;
 
154
                                break;
 
155
                        case XTThreadLockInfo::MUTEX:
 
156
                                lock_type = "xt_mutex_struct";
 
157
#ifdef XT_WIN
 
158
                                lock_name = li->li_mutex->mt_name;
 
159
#else
 
160
                                lock_name = li->li_mutex->mu_name;
 
161
#endif
 
162
                                break;
 
163
                        case XTThreadLockInfo::RW_LOCK:
 
164
                                lock_type = "xt_rwlock_struct";
 
165
                                lock_name = li->li_rwlock->rw_name;
 
166
                                break;
 
167
                        case XTThreadLockInfo::FAST_LOCK:
 
168
                                lock_type = "XTFastLock";
 
169
                                lock_name = li->li_fast_lock->fal_name;
 
170
                                break;
 
171
                        case XTThreadLockInfo::FAST_RW_LOCK:
 
172
                                lock_type = "XTXSMutexLock";
 
173
                                lock_name = li->li_fast_rwlock->xsm_name;
 
174
                                break;
 
175
                        case XTThreadLockInfo::SPIN_RW_LOCK:
 
176
                                lock_type = "XTSpinRWLock";
 
177
                                lock_name = li->li_spin_rwlock->sxs_name;
 
178
                                break;
 
179
                        case XTThreadLockInfo::ATOMIC_RW_LOCK:
 
180
                                lock_type = "XTAtomicRWLock";
 
181
                                lock_name = li->li_atomic_rwlock->arw_name;
 
182
                                break;
 
183
                        case XTThreadLockInfo::SKEW_RW_LOCK:
 
184
                                lock_type = "XTSkewRWLock";
 
185
                                lock_name = li->li_skew_rwlock->srw_name;
 
186
                                break;
 
187
                }
 
188
 
 
189
                xt_ttracef(self, "  #lock#%d: type: %s name: %s \n", count, lock_type, lock_name);
 
190
        }
 
191
}
 
192
 
 
193
#elif defined(__WIN__)
 
194
 
 
195
// Remove linker warning 4221 about empty file
 
196
namespace { char dummy; };
 
197
 
 
198
#endif
 
199