Skip to content

Misc dds & rsutils - #13704

Merged
maloel merged 3 commits into
realsenseai:developmentfrom
maloel:misc-dds
Jan 27, 2025
Merged

Misc dds & rsutils#13704
maloel merged 3 commits into
realsenseai:developmentfrom
maloel:misc-dds

Conversation

@maloel

@maloel maloel commented Jan 23, 2025

Copy link
Copy Markdown
Contributor

Separated a few commits from my upcoming PR...

The functions in timer and stopwatch has bad const designations... I changed those. Sorry about the formatting...

{
namespace time
public:
stopwatch() { _start = clock::now(); }

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.

Better to use initializer list

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.

OK, changed.

// If already set, returns immediately
// The event remains set when returning: it needs to be cleared...
void wait() const
void wait()

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.

Why did you remove the const? Semantically we don't expect wait to change internal event state

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.

Hmm I guess wait() waits for someone else to change it - even though you're expecting a change, you're no changing it yourself...
So I'll try putting back the const.

std::unique_lock< std::mutex > lock( _m );
if( ! _is_set )
_is_set = ( std::cv_status::timeout != _cv.wait( lock, timeout ) );
_is_set = ( std::cv_status::timeout != _cv.wait_for( lock, timeout ) );

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.

I don't think we should assign _is_set here, same way we don't assign in wait() function.

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.

And then the function can stay const

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.

Will do so.

std::unique_lock< std::mutex > lock( _m );
_is_set = false;
_is_set = ( std::cv_status::timeout != _cv.wait( lock, timeout ) );
_is_set = ( std::cv_status::timeout != _cv.wait_for( lock, timeout ) );

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.

Same, don't assign _is_set here.

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.

OK, but note that line 95 still is needed. And this function is not const.

Comment thread third-party/rsutils/include/rsutils/concurrency/event.h
@maloel
maloel merged commit 61c5582 into realsenseai:development Jan 27, 2025
@maloel
maloel deleted the misc-dds branch January 27, 2025 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants