flatten 20260225
This commit is contained in:
70
tjp/core/threads/TestMutex.hpp
Executable file
70
tjp/core/threads/TestMutex.hpp
Executable file
@@ -0,0 +1,70 @@
|
||||
// License: Modified MIT (NON-AI)
|
||||
// See the LICENSE file in the root directory for license information.
|
||||
// Copyright 2025 Timothy Prepscius
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include "Lock.h"
|
||||
#include "../system/Debug.h"
|
||||
#include <thread>
|
||||
#include "../types/Types.h"
|
||||
|
||||
namespace tjp::core {
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define USE_REAL_TEST_MUTEX
|
||||
#endif
|
||||
|
||||
#ifdef USE_REAL_TEST_MUTEX
|
||||
|
||||
struct TestMutex
|
||||
{
|
||||
struct Lock;
|
||||
|
||||
using V = size_t;
|
||||
std::atomic<V> v = 0;
|
||||
std::atomic<u64> c = 0;
|
||||
|
||||
Lock lock_of();
|
||||
|
||||
u64 get_thread_id() const;
|
||||
|
||||
void lock();
|
||||
void unlock();
|
||||
|
||||
bool locked_by_caller() const;
|
||||
} ;
|
||||
|
||||
struct TestMutex::Lock
|
||||
{
|
||||
TestMutex *m = nullptr;
|
||||
u64 id;
|
||||
|
||||
Lock ();
|
||||
Lock (TestMutex::Lock &&rhs);
|
||||
Lock (TestMutex &m_);
|
||||
|
||||
~Lock ();
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
struct TestMutex {
|
||||
struct Lock {
|
||||
// avoids the unused variable warning
|
||||
~Lock() {}
|
||||
};
|
||||
|
||||
void lock () {}
|
||||
void unlock () {}
|
||||
|
||||
Lock lock_of () { return TestMutex::Lock {}; }
|
||||
bool locked_by_caller() { return true; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
||||
#include "TestMutex.inl"
|
||||
Reference in New Issue
Block a user