This PR changes ThreadMap::get public API (as well as some internal parts of the class), so instead of returning a pointer to internally allocated ThreadBucket and managing it's lifecycle directly by calling release() method in LogWriter::record, the method will return a ThreadBucketPtr wrapper of it. Wrapper will do automatic and atomic reference counting upon construction/destruction and can only be moved. It is moved from signal handler callback to CircularQueue and then to LogWriter. There's no need to explicitly call any methods (except for std::move in certain cases), once Bucket goes out of scope pointer will be processed correctly. I added a couple of unit tests for thread map as well.
I also did 2 minor changes:
Removed #ifdef GETENV_NEW_THREAD_ASYNC_UNSAFE that protects controller->start().
It allows to use controller on Mac when both port and host are defined. If controller doesn't work properly for someone, it can be disabled easily at runtime, there's no need to remove it completely.
Added .clang-format file, so uniform cpp code style can be used reused. I only applied it to thread_map.h, thread_map.cpp and corresponding test, since I'm not sure everyone will like it.
Hi,
This PR changes
ThreadMap::get
public API (as well as some internal parts of the class), so instead of returning a pointer to internally allocatedThreadBucket
and managing it's lifecycle directly by callingrelease()
method inLogWriter::record
, the method will return aThreadBucketPtr
wrapper of it. Wrapper will do automatic and atomic reference counting upon construction/destruction and can only be moved. It is moved from signal handler callback toCircularQueue
and then toLogWriter
. There's no need to explicitly call any methods (except for std::move in certain cases), once Bucket goes out of scope pointer will be processed correctly. I added a couple of unit tests for thread map as well.I also did 2 minor changes:
#ifdef GETENV_NEW_THREAD_ASYNC_UNSAFE
that protectscontroller->start()
. It allows to use controller on Mac when both port and host are defined. If controller doesn't work properly for someone, it can be disabled easily at runtime, there's no need to remove it completely.thread_map.h
,thread_map.cpp
and corresponding test, since I'm not sure everyone will like it.