Re: [PATCH 01/20] lib/cobalt: Introduce cond.h
Jan Kiszka <[email protected]>
| Newsgroups | dev.linux.lists.xenomai |
|---|---|
| Message-ID | <[email protected]> |
On 20.02.26 10:08, Florian Bezdeka wrote: > Some code will be re-used later by the time64_t compile unit. Move that > code into cond.h, so code duplication is avoided. > > No modifications to the code itself. > > Signed-off-by: Florian Bezdeka <[email protected]> > --- > lib/cobalt/Makefile.am | 1 + > lib/cobalt/cond.c | 67 ++----------------------------------------- > lib/cobalt/cond.h | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 81 insertions(+), 65 deletions(-) > > diff --git a/lib/cobalt/Makefile.am b/lib/cobalt/Makefile.am > index ed7e503899f4852388fb3bf204bfe91936009d74..b1098413fbf3a8f6a5f0a85d6aceb9916b14149a 100644 > --- a/lib/cobalt/Makefile.am > +++ b/lib/cobalt/Makefile.am > @@ -1,6 +1,7 @@ > pkgconfigdir = $(libdir)/pkgconfig > > noinst_HEADERS = \ > + cond.h \ > current.h \ > umm.h \ > internal.h > diff --git a/lib/cobalt/cond.c b/lib/cobalt/cond.c > index 2d11f768edc0fe4e89944a96333d2dd76d174172..7be7fca01f53930f8504945206b2ee6ba6be1ba5 100644 > --- a/lib/cobalt/cond.c > +++ b/lib/cobalt/cond.c > @@ -20,6 +20,8 @@ > #include <string.h> > #include <pthread.h> > #include <asm/xenomai/syscall.h> > + > +#include "cond.h" > #include "current.h" > #include "internal.h" > > @@ -147,32 +149,6 @@ COBALT_IMPL(int, pthread_cond_init, (pthread_cond_t *cond, > return 0; > } > > -static int __attribute__((cold)) > - cobalt_cond_autoinit_type(const pthread_cond_t *cond) > -{ > - static const pthread_cond_t cond_initializer = > - PTHREAD_COND_INITIALIZER; > - > - return memcmp(cond, &cond_initializer, sizeof(cond_initializer)) == 0 ? > - 0 : -1; > -} > - > -static int __attribute__((cold)) > - cobalt_cond_doautoinit(union cobalt_cond_union *ucond) > -{ > - if (cobalt_cond_autoinit_type(&ucond->native_cond) < 0) > - return EINVAL; > - > - return __COBALT(pthread_cond_init(&ucond->native_cond, NULL)); > -} > - > -static inline int cobalt_cond_autoinit(union cobalt_cond_union *ucond) > -{ > - if (ucond->shadow_cond.magic != COBALT_COND_MAGIC) > - return cobalt_cond_doautoinit(ucond); > - return 0; > -} > - > /** > * @fn int pthread_cond_destroy(pthread_cond_t *cond) > * @brief Destroy a condition variable > @@ -208,45 +184,6 @@ COBALT_IMPL(int, pthread_cond_destroy, (pthread_cond_t *cond)) > return -XENOMAI_SYSCALL1( sc_cobalt_cond_destroy, _cond); > } > > -struct cobalt_cond_cleanup_t { > - struct cobalt_cond_shadow *cond; > - struct cobalt_mutex_shadow *mutex; > - unsigned count; > - int err; > -}; > - > -static void __pthread_cond_cleanup(void *data) > -{ > - struct cobalt_cond_cleanup_t *c = (struct cobalt_cond_cleanup_t *)data; > - xnhandle_t cur = cobalt_get_current(); > - int err; > - > - /* if we still own the mutex, cond_wait_prologue wasn't called yet */ > - if (xnsynch_fast_owner_check(mutex_get_ownerp(c->mutex), cur) == 0) > - return; > - > - do { > - err = XENOMAI_SYSCALL2(sc_cobalt_cond_wait_epilogue, > - c->cond, c->mutex); > - } while (err == -EINTR); > - > - c->mutex->lockcnt = c->count; > -} > - > -static inline int do_sc_cond_wait_prologue(struct cobalt_cond_shadow *cnd, > - struct cobalt_mutex_shadow *mx, > - int *err, int timed, > - const struct timespec *abstime) > -{ > -#ifdef __USE_TIME_BITS64 > - long sc_nr = sc_cobalt_cond_wait_prologue64; > -#else > - long sc_nr = sc_cobalt_cond_wait_prologue; > -#endif > - > - return XENOMAI_SYSCALL5(sc_nr, cnd, mx, err, timed, abstime); > -} > - > /** > * Wait on a condition variable. > * > diff --git a/lib/cobalt/cond.h b/lib/cobalt/cond.h > new file mode 100644 > index 0000000000000000000000000000000000000000..fbb7a02149ddfa0858def5e8741d5b044afc17b7 > --- /dev/null > +++ b/lib/cobalt/cond.h New file but no copyright header. Likely applies to more patches in this series. > @@ -0,0 +1,78 @@ > +#ifndef _LIB_COBALT_COND_H > +#define _LIB_COBALT_COND_H > + > +#include "current.h" > +#include "internal.h" > + > +#include <asm/xenomai/syscall.h> > +#include <cobalt/uapi/cond.h> > + > +#include <string.h> > +#include <pthread.h> > + > +struct cobalt_cond_cleanup_t { > + struct cobalt_cond_shadow *cond; > + struct cobalt_mutex_shadow *mutex; > + unsigned count; > + int err; > +}; > + > +static int __attribute__((cold)) > +cobalt_cond_autoinit_type(const pthread_cond_t *cond) > +{ > + static const pthread_cond_t cond_initializer = PTHREAD_COND_INITIALIZER; > + > + return memcmp(cond, &cond_initializer, sizeof(cond_initializer)) == 0 ? > + 0 : > + -1; > +} > + > +static int __attribute__((cold)) > +cobalt_cond_doautoinit(union cobalt_cond_union *ucond) > +{ > + if (cobalt_cond_autoinit_type(&ucond->native_cond) < 0) > + return EINVAL; > + > + return __COBALT(pthread_cond_init(&ucond->native_cond, NULL)); > +} > + > +static inline int cobalt_cond_autoinit(union cobalt_cond_union *ucond) > +{ > + if (ucond->shadow_cond.magic != COBALT_COND_MAGIC) > + return cobalt_cond_doautoinit(ucond); > + return 0; > +} > + > +static void __pthread_cond_cleanup(void *data) > +{ > + struct cobalt_cond_cleanup_t *c = (struct cobalt_cond_cleanup_t *)data; > + xnhandle_t cur = cobalt_get_current(); > + int err; > + > + /* if we still own the mutex, cond_wait_prologue wasn't called yet */ > + if (xnsynch_fast_owner_check(mutex_get_ownerp(c->mutex), cur) == 0) > + return; > + > + do { > + err = XENOMAI_SYSCALL2(sc_cobalt_cond_wait_epilogue, c->cond, > + c->mutex); > + } while (err == -EINTR); > + > + c->mutex->lockcnt = c->count; > +} > + > +static inline int do_sc_cond_wait_prologue(struct cobalt_cond_shadow *cnd, > + struct cobalt_mutex_shadow *mx, > + int *err, int timed, > + const struct timespec *abstime) > +{ > +#ifdef __USE_TIME_BITS64 > + long sc_nr = sc_cobalt_cond_wait_prologue64; > +#else > + long sc_nr = sc_cobalt_cond_wait_prologue; > +#endif > + > + return XENOMAI_SYSCALL5(sc_nr, cnd, mx, err, timed, abstime); > +} > + > +#endif //_LIB_COBALT_COND_H > Jan -- Siemens AG, Foundational Technologies Linux Expert Center