Subversion Repositories tpanel

Rev

Rev 317 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 317 Rev 367
Line 28... Line 28...
28
 
28
 
29
template<typename _TMutex>
29
template<typename _TMutex>
30
TLock<_TMutex>::TLock(TLock::mutex_type& __m)
30
TLock<_TMutex>::TLock(TLock::mutex_type& __m)
31
    : _M_device(__m)
31
    : _M_device(__m)
32
{
32
{
33
    DECL_TRACER("TLock<_TMutex>::TLock(TLock::mutex_type& __m)");
33
//    DECL_TRACER("TLock<_TMutex>::TLock(TLock::mutex_type& __m)");
34
 
34
 
35
    bool death = false;
35
    bool death = false;
36
    bool l = addLock(&death);
36
    bool l = addLock(&death);
37
 
37
 
38
    if ((mNoDeathLock || death) && !l)
38
    if ((mNoDeathLock || death) && !l)
Line 45... Line 45...
45
TLock<_TMutex>::TLock(TLock::mutex_type& __m, char *file, int line)
45
TLock<_TMutex>::TLock(TLock::mutex_type& __m, char *file, int line)
46
    : _M_device(__m),
46
    : _M_device(__m),
47
      mFilename(file),
47
      mFilename(file),
48
      mLineNumber(line)
48
      mLineNumber(line)
49
{
49
{
50
    DECL_TRACER("TLock<_TMutex>::TLock(TLock::mutex_type& __m)");
50
//    DECL_TRACER("TLock<_TMutex>::TLock(TLock::mutex_type& __m)");
51
 
51
 
52
    stripFileName();
52
    stripFileName();
53
    bool death = false;
53
    bool death = false;
54
    bool l = addLock(&death);
54
    bool l = addLock(&death);
55
 
55
 
Line 72... Line 72...
72
    : _M_device(__m),
72
    : _M_device(__m),
73
      mNoDeathLock(tryit),
73
      mNoDeathLock(tryit),
74
      mFilename(file),
74
      mFilename(file),
75
      mLineNumber(line)
75
      mLineNumber(line)
76
{
76
{
77
    DECL_TRACER("TLock<_TMutex>::TLock(mutex_type& __m, bool tryit, char *file, int line)");
77
//    DECL_TRACER("TLock<_TMutex>::TLock(mutex_type& __m, bool tryit, char *file, int line)");
78
 
78
 
79
    stripFileName();
79
    stripFileName();
80
    bool death = false;
80
    bool death = false;
81
    bool l = addLock(&death);
81
    bool l = addLock(&death);
82
 
82
 
Line 96... Line 96...
96
 
96
 
97
template<typename _TMutex>
97
template<typename _TMutex>
98
TLock<_TMutex>::TLock(TLock::mutex_type& __m, std::adopt_lock_t) noexcept
98
TLock<_TMutex>::TLock(TLock::mutex_type& __m, std::adopt_lock_t) noexcept
99
    : _M_device(__m)
99
    : _M_device(__m)
100
{
100
{
101
    DECL_TRACER("TLock<_TMutex>::TLock(TLock::mutex_type& __m, std::adopt_lock_t) noexcept");
101
//    DECL_TRACER("TLock<_TMutex>::TLock(TLock::mutex_type& __m, std::adopt_lock_t) noexcept");
102
}
102
}
103
 
103
 
104
template<typename _TMutex>
104
template<typename _TMutex>
105
TLock<_TMutex>::~TLock()
105
TLock<_TMutex>::~TLock()
106
{
106
{
107
    DECL_TRACER("TLock<_TMutex>::~TLock()");
107
//    DECL_TRACER("TLock<_TMutex>::~TLock()");
108
 
108
 
109
    if (removeLock())
109
    if (removeLock())
110
        _M_device.unlock();
110
        _M_device.unlock();
111
}
111
}
112
 
112
 
113
template<typename _TMutex>
113
template<typename _TMutex>
114
void TLock<_TMutex>::unlock()
114
void TLock<_TMutex>::unlock()
115
{
115
{
116
    DECL_TRACER("TLock<_TMutex>::unlock()");
116
//    DECL_TRACER("TLock<_TMutex>::unlock()");
117
 
117
 
118
    if (_locks.empty())
118
    if (_locks.empty())
119
        return;
119
        return;
120
 
120
 
121
    vector<__LOCKLIST_t>::iterator iter;
121
    vector<__LOCKLIST_t>::iterator iter;
Line 129... Line 129...
129
            iter->noDeathLock = false;
129
            iter->noDeathLock = false;
130
            _M_device.unlock();
130
            _M_device.unlock();
131
 
131
 
132
            if (mFilename.empty())
132
            if (mFilename.empty())
133
            {
133
            {
134
                MSG_DEBUG("The mutex handle " << iter->native_handle << " was released!");
134
                MSG_PROTOCOL("The mutex handle " << iter->native_handle << " was released!");
135
            }
135
            }
136
            else
136
            else
137
            {
137
            {
138
                MSG_DEBUG("The mutex handle " << iter->native_handle << " was released on file " << mFilename << " at line " << mLineNumber << "!");
138
                MSG_PROTOCOL("The mutex handle " << iter->native_handle << " was released on file " << mFilename << " at line " << mLineNumber << "!");
139
            }
139
            }
140
 
140
 
141
            return;
141
            return;
142
        }
142
        }
143
    }
143
    }
144
}
144
}
145
 
145
 
146
template<typename _TMutex>
146
template<typename _TMutex>
147
void TLock<_TMutex>::unlock(char* file, int line)
147
void TLock<_TMutex>::unlock(char* file, int line)
148
{
148
{
149
    DECL_TRACER("TLock<_TMutex>::unlock(char* file, int line)");
149
//    DECL_TRACER("TLock<_TMutex>::unlock(char* file, int line)");
150
 
150
 
151
    mFilename = file;
151
    mFilename = file;
152
    mLineNumber = line;
152
    mLineNumber = line;
153
    stripFileName();
153
    stripFileName();
154
 
154
 
Line 156... Line 156...
156
}
156
}
157
 
157
 
158
template<typename _TMutex>
158
template<typename _TMutex>
159
void TLock<_TMutex>::relock()
159
void TLock<_TMutex>::relock()
160
{
160
{
161
    DECL_TRACER("TLock<_TMutex>::relock(TLock::mutex_type& __m)");
161
//    DECL_TRACER("TLock<_TMutex>::relock(TLock::mutex_type& __m)");
162
 
162
 
163
    if (_locks.empty())
163
    if (_locks.empty())
164
        return;
164
        return;
165
 
165
 
166
    vector<__LOCKLIST_t>::iterator iter;
166
    vector<__LOCKLIST_t>::iterator iter;
Line 196... Line 196...
196
}
196
}
197
 
197
 
198
template<typename _TMutex>
198
template<typename _TMutex>
199
void TLock<_TMutex>::setNoDeathLock(bool l)
199
void TLock<_TMutex>::setNoDeathLock(bool l)
200
{
200
{
201
    DECL_TRACER("TLock<_TMutex>::setNoDeathLock(bool l)");
201
//    DECL_TRACER("TLock<_TMutex>::setNoDeathLock(bool l)");
202
 
202
 
203
    mNoDeathLock = l;
203
    mNoDeathLock = l;
204
    vector<__LOCKLIST_t>::iterator iter;
204
    vector<__LOCKLIST_t>::iterator iter;
205
    std::mutex::native_handle_type nhandle = _M_device.native_handle();
205
    std::mutex::native_handle_type nhandle = _M_device.native_handle();
206
 
206
 
Line 216... Line 216...
216
 
216
 
217
 
217
 
218
template<typename _TMutex>
218
template<typename _TMutex>
219
bool TLock<_TMutex>::addLock(bool *death)
219
bool TLock<_TMutex>::addLock(bool *death)
220
{
220
{
221
    DECL_TRACER("TLock<_TMutex>::addLock(bool *death)");
221
//    DECL_TRACER("TLock<_TMutex>::addLock(bool *death)");
222
 
222
 
223
    __LOCKLIST_t lc;
223
    __LOCKLIST_t lc;
224
    lc.state = true;
224
    lc.state = true;
225
    lc.noDeathLock = mNoDeathLock;
225
    lc.noDeathLock = mNoDeathLock;
226
    lc.native_handle = _M_device.native_handle();
226
    lc.native_handle = _M_device.native_handle();
Line 229... Line 229...
229
    {
229
    {
230
        _locks.push_back(lc);
230
        _locks.push_back(lc);
231
 
231
 
232
        if (mFilename.empty())
232
        if (mFilename.empty())
233
        {
233
        {
234
            MSG_DEBUG("Lock for mutex handle " << lc.native_handle << " was added.");
234
            MSG_PROTOCOL("Lock for mutex handle " << lc.native_handle << " was added.");
235
        }
235
        }
236
        else
236
        else
237
        {
237
        {
238
            MSG_DEBUG("Lock for mutex handle " << lc.native_handle << " was added on file " << mFilename << " at line " << mLineNumber << ".");
238
            MSG_PROTOCOL("Lock for mutex handle " << lc.native_handle << " was added on file " << mFilename << " at line " << mLineNumber << ".");
239
        }
239
        }
240
 
240
 
241
        if (death)
241
        if (death)
242
            *death = lc.noDeathLock;
242
            *death = lc.noDeathLock;
243
 
243
 
Line 284... Line 284...
284
            {
284
            {
285
                iter->state = true;
285
                iter->state = true;
286
 
286
 
287
                if (mFilename.empty())
287
                if (mFilename.empty())
288
                {
288
                {
289
                    MSG_DEBUG("Lock for mutex handle " << iter->native_handle << " was reactivated.");
289
                    MSG_PROTOCOL("Lock for mutex handle " << iter->native_handle << " was reactivated.");
290
                }
290
                }
291
                else
291
                else
292
                {
292
                {
293
                    MSG_DEBUG("Lock for mutex handle " << iter->native_handle << " was reactivated on file " << mFilename << " at line " << mLineNumber << ".");
293
                    MSG_PROTOCOL("Lock for mutex handle " << iter->native_handle << " was reactivated on file " << mFilename << " at line " << mLineNumber << ".");
294
                }
294
                }
295
 
295
 
296
                return true;
296
                return true;
297
            }
297
            }
298
        }
298
        }
Line 300... Line 300...
300
 
300
 
301
    _locks.push_back(lc);
301
    _locks.push_back(lc);
302
 
302
 
303
    if (mFilename.empty())
303
    if (mFilename.empty())
304
    {
304
    {
305
        MSG_DEBUG("Lock for mutex handle " << lc.native_handle << " was added.");
305
        MSG_PROTOCOL("Lock for mutex handle " << lc.native_handle << " was added.");
306
    }
306
    }
307
    else
307
    else
308
    {
308
    {
309
        MSG_DEBUG("Lock for mutex handle " << lc.native_handle << " was added on file " << mFilename << " at line " << mLineNumber << ".");
309
        MSG_PROTOCOL("Lock for mutex handle " << lc.native_handle << " was added on file " << mFilename << " at line " << mLineNumber << ".");
310
    }
310
    }
311
 
311
 
312
    if (death)
312
    if (death)
313
        *death = lc.noDeathLock;
313
        *death = lc.noDeathLock;
314
 
314
 
Line 316... Line 316...
316
}
316
}
317
 
317
 
318
template<typename _TMutex>
318
template<typename _TMutex>
319
void TLock<_TMutex>::wait()
319
void TLock<_TMutex>::wait()
320
{
320
{
321
    DECL_TRACER("TLock<_TMutex>::wait()");
321
//    DECL_TRACER("TLock<_TMutex>::wait()");
322
 
322
 
323
    int loops = 100;
323
    int loops = 100;
324
 
324
 
325
    while (!_M_device.try_lock() && loops >= 0)
325
    while (!_M_device.try_lock() && loops >= 0)
326
    {
326
    {
Line 333... Line 333...
333
}
333
}
334
 
334
 
335
template<typename _TMutex>
335
template<typename _TMutex>
336
bool TLock<_TMutex>::removeLock()
336
bool TLock<_TMutex>::removeLock()
337
{
337
{
338
    DECL_TRACER("TLock<_TMutex>::removeLock(__LOCKLIST_t& e)");
338
//    DECL_TRACER("TLock<_TMutex>::removeLock(__LOCKLIST_t& e)");
339
 
339
 
340
    if (_locks.empty())
340
    if (_locks.empty())
341
        return false;
341
        return false;
342
 
342
 
343
    vector<__LOCKLIST_t>::iterator iter;
343
    vector<__LOCKLIST_t>::iterator iter;
Line 347... Line 347...
347
    {
347
    {
348
        if (iter->native_handle == nhandle)
348
        if (iter->native_handle == nhandle)
349
        {
349
        {
350
            if (mFilename.empty())
350
            if (mFilename.empty())
351
            {
351
            {
352
                MSG_DEBUG("Lock for mutex handle " << iter->native_handle << " will be removed.");
352
                MSG_PROTOCOL("Lock for mutex handle " << iter->native_handle << " will be removed.");
353
            }
353
            }
354
            else
354
            else
355
            {
355
            {
356
                MSG_DEBUG("Lock for mutex handle " << iter->native_handle << " will be removed on file " << mFilename << " at line " << mLineNumber << ".");
356
                MSG_PROTOCOL("Lock for mutex handle " << iter->native_handle << " will be removed on file " << mFilename << " at line " << mLineNumber << ".");
357
            }
357
            }
358
 
358
 
359
            bool ret = iter->state;
359
            bool ret = iter->state;
360
            _locks.erase(iter);
360
            _locks.erase(iter);
361
            return ret;
361
            return ret;
Line 366... Line 366...
366
}
366
}
367
 
367
 
368
template<typename _TMutex>
368
template<typename _TMutex>
369
void TLock<_TMutex>::stripFileName()
369
void TLock<_TMutex>::stripFileName()
370
{
370
{
371
    DECL_TRACER("TLock<_TMutex>::stripFileName()");
371
//    DECL_TRACER("TLock<_TMutex>::stripFileName()");
372
 
372
 
373
    if (mFilename.empty())
373
    if (mFilename.empty())
374
        return;
374
        return;
375
 
375
 
376
    size_t pos = mFilename.find_last_of("/");
376
    size_t pos = mFilename.find_last_of("/");