-
-
Notifications
You must be signed in to change notification settings - Fork 712
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
TacyLockable with pthread mutexes #965
Comments
In the tests you can see that In your examples, you're defining the mutex and then also using I haven't used pthread_mutex_t, but I'd imagine you can just define: TracyLockable( pthread_mutex_t, MyMutex ); and then use Here's an excerpt of code I use for locking with Tracy: private:
mutable TracyLockable(Mutex, mutex);
T target;
auto lock() const
{
return ReadLock<LockableBase(Mutex)>(mutex);
} |
I tried the same with the std::mutex equivalents. I can not see why the extern declaration worked without the macro and it does not work with it. But the more important use case is to use track a mutex which is a class member. There I can not see another way to define it. Do you think your system should work with that? |
Here is the full version of the code I use for this guarding; which pairs a type T with a mutex and provides access, while working nicely with Tracy: // https://www.reddit.com/r/cpp/comments/p132c7/comment/h8b8nml/?share_id=-NRyj9iRw5TqSi4Mm381j
template <
class T,
class M = std::mutex,
template <typename...> typename WL = std::unique_lock,
template <typename...> typename RL = std::unique_lock>
struct mutex_guarded
{
mutex_guarded() = default;
~mutex_guarded() = default;
explicit mutex_guarded(T in)
: target(std::move(in))
{
}
auto read(auto f) const
{
auto l = lock();
LockMark(mutex);
return f(target);
}
auto write(auto f)
{
auto l = lock();
LockMark(mutex);
return f(target);
}
private:
mutable TracyLockable(M, mutex);
T target;
auto lock() const
{
return RL<LockableBase(M)>(mutex);
}
auto lock()
{
return WL<LockableBase(M)>(mutex);
}
}; mutex_guarded<std::unordered_map<std::string, time_point>> lastExecutionTimes_;
lastExecutionTimes_.write([&](auto& lastExecutionTimes) { ... })); |
@zach2good Edit: I was able to compile it using "-fpermissive". I had forgotten to add tracy path and lib. I wonder why you used templates. Because its more convenient to use or because there is no other way to get it to work (i.e. w/o templates)? |
I did it this way to easily mark You could easily embed |
This also means that I only have one area in my code where I deal with mutexes, and anywhere I use this template is correctly reported to Tracy |
Right. OK I get the idea with the template. I am trying to get it to work with pthread which is not using templates. Thats why after the definition with Tracy you can not
For example, the call to lock the mutex would require a pointer to the mutex
but tracy seems to assign the variable to the type I did not yet find out how to get to the original pointer or how to call the lock function in a tracy conformal way. |
I am getting compile errors when tryping to use the TacyLockable() macro
with pthread mutexes in two scenarios with gcc on Linux:
Errors
Errors
Is there a way to deal with these two settings?
The text was updated successfully, but these errors were encountered: