mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-05 12:31:33 +00:00
Add debugging code to test for various locking faux-pas's, when running in single threaded mode. This should help improve testing coverage for
threading support, without having extensive actually concurrent clients yet. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73803 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ac7087ecf0
commit
cc40f077b0
@ -15,6 +15,7 @@
|
|||||||
#define LLVM_SYSTEM_MUTEX_H
|
#define LLVM_SYSTEM_MUTEX_H
|
||||||
|
|
||||||
#include "llvm/System/Threading.h"
|
#include "llvm/System/Threading.h"
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace llvm
|
namespace llvm
|
||||||
{
|
{
|
||||||
@ -85,18 +86,32 @@ namespace llvm
|
|||||||
/// running in multithreaded mode.
|
/// running in multithreaded mode.
|
||||||
template<bool mt_only>
|
template<bool mt_only>
|
||||||
class SmartMutex : public MutexImpl {
|
class SmartMutex : public MutexImpl {
|
||||||
|
unsigned acquired;
|
||||||
|
bool recursive;
|
||||||
public:
|
public:
|
||||||
explicit SmartMutex(bool recursive = true) : MutexImpl(recursive) { }
|
explicit SmartMutex(bool rec = true) :
|
||||||
|
MutexImpl(rec), acquired(0), recursive(rec) { }
|
||||||
|
|
||||||
bool acquire() {
|
bool acquire() {
|
||||||
if (!mt_only || llvm_is_multithreaded())
|
if (!mt_only || llvm_is_multithreaded())
|
||||||
return MutexImpl::acquire();
|
return MutexImpl::acquire();
|
||||||
|
|
||||||
|
// Single-threaded debugging code. This would be racy in multithreaded
|
||||||
|
// mode, but provides not sanity checks in single threaded mode.
|
||||||
|
assert((recursive || acquired == 0) && "Lock already acquired!!");
|
||||||
|
++acquired;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool release() {
|
bool release() {
|
||||||
if (!mt_only || llvm_is_multithreaded())
|
if (!mt_only || llvm_is_multithreaded())
|
||||||
return MutexImpl::release();
|
return MutexImpl::release();
|
||||||
|
|
||||||
|
// Single-threaded debugging code. This would be racy in multithreaded
|
||||||
|
// mode, but provides not sanity checks in single threaded mode.
|
||||||
|
assert(((recursive && acquired) || (acquired == 1)) &&
|
||||||
|
"Lock not acquired before release!");
|
||||||
|
--acquired;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#define LLVM_SYSTEM_RWMUTEX_H
|
#define LLVM_SYSTEM_RWMUTEX_H
|
||||||
|
|
||||||
#include "llvm/System/Threading.h"
|
#include "llvm/System/Threading.h"
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace llvm
|
namespace llvm
|
||||||
{
|
{
|
||||||
@ -84,30 +85,50 @@ namespace llvm
|
|||||||
/// running in multithreaded mode.
|
/// running in multithreaded mode.
|
||||||
template<bool mt_only>
|
template<bool mt_only>
|
||||||
class SmartRWMutex : public RWMutexImpl {
|
class SmartRWMutex : public RWMutexImpl {
|
||||||
|
unsigned readers, writers;
|
||||||
public:
|
public:
|
||||||
explicit SmartRWMutex() : RWMutexImpl() { }
|
explicit SmartRWMutex() : RWMutexImpl(), readers(0), writers(0) { }
|
||||||
|
|
||||||
bool reader_acquire() {
|
bool reader_acquire() {
|
||||||
if (!mt_only || llvm_is_multithreaded())
|
if (!mt_only || llvm_is_multithreaded())
|
||||||
return RWMutexImpl::reader_acquire();
|
return RWMutexImpl::reader_acquire();
|
||||||
|
|
||||||
|
// Single-threaded debugging code. This would be racy in multithreaded
|
||||||
|
// mode, but provides not sanity checks in single threaded mode.
|
||||||
|
++readers;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool reader_release() {
|
bool reader_release() {
|
||||||
if (!mt_only || llvm_is_multithreaded())
|
if (!mt_only || llvm_is_multithreaded())
|
||||||
return RWMutexImpl::reader_release();
|
return RWMutexImpl::reader_release();
|
||||||
|
|
||||||
|
// Single-threaded debugging code. This would be racy in multithreaded
|
||||||
|
// mode, but provides not sanity checks in single threaded mode.
|
||||||
|
assert(readers > 0 && "Reader lock not acquired before release!");
|
||||||
|
--readers;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool writer_acquire() {
|
bool writer_acquire() {
|
||||||
if (!mt_only || llvm_is_multithreaded())
|
if (!mt_only || llvm_is_multithreaded())
|
||||||
return RWMutexImpl::writer_acquire();
|
return RWMutexImpl::writer_acquire();
|
||||||
|
|
||||||
|
// Single-threaded debugging code. This would be racy in multithreaded
|
||||||
|
// mode, but provides not sanity checks in single threaded mode.
|
||||||
|
assert(writers == 0 && "Writer lock already acquired!");
|
||||||
|
++writers;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool writer_release() {
|
bool writer_release() {
|
||||||
if (!mt_only || llvm_is_multithreaded())
|
if (!mt_only || llvm_is_multithreaded())
|
||||||
return RWMutexImpl::writer_release();
|
return RWMutexImpl::writer_release();
|
||||||
|
|
||||||
|
// Single-threaded debugging code. This would be racy in multithreaded
|
||||||
|
// mode, but provides not sanity checks in single threaded mode.
|
||||||
|
assert(writers == 1 && "Writer lock not acquired before release!");
|
||||||
|
--writers;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user