Skip to content
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

Introducing sync Mutex wrapper class #1064

Merged
merged 4 commits into from
Jan 17, 2020

Conversation

maxsharabayko
Copy link
Collaborator

@maxsharabayko maxsharabayko commented Jan 16, 2020

This is the second subset of PR #800 on the way to C++11 support.

srt::sync::Mutex class is introduced. The class wraps pthread mutex.
In future it is expected to be directly mapped to std::mutex in case SRT is built with C++11 threads.

Shortlist of Changes

  1. Introduced srt::sync::Mutex class that wraps pthread mutex.
  2. Replaced CGuard with ScopedLock and UniqueLock. Added CGuard typedef to reduce the number of renaming until Added CSync utlity for CV #1049 is merged.
  3. Renamed CRcvQueue::m_PassLock to CRcvQueue::m_BufferLock
  4. Renamed CRcvQueue::m_PassCond to CRcvQueue::m_BufferCond
  5. Replaced CTimer::sleep() by srt::sync::SleepFor(const Duration&)

Blocks #1049

@maxsharabayko maxsharabayko added Priority: High Type: Maintenance Work required to maintain or clean up the code [core] Area: Changes in SRT library core labels Jan 16, 2020
@maxsharabayko maxsharabayko added this to the v1.5.0 milestone Jan 16, 2020
and m_PassCond to m_BufferLock and m_BufferCond
@maxsharabayko maxsharabayko force-pushed the develop/sync_02_mutexes branch 3 times, most recently from d5f98b5 to 54b17c2 Compare January 17, 2020 14:16
The only place affected is the garbage collector thread. On Linux it
used to wait for 10 us, on Windows - 1 millisecond. Now 1 millisecond on
both platforms.
@maxsharabayko maxsharabayko force-pushed the develop/sync_02_mutexes branch 2 times, most recently from 1315d06 to 84c2110 Compare January 17, 2020 14:46
THREAD_RESUMED();
}
}
CGuard::leaveCS(self->m_RecvLock);
recv_lock.unlock();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unnecessary. Can be unlocked in destructor here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this unlock is done to have the following section out of the guard:

THREAD_EXIT();
HLOGC(tslog.Debug, log << self->CONID() << "tsbpd: EXITING");

Copy link
Collaborator

Choose a reason for hiding this comment

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

So, no. This THREAD_EXIT() is an entry for Makito thread tracer stuff, it should actually be at the very end of this function. The logging instruction is also alright to be under or outside the CS.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are probably right on the usage.
Still, I would like to retain the previous behavior for convenience. And previously the mutex was being explicitly unlocked.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, but it was intended to be unlocked at the end of the function. Previously, before I added the logging instruction, it was really at the end, only followed by THREAD_EXIT(). I simply added this log by jumping to the end of this function, ignoring whatever was there before. I confirm officially: it wasn't my intention to have the mutex unlocked specifically before the logging instruction. Also, the original author of this code simply didn't use CGuard.

{
// Use class member such that the method can be interrupted by others
m_tsSchedTime = nexttime;
// Use class member such that the method can be interrupted by others
Copy link
Collaborator

Choose a reason for hiding this comment

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

Better leave formatting fixes behind, if possible.

Copy link
Collaborator

@ethouris ethouris left a comment

Choose a reason for hiding this comment

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

Some smaller findings, otherwise looks good.

srtcore/sync.cpp Outdated

bool srt::sync::Mutex::try_lock()
{
return (pthread_mutex_lock(&m_mutex) == 0);
Copy link
Collaborator

@rndi rndi Jan 17, 2020

Choose a reason for hiding this comment

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

try_lock() should be using pthread_mutex_trylock() or be removed to avoid confusion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

@maxsharabayko maxsharabayko force-pushed the develop/sync_02_mutexes branch from 84c2110 to 53069ba Compare January 17, 2020 18:11
@maxsharabayko maxsharabayko requested a review from rndi January 17, 2020 18:28
@rndi rndi merged commit 7845bc4 into Haivision:master Jan 17, 2020
@maxsharabayko maxsharabayko deleted the develop/sync_02_mutexes branch January 17, 2020 20:05
@maxsharabayko maxsharabayko mentioned this pull request Jan 20, 2020
13 tasks
@maxsharabayko maxsharabayko mentioned this pull request Jan 29, 2020
18 tasks
@mbakholdina mbakholdina modified the milestones: v1.5.0, v1.4.2 Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[core] Area: Changes in SRT library core Priority: High Type: Maintenance Work required to maintain or clean up the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants