mirror of
https://github.com/latentPrion/libspinscale.git
synced 2026-02-27 14:36:04 +00:00
Compare commits
3 Commits
3f3ff1283f
...
e77ecd447d
| Author | SHA1 | Date | |
|---|---|---|---|
| e77ecd447d | |||
| 130921062c | |||
| 18b632e5bb |
@@ -76,6 +76,8 @@ add_library(spinscale SHARED
|
||||
src/componentThread.cpp
|
||||
src/component.cpp
|
||||
src/puppetApplication.cpp
|
||||
src/runtime.cpp
|
||||
src/callableTracer.cpp
|
||||
)
|
||||
|
||||
# Conditionally add qutexAcquisitionHistoryTracker.cpp only when debug locks
|
||||
|
||||
@@ -8,11 +8,6 @@
|
||||
#include <cstdint>
|
||||
#include <spinscale/componentThread.h>
|
||||
|
||||
// Forward declaration - OptionParser is defined in smocore/include/opts.h
|
||||
// If you need tracing, include opts.h before including this header
|
||||
// The code will check for OPTS_H define to see if opts.h has been included
|
||||
class OptionParser;
|
||||
|
||||
namespace sscl {
|
||||
|
||||
/**
|
||||
@@ -50,11 +45,8 @@ public:
|
||||
|
||||
void operator()()
|
||||
{
|
||||
// OptionParser::getOptions() requires opts.h to be included
|
||||
// Only check traceCallables if opts.h has been included (OPTS_H is defined)
|
||||
#ifdef CONFIG_DEBUG_TRACE_CALLABLES
|
||||
#ifdef OPTS_H
|
||||
if (OptionParser::getOptions().traceCallables)
|
||||
#ifdef CONFIG_DEBUG_TRACE_CALLABLES
|
||||
if (optTraceCallables)
|
||||
{
|
||||
std::cout << "" << __func__ << ": On thread "
|
||||
<< (ComponentThread::tlsInitialized()
|
||||
@@ -65,12 +57,14 @@ public:
|
||||
<< ", return addr 1: " << returnAddr1
|
||||
<< std::endl;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
callable();
|
||||
}
|
||||
|
||||
public:
|
||||
/// Set by application (e.g. from opts) to enable per-callable trace output
|
||||
static bool optTraceCallables;
|
||||
|
||||
/// Name of the function that created this callable
|
||||
std::string callerFuncName;
|
||||
/// Line number where this callable was created
|
||||
@@ -115,7 +109,7 @@ private:
|
||||
// e.g., "void smo::SomeClass::method(int, int)"
|
||||
// __builtin_return_address(0) = direct caller
|
||||
// __builtin_return_address(1) = caller before that
|
||||
#define STC(arg) smo::CallableTracer( \
|
||||
#define STC(arg) sscl::CallableTracer( \
|
||||
__PRETTY_FUNCTION__, \
|
||||
__LINE__, \
|
||||
__builtin_return_address(0), \
|
||||
@@ -126,7 +120,7 @@ private:
|
||||
// e.g., "void __cdecl smo::SomeClass::method(int, int)"
|
||||
// _ReturnAddress() = direct caller (only one level available)
|
||||
#include <intrin.h>
|
||||
#define STC(arg) smo::CallableTracer( \
|
||||
#define STC(arg) sscl::CallableTracer( \
|
||||
__FUNCSIG__, \
|
||||
__LINE__, \
|
||||
_ReturnAddress(), \
|
||||
@@ -135,7 +129,7 @@ private:
|
||||
#else
|
||||
// Fallback to standard __func__ (unqualified name only)
|
||||
// No return address support
|
||||
#define STC(arg) smo::CallableTracer( \
|
||||
#define STC(arg) sscl::CallableTracer( \
|
||||
__func__, \
|
||||
__LINE__, \
|
||||
nullptr, \
|
||||
|
||||
@@ -53,6 +53,8 @@ struct CrtCommandLineArgs
|
||||
static void set(int argc, char *argv[], char *envp[]);
|
||||
};
|
||||
|
||||
extern CrtCommandLineArgs crtCommandLineArgs;
|
||||
|
||||
} // namespace sscl
|
||||
|
||||
#endif // _MARIONETTE_H
|
||||
|
||||
76
include/spinscale/sequenceLock.h
Normal file
76
include/spinscale/sequenceLock.h
Normal file
@@ -0,0 +1,76 @@
|
||||
#ifndef SPINSCALE_SEQUENCE_LOCK_H
|
||||
#define SPINSCALE_SEQUENCE_LOCK_H
|
||||
|
||||
#include <atomic>
|
||||
#include <optional>
|
||||
|
||||
namespace sscl {
|
||||
|
||||
/**
|
||||
* @brief Sequence lock synchronization primitive
|
||||
*
|
||||
* A reader-writer synchronization primitive where writers increment the
|
||||
* sequence number (odd = writing in progress, even = stable) and readers
|
||||
* check the sequence number to detect concurrent modifications.
|
||||
*/
|
||||
class SequenceLock
|
||||
{
|
||||
public:
|
||||
SequenceLock()
|
||||
: sequenceNo(0)
|
||||
{}
|
||||
|
||||
~SequenceLock() = default;
|
||||
|
||||
// Non-copyable, non-movable (std::atomic is neither copyable nor movable)
|
||||
SequenceLock(const SequenceLock&) = delete;
|
||||
SequenceLock& operator=(const SequenceLock&) = delete;
|
||||
SequenceLock(SequenceLock&&) = delete;
|
||||
SequenceLock& operator=(SequenceLock&&) = delete;
|
||||
|
||||
/* Atomically increments sequenceNo and issues a release barrier.
|
||||
* Makes the sequence number odd, indicating a write is in progress.
|
||||
*/
|
||||
void writeAcquire()
|
||||
{ sequenceNo.fetch_add(1, std::memory_order_release); }
|
||||
|
||||
/* Atomically increments sequenceNo and issues a release barrier.
|
||||
* Makes the sequence number even again, indicating write is complete.
|
||||
*/
|
||||
void writeRelease()
|
||||
{ sequenceNo.fetch_add(1, std::memory_order_release); }
|
||||
|
||||
/* Issues an acquire barrier and checks if the sequence number is even
|
||||
* (stable state). If odd (writer active), returns nullopt. Otherwise
|
||||
* returns the sequence number.
|
||||
*
|
||||
* @return std::nullopt if writer is active, otherwise the sequence number
|
||||
*/
|
||||
std::optional<size_t> readAcquire()
|
||||
{
|
||||
size_t seq = sequenceNo.load(std::memory_order_acquire);
|
||||
if (seq & 1) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return seq;
|
||||
}
|
||||
|
||||
/* Issues an acquire barrier and checks if the sequence number matches
|
||||
* the original value from readAcquire(). If equal, the read was consistent.
|
||||
*
|
||||
* @param originalSequenceNo The sequence number obtained from readAcquire()
|
||||
* @return true if read was consistent, false if writer modified during read
|
||||
*/
|
||||
bool readRelease(size_t originalSequenceNo)
|
||||
{
|
||||
size_t seq = sequenceNo.load(std::memory_order_acquire);
|
||||
return seq == originalSequenceNo;
|
||||
}
|
||||
|
||||
private:
|
||||
std::atomic<size_t> sequenceNo;
|
||||
};
|
||||
|
||||
} // namespace sscl
|
||||
|
||||
#endif // SPINSCALE_SEQUENCE_LOCK_H
|
||||
7
src/callableTracer.cpp
Normal file
7
src/callableTracer.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <spinscale/callableTracer.h>
|
||||
|
||||
namespace sscl {
|
||||
|
||||
bool CallableTracer::optTraceCallables = false;
|
||||
|
||||
} // namespace sscl
|
||||
12
src/runtime.cpp
Normal file
12
src/runtime.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <spinscale/marionette.h>
|
||||
|
||||
namespace sscl {
|
||||
|
||||
CrtCommandLineArgs crtCommandLineArgs(0, nullptr, nullptr);
|
||||
|
||||
void CrtCommandLineArgs::set(int argc, char *argv[], char *envp[])
|
||||
{
|
||||
crtCommandLineArgs = CrtCommandLineArgs(argc, argv, envp);
|
||||
}
|
||||
|
||||
} // namespace sscl
|
||||
Reference in New Issue
Block a user