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

Replace SharedBuffer::Semaphore with Core::SharedSemaphore #1737

Merged
merged 31 commits into from
Oct 10, 2024

Conversation

nxtum
Copy link
Contributor

@nxtum nxtum commented Sep 6, 2024

In SharedBuffer, a class "Semaphore" was being used. This used <semaphore.h>, and the problem was due to sem_clockwait not available on the apple platform and not in the musl library.

In Sync.h, a class "BinarySemaphore" (previously "BinairySemaphore") was defined, which instead uses <pthread.h>, using mutex and condition variables instead.

Other differences include constructor values as SharedBuffer::Semaphore would take either TCHAR or a sem_t* depending on platform, whilst Core::BinarySemaphore takes in a bool flag.

Essentially, they try to do the same thing, as both act as a binary semaphore

@sebaszm sebaszm changed the title SharedBuffer::Semaphore or Core::BinarySemaphore (BinairySemaphore) Replace SharedBuffer::Semaphore with Core::BinarySemaphore Sep 6, 2024
@pwielders
Copy link
Contributor

I think we also need to "move" the shared over process boundary feature into the Binary semaphore than.. Now I do not think that the semaphore (at least on windows), can be shared over process boundaries. That was the name shared between the two processes. I think this feature is now lost and the SharedBuffer no longer works on WIndows...

@pwielders
Copy link
Contributor

@nxtum I think @sebaszm came with some good enhancements/improvements to have the SharedSemaphore a static size_t Size() const; operator to expose the size of the (sem_t/windows) struct and to add the max value for this Semaphore..

@sebaszm sebaszm changed the title Replace SharedBuffer::Semaphore with Core::BinarySemaphore Replace SharedBuffer::Semaphore with Core::SharedSemaphore Sep 23, 2024
@nxtum nxtum requested a review from sebaszm September 26, 2024 14:02
Source/core/Sync.cpp Outdated Show resolved Hide resolved
Source/core/Sync.cpp Outdated Show resolved Hide resolved
Source/core/Sync.cpp Show resolved Hide resolved
Source/core/Sync.cpp Outdated Show resolved Hide resolved
Source/core/Sync.h Outdated Show resolved Hide resolved
Copy link
Contributor

@pwielders pwielders left a comment

Choose a reason for hiding this comment

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

Questions and discussions added :-) Maybe a confcall/skype chat in TPX ?

@sebaszm sebaszm self-requested a review October 3, 2024 11:19
@pwielders pwielders self-requested a review October 4, 2024 09:18
pwielders
pwielders previously approved these changes Oct 4, 2024
Copy link
Contributor

@pwielders pwielders left a comment

Choose a reason for hiding this comment

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

Yee we saved potentially 4 bytes on a 32 bit platform! Looks very good now!

Copy link
Contributor

@sebaszm sebaszm left a comment

Choose a reason for hiding this comment

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

(also please mind the whitespaces)

#else
, _producer(reinterpret_cast<uint8_t*>(_administration) + sizeof(Administration))
, _consumer(reinterpret_cast<uint8_t*>(_administration) + sizeof(Administration) + SharedSemaphore::Size())
#endif
, _customerAdministration(PointerAlign(&(reinterpret_cast<uint8_t*>(_administration)[sizeof(Administration)])))
Copy link
Contributor

Choose a reason for hiding this comment

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

customerAdministration needs to be adjusted, now it overwrites the semaphore structures

Source/core/SharedBuffer.cpp Outdated Show resolved Hide resolved
Source/core/SharedBuffer.cpp Outdated Show resolved Hide resolved
Source/core/Sync.cpp Outdated Show resolved Hide resolved
Source/core/Sync.cpp Outdated Show resolved Hide resolved
Source/core/Sync.cpp Outdated Show resolved Hide resolved
}

bool
SharedSemaphore::IsLocked()
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's better to change this to Count() and return the current semaphore lock value? IsLocked() limits this to a binary semaphore interface again.

Copy link
Contributor

@pwielders pwielders Oct 8, 2024

Choose a reason for hiding this comment

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

I do agree here with @sebaszm but see it is not adapted, so I guess this is the last bit we need to change. I assume that if Cunt() const -> 0 it IsLocked() const -> true

@nxtum nxtum requested a review from sebaszm October 8, 2024 12:13
sebaszm
sebaszm previously approved these changes Oct 8, 2024
public:
uint32_t Lock(const uint32_t waitTime);
uint32_t Unlock();
bool IsLocked();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the method should be uint32_t Count() const;

pwielders
pwielders previously approved these changes Oct 9, 2024
@pwielders pwielders requested a review from sebaszm October 9, 2024 12:32
Copy link
Contributor

@sebaszm sebaszm left a comment

Choose a reason for hiding this comment

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

minor things, we're almost there!

Source/core/Sync.cpp Show resolved Hide resolved
Source/core/Sync.cpp Show resolved Hide resolved
Source/core/Sync.cpp Outdated Show resolved Hide resolved
Source/core/Sync.cpp Outdated Show resolved Hide resolved
Source/core/Sync.cpp Outdated Show resolved Hide resolved
Source/core/Sync.cpp Show resolved Hide resolved
Copy link
Contributor

@pwielders pwielders left a comment

Choose a reason for hiding this comment

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

LGTM :-)

@pwielders pwielders requested a review from sebaszm October 9, 2024 16:53
@sebaszm sebaszm merged commit 0161d8e into rdkcentral:master Oct 10, 2024
55 of 56 checks passed
@nxtum nxtum deleted the moveSemClockwait branch October 14, 2024 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants