-
Notifications
You must be signed in to change notification settings - Fork 1
Thread name #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Thread name #1
Conversation
…g header, to use a string instead of the thread id. Though, thread id will be use as default value until you reach the directive to add a name to a thread id. You can after change the value, or delete the id-string association
…EAD_NAME, mlog::Options::bindThreadName and mlog::Options::unbindThreadName
doc/logs_doc.doxy
Outdated
| * @param[in] name Name that should be displayed instead of an id | ||
| * @see mlog::Options::unbidThreadName | ||
| * | ||
| * @fn void mlog::Options::unbidThreadName(const std::thread::id& id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A n is missing right here, (unbid instead of unbind), please add it in order to get consistent documentation.
doc/logs_doc.doxy
Outdated
| * | ||
| * @param[in] id The identifier returned by std::thread::get_id() | ||
| * @param[in] name Name that should be displayed instead of an id | ||
| * @see mlog::Options::unbidThreadName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same story here, unbid instead of unbind.
doc/logs_doc.doxy
Outdated
| * @var mlog::__details::__Static_declarer::THREAD_NAME | ||
| * The container for bounds between thread id and a string value | ||
| * @see mlog::Options::bindThreadName | ||
| * @see mlog::Options::unbidThreadName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here again.
logs.hpp
Outdated
| case -3: | ||
| # ifdef MTL_LOG_WITH_THREADS | ||
| out << "0x" << std::hex << std::this_thread::get_id() << std::dec; | ||
| # ifdef _REENTRANT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use MTL_LOG_WITH_THREADS macro instead of _REENTRANT.
logs.hpp
Outdated
| static bool ENABLE_ALPHA_BOOL; | ||
| static MTL_LOG_NAMESPACE::__details::__Header FORMAT; | ||
|
|
||
| # ifdef _REENTRANT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MTL_LOG_WITH_THREADS instead of _REENTRANT
logs.hpp
Outdated
| MTL_LOG_LOCK; | ||
| return MTL_LOG_NAMESPACE::Options::FORMAT; | ||
| } | ||
| # ifdef _REENTRANT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MTL_LOG_WITH_THREADS
logs.hpp
Outdated
| { | ||
| MTL_LOG_NAMESPACE::Options::THREAD_NAME.insert(std::make_pair(id, name)); | ||
| } | ||
| static void unbidThreadName(const std::thread::id& id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unbid instead of unbind
logs.hpp
Outdated
| MTL_LOG_NAMESPACE::Options::C_BLANK, | ||
| MTL_LOG_NAMESPACE::Options::isColorEnabled()); | ||
| MTL_LOG_NAMESPACE::Options::isColorEnabled(), | ||
| # ifdef _REENTRANT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MTL_LOG_WITH_THREADS
doc/logs_doc.doxy
Outdated
| * tag will print the thread id | ||
| * | ||
| * @param[in] id The identifier returned by std::thread::get_id() | ||
| * @see mlog::Options::bidThreadName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bid instead of bind
logs.hpp
Outdated
| const char *const nocolor, bool colorEnabled) | ||
| const char *const nocolor, bool colorEnabled, const void* threads_names) | ||
| { | ||
| # ifdef _REENTRANT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MTL_LOG_WITh_THREADS
|
I don't think this is a good idea to provide functions if and only if a special flag or macro was provided. Also, you could skip the first argument (std::thread::id) by adding it on the function body directly, assuming the function does something only if we're working with threads. Then users won't have to write it by themselve. |
The functions or now always visible, and they don't need the thread id any more. If MTL_LOG_WITH_THREADS is defined, then the function will have a job to do, otherwise it returns immediately.
|
I suppose that the fixes added are good, if you mind check one more time, and I think we'll be good ! |
logs.hpp
Outdated
| # endif | ||
| } | ||
| static void unbidThreadName(const std::thread::id& id) | ||
| static void unbidThreadName() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unbid is still here, and be explicit about functions that doesn't take parameter (consistence with the entire file) with void keyword.
|
It looks well, but one more complaint, why void* ? |
|
Tested with openMP with a simple pragma omp parallel and it seems to work |
…an be changed when we find a way to use thread with mingw.Addition of MTL_THREAD_ID that is thread id type when MTL_LOG_WITH_THREADS is defined, otherwise it's int type. This macro avoid errors. The display function contains the THREAD parameter only if MTL_LOG_WITH_THREADS is defined. Modification of bindThreadName, now there are two functions. The first one binds the given name to the current thread id, while the other one binds a specific thread id to the given name.
I've added a feature that binds a thread id to a string.
This allows a user to set a name to several threads.
It gives thins kind of output for this code :
Gives :
Assuming we have
./test.cppand./logs.hpp