flatten 20260225

This commit is contained in:
Timothy Prepscius
2026-02-25 12:43:06 -05:00
commit 996151a56a
521 changed files with 46722 additions and 0 deletions

65
tjp/core/threads/ThreadSafe.hpp Executable file
View File

@@ -0,0 +1,65 @@
// License: Modified MIT (NON-AI)
// See the LICENSE file in the root directory for license information.
// Copyright 2025 Timothy Prepscius
#pragma once
#include "Lock.h"
namespace tjp::core {
template<typename T, typename MutexType = Mutex>
struct Accessor;
template<typename T, typename MutexType = Mutex>
struct ThreadSafe
{
using A = Accessor<T, MutexType>;
using A_const = Accessor<const T, MutexType>;
T v;
mutable MutexType mutex;
A access ()
{
return A { &v, &mutex };
}
A_const access () const
{
return A_const { &v, &mutex };
}
template<typename F>
auto with(F &&f)
{
auto lk = lock_of(mutex);
return f(v);
}
} ;
template<typename T, typename MutexType>
struct Accessor
{
using V = ThreadSafe<T, MutexType>;
T *v;
typename MutexType::Lock lock;
Accessor(T *v_, MutexType *m) :
v(v_),
lock(*m)
{
}
T *operator ->()
{
return v;
}
T &operator *()
{
return *v;
}
} ;
} // namespace