Skip to content

Add TSMutex lock guard#13188

Open
bneradt wants to merge 1 commit into
apache:masterfrom
bneradt:tsmutex-lock-guard
Open

Add TSMutex lock guard#13188
bneradt wants to merge 1 commit into
apache:masterfrom
bneradt:tsmutex-lock-guard

Conversation

@bneradt
Copy link
Copy Markdown
Contributor

@bneradt bneradt commented May 21, 2026

Plugin code that protects small critical sections with TSMutex has to pair
every early return with a matching unlock. That pattern is easy to get wrong
and makes the intended lock lifetime harder to see.

This adds a small TSMutexLockGuard helper to the plugin API and uses it in
plugin code where the mutex naturally stays locked until a return path.

Plugin code that protects small critical sections with TSMutex has to pair
every early return with a matching unlock. That pattern is easy to get wrong
and makes the intended lock lifetime harder to see.

This adds a small TSMutexLockGuard helper to the plugin API and uses it in
plugin code where the mutex naturally stays locked until a return path.
Copilot AI review requested due to automatic review settings May 21, 2026 19:13
@bneradt bneradt added this to the 11.0.0 milestone May 21, 2026
@bneradt bneradt self-assigned this May 21, 2026
@bneradt bneradt added TS API Plugins Enhancement easy_review No new logic, easy to review. Feedback Needed Request people to provide feedback. labels May 21, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@zwoop zwoop requested review from masaori335 and zwoop May 21, 2026 20:58
Comment thread include/ts/ts.h
class TSMutexLockGuard
{
public:
explicit TSMutexLockGuard(TSMutex mutexp) : m_mutex(mutexp) { TSMutexLock(m_mutex); }
Copy link
Copy Markdown
Contributor

@zwoop zwoop May 21, 2026

Choose a reason for hiding this comment

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

[[nodiscard("Did you forget to name your lock guard variable?")]]
explicit TSMutexLockGuard(TSMutex mutexp) : m_mutex(mutexp) { TSMutexLock(m_mutex); }

or some such ? This prevents a user from accidentally making a no-op lock guard (which almost certainly is not what they want). Albeit nitpicky, it feels useful in a public (plugin) API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

easy_review No new logic, easy to review. Enhancement Feedback Needed Request people to provide feedback. Plugins TS API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants