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

add synchronization primitives for zenoh-c (similar to zenoh-pico) #250

Merged

Conversation

DenisBiryukov91
Copy link
Contributor

Adds support for mutexes (zp_mutex_.... functions), condvars (zp_condvar_... functions) and tasks(threads) (zp_task_... functions) similar to the one provided in zenoh-pico (partially addresses #247)

@eclipse-zenoh-bot
Copy link
Contributor

@DenisBiryukov91 If this pull request contains a bugfix or a new feature, then please consider using Closes #ISSUE-NUMBER syntax to link it to an issue.

Copy link
Contributor

@milyin milyin left a comment

Choose a reason for hiding this comment

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

Great job!
Only one correction: if this api will be the same for zenoh and zenoh-pico, prefix should be z_. If they are specific for zenoh-c and differs from pico ones, they should be zc_, but it's not the case here, as far as I see.
The zp_ prefix should not appear in zenoh-c, it's for zenoh-pico specific functions.
Later in zenoh-pico we can also rename them from zp_ to z_ and maybe add defines for backward compatibility.

impl_guarded_transmute!(z_mutex_t, ZMutexPtr);
impl_guarded_transmute!(ZMutexPtr, z_mutex_t);

const EBUSY: i8 = -1;
Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I see these error values doubles the ones from pthread library (https://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_mutex_init.html). This should be at least commented and maybe exposed in the documentation.

Copy link
Contributor

@milyin milyin left a comment

Choose a reason for hiding this comment

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

Related to this issue eclipse-zenoh/zenoh-cpp#102

impl_guarded_transmute!(ZMutexPtr, z_mutex_t);

// try to use the same error codes as in GNU pthreads
const EBUSY: i8 = 16;
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't fit the agreement, that the error value should be always negative. This agreement is used here for example: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/include/zenohcxx/impl.hxx#L59-L69
Though this agreement is already violated in zenoh-pico by these functions like z_mutex_init which directly returns values from pthread. So it seems like that it's necessary to reevaluate the assumption that error value is alvays negative

Copy link
Member

Choose a reason for hiding this comment

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

I believe error values should always be negative.
I would consider as a bug the fact that z_mutex_init directly returns values from pthread in zenoh-pico.

Copy link
Contributor

Choose a reason for hiding this comment

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

made issue in zenoh-pico
eclipse-zenoh/zenoh-pico#358

@milyin milyin merged commit 5d7bb83 into eclipse-zenoh:main Feb 28, 2024
5 checks passed
@DenisBiryukov91 DenisBiryukov91 deleted the feature/platform-primitives branch May 3, 2024 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants