c-mesh-api icon indicating copy to clipboard operation
c-mesh-api copied to clipboard

Platform_lock_request return value not evaluated

Open pahaseag opened this issue 3 years ago • 1 comments

The platform_lock_request() function returns a bool. The desired behaviour regarding the return value is not described in the platform.h file but looking at the linux implementation, false is returned when no lock can be aquired (see https://github.com/wirepas/c-mesh-api/blob/master/lib/platform/linux/platform.c#L245).

However, in the API (wpc) the return value of Platform_lock_request() is never checked, e.g. see here https://github.com/wirepas/c-mesh-api/blob/master/lib/wpc/wpc_internal.c#L332. In the mentioned example the code after Platform_lock_request() is executed even if no lock can be acquired. The callers of the Platform_lock_request() are mostly located in the functionality and are not intended to be changed by a user/customer. Should the return value of Platform_lock_request() not be evaluated and corresponding actions implemented if the lock can not be acquired?

pahaseag avatar Sep 15 '22 08:09 pahaseag

Hello,

Thanks for the feedback. Yes you are correct, the code is ambiguous (and a bit wrong ;-) )

In the code, we always assume that platform_lock_request() return successfully. It can of course block the calling thread, but it should never returned without the lock being acquired (as mention in the Linux implementation it should never happen)

But in other platform in may be a bit harder to ensure.

I quickly checked the different places where it is called and it shouldn't be a big deal to handle the case where false is returned (ie propagate the error).

That being said, if it happens there is probably a problem in the design.

Best regards, Gwendal

GwendalRaoul avatar Sep 15 '22 16:09 GwendalRaoul