Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,15 @@

#pragma once

#include <cstdint>
// Platform integration provides ScopedCoreLock and ScopedECULock in the
// middleware::concurrency::integration namespace via lock_types.h.
// The concrete types will be provided at build time.
#include <middleware/concurrency/lock_types.h>

namespace middleware::concurrency
{

/**
* Suspend all interrupts.
* Platform-specific function that suspends all interrupts to ensure critical sections
* are protected. This is used in conjunction with lock strategies for thread-safe operations.
* The implementation must be provided for each platform integration.
*/
extern void suspendAllInterrupts();

/**
* Scoped lock for single-core protection.
* RAII-style lock that protects critical sections within a single core by disabling
* interrupts or using other single-core synchronization mechanisms. The lock is acquired in the
* constructor and automatically released in the destructor, ensuring proper cleanup even in the
* presence of exceptions.
* The implementation must be provided for each platform integration.
*/
struct ScopedCoreLock
{
/** Acquires the single-core lock. */
ScopedCoreLock();

/** Releases the single-core lock. */
~ScopedCoreLock();

ScopedCoreLock(ScopedCoreLock const&) = delete;
ScopedCoreLock& operator=(ScopedCoreLock const&) = delete;
};

/**
* Scoped lock for ECU-wide (multi-core) protection.
* RAII-style lock that protects critical sections across multiple cores in an ECU by
* using hardware-supported spinlocks or other multi-core synchronization mechanisms. The lock is
* acquired in the constructor and automatically released in the destructor, ensuring proper
* cleanup even in the presence of exceptions.
* The implementation must be provided for each platform integration.
*/
struct ScopedECULock
{
/** Acquires the ECU-wide lock using \p lock. */
ScopedECULock(uint8_t volatile* lock);

/** Releases the ECU-wide lock. */
~ScopedECULock();

ScopedECULock(ScopedECULock const&) = delete;
ScopedECULock& operator=(ScopedECULock const&) = delete;
};
using ScopedCoreLock = ::middleware::concurrency::integration::ScopedCoreLock;
using ScopedECULock = ::middleware::concurrency::integration::ScopedECULock;

} // namespace middleware::concurrency
2 changes: 0 additions & 2 deletions libs/bsw/middleware/src/middleware/core/ProxyBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ void ProxyBase::checkCrossThreadError(uint32_t const initId) const
auto const currentTaskId = ::middleware::os::getProcessId();
if (initId != currentTaskId)
{
::middleware::concurrency::suspendAllInterrupts();

logger::logCrossThreadViolation(
logger::LogLevel::Critical,
logger::Error::ProxyCrossThreadViolation,
Expand Down
2 changes: 0 additions & 2 deletions libs/bsw/middleware/src/middleware/core/SkeletonBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ void SkeletonBase::checkCrossThreadError(uint32_t const initId) const
auto const currentTaskId = ::middleware::os::getProcessId();
if (initId != currentTaskId)
{
::middleware::concurrency::suspendAllInterrupts();

logger::logCrossThreadViolation(
logger::LogLevel::Critical,
logger::Error::SkeletonCrossThreadViolation,
Expand Down
4 changes: 3 additions & 1 deletion libs/bsw/middleware/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
add_executable(
middlewareTest
src/concurrency/ConcurrencyDefinitions.cpp
src/core/ClusterConfigurationTest.cpp
src/core/ConnectionTest.cpp
src/core/DbManipulatorTest.cpp
Expand All @@ -24,6 +23,9 @@ add_executable(

target_include_directories(middlewareTest PUBLIC src)

target_include_directories(middleware
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)

target_link_libraries(middlewareTest PRIVATE middleware gmock gtest_main)

gtest_discover_tests(middlewareTest PROPERTIES LABELS "middlewareTest")
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <cstdint>

namespace middleware::concurrency::integration
{

/**
* No-op scope guard for single-core lock — test/host stub.
*/
struct ScopedCoreLock
{
ScopedCoreLock() = default;
~ScopedCoreLock() = default;

ScopedCoreLock(ScopedCoreLock const&) = delete;
ScopedCoreLock& operator=(ScopedCoreLock const&) = delete;
ScopedCoreLock(ScopedCoreLock&&) = delete;
ScopedCoreLock& operator=(ScopedCoreLock&&) = delete;
};

/**
* No-op scope guard for ECU-wide lock — test/host stub.
*/
struct ScopedECULock
{
explicit ScopedECULock(uint8_t volatile*) {}

~ScopedECULock() = default;

ScopedECULock(ScopedECULock const&) = delete;
ScopedECULock& operator=(ScopedECULock const&) = delete;
ScopedECULock(ScopedECULock&&) = delete;
ScopedECULock& operator=(ScopedECULock&&) = delete;
};

} // namespace middleware::concurrency::integration

This file was deleted.

Loading