Skip to content

Commit 000881f

Browse files
committed
[refactoring][SerialPrinter]: Remove atomic print lock from SerialPrinter
Eliminated the use of std::atomic<bool> print_lock and related locking logic from SerialPrinter.</bool> Simplified the print() method to directly invoke PrintHandler::create without contention checks. Updated method signature to be const-correct. Signed-off-by: Goran Mišković <[email protected]>
1 parent 25b7101 commit 000881f

File tree

2 files changed

+2
-14
lines changed

2 files changed

+2
-14
lines changed

include/SerialPrinter.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ namespace e5 {
4747
* @param message std::string to print
4848
* @return PICO_OK on success, or error code on failure
4949
*/
50-
uint32_t print(std::unique_ptr<std::string> message);
51-
52-
static std::atomic<bool> print_lock; ///< Global serialization and re-entrancy guard
50+
uint32_t print(std::unique_ptr<std::string> message) const;
5351
};
5452

5553
} // namespace e5

src/SerialPrinter.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,15 @@
1010
#include "ContextManager.hpp"
1111
#include "MessageBuffer.hpp"
1212
#include "PrintHandler.hpp"
13-
#include <atomic>
1413

1514
namespace e5 {
1615

17-
std::atomic<bool> SerialPrinter::print_lock{false};
18-
1916
// Constructor implementation
2017
SerialPrinter::SerialPrinter(const AsyncCtx &ctx) : m_ctx(ctx) {}
2118

2219
// Print method implementation for std::string
23-
uint32_t SerialPrinter::print(std::unique_ptr<std::string> message) {
24-
bool expected = false;
25-
// Use class static member for serialization and reentrancy guard
26-
if (!print_lock.compare_exchange_strong(expected, true, std::memory_order_acquire)) {
27-
// Lock is already held, skip or handle contention (for test, just return error)
28-
return PICO_ERROR_RESOURCE_IN_USE; // Indicate contention
29-
}
20+
uint32_t SerialPrinter::print(std::unique_ptr<std::string> message) const {
3021
PrintHandler::create(m_ctx, std::move(message));
31-
print_lock.store(false, std::memory_order_release);
3222
return PICO_OK; // Return success code
3323
}
3424

0 commit comments

Comments
 (0)