Skip to content
Merged
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
6 changes: 4 additions & 2 deletions include/tscpp/util/TsSharedMutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ class shared_mutex
if (error != 0) {
_call_fatal("pthread_rwlock_rdlock", &_lock, error);
}
X(TSAssert(_shared >= 0);)
X(++_shared;)
X(TSAssert(_shared > 0);)
}

bool
Expand Down Expand Up @@ -184,8 +186,8 @@ class shared_mutex

// In debug builds, make sure shared vs. exlusive locks and unlocks are properly paired.
//
X(std::atomic<bool> _exclusive;)
X(std::atomic<int> _shared;)
X(std::atomic<bool> _exclusive{false};)
X(std::atomic<int> _shared{0};)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to this: https://en.cppreference.com/w/cpp/atomic/atomic/atomic

The default constructor is trivial: no initialization takes place other than zero initialization of static and thread-local objects. std::atomic_init may be used to complete initialization.

I also ran into an uninitialized value during local testing, which drove this change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, sorry, I thought the std::atomic constructor always zero initialized, even for stack instances.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem!

};

} // end namespace ts
Expand Down