// 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 struct Accessor; template struct ThreadSafe { using A = Accessor; using A_const = Accessor; T v; mutable MutexType mutex; A access () { return A { &v, &mutex }; } A_const access () const { return A_const { &v, &mutex }; } template auto with(F &&f) { auto lk = lock_of(mutex); return f(v); } } ; template struct Accessor { using V = ThreadSafe; T *v; typename MutexType::Lock lock; Accessor(T *v_, MutexType *m) : v(v_), lock(*m) { } T *operator ->() { return v; } T &operator *() { return *v; } } ; } // namespace