From 34d76df7d9ec299e79763dfdbb757e34066d64fa Mon Sep 17 00:00:00 2001 From: Hayodea Hekol Date: Sat, 27 Dec 2025 16:21:22 -0400 Subject: [PATCH] Spinscale: create new namespace sscl --- .../attachmentSupport/stimulusProducer.cpp | 4 +- commonLibs/livoxProto1/broadcastListener.cpp | 8 +- commonLibs/livoxProto1/broadcastListener.h | 6 +- commonLibs/livoxProto1/core.cpp | 20 ++-- commonLibs/livoxProto1/core.h | 10 +- commonLibs/livoxProto1/device.cpp | 82 ++++++------- commonLibs/livoxProto1/device.h | 24 ++-- commonLibs/livoxProto1/livoxProto1.cpp | 14 +-- commonLibs/livoxProto1/livoxProto1.h | 16 +-- commonLibs/livoxProto1/udpCommandDemuxer.cpp | 8 +- commonLibs/livoxProto1/udpCommandDemuxer.h | 6 +- include/user/senseApiDesc.h | 15 ++- include/user/stimulusProducer.h | 4 +- .../include/spinscale/asynchronousBridge.h | 4 +- .../spinscale/asynchronousContinuation.h | 4 +- .../asynchronousContinuationChainLink.h | 4 +- .../include/spinscale/asynchronousLoop.h | 4 +- .../include/spinscale/callableTracer.h | 4 +- libspinscale/include/spinscale/callback.h | 4 +- libspinscale/include/spinscale/component.h | 4 +- .../include/spinscale/componentThread.h | 20 ++-- .../include/spinscale/dependencyGraph.h | 4 +- libspinscale/include/spinscale/lockSet.h | 4 +- .../include/spinscale/lockerAndInvokerBase.h | 4 +- .../include/spinscale/puppetApplication.h | 4 +- libspinscale/include/spinscale/qutex.h | 4 +- .../qutexAcquisitionHistoryTracker.h | 4 +- .../serializedAsynchronousContinuation.h | 4 +- libspinscale/include/spinscale/spinLock.h | 4 +- libspinscale/src/component.cpp | 10 +- libspinscale/src/componentThread.cpp | 22 ++-- libspinscale/src/lockerAndInvokerBase.cpp | 4 +- libspinscale/src/puppetApplication.cpp | 4 +- libspinscale/src/qutex.cpp | 4 +- .../src/qutexAcquisitionHistoryTracker.cpp | 4 +- main.cpp | 2 +- smocore/body/body.cpp | 32 +++--- smocore/componentThread.cpp | 14 +-- smocore/deviceManager/deviceManager.cpp | 108 +++++++++--------- smocore/deviceManager/deviceReattacher.cpp | 8 +- smocore/director/director.cpp | 4 +- smocore/include/body/body.h | 9 +- smocore/include/componentThread.h | 2 +- smocore/include/deviceManager/device.h | 2 +- smocore/include/deviceManager/deviceManager.h | 22 ++-- .../include/deviceManager/deviceReattacher.h | 8 +- smocore/include/director/director.h | 5 +- smocore/include/marionette/marionette.h | 8 +- smocore/include/mind.h | 12 +- smocore/include/mindThread.h | 6 +- smocore/include/simulator/simulator.h | 5 +- smocore/include/stimBuffApis/stimBuffApiLib.h | 2 +- .../include/stimBuffApis/stimBuffApiManager.h | 6 +- smocore/marionette/lifetime.cpp | 32 +++--- smocore/marionette/main.cpp | 47 ++++---- smocore/mind.cpp | 34 +++--- smocore/simulator/simulator.cpp | 4 +- smocore/stimBuffApis/stimBuffApiManager.cpp | 10 +- .../livoxGen1/ioUringAssemblyEngine.cpp | 38 +++--- .../livoxGen1/ioUringAssemblyEngine.h | 8 +- stimBuffApis/livoxGen1/livoxGen1.cpp | 18 +-- .../openClCollatingAndMeshingEngine.cpp | 32 +++--- .../openClCollatingAndMeshingEngine.h | 6 +- .../livoxGen1/pcloudStimulusProducer.cpp | 20 ++-- .../livoxGen1/pcloudStimulusProducer.h | 2 +- stimBuffApis/xcbWindow/xcbWindow.cpp | 6 +- tests/smocore/qutex_tests.cpp | 6 +- 67 files changed, 434 insertions(+), 429 deletions(-) diff --git a/commonLibs/attachmentSupport/stimulusProducer.cpp b/commonLibs/attachmentSupport/stimulusProducer.cpp index 3dda6cf..a33d053 100644 --- a/commonLibs/attachmentSupport/stimulusProducer.cpp +++ b/commonLibs/attachmentSupport/stimulusProducer.cpp @@ -92,7 +92,7 @@ void StimulusProducer::destroyAttachedStimulusBuffer( void StimulusProducer::stop() { { - SpinLock::Guard lock(shouldContinueLock); + sscl::SpinLock::Guard lock(shouldContinueLock); shouldContinue = false; } @@ -131,7 +131,7 @@ void StimulusProducer::onTimeout(const boost::system::error_code& error) return; } - SpinLock::Guard lock(shouldContinueLock); + sscl::SpinLock::Guard lock(shouldContinueLock); if (!shouldContinue) { return; } diff --git a/commonLibs/livoxProto1/broadcastListener.cpp b/commonLibs/livoxProto1/broadcastListener.cpp index f11112a..00714b7 100644 --- a/commonLibs/livoxProto1/broadcastListener.cpp +++ b/commonLibs/livoxProto1/broadcastListener.cpp @@ -10,7 +10,7 @@ namespace livoxProto1 { namespace comms { BroadcastListener::BroadcastListener( - const std::shared_ptr& componentThread, + const std::shared_ptr& componentThread, uint16_t listeningPort, uint16_t connectPort ) : componentThread(componentThread), @@ -94,7 +94,7 @@ void BroadcastListener::broadcastMsgInd( reinterpret_cast(msg->broadcast_code)); // Early return if device already exists - smo::SpinLock::Guard lock(isListeningLock); + sscl::SpinLock::Guard lock(isListeningLock); if (deviceExists(broadcastCode)) { @@ -134,7 +134,7 @@ void BroadcastListener::start(void) * away. */ { - smo::SpinLock::Guard lock(isListeningLock); + sscl::SpinLock::Guard lock(isListeningLock); socket.open(boost::asio::ip::udp::v4()); socket.bind(listeningEndpoint); @@ -172,7 +172,7 @@ void BroadcastListener::startReceive(void) void BroadcastListener::stop(void) { { - smo::SpinLock::Guard lock(isListeningLock); + sscl::SpinLock::Guard lock(isListeningLock); if (!isListening) { return; } isListening = false; diff --git a/commonLibs/livoxProto1/broadcastListener.h b/commonLibs/livoxProto1/broadcastListener.h index 4963a77..8582dc9 100644 --- a/commonLibs/livoxProto1/broadcastListener.h +++ b/commonLibs/livoxProto1/broadcastListener.h @@ -29,7 +29,7 @@ class BroadcastListener { public: BroadcastListener( - const std::shared_ptr& componentThread, + const std::shared_ptr& componentThread, uint16_t listeningPort=55000, uint16_t connectPort=65000); ~BroadcastListener() = default; @@ -54,7 +54,7 @@ private: void startReceive(void); private: - std::shared_ptr componentThread; + std::shared_ptr componentThread; /** EXPLANATION: * The Livox proto says that client devices will spam broadcast UDP * dgrams to us on the listening port. We can then use the source IP from @@ -68,7 +68,7 @@ private: boost::asio::ip::udp::socket socket; boost::asio::ip::udp::endpoint listeningEndpoint, senderEndpoint; - smo::SpinLock isListeningLock; + sscl::SpinLock isListeningLock; bool isListening; uint8_t bcastMsgRecvBuffer[UDP_BCAST_MSG_BUFFER_NBYTES]; diff --git a/commonLibs/livoxProto1/core.cpp b/commonLibs/livoxProto1/core.cpp index f096974..03837ed 100644 --- a/commonLibs/livoxProto1/core.cpp +++ b/commonLibs/livoxProto1/core.cpp @@ -74,7 +74,7 @@ std::optional> DeviceManager::getDevice( // GetOrCreateDeviceReq nested class implementation class DeviceManager::GetOrCreateDeviceReq -: public smo::NonPostedAsynchronousContinuation< +: public sscl::NonPostedAsynchronousContinuation< livoxProto1_getOrCreateDeviceReqCbFn> { public: @@ -86,8 +86,8 @@ public: GetOrCreateDeviceReq( DeviceManager& mgr, std::shared_ptr device, - smo::Callback cb) - : smo::NonPostedAsynchronousContinuation< + sscl::Callback cb) + : sscl::NonPostedAsynchronousContinuation< livoxProto1_getOrCreateDeviceReqCbFn>(std::move(cb)), deviceManager(mgr), pendingDevice(device) {} @@ -128,11 +128,11 @@ public: void DeviceManager::getOrCreateDeviceReq( const std::string &deviceIdentifier, - const std::shared_ptr& componentThread, + const std::shared_ptr& componentThread, int commandTimeoutMs, int retryDelayMs, const std::string& smoIp, uint8_t smoSubnetNbits, uint16_t dataPort, uint16_t cmdPort, uint16_t imuPort, - smo::Callback callback) + sscl::Callback callback) { // Validate smoIp format using Boost.Asio IPv4 validation if (!smoIp.empty() && !comms::isValidIPv4(smoIp)) @@ -179,7 +179,7 @@ void DeviceManager::getOrCreateDeviceReq( } class DeviceManager::DestroyDeviceReq -: public smo::NonPostedAsynchronousContinuation< +: public sscl::NonPostedAsynchronousContinuation< livoxProto1_destroyDeviceReqCbFn> { public: @@ -190,8 +190,8 @@ public: DestroyDeviceReq( DeviceManager& mgr, std::shared_ptr device, - smo::Callback cb) - : smo::NonPostedAsynchronousContinuation< + sscl::Callback cb) + : sscl::NonPostedAsynchronousContinuation< livoxProto1_destroyDeviceReqCbFn>(std::move(cb)), deviceManager(mgr), pendingDevice(device) {} @@ -220,7 +220,7 @@ public: void DeviceManager::destroyDeviceReq( std::shared_ptr dev, - smo::Callback callback + sscl::Callback callback ) { /** EXPLANATION: @@ -245,7 +245,7 @@ void DeviceManager::destroyDeviceReq( request.get(), request, std::placeholders::_1)}); } -void main(const std::shared_ptr &componentThread, +void main(const std::shared_ptr &componentThread, const smo::stim_buff::SmoCallbacks& smoCallbacks) { if (protoState.isInitialized) { diff --git a/commonLibs/livoxProto1/core.h b/commonLibs/livoxProto1/core.h index 9cb6a9d..a430826 100644 --- a/commonLibs/livoxProto1/core.h +++ b/commonLibs/livoxProto1/core.h @@ -25,15 +25,15 @@ public: void getOrCreateDeviceReq( const std::string &deviceIdentifier, - const std::shared_ptr& componentThread, + const std::shared_ptr& componentThread, int commandTimeoutMs, int retryDelayMs, const std::string& smoIp, uint8_t smoSubnetNbits, uint16_t dataPort, uint16_t cmdPort, uint16_t imuPort, - smo::Callback callback); + sscl::Callback callback); void destroyDeviceReq( std::shared_ptr device, - smo::Callback callback); + sscl::Callback callback); std::optional> getDevice( const std::string &deviceIdentifier); @@ -59,7 +59,7 @@ public: }; void main( - const std::shared_ptr &componentThread, + const std::shared_ptr &componentThread, const smo::stim_buff::SmoCallbacks& smoCallbacks); void exit(void); @@ -67,7 +67,7 @@ void exit(void); struct ProtoState { bool isInitialized = false; - std::shared_ptr componentThread; + std::shared_ptr componentThread; std::unique_ptr deviceManager; smo::stim_buff::SmoCallbacks smoCallbacks; }; diff --git a/commonLibs/livoxProto1/device.cpp b/commonLibs/livoxProto1/device.cpp index 5d5ec39..b947046 100644 --- a/commonLibs/livoxProto1/device.cpp +++ b/commonLibs/livoxProto1/device.cpp @@ -90,7 +90,7 @@ std::string DiscoveredDevice::getDeviceTypeName(void) const } // namespace comms Device::Device(const std::string &deviceIdentifier, - const std::shared_ptr& componentThread, + const std::shared_ptr& componentThread, int commandTimeoutMs, int retryDelayMs, const std::string& smoIp, uint8_t smoSubnetNbits, uint16_t dataPort, uint16_t cmdPort, uint16_t imuPort) @@ -124,15 +124,15 @@ Device::~Device() * This class manages the overall device connection process including handshake and heartbeat setup */ class Device::ConnectReq -: public smo::NonPostedAsynchronousContinuation +: public sscl::NonPostedAsynchronousContinuation { private: Device& device; boost::asio::deadline_timer delayTimer; public: - ConnectReq(Device& dev, smo::Callback cb) - : smo::NonPostedAsynchronousContinuation( + ConnectReq(Device& dev, sscl::Callback cb) + : sscl::NonPostedAsynchronousContinuation( std::move(cb)), device(dev), delayTimer(dev.componentThread->getIoService()) {} @@ -216,7 +216,7 @@ public: { callOriginalCallback(false); } }; -void Device::connectReq(smo::Callback callback) +void Device::connectReq(sscl::Callback callback) { // Create the connection request object to hold state and callbacks auto request = std::make_shared(*this, std::move(callback)); @@ -233,7 +233,7 @@ void Device::connectReq(smo::Callback callback) } class Device::ConnectToKnownDeviceReq -: public smo::NonPostedAsynchronousContinuation< +: public sscl::NonPostedAsynchronousContinuation< Device::connectToKnownDeviceReqCbFn> { public: @@ -241,8 +241,8 @@ public: std::string deviceIP; std::shared_ptr deviceInfo; - ConnectToKnownDeviceReq(Device& dev, smo::Callback cb) - : smo::NonPostedAsynchronousContinuation< + ConnectToKnownDeviceReq(Device& dev, sscl::Callback cb) + : sscl::NonPostedAsynchronousContinuation< Device::connectToKnownDeviceReqCbFn>(std::move(cb)), device(dev) {} @@ -269,7 +269,7 @@ public: * broadcastListener. */ void Device::connectToKnownDeviceReq( - smo::Callback callback + sscl::Callback callback ) { // Create the connection request object to hold state and callbacks @@ -336,7 +336,7 @@ void Device::connectToKnownDeviceReq( } class Device::ConnectByDeviceIdentifierReq -: public smo::NonPostedAsynchronousContinuation< +: public sscl::NonPostedAsynchronousContinuation< Device::connectByDeviceIdentifierReqCbFn> { public: @@ -344,8 +344,8 @@ public: std::string deviceIP; ConnectByDeviceIdentifierReq( - Device& dev, smo::Callback cb) - : smo::NonPostedAsynchronousContinuation< + Device& dev, sscl::Callback cb) + : sscl::NonPostedAsynchronousContinuation< Device::connectByDeviceIdentifierReqCbFn>( std::move(cb)), device(dev) {} @@ -370,7 +370,7 @@ public: }; void Device::connectByDeviceIdentifierReq( - smo::Callback callback + sscl::Callback callback ) { /** EXPLANATION: @@ -419,13 +419,13 @@ void Device::connectByDeviceIdentifierReq( } class Device::ExecuteHandshakeReq -: public smo::NonPostedAsynchronousContinuation< +: public sscl::NonPostedAsynchronousContinuation< Device::executeHandshakeReqCbFn> { public: friend void Device::executeHandshakeReq( const std::string& deviceIP, - smo::Callback callback); + sscl::Callback callback); enum class SocketState { @@ -459,8 +459,8 @@ public: Device& dev, const std::string& deviceIP, std::shared_ptr &cmdEndpointFdDesc, - smo::Callback cb) - : smo::NonPostedAsynchronousContinuation( + sscl::Callback cb) + : sscl::NonPostedAsynchronousContinuation( std::move(cb)), device(dev), deviceIP(deviceIP), cmdEndpointFdDesc(cmdEndpointFdDesc), @@ -753,7 +753,7 @@ private: void Device::executeHandshakeReq( const std::string& deviceIP, - smo::Callback callback + sscl::Callback callback ) { // Get the command endpoint from the UdpCommandDemuxer @@ -803,7 +803,7 @@ void Device::executeHandshakeReq( } } -void Device::disconnectReq(smo::Callback callback) +void Device::disconnectReq(sscl::Callback callback) { // Stop heartbeat first stopHeartbeat(); @@ -1042,7 +1042,7 @@ void Device::startHeartbeat() } // Register heartbeat ACK handler (cmd_set=0x00, cmd_id=0x03) - smo::SpinLock::Guard lock(heartbeatActiveLock); + sscl::SpinLock::Guard lock(heartbeatActiveLock); registerUdpCommandHandler( 0x00, 0x03, discardHeartbeatAck, discoveredDevice.ipAddr); @@ -1060,7 +1060,7 @@ void Device::startHeartbeat() void Device::stopHeartbeat() { { - smo::SpinLock::Guard lock(heartbeatActiveLock); + sscl::SpinLock::Guard lock(heartbeatActiveLock); heartbeatActive.store(false); unregisterUdpCommandHandler(0x00, 0x03, discoveredDevice.ipAddr); @@ -1168,7 +1168,7 @@ void Device::onHeartbeatTimer(const boost::system::error_code& error) // Send next heartbeat { - smo::SpinLock::Guard lock(heartbeatActiveLock); + sscl::SpinLock::Guard lock(heartbeatActiveLock); if (!heartbeatActive.load()) { return; } @@ -1331,7 +1331,7 @@ std::optional Device::getSmoIp(const std::string& deviceIP) // Base class for both enable and disable pcloud data requests template class EnDisablePcloudDataReq -: public smo::NonPostedAsynchronousContinuation +: public sscl::NonPostedAsynchronousContinuation { public: enum class SocketState @@ -1362,8 +1362,8 @@ public: protected: EnDisablePcloudDataReq( Device& dev, - smo::Callback cb) - : smo::NonPostedAsynchronousContinuation(std::move(cb)), + sscl::Callback cb) + : sscl::NonPostedAsynchronousContinuation(std::move(cb)), device(dev), timeoutTimer(device.componentThread->getIoService()) {} @@ -1608,11 +1608,11 @@ class Device::EnablePcloudDataReq { public: friend void Device::enablePcloudDataReq( - smo::Callback callback); + sscl::Callback callback); EnablePcloudDataReq( Device& dev, - smo::Callback cb) + sscl::Callback cb) : EnDisablePcloudDataReq(dev, std::move(cb)) {} @@ -1643,11 +1643,11 @@ class Device::DisablePcloudDataReq { public: friend void Device::disablePcloudDataReq( - smo::Callback callback); + sscl::Callback callback); DisablePcloudDataReq( Device& dev, - smo::Callback cb) + sscl::Callback cb) : EnDisablePcloudDataReq( dev, std::move(cb)) {} @@ -1675,7 +1675,7 @@ private: }; void Device::enablePcloudDataReq( - smo::Callback callback + sscl::Callback callback ) { auto request = std::make_shared( @@ -1702,7 +1702,7 @@ void Device::enablePcloudDataReq( } void Device::disablePcloudDataReq( - smo::Callback callback + sscl::Callback callback ) { auto request = std::make_shared( @@ -1858,7 +1858,7 @@ void Device::unregisterUdpCommandHandler( // SetReturnModeReq continuation class class Device::SetReturnModeReq -: public smo::NonPostedAsynchronousContinuation +: public sscl::NonPostedAsynchronousContinuation { public: enum class SocketState @@ -1890,12 +1890,12 @@ public: public: friend void Device::setReturnModeReq( uint8_t returnMode, - smo::Callback callback); + sscl::Callback callback); SetReturnModeReq( Device& dev, uint8_t mode, - smo::Callback cb) - : smo::NonPostedAsynchronousContinuation( + sscl::Callback cb) + : sscl::NonPostedAsynchronousContinuation( std::move(cb)), device(dev), returnMode(mode), timeoutTimer(device.componentThread->getIoService()) @@ -2107,7 +2107,7 @@ public: // GetReturnModeReq continuation class class Device::GetReturnModeReq -: public smo::NonPostedAsynchronousContinuation +: public sscl::NonPostedAsynchronousContinuation { public: enum class SocketState @@ -2137,12 +2137,12 @@ public: public: friend void Device::getReturnModeReq( - smo::Callback callback); + sscl::Callback callback); GetReturnModeReq( Device& dev, - smo::Callback cb) - : smo::NonPostedAsynchronousContinuation( + sscl::Callback cb) + : sscl::NonPostedAsynchronousContinuation( std::move(cb)), device(dev), timeoutTimer(device.componentThread->getIoService()) @@ -2351,7 +2351,7 @@ public: void Device::setReturnModeReq( uint8_t returnMode, - smo::Callback callback + sscl::Callback callback ) { auto request = std::make_shared( @@ -2378,7 +2378,7 @@ void Device::setReturnModeReq( } void Device::getReturnModeReq( - smo::Callback callback + sscl::Callback callback ) { auto request = std::make_shared( diff --git a/commonLibs/livoxProto1/device.h b/commonLibs/livoxProto1/device.h index bdbc7ad..6646cec 100644 --- a/commonLibs/livoxProto1/device.h +++ b/commonLibs/livoxProto1/device.h @@ -77,7 +77,7 @@ class Device { public: Device(const std::string &deviceIdentifier, - const std::shared_ptr& componentThread, + const std::shared_ptr& componentThread, int commandTimeoutMs, int retryDelayMs, const std::string& smoIp, uint8_t smoSubnetNbits, uint16_t dataPort, uint16_t cmdPort, uint16_t imuPort); @@ -163,27 +163,27 @@ public: getReturnModeReqCbFn; // Async connection methods - void connectReq(smo::Callback callback); + void connectReq(sscl::Callback callback); void connectToKnownDeviceReq( - smo::Callback callback); + sscl::Callback callback); void connectByDeviceIdentifierReq( - smo::Callback callback); + sscl::Callback callback); void executeHandshakeReq( const std::string& deviceIP, - smo::Callback callback); - void disconnectReq(smo::Callback callback); - void enablePcloudDataReq(smo::Callback callback); - void disablePcloudDataReq(smo::Callback callback); + sscl::Callback callback); + void disconnectReq(sscl::Callback callback); + void enablePcloudDataReq(sscl::Callback callback); + void disablePcloudDataReq(sscl::Callback callback); void setReturnModeReq( - uint8_t returnMode, smo::Callback callback); - void getReturnModeReq(smo::Callback callback); + uint8_t returnMode, sscl::Callback callback); + void getReturnModeReq(sscl::Callback callback); public: comms::DiscoveredDevice discoveredDevice; std::atomic nAttachedStimulusProducers; // Configuration - std::shared_ptr componentThread; + std::shared_ptr componentThread; int commandTimeoutMs, retryDelayMs; std::string smoIp; std::string detectedSmoListeningIp; @@ -193,7 +193,7 @@ public: // Heartbeat state std::unique_ptr heartbeatTimer; std::atomic heartbeatActive; - smo::SpinLock heartbeatActiveLock; + sscl::SpinLock heartbeatActiveLock; // Point cloud data state std::atomic pcloudDataActive; diff --git a/commonLibs/livoxProto1/livoxProto1.cpp b/commonLibs/livoxProto1/livoxProto1.cpp index b683e55..11a5407 100644 --- a/commonLibs/livoxProto1/livoxProto1.cpp +++ b/commonLibs/livoxProto1/livoxProto1.cpp @@ -12,11 +12,11 @@ extern "C" { void livoxProto1_getOrCreateDeviceReq( const std::string& deviceIdentifier, - const std::shared_ptr& componentThread, + const std::shared_ptr& componentThread, int commandTimeoutMs, int retryDelayMs, const std::string& smoIp, uint8_t smoSubnetNbits, uint16_t dataPort, uint16_t cmdPort, uint16_t imuPort, - smo::Callback callback + sscl::Callback callback ) { // Get the global DeviceManager instance @@ -39,7 +39,7 @@ void livoxProto1_getOrCreateDeviceReq( void livoxProto1_destroyDeviceReq( std::shared_ptr device, - smo::Callback callback + sscl::Callback callback ) { auto& protoState = livoxProto1::getProtoState(); @@ -54,7 +54,7 @@ void livoxProto1_destroyDeviceReq( } void livoxProto1_main( - const std::shared_ptr& componentThread, + const std::shared_ptr& componentThread, const smo::stim_buff::SmoCallbacks& smoCallbacks) { livoxProto1::main(componentThread, smoCallbacks); @@ -67,7 +67,7 @@ void livoxProto1_exit(void) void livoxProto1_device_enablePcloudDataReq( std::shared_ptr device, - smo::Callback callback + sscl::Callback callback ) { if (!device) @@ -81,7 +81,7 @@ void livoxProto1_device_enablePcloudDataReq( void livoxProto1_device_disablePcloudDataReq( std::shared_ptr device, - smo::Callback callback + sscl::Callback callback ) { if (!device) @@ -95,7 +95,7 @@ void livoxProto1_device_disablePcloudDataReq( void livoxProto1_device_getReturnModeReq( std::shared_ptr device, - smo::Callback callback + sscl::Callback callback ) { if (!device) diff --git a/commonLibs/livoxProto1/livoxProto1.h b/commonLibs/livoxProto1/livoxProto1.h index 9891fd2..834b58d 100644 --- a/commonLibs/livoxProto1/livoxProto1.h +++ b/commonLibs/livoxProto1/livoxProto1.h @@ -14,6 +14,8 @@ namespace smo { namespace stim_buff { struct SmoCallbacks; } +} +namespace sscl { class ComponentThread; } @@ -31,7 +33,7 @@ extern "C" { * @param smoCallbacks Callbacks provided by SMO */ typedef void livoxProto1_mainFn( - const std::shared_ptr& componentThread, + const std::shared_ptr& componentThread, const smo::stim_buff::SmoCallbacks& smoCallbacks); /** @@ -58,34 +60,34 @@ typedef std::function< typedef void livoxProto1_getOrCreateDeviceReqFn( const std::string& deviceIdentifier, - const std::shared_ptr& componentThread, + const std::shared_ptr& componentThread, int commandTimeoutMs, int retryDelayMs, const std::string& smoIp, uint8_t smoSubnetNbits, uint16_t dataPort, uint16_t cmdPort, uint16_t imuPort, - smo::Callback callback); + sscl::Callback callback); typedef std::function livoxProto1_destroyDeviceReqCbFn; typedef void livoxProto1_destroyDeviceReqFn( std::shared_ptr device, - smo::Callback callback); + sscl::Callback callback); typedef std::function livoxProto1_device_enablePcloudDataReqCbFn; typedef void livoxProto1_device_enablePcloudDataReqFn( std::shared_ptr device, - smo::Callback callback); + sscl::Callback callback); typedef std::function livoxProto1_device_disablePcloudDataReqCbFn; typedef void livoxProto1_device_disablePcloudDataReqFn( std::shared_ptr device, - smo::Callback callback); + sscl::Callback callback); typedef std::function livoxProto1_device_getReturnModeReqCbFn; typedef void livoxProto1_device_getReturnModeReqFn( std::shared_ptr device, - smo::Callback callback); + sscl::Callback callback); typedef std::shared_ptr livoxProto1_getPcloudDataFdDescFn(void); diff --git a/commonLibs/livoxProto1/udpCommandDemuxer.cpp b/commonLibs/livoxProto1/udpCommandDemuxer.cpp index 888ec4d..38fba57 100644 --- a/commonLibs/livoxProto1/udpCommandDemuxer.cpp +++ b/commonLibs/livoxProto1/udpCommandDemuxer.cpp @@ -16,7 +16,7 @@ namespace livoxProto1 { namespace comms { UdpCommandDemuxer::UdpCommandDemuxer( - const std::shared_ptr &componentThread, + const std::shared_ptr &componentThread, DeviceManager &deviceManager, uint16_t commandPort, uint16_t dataPort @@ -44,7 +44,7 @@ void UdpCommandDemuxer::start() try { { - smo::SpinLock::Guard lock(isActiveAndShouldStopLock); + sscl::SpinLock::Guard lock(isActiveAndShouldStopLock); setupSockets(); isActive.store(true); @@ -71,7 +71,7 @@ void UdpCommandDemuxer::start() void UdpCommandDemuxer::stop() { { - smo::SpinLock::Guard lock(isActiveAndShouldStopLock); + sscl::SpinLock::Guard lock(isActiveAndShouldStopLock); if (!isActive.load()) { return; } @@ -291,7 +291,7 @@ void UdpCommandDemuxer::onDataReady(const boost::system::error_code &error) return; } - smo::SpinLock::Guard lock(isActiveAndShouldStopLock); + sscl::SpinLock::Guard lock(isActiveAndShouldStopLock); if (!isActive.load() || shouldStop.load()) { return; } diff --git a/commonLibs/livoxProto1/udpCommandDemuxer.h b/commonLibs/livoxProto1/udpCommandDemuxer.h index 9748036..75e3da3 100644 --- a/commonLibs/livoxProto1/udpCommandDemuxer.h +++ b/commonLibs/livoxProto1/udpCommandDemuxer.h @@ -37,7 +37,7 @@ class UdpCommandDemuxer { public: UdpCommandDemuxer( - const std::shared_ptr& componentThread, + const std::shared_ptr& componentThread, DeviceManager& deviceManager, uint16_t commandPort = 56001, uint16_t dataPort = 56000); @@ -76,13 +76,13 @@ private: void onDataReady(const boost::system::error_code& error); void processIncomingData(); - std::shared_ptr componentThread; + std::shared_ptr componentThread; DeviceManager& deviceManager; uint16_t commandPort; uint16_t dataPort; // State management - smo::SpinLock isActiveAndShouldStopLock; + sscl::SpinLock isActiveAndShouldStopLock; std::atomic isActive{false}; std::atomic shouldStop{false}; diff --git a/include/user/senseApiDesc.h b/include/user/senseApiDesc.h index 195523b..6b84598 100644 --- a/include/user/senseApiDesc.h +++ b/include/user/senseApiDesc.h @@ -10,6 +10,7 @@ #include #include #include +#include #define CL_TARGET_OPENCL_VERSION 120 #include @@ -17,8 +18,6 @@ class OptionParser; namespace smo { -class ComponentThread; - namespace compute { class ClBuffer; class ComputeDevice; @@ -45,7 +44,7 @@ struct SmoThreadingModelDesc * done on the ComponentThread for the thread that SMO provided in the * attachDeviceReq call. */ - std::shared_ptr componentThread; + std::shared_ptr componentThread; }; typedef std::function)> @@ -57,11 +56,11 @@ typedef int (sal_mlo_initializeIndFn)(void); typedef int (sal_mlo_finalizeIndFn)(void); typedef void (sal_mlo_attachDeviceReqFn)( const std::shared_ptr& desc, - const std::shared_ptr& componentThread, - Callback cb); + const std::shared_ptr& componentThread, + sscl::Callback cb); typedef void (sal_mlo_detachDeviceReqFn)( const std::shared_ptr& desc, - Callback cb); + sscl::Callback cb); /** * @brief Hooks provided by Salmanoff to senseApi libraries. @@ -88,9 +87,9 @@ struct SmoCallbacks * @return Shared pointer to the current ComponentThread * * This function provides access to the current ComponentThread instance, - * equivalent to calling ComponentThread::getSelf(). + * equivalent to calling sscl::ComponentThread::getSelf(). */ - std::shared_ptr (*ComponentThread_getSelf)(void); + std::shared_ptr (*ComponentThread_getSelf)(void); /** * @brief Get the OptionParser singleton instance diff --git a/include/user/stimulusProducer.h b/include/user/stimulusProducer.h index f8d0116..0208814 100644 --- a/include/user/stimulusProducer.h +++ b/include/user/stimulusProducer.h @@ -86,7 +86,7 @@ public: bool hasBufferWithQualeIfaceApi(const std::string& qualeIfaceApi) const; protected: - SpinLock frameAssemblyRateLimiter; + sscl::SpinLock frameAssemblyRateLimiter; // Virtual functions for derived classes to override virtual int getStopDelayMs() const @@ -106,7 +106,7 @@ public: private: boost::asio::io_service& ioService; protected: - SpinLock shouldContinueLock; + sscl::SpinLock shouldContinueLock; bool shouldContinue; private: boost::asio::deadline_timer timer; diff --git a/libspinscale/include/spinscale/asynchronousBridge.h b/libspinscale/include/spinscale/asynchronousBridge.h index 85e3649..99d050d 100644 --- a/libspinscale/include/spinscale/asynchronousBridge.h +++ b/libspinscale/include/spinscale/asynchronousBridge.h @@ -5,7 +5,7 @@ #include #include -namespace smo { +namespace sscl { class AsynchronousBridge { @@ -53,6 +53,6 @@ private: boost::asio::io_service &io_service; }; -} // namespace smo +} // namespace sscl #endif // ASYNCHRONOUS_BRIDGE_H diff --git a/libspinscale/include/spinscale/asynchronousContinuation.h b/libspinscale/include/spinscale/asynchronousContinuation.h index a1e138e..e907b70 100644 --- a/libspinscale/include/spinscale/asynchronousContinuation.h +++ b/libspinscale/include/spinscale/asynchronousContinuation.h @@ -10,7 +10,7 @@ #include -namespace smo { +namespace sscl { /** * AsynchronousContinuation - Template base class for async sequence management @@ -153,6 +153,6 @@ public: std::shared_ptr caller; }; -} // namespace smo +} // namespace sscl #endif // ASYNCHRONOUS_CONTINUATION_H diff --git a/libspinscale/include/spinscale/asynchronousContinuationChainLink.h b/libspinscale/include/spinscale/asynchronousContinuationChainLink.h index 60e8893..e9b05da 100644 --- a/libspinscale/include/spinscale/asynchronousContinuationChainLink.h +++ b/libspinscale/include/spinscale/asynchronousContinuationChainLink.h @@ -3,7 +3,7 @@ #include -namespace smo { +namespace sscl { /** * @brief Base class for all asynchronous continuation chain links @@ -27,6 +27,6 @@ public: getCallersContinuationShPtr() const = 0; }; -} // namespace smo +} // namespace sscl #endif // ASYNCHRONOUS_CONTINUATION_CHAIN_LINK_H diff --git a/libspinscale/include/spinscale/asynchronousLoop.h b/libspinscale/include/spinscale/asynchronousLoop.h index 6db5dd8..bccb12d 100644 --- a/libspinscale/include/spinscale/asynchronousLoop.h +++ b/libspinscale/include/spinscale/asynchronousLoop.h @@ -3,7 +3,7 @@ #include -namespace smo { +namespace sscl { class AsynchronousLoop { @@ -64,6 +64,6 @@ public: std::atomic nSucceeded, nFailed; }; -} // namespace smo +} // namespace sscl #endif // ASYNCHRONOUS_LOOP_H diff --git a/libspinscale/include/spinscale/callableTracer.h b/libspinscale/include/spinscale/callableTracer.h index 4f707a9..3774a3c 100644 --- a/libspinscale/include/spinscale/callableTracer.h +++ b/libspinscale/include/spinscale/callableTracer.h @@ -13,7 +13,7 @@ // The code will check for OPTS_H define to see if opts.h has been included class OptionParser; -namespace smo { +namespace sscl { /** * @brief CallableTracer - Wraps callables with metadata for debugging @@ -85,7 +85,7 @@ private: std::function callable; }; -} // namespace smo +} // namespace sscl /** * @brief STC - SMO Traceable Callable macro diff --git a/libspinscale/include/spinscale/callback.h b/libspinscale/include/spinscale/callback.h index baaf293..1dfeb50 100644 --- a/libspinscale/include/spinscale/callback.h +++ b/libspinscale/include/spinscale/callback.h @@ -3,7 +3,7 @@ #include -namespace smo { +namespace sscl { // Forward declaration class AsynchronousContinuationChainLink; @@ -26,6 +26,6 @@ public: CbFnT callbackFn; }; -} // namespace smo +} // namespace sscl #endif // SPINSCALE_CALLBACK_H diff --git a/libspinscale/include/spinscale/component.h b/libspinscale/include/spinscale/component.h index 21e97cb..0fb3b04 100644 --- a/libspinscale/include/spinscale/component.h +++ b/libspinscale/include/spinscale/component.h @@ -7,7 +7,7 @@ #include #include -namespace smo { +namespace sscl { class ComponentThread; @@ -36,6 +36,6 @@ public: PuppetApplication &parent; }; -} // namespace smo +} // namespace sscl #endif // COMPONENT_H diff --git a/libspinscale/include/spinscale/componentThread.h b/libspinscale/include/spinscale/componentThread.h index 87a8935..ae66495 100644 --- a/libspinscale/include/spinscale/componentThread.h +++ b/libspinscale/include/spinscale/componentThread.h @@ -17,7 +17,7 @@ #include #include -namespace smo { +namespace sscl { class MarionetteThread; class PuppetThread; @@ -148,17 +148,19 @@ public: class ThreadLifetimeMgmtOp; }; -namespace mrntt { -extern std::shared_ptr thread; -} // namespace mrntt +} // namespace sscl +namespace smo { +namespace mrntt { +extern std::shared_ptr thread; +} // namespace mrntt } // namespace smo -// Forward declaration for spinscale namespace functions and variables -// Must be after smo namespace so ThreadId is defined -namespace spinscale { -extern smo::ThreadId marionetteThreadId; -void setMarionetteThreadId(smo::ThreadId id); +// Forward declaration for sscl namespace functions and variables +// Must be after sscl namespace so ThreadId is defined +namespace sscl { +extern sscl::ThreadId marionetteThreadId; +void setMarionetteThreadId(sscl::ThreadId id); } #endif // COMPONENT_THREAD_H diff --git a/libspinscale/include/spinscale/dependencyGraph.h b/libspinscale/include/spinscale/dependencyGraph.h index 8433604..2cefe45 100644 --- a/libspinscale/include/spinscale/dependencyGraph.h +++ b/libspinscale/include/spinscale/dependencyGraph.h @@ -6,7 +6,7 @@ #include #include -namespace smo { +namespace sscl { // Forward declarations class AsynchronousContinuationChainLink; @@ -80,6 +80,6 @@ private: AdjacencyList adjacencyList; }; -} // namespace smo +} // namespace sscl #endif // DEPENDENCY_GRAPH_H diff --git a/libspinscale/include/spinscale/lockSet.h b/libspinscale/include/spinscale/lockSet.h index e87c382..e00687c 100644 --- a/libspinscale/include/spinscale/lockSet.h +++ b/libspinscale/include/spinscale/lockSet.h @@ -9,7 +9,7 @@ #include #include -namespace smo { +namespace sscl { // Forward declarations template @@ -255,6 +255,6 @@ private: bool allLocksAcquired, registeredInQutexQueues; }; -} // namespace smo +} // namespace sscl #endif // LOCK_SET_H diff --git a/libspinscale/include/spinscale/lockerAndInvokerBase.h b/libspinscale/include/spinscale/lockerAndInvokerBase.h index 532a6c2..528ebef 100644 --- a/libspinscale/include/spinscale/lockerAndInvokerBase.h +++ b/libspinscale/include/spinscale/lockerAndInvokerBase.h @@ -4,7 +4,7 @@ #include #include -namespace smo { +namespace sscl { // Forward declaration class Qutex; @@ -82,6 +82,6 @@ protected: const void* serializedContinuationVaddr; }; -} // namespace smo +} // namespace sscl #endif // LOCKER_AND_INVOKER_BASE_H diff --git a/libspinscale/include/spinscale/puppetApplication.h b/libspinscale/include/spinscale/puppetApplication.h index 40d796e..24b5e06 100644 --- a/libspinscale/include/spinscale/puppetApplication.h +++ b/libspinscale/include/spinscale/puppetApplication.h @@ -8,7 +8,7 @@ #include #include -namespace smo { +namespace sscl { class PuppetApplication : public std::enable_shared_from_this @@ -63,6 +63,6 @@ private: class PuppetThreadLifetimeMgmtOp; }; -} // namespace smo +} // namespace sscl #endif // PUPPET_APPLICATION_H diff --git a/libspinscale/include/spinscale/qutex.h b/libspinscale/include/spinscale/qutex.h index 6686e42..dfa06f8 100644 --- a/libspinscale/include/spinscale/qutex.h +++ b/libspinscale/include/spinscale/qutex.h @@ -8,7 +8,7 @@ #include #include -namespace smo { +namespace sscl { /** * @brief Qutex - Queue-based mutex for asynchronous lock management @@ -102,6 +102,6 @@ public: bool isOwned; }; -} // namespace smo +} // namespace sscl #endif // QUTEX_H diff --git a/libspinscale/include/spinscale/qutexAcquisitionHistoryTracker.h b/libspinscale/include/spinscale/qutexAcquisitionHistoryTracker.h index 7cee9d0..73a6aa7 100644 --- a/libspinscale/include/spinscale/qutexAcquisitionHistoryTracker.h +++ b/libspinscale/include/spinscale/qutexAcquisitionHistoryTracker.h @@ -8,7 +8,7 @@ #include "spinLock.h" -namespace smo { +namespace sscl { // Forward declarations class Qutex; @@ -159,6 +159,6 @@ private: AcquisitionHistoryMap acquisitionHistory; }; -} // namespace smo +} // namespace sscl #endif // QUTEX_ACQUISITION_HISTORY_TRACKER_H diff --git a/libspinscale/include/spinscale/serializedAsynchronousContinuation.h b/libspinscale/include/spinscale/serializedAsynchronousContinuation.h index 6fda6d9..eddd960 100644 --- a/libspinscale/include/spinscale/serializedAsynchronousContinuation.h +++ b/libspinscale/include/spinscale/serializedAsynchronousContinuation.h @@ -14,7 +14,7 @@ #include #include -namespace smo { +namespace sscl { template class SerializedAsynchronousContinuation @@ -583,6 +583,6 @@ void SerializedAsynchronousContinuation invocationTarget(); } -} // namespace smo +} // namespace sscl #endif // SERIALIZED_ASYNCHRONOUS_CONTINUATION_H diff --git a/libspinscale/include/spinscale/spinLock.h b/libspinscale/include/spinscale/spinLock.h index 0d6b8e5..0b3300e 100644 --- a/libspinscale/include/spinscale/spinLock.h +++ b/libspinscale/include/spinscale/spinLock.h @@ -14,7 +14,7 @@ #include #endif -namespace smo { +namespace sscl { /** * @brief Simple spinlock using std::atomic @@ -116,6 +116,6 @@ private: std::atomic locked; }; -} // namespace smo +} // namespace sscl #endif // SPIN_LOCK_H diff --git a/libspinscale/src/component.cpp b/libspinscale/src/component.cpp index 020952f..6d9c069 100644 --- a/libspinscale/src/component.cpp +++ b/libspinscale/src/component.cpp @@ -2,7 +2,7 @@ #include #include -namespace smo { +namespace sscl { Component::Component(const std::shared_ptr &thread) : thread(thread) @@ -16,14 +16,16 @@ parent(parent) { } +} // namespace sscl + +namespace smo { namespace mrntt { MarionetteComponent::MarionetteComponent( - const std::shared_ptr &thread) -: Component(thread) + const std::shared_ptr &thread) +: sscl::Component(thread) { } } // namespace mrntt - } // namespace smo diff --git a/libspinscale/src/componentThread.cpp b/libspinscale/src/componentThread.cpp index f181301..c8f8377 100644 --- a/libspinscale/src/componentThread.cpp +++ b/libspinscale/src/componentThread.cpp @@ -11,27 +11,27 @@ #include #include -namespace spinscale { +namespace sscl { // Global variable to store the marionette thread ID // Default value is 0, but should be set by application code via setMarionetteThreadId() -smo::ThreadId marionetteThreadId = 0; +sscl::ThreadId marionetteThreadId = 0; -void setMarionetteThreadId(smo::ThreadId id) +void setMarionetteThreadId(sscl::ThreadId id) { marionetteThreadId = id; } -} // namespace spinscale +} // namespace sscl -namespace smo { +namespace sscl { thread_local std::shared_ptr thisComponentThread; // Implementation of static method std::shared_ptr ComponentThread::getMrntt() { - return mrntt::thread; + return smo::mrntt::thread; } void MarionetteThread::initializeTls(void) @@ -179,13 +179,13 @@ void PuppetThread::joltThreadReq(Callback callback) * the operation is posted to this thread's io_service (which is a member * of this object), the object must be alive when the operation executes. */ - if (id == spinscale::marionetteThreadId) + if (id == sscl::marionetteThreadId) { throw std::runtime_error(std::string(__func__) + ": invoked on mrntt thread"); } - std::shared_ptr mrntt = mrntt::thread; + std::shared_ptr mrntt = smo::mrntt::thread; auto request = std::make_shared( mrntt, *this, callback); @@ -228,7 +228,7 @@ void PuppetThread::exitThreadReq(Callback callback) void PuppetThread::pauseThreadReq(Callback callback) { - if (id == spinscale::marionetteThreadId) + if (id == sscl::marionetteThreadId) { throw std::runtime_error(std::string(__func__) + ": invoked on mrntt thread"); @@ -246,7 +246,7 @@ void PuppetThread::pauseThreadReq(Callback callback) void PuppetThread::resumeThreadReq(Callback callback) { - if (id == spinscale::marionetteThreadId) + if (id == sscl::marionetteThreadId) { throw std::runtime_error(std::string(__func__) + ": invoked on mrntt thread"); @@ -310,4 +310,4 @@ void PuppetThread::pinToCpu(int cpuId) pinnedCpuId = cpuId; } -} // namespace smo +} // namespace sscl diff --git a/libspinscale/src/lockerAndInvokerBase.cpp b/libspinscale/src/lockerAndInvokerBase.cpp index 0f0c22f..47df4a1 100644 --- a/libspinscale/src/lockerAndInvokerBase.cpp +++ b/libspinscale/src/lockerAndInvokerBase.cpp @@ -1,5 +1,5 @@ #include -namespace smo { +namespace sscl { -} // namespace smo +} // namespace sscl diff --git a/libspinscale/src/puppetApplication.cpp b/libspinscale/src/puppetApplication.cpp index 222b8be..ef58ed9 100644 --- a/libspinscale/src/puppetApplication.cpp +++ b/libspinscale/src/puppetApplication.cpp @@ -5,7 +5,7 @@ #include #include -namespace smo { +namespace sscl { PuppetApplication::PuppetApplication( const std::vector> &threads) @@ -218,4 +218,4 @@ void PuppetApplication::distributeAndPinThreadsAcrossCpus() << "across " << cpuCount << " CPUs\n"; } -} // namespace smo +} // namespace sscl diff --git a/libspinscale/src/qutex.cpp b/libspinscale/src/qutex.cpp index 672bc2c..ac1b7c2 100644 --- a/libspinscale/src/qutex.cpp +++ b/libspinscale/src/qutex.cpp @@ -1,7 +1,7 @@ #include #include -namespace smo { +namespace sscl { bool Qutex::tryAcquire( const LockerAndInvokerBase &tryingLockvoker, int nRequiredLocks @@ -377,4 +377,4 @@ void Qutex::release() front.awaken(); } -} // namespace smo +} // namespace sscl diff --git a/libspinscale/src/qutexAcquisitionHistoryTracker.cpp b/libspinscale/src/qutexAcquisitionHistoryTracker.cpp index 1964c47..4731ca0 100644 --- a/libspinscale/src/qutexAcquisitionHistoryTracker.cpp +++ b/libspinscale/src/qutexAcquisitionHistoryTracker.cpp @@ -8,7 +8,7 @@ #include #include -namespace smo { +namespace sscl { void DependencyGraph::addNode(const Node& node) { @@ -390,4 +390,4 @@ bool QutexAcquisitionHistoryTracker return true; } -} // namespace smo +} // namespace sscl diff --git a/main.cpp b/main.cpp index ef0684c..55e88b0 100644 --- a/main.cpp +++ b/main.cpp @@ -7,7 +7,7 @@ int main(int argc, char *argv[], char *envp[]) { // Set the marionette thread ID before using any ComponentThread functionality - spinscale::setMarionetteThreadId(smo::SmoThreadId::MRNTT); + sscl::setMarionetteThreadId(smo::SmoThreadId::MRNTT); pthread_setname_np(pthread_self(), "smo:CRT:main"); /* We don't do anything inside of main() * Main merely waits for the marionette thread to exit. diff --git a/smocore/body/body.cpp b/smocore/body/body.cpp index 0aafe11..bf45eee 100644 --- a/smocore/body/body.cpp +++ b/smocore/body/body.cpp @@ -14,32 +14,32 @@ namespace smo { namespace body { -Body::Body(Mind &parent, const std::shared_ptr &thread) - : PuppetComponent(parent, thread) +Body::Body(Mind &parent, const std::shared_ptr &thread) +: sscl::PuppetComponent(static_cast(parent), thread) { } class Body::InitializeReq -: public PostedAsynchronousContinuation +: public sscl::PostedAsynchronousContinuation { public: InitializeReq( - PuppetApplication &parent, - const std::shared_ptr &caller, - Callback callback) - : PostedAsynchronousContinuation(caller, callback), + sscl::PuppetApplication &parent, + const std::shared_ptr &caller, + sscl::Callback callback) + : sscl::PostedAsynchronousContinuation(caller, callback), parent(parent) {} private: - PuppetApplication &parent; + sscl::PuppetApplication &parent; public: void initializeReq1_posted( [[maybe_unused]] std::shared_ptr context ) { - auto self = ComponentThread::getSelf(); + auto self = sscl::ComponentThread::getSelf(); if (self->id != SmoThreadId::BODY) { throw std::runtime_error(std::string(__func__) @@ -94,7 +94,7 @@ public: void initializeReq2( [[maybe_unused]] std::shared_ptr context, - smo::AsynchronousLoop &results + sscl::AsynchronousLoop &results ) { std::cout << "Mrntt: attached " @@ -116,7 +116,7 @@ public: [[maybe_unused]] std::shared_ptr context ) { - auto self = ComponentThread::getSelf(); + auto self = sscl::ComponentThread::getSelf(); if (self->id != SmoThreadId::BODY) { throw std::runtime_error(std::string(__func__) @@ -133,7 +133,7 @@ public: void finalizeReq2( [[maybe_unused]] std::shared_ptr context, - smo::AsynchronousLoop &results + sscl::AsynchronousLoop &results ) { std::cout << "Mrntt: Successfully detached " @@ -149,9 +149,9 @@ public: } }; -void Body::initializeReq(Callback callback) +void Body::initializeReq(sscl::Callback callback) { - auto mrntt = ComponentThread::getSelf(); + auto mrntt = sscl::ComponentThread::getSelf(); if (mrntt->id != SmoThreadId::MRNTT) { @@ -168,9 +168,9 @@ void Body::initializeReq(Callback callback) request.get(), request))); } -void Body::finalizeReq(Callback callback) +void Body::finalizeReq(sscl::Callback callback) { - auto mrntt = ComponentThread::getSelf(); + auto mrntt = sscl::ComponentThread::getSelf(); if (mrntt->id != SmoThreadId::MRNTT) { diff --git a/smocore/componentThread.cpp b/smocore/componentThread.cpp index 3197161..2f3f9f9 100644 --- a/smocore/componentThread.cpp +++ b/smocore/componentThread.cpp @@ -4,20 +4,20 @@ #include #include -namespace smo { +namespace sscl { -std::string ComponentThread::getThreadName(ThreadId id) +std::string ComponentThread::getThreadName(sscl::ThreadId id) { // Cast ThreadId to SmoThreadId for validation and lookup - SmoThreadId smoId = static_cast(id); - if (static_cast(smoId) >= static_cast(SmoThreadId::N_ITEMS)) + smo::SmoThreadId smoId = static_cast(id); + if (static_cast(smoId) >= static_cast(smo::SmoThreadId::N_ITEMS)) { throw std::runtime_error(std::string(__func__) + ": Invalid thread ID"); } // Use function-local static to ensure proper initialization order - static const std::string threadNames[static_cast(SmoThreadId::N_ITEMS)] + static const std::string threadNames[static_cast(smo::SmoThreadId::N_ITEMS)] = { "mrntt", "director", @@ -30,7 +30,7 @@ std::string ComponentThread::getThreadName(ThreadId id) return threadNames[static_cast(smoId)]; } -void PuppetThread::main(PuppetThread& self) +void sscl::PuppetThread::main(sscl::PuppetThread& self) { std::string threadName = "smo:" + self.name; pthread_setname_np(pthread_self(), threadName.c_str()); @@ -87,4 +87,4 @@ void PuppetThread::main(PuppetThread& self) std::cout << self.name << ":" << __func__ << ": Exited event loop" << "\n"; } -} // namespace smo +} // namespace sscl diff --git a/smocore/deviceManager/deviceManager.cpp b/smocore/deviceManager/deviceManager.cpp index 94f58f1..6906c95 100644 --- a/smocore/deviceManager/deviceManager.cpp +++ b/smocore/deviceManager/deviceManager.cpp @@ -45,15 +45,15 @@ const std::string DeviceManager::stringifyDeviceSpecs(void) } class DeviceManager::NewDeviceAttachmentSpecInd -: public SerializedAsynchronousContinuation +: public sscl::SerializedAsynchronousContinuation { public: NewDeviceAttachmentSpecInd( const DeviceAttachmentSpec &spec, - const std::shared_ptr &caller, - Callback cb, - std::vector> requiredLocks) - : SerializedAsynchronousContinuation( + const std::shared_ptr &caller, + sscl::Callback cb, + std::vector> requiredLocks) + : sscl::SerializedAsynchronousContinuation( caller, cb, requiredLocks), spec(spec) {} @@ -171,15 +171,15 @@ public: }; class DeviceManager::RemoveDeviceAttachmentSpecReq -: public SerializedAsynchronousContinuation +: public sscl::SerializedAsynchronousContinuation { public: RemoveDeviceAttachmentSpecReq( const DeviceAttachmentSpec &spec, - const std::shared_ptr &caller, - Callback cb, - std::vector> requiredLocks) - : SerializedAsynchronousContinuation( + const std::shared_ptr &caller, + sscl::Callback cb, + std::vector> requiredLocks) + : sscl::SerializedAsynchronousContinuation( caller, cb, requiredLocks), spec(spec) {} @@ -293,13 +293,13 @@ public: void DeviceManager::newDeviceAttachmentSpecInd( const DeviceAttachmentSpec &spec, - Callback callback) + sscl::Callback callback) { - const auto& caller = ComponentThread::getSelf(); + const auto& caller = sscl::ComponentThread::getSelf(); auto request = std::make_shared( spec, caller, callback, - LockSet::Set{ + sscl::LockSet::Set{ std::ref(DeviceManager::getInstance().qutex) }); @@ -312,13 +312,13 @@ void DeviceManager::newDeviceAttachmentSpecInd( void DeviceManager::removeDeviceAttachmentSpecReq( const DeviceAttachmentSpec &spec, - Callback callback) + sscl::Callback callback) { - const auto& caller = ComponentThread::getSelf(); + const auto& caller = sscl::ComponentThread::getSelf(); auto request = std::make_shared( spec, caller, callback, - LockSet::Set{ + sscl::LockSet::Set{ std::ref(DeviceManager::getInstance().qutex) }); @@ -331,17 +331,17 @@ void DeviceManager::removeDeviceAttachmentSpecReq( } class DeviceManager::AttachStimBuffDeviceReq -: public SerializedAsynchronousContinuation< +: public sscl::SerializedAsynchronousContinuation< DeviceManager::attachStimBuffDeviceReqCbFn> { public: AttachStimBuffDeviceReq( const std::shared_ptr& spec, - const std::shared_ptr &caller, - Callback cb, + const std::shared_ptr &caller, + sscl::Callback cb, std::shared_ptr &stimBuffApiLib, - std::vector> requiredLocks) - : SerializedAsynchronousContinuation( + std::vector> requiredLocks) + : sscl::SerializedAsynchronousContinuation( caller, cb, requiredLocks), spec(spec), stimBuffApiLib(stimBuffApiLib) {} @@ -386,7 +386,7 @@ public: * Introspectors are attached to the body thread; extrospectors are * attached to the world thread. */ - std::shared_ptr threadForAttachment; + std::shared_ptr threadForAttachment; if (spec->sensorType == 'e') { threadForAttachment = mind::globalMind->world.thread; @@ -473,10 +473,10 @@ public: void DeviceManager::attachStimBuffDeviceReq( const std::shared_ptr& spec, - Callback cb + sscl::Callback cb ) { - const auto& caller = ComponentThread::getSelf(); + const auto& caller = sscl::ComponentThread::getSelf(); // Get the stim buff API lib's qutex auto libOpt = stim_buff::StimBuffApiManager::getInstance() @@ -494,7 +494,7 @@ void DeviceManager::attachStimBuffDeviceReq( auto request = std::make_shared( spec, caller, cb, libOpt.value(), - LockSet::Set{ + sscl::LockSet::Set{ std::ref(stim_buff::StimBuffApiManager::getInstance().qutex), std::ref(lib.qutex) }); @@ -508,10 +508,10 @@ void DeviceManager::attachStimBuffDeviceReq( void DeviceManager::detachStimBuffDeviceReq( const std::shared_ptr& spec, - Callback cb + sscl::Callback cb ) { - const auto& caller = ComponentThread::getSelf(); + const auto& caller = sscl::ComponentThread::getSelf(); // Get the stim buff API lib's qutex auto libOpt = stim_buff::StimBuffApiManager::getInstance() @@ -529,7 +529,7 @@ void DeviceManager::detachStimBuffDeviceReq( auto request = std::make_shared( spec, caller, cb, libOpt.value(), - LockSet::Set{ + sscl::LockSet::Set{ std::ref(stim_buff::StimBuffApiManager::getInstance().qutex), std::ref(lib.qutex) }); @@ -542,16 +542,16 @@ void DeviceManager::detachStimBuffDeviceReq( } class DeviceManager::AttachAllUnattachedDevicesFromReq -: public PostedAsynchronousContinuation< +: public sscl::PostedAsynchronousContinuation< attachAllUnattachedDevicesFromReqCbFn> { public: AttachAllUnattachedDevicesFromReq( const unsigned int totalNSpecs, const std::shared_ptr>& specs, - const std::shared_ptr& caller, - Callback cb) - : PostedAsynchronousContinuation( + const std::shared_ptr& caller, + sscl::Callback cb) + : sscl::PostedAsynchronousContinuation( caller, cb), loop(totalNSpecs), specs(specs) {} @@ -606,23 +606,23 @@ public: } public: - AsynchronousLoop loop; + sscl::AsynchronousLoop loop; std::shared_ptr> specs; }; void DeviceManager::attachAllUnattachedDevicesFromReq( const std::shared_ptr> &specs, - Callback cb + sscl::Callback cb ) { if (specs->size() == 0) { - AsynchronousLoop tmp(0); + sscl::AsynchronousLoop tmp(0); cb.callbackFn(tmp); return; } - const auto& caller = ComponentThread::getSelf(); + const auto& caller = sscl::ComponentThread::getSelf(); auto request = std::make_shared( specs->size(), specs, caller, std::move(cb)); @@ -634,7 +634,7 @@ void DeviceManager::attachAllUnattachedDevicesFromReq( } void DeviceManager::attachAllUnattachedDevicesFromCmdlineReq( - Callback cb + sscl::Callback cb ) { auto specs = std::make_shared>( @@ -643,15 +643,15 @@ void DeviceManager::attachAllUnattachedDevicesFromCmdlineReq( } class DeviceManager::AttachAllUnattachedDevicesFromKnownListReq -: public SerializedAsynchronousContinuation< +: public sscl::SerializedAsynchronousContinuation< attachAllUnattachedDevicesFromReqCbFn> { public: AttachAllUnattachedDevicesFromKnownListReq( - const std::shared_ptr &caller, - Callback cb, - std::vector> requiredLocks) - : SerializedAsynchronousContinuation< + const std::shared_ptr &caller, + sscl::Callback cb, + std::vector> requiredLocks) + : sscl::SerializedAsynchronousContinuation< attachAllUnattachedDevicesFromReqCbFn>( caller, cb, requiredLocks) {} @@ -703,7 +703,7 @@ public: void attachAllUnattachedDevicesFromKnownListReq2( [[maybe_unused]] std::shared_ptr context, - AsynchronousLoop loop + sscl::AsynchronousLoop loop ) { callOriginalCb(loop); @@ -711,14 +711,14 @@ public: }; void DeviceManager::attachAllUnattachedDevicesFromKnownListReq( - Callback cb + sscl::Callback cb ) { - const auto& caller = ComponentThread::getSelf(); + const auto& caller = sscl::ComponentThread::getSelf(); auto request = std::make_shared( caller, cb, - LockSet::Set{ + sscl::LockSet::Set{ std::ref(DeviceManager::getInstance().qutex) }); @@ -731,15 +731,15 @@ void DeviceManager::attachAllUnattachedDevicesFromKnownListReq( } class DeviceManager::DetachAllAttachedDeviceRoles -: public PostedAsynchronousContinuation< +: public sscl::PostedAsynchronousContinuation< detachAllAttachedDeviceRolesCbFn> { public: DetachAllAttachedDeviceRoles( const unsigned int totalNSpecs, - const std::shared_ptr& caller, - Callback cb) - : PostedAsynchronousContinuation( + const std::shared_ptr& caller, + sscl::Callback cb) + : sscl::PostedAsynchronousContinuation( caller, cb), loop(totalNSpecs) {} @@ -788,21 +788,21 @@ public: } public: - AsynchronousLoop loop; + sscl::AsynchronousLoop loop; }; void DeviceManager::detachAllAttachedDeviceRoles( - Callback cb + sscl::Callback cb ) { if (DeviceManager::getInstance().attachedDeviceRoles.size() == 0) { - AsynchronousLoop tmp(0); + sscl::AsynchronousLoop tmp(0); cb.callbackFn(tmp); return; } - const auto& caller = ComponentThread::getSelf(); + const auto& caller = sscl::ComponentThread::getSelf(); auto request = std::make_shared( DeviceManager::getInstance().attachedDeviceRoles.size(), caller, std::move(cb)); diff --git a/smocore/deviceManager/deviceReattacher.cpp b/smocore/deviceManager/deviceReattacher.cpp index bdee16d..8e742d1 100644 --- a/smocore/deviceManager/deviceReattacher.cpp +++ b/smocore/deviceManager/deviceReattacher.cpp @@ -9,7 +9,7 @@ namespace smo { namespace device { -static void reattachmentCb(AsynchronousLoop& results) +static void reattachmentCb(sscl::AsynchronousLoop& results) { if (results.nTotal == 0) { return; } @@ -19,7 +19,7 @@ static void reattachmentCb(AsynchronousLoop& results) } DeviceReattacher::DeviceReattacher( - DeviceManager& parent, std::shared_ptr ioThread) + DeviceManager& parent, std::shared_ptr ioThread) : parent(parent), ioThread(ioThread), shouldContinue(false), timer(ioThread->getIoService()) { @@ -34,7 +34,7 @@ void DeviceReattacher::start() void DeviceReattacher::stop() { { - SpinLock::Guard lock(shouldContinueLock); + sscl::SpinLock::Guard lock(shouldContinueLock); shouldContinue = false; } @@ -70,7 +70,7 @@ void DeviceReattacher::onTimeout(const boost::system::error_code& error) return; } - SpinLock::Guard lock(shouldContinueLock); + sscl::SpinLock::Guard lock(shouldContinueLock); if (!shouldContinue) { return; } diff --git a/smocore/director/director.cpp b/smocore/director/director.cpp index 23d51dd..3854406 100644 --- a/smocore/director/director.cpp +++ b/smocore/director/director.cpp @@ -6,8 +6,8 @@ namespace smo { namespace director { -Director::Director(Mind &parent, const std::shared_ptr &thread) -: PuppetComponent(static_cast(parent), thread) +Director::Director(Mind &parent, const std::shared_ptr &thread) +: sscl::PuppetComponent(static_cast(parent), thread) { } diff --git a/smocore/include/body/body.h b/smocore/include/body/body.h index eee8a26..58ffb06 100644 --- a/smocore/include/body/body.h +++ b/smocore/include/body/body.h @@ -9,20 +9,19 @@ namespace smo { class Mind; -class ComponentThread; namespace body { class Body -: public PuppetComponent +: public sscl::PuppetComponent { public: - Body(Mind &parent, const std::shared_ptr &thread); + Body(Mind &parent, const std::shared_ptr &thread); ~Body() = default; typedef std::function bodyLifetimeMgmtOpCbFn; - void initializeReq(Callback callback); - void finalizeReq(Callback callback); + void initializeReq(sscl::Callback callback); + void finalizeReq(sscl::Callback callback); private: class InitializeReq; diff --git a/smocore/include/componentThread.h b/smocore/include/componentThread.h index b7f793f..c6d167a 100644 --- a/smocore/include/componentThread.h +++ b/smocore/include/componentThread.h @@ -9,7 +9,7 @@ namespace smo { // Application-specific thread ID enum // Using regular enum (not enum class) to allow implicit conversion to ThreadId -enum SmoThreadId : ThreadId +enum SmoThreadId : sscl::ThreadId { MRNTT = 0, DIRECTOR, diff --git a/smocore/include/deviceManager/device.h b/smocore/include/deviceManager/device.h index 5caba7f..6a1e1c7 100644 --- a/smocore/include/deviceManager/device.h +++ b/smocore/include/deviceManager/device.h @@ -33,7 +33,7 @@ public: public: std::string deviceIdentifier; std::vector> deviceRoles; - Qutex qutex; + sscl::Qutex qutex; }; } // namespace device diff --git a/smocore/include/deviceManager/deviceManager.h b/smocore/include/deviceManager/deviceManager.h index c0c38a8..85f87d1 100644 --- a/smocore/include/deviceManager/deviceManager.h +++ b/smocore/include/deviceManager/deviceManager.h @@ -55,10 +55,10 @@ public: void newDeviceAttachmentSpecInd( const DeviceAttachmentSpec &spec, - Callback callback); + sscl::Callback callback); void removeDeviceAttachmentSpecReq( const DeviceAttachmentSpec &spec, - Callback callback); + sscl::Callback callback); // Device attachment/detachment methods moved from SenseApiManager typedef stim_buff::sal_mlo_attachDeviceReqCbFn attachStimBuffDeviceReqCbFn; @@ -66,25 +66,25 @@ public: void attachStimBuffDeviceReq( const std::shared_ptr& spec, - Callback cb); + sscl::Callback cb); void detachStimBuffDeviceReq( const std::shared_ptr& spec, - Callback cb); + sscl::Callback cb); - typedef std::function + typedef std::function attachAllUnattachedDevicesFromReqCbFn; - typedef std::function + typedef std::function detachAllAttachedDeviceRolesCbFn; void attachAllUnattachedDevicesFromReq( const std::shared_ptr> &specs, - Callback cb); + sscl::Callback cb); void attachAllUnattachedDevicesFromKnownListReq( - Callback cb); + sscl::Callback cb); void attachAllUnattachedDevicesFromCmdlineReq( - Callback cb); + sscl::Callback cb); void detachAllAttachedDeviceRoles( - Callback cb); + sscl::Callback cb); private: DeviceManager() @@ -95,7 +95,7 @@ private: DeviceManager& operator=(const DeviceManager&) = delete; public: - Qutex qutex; + sscl::Qutex qutex; std::string allDapSpecs; static std::vector> deviceAttachmentSpecs; diff --git a/smocore/include/deviceManager/deviceReattacher.h b/smocore/include/deviceManager/deviceReattacher.h index 85af6f3..08efc81 100644 --- a/smocore/include/deviceManager/deviceReattacher.h +++ b/smocore/include/deviceManager/deviceReattacher.h @@ -9,8 +9,6 @@ namespace smo { -class ComponentThread; - namespace device { class DeviceManager; @@ -19,7 +17,7 @@ class DeviceReattacher { public: DeviceReattacher( - DeviceManager& parent, std::shared_ptr ioThread); + DeviceManager& parent, std::shared_ptr ioThread); ~DeviceReattacher() = default; // Non-copyable @@ -35,8 +33,8 @@ private: void onTimeout(const boost::system::error_code& error); DeviceManager &parent; - std::shared_ptr ioThread; - SpinLock shouldContinueLock; + std::shared_ptr ioThread; + sscl::SpinLock shouldContinueLock; bool shouldContinue; boost::asio::deadline_timer timer; }; diff --git a/smocore/include/director/director.h b/smocore/include/director/director.h index 488f406..83b4964 100644 --- a/smocore/include/director/director.h +++ b/smocore/include/director/director.h @@ -10,15 +10,14 @@ namespace smo { class Mind; -class ComponentThread; namespace director { class Director -: public PuppetComponent +: public sscl::PuppetComponent { public: - Director(Mind &parent, const std::shared_ptr &thread); + Director(Mind &parent, const std::shared_ptr &thread); ~Director() = default; void negtrinEventInd(void); diff --git a/smocore/include/marionette/marionette.h b/smocore/include/marionette/marionette.h index d3413b0..5eb0c7d 100644 --- a/smocore/include/marionette/marionette.h +++ b/smocore/include/marionette/marionette.h @@ -13,16 +13,16 @@ class MarionetteThread; namespace mrntt { class MarionetteComponent -: public Component +: public sscl::Component { public: - MarionetteComponent(const std::shared_ptr &thread); + MarionetteComponent(const std::shared_ptr &thread); ~MarionetteComponent() = default; public: typedef std::function mrnttLifetimeMgmtOpCbFn; - void initializeReq(Callback callback); - void finalizeReq(Callback callback); + void initializeReq(sscl::Callback callback); + void finalizeReq(sscl::Callback callback); // Intentionally doesn't take a callback. void exceptionInd(); diff --git a/smocore/include/mind.h b/smocore/include/mind.h index 1812fc8..c158937 100644 --- a/smocore/include/mind.h +++ b/smocore/include/mind.h @@ -18,18 +18,18 @@ namespace smo { class Mind -: public PuppetApplication +: public sscl::PuppetApplication { public: Mind(void); ~Mind(void) = default; typedef std::function mindLifetimeMgmtOpCbFn; - void initializeReq(Callback callback); - void finalizeReq(Callback callback); + void initializeReq(sscl::Callback callback); + void finalizeReq(sscl::Callback callback); // ComponentThread access methods - std::shared_ptr getComponentThread(ThreadId id) const; + std::shared_ptr getComponentThread(sscl::ThreadId id) const; std::shared_ptr getComponentThread( const std::string& name) const; // Get all this Mind's component threads. @@ -38,9 +38,9 @@ public: public: director::Director director; simulator::Simulator canvas; - PuppetComponent subconscious; + sscl::PuppetComponent subconscious; body::Body body; - PuppetComponent world; + sscl::PuppetComponent world; private: friend class body::Body; diff --git a/smocore/include/mindThread.h b/smocore/include/mindThread.h index 2b89f66..dd889c7 100644 --- a/smocore/include/mindThread.h +++ b/smocore/include/mindThread.h @@ -9,11 +9,11 @@ namespace smo { class Mind; // Forward declaration class MindThread -: public PuppetThread +: public sscl::PuppetThread { public: - MindThread(ThreadId _id, Mind& parent) - : PuppetThread(_id), + MindThread(sscl::ThreadId _id, Mind& parent) + : sscl::PuppetThread(_id), parent(parent) { } diff --git a/smocore/include/simulator/simulator.h b/smocore/include/simulator/simulator.h index 23657c4..da9c273 100644 --- a/smocore/include/simulator/simulator.h +++ b/smocore/include/simulator/simulator.h @@ -9,15 +9,14 @@ namespace smo { class Mind; -class ComponentThread; namespace simulator { class Simulator -: public PuppetComponent +: public sscl::PuppetComponent { public: - Simulator(Mind &parent, const std::shared_ptr &thread); + Simulator(Mind &parent, const std::shared_ptr &thread); ~Simulator() = default; void initialize(); diff --git a/smocore/include/stimBuffApis/stimBuffApiLib.h b/smocore/include/stimBuffApis/stimBuffApiLib.h index 5e1b2f9..0c0541d 100644 --- a/smocore/include/stimBuffApis/stimBuffApiLib.h +++ b/smocore/include/stimBuffApis/stimBuffApiLib.h @@ -51,7 +51,7 @@ public: public: std::string libraryPath; - Qutex qutex; + sscl::Qutex qutex; std::atomic isBeingDestroyed; std::unique_ptr dlopen_handle; /* UNIMPLEMENTED: API-specific cmdline options. These affect this specific diff --git a/smocore/include/stimBuffApis/stimBuffApiManager.h b/smocore/include/stimBuffApis/stimBuffApiManager.h index 81dede0..c7ddb0b 100644 --- a/smocore/include/stimBuffApis/stimBuffApiManager.h +++ b/smocore/include/stimBuffApis/stimBuffApiManager.h @@ -32,7 +32,7 @@ public: StimBuffApiLib& loadStimBuffApiLib( const std::string& libraryPath, - const std::shared_ptr& componentThread); + const std::shared_ptr& componentThread); std::optional> getStimBuffApiLib( const std::string& libraryPath); @@ -44,7 +44,7 @@ public: void finalizeStimBuffApiLib(StimBuffApiLib& lib); void loadAllStimBuffApiLibsFromOptions( - const std::shared_ptr& componentThread); + const std::shared_ptr& componentThread); void unloadAllStimBuffApiLibs(void); void initializeAllStimBuffApiLibs(void); @@ -64,7 +64,7 @@ private: std::vector> stimBuffApiLibs; public: - Qutex qutex; + sscl::Qutex qutex; public: static std::optional searchForLibInSmoSearchPaths( diff --git a/smocore/marionette/lifetime.cpp b/smocore/marionette/lifetime.cpp index 3897ca0..587b152 100644 --- a/smocore/marionette/lifetime.cpp +++ b/smocore/marionette/lifetime.cpp @@ -13,13 +13,13 @@ namespace smo { namespace mrntt { class MarionetteComponent::MrnttLifetimeMgmtOp -: public PostedAsynchronousContinuation +: public sscl::PostedAsynchronousContinuation { public: MrnttLifetimeMgmtOp( - MarionetteComponent &parent, const std::shared_ptr &caller, - Callback callback) - : PostedAsynchronousContinuation( + MarionetteComponent &parent, const std::shared_ptr &caller, + sscl::Callback callback) + : sscl::PostedAsynchronousContinuation( caller, callback), parent(parent) {} @@ -32,7 +32,7 @@ public: [[maybe_unused]] std::shared_ptr context ) { - auto self = ComponentThread::getSelf(); + auto self = sscl::ComponentThread::getSelf(); if (self->id != SmoThreadId::MRNTT) { throw std::runtime_error(std::string(__func__) @@ -70,7 +70,7 @@ public: [[maybe_unused]] std::shared_ptr context ) { - auto self = ComponentThread::getSelf(); + auto self = sscl::ComponentThread::getSelf(); if (self->id != SmoThreadId::MRNTT) { throw std::runtime_error(std::string(__func__) @@ -118,12 +118,12 @@ public: }; class MarionetteComponent::TerminationEvent -: public PostedAsynchronousContinuation +: public sscl::PostedAsynchronousContinuation { public: TerminationEvent( - const std::shared_ptr &caller) - : PostedAsynchronousContinuation( + const std::shared_ptr &caller) + : sscl::PostedAsynchronousContinuation( caller, {nullptr, nullptr}) {} @@ -132,7 +132,7 @@ public: [[maybe_unused]] std::shared_ptr context ) { - auto self = ComponentThread::getSelf(); + auto self = sscl::ComponentThread::getSelf(); if (self->id != SmoThreadId::MRNTT) { throw std::runtime_error(std::string(__func__) @@ -146,9 +146,9 @@ public: }; void MarionetteComponent::initializeReq( - Callback callback) + sscl::Callback callback) { - auto mrntt = ComponentThread::getSelf(); + auto mrntt = sscl::ComponentThread::getSelf(); if (mrntt->id != SmoThreadId::MRNTT) { @@ -166,9 +166,9 @@ void MarionetteComponent::initializeReq( } void MarionetteComponent::finalizeReq( - Callback callback) + sscl::Callback callback) { - auto mrntt = ComponentThread::getSelf(); + auto mrntt = sscl::ComponentThread::getSelf(); if (mrntt->id != SmoThreadId::MRNTT) { @@ -187,8 +187,8 @@ void MarionetteComponent::finalizeReq( void MarionetteComponent::exceptionInd() { - auto faultyThread = ComponentThread::getSelf(); - auto mrntt = ComponentThread::getMrntt(); + auto faultyThread = sscl::ComponentThread::getSelf(); + auto mrntt = sscl::ComponentThread::getMrntt(); auto request = std::make_shared( faultyThread); diff --git a/smocore/marionette/main.cpp b/smocore/marionette/main.cpp index 2a2450d..d4af030 100644 --- a/smocore/marionette/main.cpp +++ b/smocore/marionette/main.cpp @@ -8,8 +8,9 @@ #include #include #include -#include +#include #include +#include #include #include @@ -25,14 +26,14 @@ void CrtCommandLineArgs::set(int argc, char *argv[], char *envp[]) namespace mrntt { std::atomic exitCode; // Global marionette thread instance -std::shared_ptr thread = - std::make_shared(); -MarionetteComponent mrntt(thread); +std::shared_ptr thread = + std::make_shared(); +MarionetteComponent mrntt(std::static_pointer_cast(thread)); void exitMarionetteLoop() { - mrntt::thread->keepLooping = false; - mrntt::thread->getIoService().stop(); + thread->keepLooping = false; + thread->getIoService().stop(); std::cout << "Mrntt: Signaled main loop to exit." << "\n"; } @@ -65,6 +66,10 @@ void marionetteInitializeReqCb(bool success) } // namespace mrntt +} // namespace smo + +namespace sscl { + void MarionetteThread::main(MarionetteThread& self) { std::string threadName = "smo:" + self.name; @@ -73,7 +78,7 @@ void MarionetteThread::main(MarionetteThread& self) std::cout << __func__ << ": Waiting for command line JOLT" << std::endl; self.getIoService().run(); self.initializeTls(); - mrntt::exitCode = EXIT_SUCCESS; + smo::mrntt::exitCode = EXIT_SUCCESS; static boost::asio::signal_set signals(self.getIoService(), SIGINT); bool callShutdownSalmanoff = false; @@ -95,8 +100,8 @@ void MarionetteThread::main(MarionetteThread& self) default: break; } - mrntt::mrntt.finalizeReq({nullptr, std::bind( - &mrntt::marionetteFinalizeReqCb, + smo::mrntt::mrntt.finalizeReq({nullptr, std::bind( + &smo::mrntt::marionetteFinalizeReqCb, std::placeholders::_1)}); } ); @@ -107,8 +112,8 @@ void MarionetteThread::main(MarionetteThread& self) << std::endl; options.parseArguments( - crtCommandLineArgs.argc, crtCommandLineArgs.argv, - crtCommandLineArgs.envp); + smo::crtCommandLineArgs.argc, smo::crtCommandLineArgs.argv, + smo::crtCommandLineArgs.envp); std::cout << __func__ << ": " << options.stringifyOptions() << std::endl; @@ -135,12 +140,12 @@ void MarionetteThread::main(MarionetteThread& self) * The latter is cleaner and more resource-respecting. The former is * easier to implement. */ - initializeSalmanoff(); + smo::initializeSalmanoff(); callShutdownSalmanoff = true; // Create new Mind instance just before initializeReq - mrntt::mrntt.initializeReq({nullptr, std::bind( - &mrntt::marionetteInitializeReqCb, std::placeholders::_1)}); + smo::mrntt::mrntt.initializeReq({nullptr, std::bind( + &smo::mrntt::marionetteInitializeReqCb, std::placeholders::_1)}); std::cout << __func__ << ": Entering event loop" << "\n"; @@ -183,8 +188,8 @@ void MarionetteThread::main(MarionetteThread& self) if (sendExceptionInd) { - mrntt::exitCode = EXIT_FAILURE; - mrntt::mrntt.exceptionInd(); + smo::mrntt::exitCode = EXIT_FAILURE; + smo::mrntt::mrntt.exceptionInd(); } } @@ -197,7 +202,7 @@ void MarionetteThread::main(MarionetteThread& self) if (typeid(e) == typeid(OptionsParserError)) { - mrntt::exitCode = EXIT_FAILURE; + smo::mrntt::exitCode = EXIT_FAILURE; out = &std::cerr; outUsageMsg = std::string(__func__) + ": "; } @@ -208,17 +213,17 @@ void MarionetteThread::main(MarionetteThread& self) { std::cerr << __func__ << ": Exception occurred: " << e.what() << std::endl; - mrntt::exitCode = EXIT_FAILURE; + smo::mrntt::exitCode = EXIT_FAILURE; } catch (...) { std::cerr << __func__ << ": Unknown exception occurred" << std::endl; - mrntt::exitCode = EXIT_FAILURE; + smo::mrntt::exitCode = EXIT_FAILURE; } if (callShutdownSalmanoff) { - shutdownSalmanoff(); + smo::shutdownSalmanoff(); } } -} // namespace smo +} // namespace sscl diff --git a/smocore/mind.cpp b/smocore/mind.cpp index 69c1bbb..0ab8eaf 100644 --- a/smocore/mind.cpp +++ b/smocore/mind.cpp @@ -14,8 +14,8 @@ namespace smo { Mind::Mind(void) - : PuppetApplication( - std::vector>{ + : sscl::PuppetApplication( + std::vector>{ std::make_shared(SmoThreadId::DIRECTOR, *this), std::make_shared(SmoThreadId::SIMULATOR, *this), std::make_shared(SmoThreadId::SUBCONSCIOUS, *this), @@ -24,22 +24,22 @@ Mind::Mind(void) , std::make_shared(SmoThreadId::WORLD, *this) #endif }), - director(*this, std::static_pointer_cast(componentThreads[0])), - canvas(*this, std::static_pointer_cast(componentThreads[1])), - subconscious(*this, std::static_pointer_cast(componentThreads[2])), - body(*this, std::static_pointer_cast(componentThreads[3])), + director(*this, std::static_pointer_cast(componentThreads[0])), + canvas(*this, std::static_pointer_cast(componentThreads[1])), + subconscious(*this, std::static_pointer_cast(componentThreads[2])), + body(*this, std::static_pointer_cast(componentThreads[3])), world(*this, #ifndef CONFIG_WORLD_USE_BODY_THREAD - std::static_pointer_cast(componentThreads[4]) + std::static_pointer_cast(componentThreads[4]) #else - std::static_pointer_cast(componentThreads[3]) + std::static_pointer_cast(componentThreads[3]) #endif ) { } std::shared_ptr -Mind::getComponentThread(ThreadId id) const +Mind::getComponentThread(sscl::ThreadId id) const { if (id == SmoThreadId::MRNTT) { @@ -98,13 +98,13 @@ Mind::getMindThreads() const } class Mind::MindLifetimeMgmtOp -: public PostedAsynchronousContinuation +: public sscl::PostedAsynchronousContinuation { public: MindLifetimeMgmtOp( - Mind &parent, const std::shared_ptr &caller, - Callback callback) - : PostedAsynchronousContinuation( + Mind &parent, const std::shared_ptr &caller, + sscl::Callback callback) + : sscl::PostedAsynchronousContinuation( caller, callback), parent(parent) {} @@ -209,7 +209,7 @@ public: } }; -void Mind::initializeReq(Callback callback) +void Mind::initializeReq(sscl::Callback callback) { /* Distribute threads across available CPUs */ try @@ -223,7 +223,7 @@ void Mind::initializeReq(Callback callback) "Error: " << e.what() << "\n"; } - const auto& caller = ComponentThread::getSelf(); + const auto& caller = sscl::ComponentThread::getSelf(); auto request = std::make_shared( *this, caller, callback); @@ -233,9 +233,9 @@ void Mind::initializeReq(Callback callback) request.get(), request))); } -void Mind::finalizeReq(Callback callback) +void Mind::finalizeReq(sscl::Callback callback) { - const auto& caller = ComponentThread::getSelf(); + const auto& caller = sscl::ComponentThread::getSelf(); auto request = std::make_shared( *this, caller, callback); diff --git a/smocore/simulator/simulator.cpp b/smocore/simulator/simulator.cpp index 0911192..504d5bd 100644 --- a/smocore/simulator/simulator.cpp +++ b/smocore/simulator/simulator.cpp @@ -4,8 +4,8 @@ namespace smo { namespace simulator { -Simulator::Simulator(Mind &parent, const std::shared_ptr &thread) -: PuppetComponent(static_cast(parent), thread) +Simulator::Simulator(Mind &parent, const std::shared_ptr &thread) +: sscl::PuppetComponent(static_cast(parent), thread) { } diff --git a/smocore/stimBuffApis/stimBuffApiManager.cpp b/smocore/stimBuffApis/stimBuffApiManager.cpp index 67f62ad..2bcf991 100644 --- a/smocore/stimBuffApis/stimBuffApiManager.cpp +++ b/smocore/stimBuffApis/stimBuffApiManager.cpp @@ -74,10 +74,10 @@ static std::optional searchForLibInSmoSearchPaths( return std::nullopt; } -/* Local static function to wrap ComponentThread::getSelf for SmoCallbacks */ -static std::shared_ptr ComponentThread_getSelf() +/* Local static function to wrap sscl::ComponentThread::getSelf for SmoCallbacks */ +static std::shared_ptr ComponentThread_getSelf() { - return ComponentThread::getSelf(); + return sscl::ComponentThread::getSelf(); } /* Local static function to wrap OptionParser::getOptions for SmoCallbacks */ @@ -145,7 +145,7 @@ std::optional StimBuffApiManager::searchForLibInSmoSearchPaths( StimBuffApiLib& StimBuffApiManager::loadStimBuffApiLib( const std::string& libraryPath, - const std::shared_ptr& componentThread + const std::shared_ptr& componentThread ) { std::optional fullPath = searchForLibInSmoSearchPaths( @@ -252,7 +252,7 @@ void StimBuffApiManager::unloadAllStimBuffApiLibs(void) } void StimBuffApiManager::loadAllStimBuffApiLibsFromOptions( - const std::shared_ptr& componentThread + const std::shared_ptr& componentThread ) { const auto& options = OptionParser::getOptions(); diff --git a/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp b/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp index b807fd0..08ce1f4 100644 --- a/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp +++ b/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp @@ -71,7 +71,7 @@ bool IoUringAssemblyEngine::setup() { // Defensive check to prevent double-calling { - SpinLock::Guard lock(shouldAcceptRequestsLock); + sscl::SpinLock::Guard lock(shouldAcceptRequestsLock); if (shouldAcceptRequests) { throw std::runtime_error(std::string(__func__) + ": setup() called " @@ -180,7 +180,7 @@ void IoUringAssemblyEngine::finalize() { auto& ioService = smoHooksPtr->ComponentThread_getSelf()->getIoService(); - AsynchronousBridge bridge(ioService); + sscl::AsynchronousBridge bridge(ioService); boost::asio::deadline_timer timeoutTimer(ioService); /** EXPLANATION: @@ -329,7 +329,7 @@ void IoUringAssemblyEngine::resetAndAssembleFrame( bool IoUringAssemblyEngine::stop() { // Acquire and release lock tightly around setting the flag - SpinLock::Guard lock(shouldAcceptRequestsLock); + sscl::SpinLock::Guard lock(shouldAcceptRequestsLock); bool wasAcceptingRequests = shouldAcceptRequests; shouldAcceptRequests = false; return wasAcceptingRequests; @@ -427,22 +427,22 @@ cleanup_eventfd: // Continuation class for assembleFrameReq class IoUringAssemblyEngine::AssembleFrameReq -: public PostedAsynchronousContinuation< +: public sscl::PostedAsynchronousContinuation< IoUringAssemblyEngine::assembleFrameReqCbFn> { public: AssembleFrameReq( IoUringAssemblyEngine& engine_, - const std::shared_ptr& caller, - Callback cb) - : PostedAsynchronousContinuation< + const std::shared_ptr& caller, + sscl::Callback cb) + : sscl::PostedAsynchronousContinuation< IoUringAssemblyEngine::assembleFrameReqCbFn>(caller, cb), engine(engine_), loop(engine_.frameAssemblyDesc->numSlots), timerFired(false), handlerExecuted(false) {} - void callOriginalCallback(bool success, AsynchronousLoop loop) + void callOriginalCallback(bool success, sscl::AsynchronousLoop loop) { callOriginalCb(success, loop); } @@ -451,16 +451,16 @@ public: void assembleFrameReq1_posted( std::shared_ptr context) { - SpinLock::Guard lock(engine.shouldAcceptRequestsLock); + sscl::SpinLock::Guard lock(engine.shouldAcceptRequestsLock); if (!engine.shouldAcceptRequests) { - context->callOriginalCallback(false, AsynchronousLoop(0)); + context->callOriginalCallback(false, sscl::AsynchronousLoop(0)); return; } // Initialize loop with number of slots - context->loop = AsynchronousLoop(engine.frameAssemblyDesc->numSlots); + context->loop = sscl::AsynchronousLoop(engine.frameAssemblyDesc->numSlots); // Record assembly start time engine.assemblyStartTime = std::chrono::high_resolution_clock::now(); @@ -505,7 +505,7 @@ public: * indeed seen a SEGFAULT even in the current code with locking, so * I'm going to hold the lock here for now. */ - SpinLock::Guard lock(context->engine.shouldAcceptRequestsLock); + sscl::SpinLock::Guard lock(context->engine.shouldAcceptRequestsLock); if (!context->engine.shouldAcceptRequests) { @@ -636,19 +636,19 @@ public: public: IoUringAssemblyEngine& engine; - AsynchronousLoop loop; + sscl::AsynchronousLoop loop; std::atomic timerFired; std::atomic handlerExecuted; }; void IoUringAssemblyEngine::assembleFrameReq( - Callback cb) + sscl::Callback cb) { { - SpinLock::Guard lock(shouldAcceptRequestsLock); + sscl::SpinLock::Guard lock(shouldAcceptRequestsLock); if (!shouldAcceptRequests) { - cb.callbackFn(false, AsynchronousLoop(0)); + cb.callbackFn(false, sscl::AsynchronousLoop(0)); return; } } @@ -677,7 +677,7 @@ void IoUringAssemblyEngine::onEventfdRead( * IoUringAssemblyEngine's per-assembly state isn't destroyed while this * handler is running. */ - SpinLock::Guard lock(shouldAcceptRequestsLock); + sscl::SpinLock::Guard lock(shouldAcceptRequestsLock); /** EXPLANATION: * You'd think we should put check for shouldAcceptRequests here and * `return` here if !shouldAcceptRequests, but we shouldn't because @@ -763,7 +763,7 @@ void IoUringAssemblyEngine::fillUnAssembledSlotsWithDummyDgrams() } } -void IoUringAssemblyEngine::randomDummySlotFiller(AsynchronousLoop& loop) +void IoUringAssemblyEngine::randomDummySlotFiller(sscl::AsynchronousLoop& loop) { if (!frameAssemblyDesc) { return; } @@ -816,7 +816,7 @@ void IoUringAssemblyEngine::randomDummySlotFiller(AsynchronousLoop& loop) numDummiesToCreate = dummiesCreated; } - // Update the AsynchronousLoop to reflect the new number of dummies + // Update the sscl::AsynchronousLoop to reflect the new number of dummies // Since we only reach here when nSucceeded == nTotal and nFailed == 0, // we can directly calculate the new values uint32_t newSucceeded = nTotal - static_cast(numDummiesToCreate); diff --git a/stimBuffApis/livoxGen1/ioUringAssemblyEngine.h b/stimBuffApis/livoxGen1/ioUringAssemblyEngine.h index 21a5b86..6c7696d 100644 --- a/stimBuffApis/livoxGen1/ioUringAssemblyEngine.h +++ b/stimBuffApis/livoxGen1/ioUringAssemblyEngine.h @@ -40,8 +40,8 @@ public: bool setup(); void finalize(); - typedef std::function assembleFrameReqCbFn; - void assembleFrameReq(Callback cb); + typedef std::function assembleFrameReqCbFn; + void assembleFrameReq(sscl::Callback cb); // Telemetry helpers static size_t computePointsPerFrame(int returnMode, size_t nDgramsPerFrame) @@ -82,7 +82,7 @@ private: * Flag to indicate whether engine should accept new requests. * Set by setup(), cleared by stop(). */ - SpinLock shouldAcceptRequestsLock; + sscl::SpinLock shouldAcceptRequestsLock; bool shouldAcceptRequests; size_t nDgramsPerStagingBufferFrame; @@ -106,7 +106,7 @@ private: std::chrono::high_resolution_clock::time_point assemblyEndTime; void fillUnAssembledSlotsWithDummyDgrams(); - void randomDummySlotFiller(AsynchronousLoop& loop); + void randomDummySlotFiller(sscl::AsynchronousLoop& loop); void onEventfdRead( const boost::system::error_code& error, std::size_t bytes_transferred); diff --git a/stimBuffApis/livoxGen1/livoxGen1.cpp b/stimBuffApis/livoxGen1/livoxGen1.cpp index 7355f09..863c8cc 100644 --- a/stimBuffApis/livoxGen1/livoxGen1.cpp +++ b/stimBuffApis/livoxGen1/livoxGen1.cpp @@ -119,13 +119,13 @@ LivoxProto1DllState livoxProto1; // Continuation classes for async operations class AttachDeviceReq -: public smo::NonPostedAsynchronousContinuation +: public sscl::NonPostedAsynchronousContinuation { public: AttachDeviceReq( const std::shared_ptr& spec, - smo::Callback cb) - : smo::NonPostedAsynchronousContinuation( + sscl::Callback cb) + : sscl::NonPostedAsynchronousContinuation( std::move(cb)), spec(spec) {} @@ -388,14 +388,14 @@ public: }; class DetachDeviceReq -: public smo::NonPostedAsynchronousContinuation +: public sscl::NonPostedAsynchronousContinuation { public: DetachDeviceReq( const std::shared_ptr& spec, const std::shared_ptr& stimBuffer, - smo::Callback cb) - : smo::NonPostedAsynchronousContinuation( + sscl::Callback cb) + : sscl::NonPostedAsynchronousContinuation( std::move(cb)), spec(spec), stimBuffer(stimBuffer) {} @@ -658,8 +658,8 @@ extern "C" int livoxGen1_finalizeInd(void) extern "C" void livoxGen1_attachDeviceReq( const std::shared_ptr& desc, - const std::shared_ptr& componentThread, - Callback cb + const std::shared_ptr& componentThread, + sscl::Callback cb ) { if (!livoxProto1.livoxProto1_getOrCreateDeviceReq) @@ -847,7 +847,7 @@ extern "C" void livoxGen1_attachDeviceReq( extern "C" void livoxGen1_detachDeviceReq( const std::shared_ptr& desc, - Callback cb + sscl::Callback cb ) { // Case 1: Check if StimBuffer doesn't exist (early return) diff --git a/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.cpp b/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.cpp index 936b17f..acb350c 100644 --- a/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.cpp +++ b/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.cpp @@ -65,7 +65,7 @@ bool OpenClCollatingAndMeshingEngine::setup() { // Defensive check to prevent double-calling { - SpinLock::Guard lock(shouldAcceptRequestsLock); + sscl::SpinLock::Guard lock(shouldAcceptRequestsLock); if (shouldAcceptRequests) { throw std::runtime_error(std::string(__func__) + ": setup() called " @@ -224,7 +224,7 @@ void OpenClCollatingAndMeshingEngine::finalize() int delayMs = std::max(OCLCOLLMESH_ENGN_FINALIZE_DELAY_MS, 0); auto& ioService = smoHooksPtr->ComponentThread_getSelf()->getIoService(); - AsynchronousBridge bridge(ioService); + sscl::AsynchronousBridge bridge(ioService); boost::asio::deadline_timer timeoutTimer(ioService); /** EXPLANATION: @@ -763,7 +763,7 @@ bool OpenClCollatingAndMeshingEngine::setupCollateDgramsArgs( bool OpenClCollatingAndMeshingEngine::stop() { // Acquire and release lock tightly around setting the flag - SpinLock::Guard lock(shouldAcceptRequestsLock); + sscl::SpinLock::Guard lock(shouldAcceptRequestsLock); bool wasAcceptingRequests = shouldAcceptRequests; shouldAcceptRequests = false; return wasAcceptingRequests; @@ -1015,11 +1015,11 @@ void OpenClCollatingAndMeshingEngine::produceAmbienceStimulusFrame( } class OpenClCollatingAndMeshingEngine::CompactCollateAndMeshFrameReq -: public PostedAsynchronousContinuation +: public sscl::PostedAsynchronousContinuation { private: OpenClCollatingAndMeshingEngine& engine; - AsynchronousLoop frameAssemblyResult; + sscl::AsynchronousLoop frameAssemblyResult; StimulusFrame& stimulusFrame; std::optional> intensityStimFrame; std::optional> ambienceStimFrame; @@ -1027,13 +1027,13 @@ private: public: CompactCollateAndMeshFrameReq( OpenClCollatingAndMeshingEngine& engine_, - AsynchronousLoop& asyncLoop, + sscl::AsynchronousLoop& asyncLoop, StimulusFrame& stimulusFrame_, std::optional> intensityStimFrame_, std::optional> ambienceStimFrame_, - const std::shared_ptr& caller, - Callback cb) - : PostedAsynchronousContinuation( + const std::shared_ptr& caller, + sscl::Callback cb) + : sscl::PostedAsynchronousContinuation( caller, cb), engine(engine_), frameAssemblyResult(asyncLoop), stimulusFrame(stimulusFrame_), @@ -1049,7 +1049,7 @@ public: void compactCollateAndMeshFrameReq1_doCompact_posted( std::shared_ptr context) { - SpinLock::Guard lock(engine.shouldAcceptRequestsLock); + sscl::SpinLock::Guard lock(engine.shouldAcceptRequestsLock); if (!engine.shouldAcceptRequests) { callOriginalCallback(false); @@ -1080,7 +1080,7 @@ public: std::shared_ptr context, cl_int compactStatus) { - SpinLock::Guard lock(engine.shouldAcceptRequestsLock); + sscl::SpinLock::Guard lock(engine.shouldAcceptRequestsLock); if (!engine.shouldAcceptRequests) { /** EXPLANATION: @@ -1121,7 +1121,7 @@ public: void compactCollateAndMeshFrameReq3_doCollate_posted( std::shared_ptr context) { - SpinLock::Guard lock(engine.shouldAcceptRequestsLock); + sscl::SpinLock::Guard lock(engine.shouldAcceptRequestsLock); if (!engine.shouldAcceptRequests) { callOriginalCallback(false); @@ -1153,7 +1153,7 @@ public: [[maybe_unused]] std::shared_ptr context, cl_int collateStatus) { - SpinLock::Guard lock(engine.shouldAcceptRequestsLock); + sscl::SpinLock::Guard lock(engine.shouldAcceptRequestsLock); if (!engine.shouldAcceptRequests) { /* We intentionally don't call collateKernelComplete() here for the @@ -1273,13 +1273,13 @@ public: }; void OpenClCollatingAndMeshingEngine::compactCollateAndMeshFrameReq( - AsynchronousLoop& asyncLoop, StimulusFrame& stimulusFrame, + sscl::AsynchronousLoop& asyncLoop, StimulusFrame& stimulusFrame, std::optional> intensityStimFrame, std::optional> ambienceStimFrame, - Callback callback) + sscl::Callback callback) { { - SpinLock::Guard lock(shouldAcceptRequestsLock); + sscl::SpinLock::Guard lock(shouldAcceptRequestsLock); if (!shouldAcceptRequests) { callback.callbackFn(false, stimulusFrame); diff --git a/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.h b/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.h index 718e2ef..bf7b5de 100644 --- a/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.h +++ b/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.h @@ -78,10 +78,10 @@ public: typedef std::function compactCollateAndMeshFrameReqCbFn; void compactCollateAndMeshFrameReq( - AsynchronousLoop& asyncLoop, StimulusFrame& stimulusFrame, + sscl::AsynchronousLoop& asyncLoop, StimulusFrame& stimulusFrame, std::optional> intensityStimFrame, std::optional> ambienceStimFrame, - Callback callback); + sscl::Callback callback); private: // Callback function types @@ -133,7 +133,7 @@ private: cl_mem clAverageIntensityBuffer; // State tracking - SpinLock shouldAcceptRequestsLock; + sscl::SpinLock shouldAcceptRequestsLock; bool shouldAcceptRequests; bool compactIsRunning; bool collateIsRunning; diff --git a/stimBuffApis/livoxGen1/pcloudStimulusProducer.cpp b/stimBuffApis/livoxGen1/pcloudStimulusProducer.cpp index 409530b..de155e0 100644 --- a/stimBuffApis/livoxGen1/pcloudStimulusProducer.cpp +++ b/stimBuffApis/livoxGen1/pcloudStimulusProducer.cpp @@ -362,11 +362,11 @@ void PcloudStimulusProducer::stimFrameProductionTimesliceInd() } class PcloudStimulusProducer::ProduceFrameReq -: public PostedAsynchronousContinuation +: public sscl::PostedAsynchronousContinuation { private: PcloudStimulusProducer& pcloudProducer; - AsynchronousLoop frameAssemblyResult; + sscl::AsynchronousLoop frameAssemblyResult; StimulusFrame& stimulusFrame; std::optional> intensityStimFrame; std::optional> ambienceStimFrame; @@ -374,9 +374,9 @@ private: public: ProduceFrameReq( PcloudStimulusProducer& producer, - const std::shared_ptr& caller, - Callback cb) - : PostedAsynchronousContinuation(caller, cb), + const std::shared_ptr& caller, + sscl::Callback cb) + : sscl::PostedAsynchronousContinuation(caller, cb), pcloudProducer(producer), frameAssemblyResult(0), stimulusFrame(producer.tempStimulusFrame) @@ -393,7 +393,7 @@ public: void produceFrameReq1_doAssemble_posted( std::shared_ptr context) { - SpinLock::Guard lock(pcloudProducer.shouldContinueLock); + sscl::SpinLock::Guard lock(pcloudProducer.shouldContinueLock); if (!pcloudProducer.shouldContinue) { callOriginalCallback(); @@ -409,9 +409,9 @@ public: void produceFrameReq2_assembleDone( std::shared_ptr context, - bool success, AsynchronousLoop loop) + bool success, sscl::AsynchronousLoop loop) { - SpinLock::Guard lock(pcloudProducer.shouldContinueLock); + sscl::SpinLock::Guard lock(pcloudProducer.shouldContinueLock); if (!pcloudProducer.shouldContinue) { callOriginalCallback(); @@ -490,7 +490,7 @@ public: context->ambienceStimFrame->get().lock.writeRelease(); } - SpinLock::Guard lock(pcloudProducer.shouldContinueLock); + sscl::SpinLock::Guard lock(pcloudProducer.shouldContinueLock); if (!pcloudProducer.shouldContinue) { callOriginalCallback(); @@ -517,7 +517,7 @@ public: }; void PcloudStimulusProducer::produceFrameReq( - smo::Callback callback) + sscl::Callback callback) { /** EXPLANATION: * We shouldn't acquire the StimulusProducer::shouldContinueLock here because diff --git a/stimBuffApis/livoxGen1/pcloudStimulusProducer.h b/stimBuffApis/livoxGen1/pcloudStimulusProducer.h index dfabc60..20245c5 100644 --- a/stimBuffApis/livoxGen1/pcloudStimulusProducer.h +++ b/stimBuffApis/livoxGen1/pcloudStimulusProducer.h @@ -80,7 +80,7 @@ protected: typedef std::function produceFrameReqCbFn; public: - void produceFrameReq(smo::Callback callback); + void produceFrameReq(sscl::Callback callback); size_t nDgramsPerStagingBufferFrame; std::shared_ptr device; diff --git a/stimBuffApis/xcbWindow/xcbWindow.cpp b/stimBuffApis/xcbWindow/xcbWindow.cpp index 7d8dae9..0c752c9 100644 --- a/stimBuffApis/xcbWindow/xcbWindow.cpp +++ b/stimBuffApis/xcbWindow/xcbWindow.cpp @@ -276,8 +276,8 @@ static int xcbWindow_finalizeInd(void) static void xcbWindow_attachDeviceReq( const std::shared_ptr& desc, - const std::shared_ptr& componentThread, - smo::Callback cb + const std::shared_ptr& componentThread, + sscl::Callback cb ) { // Not used yet, but may be used later. @@ -302,7 +302,7 @@ static void xcbWindow_attachDeviceReq( static void xcbWindow_detachDeviceReq( const std::shared_ptr& spec, - smo::Callback cb + sscl::Callback cb ) { auto it = std::find_if(g_attachedWindows.begin(), g_attachedWindows.end(), diff --git a/tests/smocore/qutex_tests.cpp b/tests/smocore/qutex_tests.cpp index 8504d02..8bacd27 100644 --- a/tests/smocore/qutex_tests.cpp +++ b/tests/smocore/qutex_tests.cpp @@ -15,10 +15,10 @@ public: : LockerAndInvokerBase(addr), awakened(false) {} bool awakened; - Qutex* registeredQutex = nullptr; + sscl::Qutex* registeredQutex = nullptr; List::iterator queueIterator; - List::iterator getLockvokerIteratorForQutex(Qutex& qutex) override { + List::iterator getLockvokerIteratorForQutex(sscl::Qutex& qutex) override { registeredQutex = &qutex; queueIterator = qutex.registerInQueue(std::shared_ptr(this)); return queueIterator; @@ -44,7 +44,7 @@ protected: // Clean up } - Qutex qutex; + sscl::Qutex qutex; std::shared_ptr mock1, mock2, mock3, mock4, mock5; // Unique addresses for testing