Update: _Semaphore_Wait_timed to include clock selection

Message ID 20260224144856.431478-1-mez3n1151@gmail.com
State New
Headers
Series Update: _Semaphore_Wait_timed to include clock selection |

Commit Message

Mazen Adel Elmessady Feb. 24, 2026, 2:48 p.m. UTC
  Updated _Semaphore_Wait_timed (which is currently unused in RTEMS)
to _Semaphore_Wait_timed_clock which
to be used in RTEMS sempahore API.
This will ease the support of the new clock
functions added in Posix Issue 8.
---
 newlib/libc/sys/rtems/include/sys/lock.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
  

Comments

Sebastian Huber Feb. 26, 2026, 12:06 a.m. UTC | #1
Hello Mazen,

it would be quite simple to implement _Semaphore_Wait_timed() if you have _Semaphore_Wait_timed_clock(). I would keep the declaration and only add _Semaphore_Wait_timed_clock().

Would it make sense to add the clock variants also for the other operations (mutex, ...)?

Kind regards,
Sebastian
  
Sebastian Huber Feb. 26, 2026, 2:08 p.m. UTC | #2
----- Am 26. Feb 2026 um 14:29 schrieb Mazen Adel Elmessady mez3n1151@gmail.com:

> Hello Sebastian,
> 
> I already added the clock variants of (mutex, condwait, rwlock) to RTEMS a
> while back, I had to update their headers in newlib too.

I don't see any updates in Newlib:

git log -1 newlib/libc/sys/rtems/include/sys/lock.h
commit dadc9e7e4addbaad6c3249c883a80f6f8a33eafd
Author: Sebastian Huber <sebastian.huber@embedded-brains.de>
Date:   Tue Nov 28 08:00:33 2017 +0100

> 
> Kind regards,
> Mazen
> 
> On Thu, Feb 26, 2026 at 2:07 AM Sebastian Huber <
> sebastian.huber@embedded-brains.de> wrote:
> 
>> Hello Mazen,
>>
>> it would be quite simple to implement _Semaphore_Wait_timed() if you have
>> _Semaphore_Wait_timed_clock(). I would keep the declaration and only add
>> _Semaphore_Wait_timed_clock().
>>
>> Would it make sense to add the clock variants also for the other
>> operations (mutex, ...)?
>>
>> Kind regards,
>> Sebastian
>>
>> --
>> Visit us at EMBEDDED WORLD 2026 in Nuremberg 10 to 12 March, Hall 4 Booth
>> 622!
>> --
>> embedded brains GmbH & Co. KG
>> Herr Sebastian HUBER
>> Dornierstr. 4
>> 82178 Puchheim
>> Germany
>> email: sebastian.huber@embedded-brains.de
>> phone: +49-89-18 94 741 - 16
>> fax:   +49-89-18 94 741 - 08
>>
>> Registergericht: Amtsgericht München
>> Registernummer: HRB 157899
>> Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
>> Unsere Datenschutzerklärung finden Sie hier:
>> https://embedded-brains.de/datenschutzerklaerung/
  
Sebastian Huber March 2, 2026, 1:38 a.m. UTC | #3
----- Am 26. Feb 2026 um 16:37 schrieb Mazen Adel Elmessady mez3n1151@gmail.com:

> Sorry, I thought you meant the Posix APIs themselves.
> It would make sense to add them since they will help if we want to refactor
> the code, however the Posix APIs are working as is.
> If you want to I can make a separate patch file for each.

Changes in Newlib are always an issue for RTEMS if you want to do a git bisect over a longer time span.

I would not remove existing declarations, even if there is not yet an RTEMS implementation. We may need them in the future.

If you add a timed clock function, for one synchronization object class, then I would also add declarations for all the other *_timed() functions as well. We may need them at some point in time for the C++/libgomp support in GCC.
  

Patch

diff --git a/newlib/libc/sys/rtems/include/sys/lock.h b/newlib/libc/sys/rtems/include/sys/lock.h
index d6169025b..c2728ce5a 100644
--- a/newlib/libc/sys/rtems/include/sys/lock.h
+++ b/newlib/libc/sys/rtems/include/sys/lock.h
@@ -27,6 +27,7 @@ 
 #define _SYS_LOCK_H_
 
 #include <sys/cdefs.h>
+#include <sys/_timespec.h>
 #include <stddef.h>
 
 __BEGIN_DECLS
@@ -295,8 +296,8 @@  _Semaphore_Get_name(const struct _Semaphore_Control *_semaphore)
 
 void _Semaphore_Wait(struct _Semaphore_Control *);
 
-int _Semaphore_Wait_timed(struct _Semaphore_Control *,
-    const struct timespec *);
+int _Semaphore_Wait_timed_clock(struct _Semaphore_Control *,
+    const struct timespec *, __clockid_t);
 
 int _Semaphore_Wait_timed_ticks(struct _Semaphore_Control *, __uint32_t);