Re: [PATCH 12/20] lib/cobalt: select: Move select services into wrappers_time64.c

Jan Kiszka <[email protected]>
Newsgroups dev.linux.lists.xenomai
Message-ID <[email protected]>
On 20.02.26 10:08, Florian Bezdeka wrote:
> select.c is no longer needed as everything inside is time64_t affected.
> 
> Signed-off-by: Florian Bezdeka <[email protected]>
> ---
>  lib/cobalt/Makefile.am       |   1 -
>  lib/cobalt/select.c          | 108 -------------------------------------------
>  lib/cobalt/wrappers_time64.c |  86 ++++++++++++++++++++++++++++++++++
>  3 files changed, 86 insertions(+), 109 deletions(-)
> 
> diff --git a/lib/cobalt/Makefile.am b/lib/cobalt/Makefile.am
> index 17e203f9015fe2bb5306609e4d51c62f3a725780..c31f030117dfc3ddf5ae386897fbc8a2435912a8 100644
> --- a/lib/cobalt/Makefile.am
> +++ b/lib/cobalt/Makefile.am
> @@ -33,7 +33,6 @@ libcobalt_la_SOURCES =		\
>  	printf.c		\
>  	rtdm.c			\
>  	sched.c			\
> -	select.c		\
>  	semaphore.c		\
>  	signal.c		\
>  	sigshadow.c		\
> diff --git a/lib/cobalt/select.c b/lib/cobalt/select.c
> deleted file mode 100644
> index 5472e991e126c2f521b346a7cf3c884bbf6f6317..0000000000000000000000000000000000000000
> --- a/lib/cobalt/select.c
> +++ /dev/null
> @@ -1,108 +0,0 @@
> -/*
> - * Copyright (C) 2010 Gilles Chanteperdrix <[email protected]>

Make sure to not lose copyright notices...

Jan

> - *
> - * This library is free software; you can redistribute it and/or
> - * modify it under the terms of the GNU Lesser General Public
> - * License as published by the Free Software Foundation; either
> - * version 2 of the License, or (at your option) any later version.
> - *
> - * This library is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> - * Lesser General Public License for more details.
> -
> - * You should have received a copy of the GNU Lesser General Public
> - * License along with this library; if not, write to the Free Software
> - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
> - */
> -
> -#include <errno.h>
> -#include <pthread.h>
> -#include <sys/select.h>
> -#include <asm/xenomai/syscall.h>
> -
> -#if __USE_TIME_BITS64 && __TIMESIZE == 32
> -
> -#define USEC_PER_SEC	1000000L
> -#define NSEC_PER_USEC	1000L
> -
> -/*
> - * The time64 wrapper for select() is a little different:
> - * There is no y2038 safe syscall for select() itself, but we have pselect()
> - * without signal support.
> - */
> -static inline int do_select(int __nfds, fd_set *__restrict __readfds,
> -			      fd_set *__restrict __writefds,
> -			      fd_set *__restrict __exceptfds,
> -			      struct timeval *__restrict __timeout)
> -{
> -	struct timespec to;
> -	int err, oldtype;
> -
> -	if (__timeout) {
> -		to.tv_sec =
> -			__timeout->tv_sec + (__timeout->tv_usec / USEC_PER_SEC);
> -		to.tv_nsec =
> -			(__timeout->tv_usec % USEC_PER_SEC) * NSEC_PER_USEC;
> -	}
> -
> -	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
> -
> -	/*
> -	 * Note: No sigmask here, we already reached the limit of 5
> -	 * syscall parameters
> -	 */
> -	err = XENOMAI_SYSCALL5(sc_cobalt_pselect64, __nfds, __readfds,
> -			       __writefds, __exceptfds, __timeout ? &to : NULL);
> -
> -	pthread_setcanceltype(oldtype, NULL);
> -
> -	if (err == -EADV || err == -EPERM || err == -ENOSYS) {
> -		err = __STD(__select64(__nfds, __readfds, __writefds,
> -				       __exceptfds, __timeout));
> -	} else if (__timeout) {
> -		__timeout->tv_sec = to.tv_sec;
> -		__timeout->tv_usec = to.tv_nsec / 1000;
> -	}
> -
> -	if (err >= 0)
> -		return err;
> -
> -	errno = -err;
> -	return -1;
> -}
> -#else
> -static inline int do_select(int __nfds, fd_set *__restrict __readfds,
> -			    fd_set *__restrict __writefds,
> -			    fd_set *__restrict __exceptfds,
> -			    struct timeval *__restrict __timeout)
> -{
> -	int err, oldtype;
> -
> -	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
> -
> -	err = XENOMAI_SYSCALL5(sc_cobalt_select, __nfds,
> -			       __readfds, __writefds, __exceptfds, __timeout);
> -
> -	pthread_setcanceltype(oldtype, NULL);
> -
> -	if (err == -EADV || err == -EPERM || err == -ENOSYS)
> -		return __STD(select(__nfds, __readfds,
> -				    __writefds, __exceptfds, __timeout));
> -
> -	if (err >= 0)
> -		return err;
> -
> -	errno = -err;
> -	return -1;
> -}
> -#endif
> -
> -COBALT_IMPL_TIME64(int, select, __select64,
> -		   (int __nfds, fd_set *__restrict __readfds,
> -		    fd_set *__restrict __writefds,
> -		    fd_set *__restrict __exceptfds,
> -		    struct timeval *__restrict __timeout))
> -{
> -	return do_select(__nfds, __readfds, __writefds, __exceptfds, __timeout);
> -}
> diff --git a/lib/cobalt/wrappers_time64.c b/lib/cobalt/wrappers_time64.c
> index ded0232824fade9b2f656c03ac3e5515fb5f8b38..7b634976eb07d7ae143b4567983dbea7f4ddebea 100644
> --- a/lib/cobalt/wrappers_time64.c
> +++ b/lib/cobalt/wrappers_time64.c
> @@ -754,3 +754,89 @@ COBALT_IMPL_TIME64(int, setsockopt, __setsockopt64,
>  
>  	return __STD(setsockopt(fd, level, optname, optval, optlen));
>  }
> +
> +#if __USE_TIME_BITS64 && __TIMESIZE == 32
> +
> +#define USEC_PER_SEC	1000000L
> +#define NSEC_PER_USEC	1000L
> +
> +/*
> + * The time64 wrapper for select() is a little different:
> + * There is no y2038 safe syscall for select() itself, but we have pselect()
> + * without signal support.
> + */
> +static inline int do_select(int __nfds, fd_set *__restrict __readfds,
> +			      fd_set *__restrict __writefds,
> +			      fd_set *__restrict __exceptfds,
> +			      struct timeval *__restrict __timeout)
> +{
> +	struct timespec to;
> +	int err, oldtype;
> +
> +	if (__timeout) {
> +		to.tv_sec =
> +			__timeout->tv_sec + (__timeout->tv_usec / USEC_PER_SEC);
> +		to.tv_nsec =
> +			(__timeout->tv_usec % USEC_PER_SEC) * NSEC_PER_USEC;
> +	}
> +
> +	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
> +
> +	/*
> +	 * Note: No sigmask here, we already reached the limit of 5
> +	 * syscall parameters
> +	 */
> +	err = XENOMAI_SYSCALL5(sc_cobalt_pselect64, __nfds, __readfds,
> +			       __writefds, __exceptfds, __timeout ? &to : NULL);
> +
> +	pthread_setcanceltype(oldtype, NULL);
> +
> +	if (err == -EADV || err == -EPERM || err == -ENOSYS) {
> +		err = __STD(__select64(__nfds, __readfds, __writefds,
> +				       __exceptfds, __timeout));
> +	} else if (__timeout) {
> +		__timeout->tv_sec = to.tv_sec;
> +		__timeout->tv_usec = to.tv_nsec / 1000;
> +	}
> +
> +	if (err >= 0)
> +		return err;
> +
> +	errno = -err;
> +	return -1;
> +}
> +#else
> +static inline int do_select(int __nfds, fd_set *__restrict __readfds,
> +			    fd_set *__restrict __writefds,
> +			    fd_set *__restrict __exceptfds,
> +			    struct timeval *__restrict __timeout)
> +{
> +	int err, oldtype;
> +
> +	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
> +
> +	err = XENOMAI_SYSCALL5(sc_cobalt_select, __nfds,
> +			       __readfds, __writefds, __exceptfds, __timeout);
> +
> +	pthread_setcanceltype(oldtype, NULL);
> +
> +	if (err == -EADV || err == -EPERM || err == -ENOSYS)
> +		return __STD(select(__nfds, __readfds,
> +				    __writefds, __exceptfds, __timeout));
> +
> +	if (err >= 0)
> +		return err;
> +
> +	errno = -err;
> +	return -1;
> +}
> +#endif
> +
> +COBALT_IMPL_TIME64(int, select, __select64,
> +		   (int __nfds, fd_set *__restrict __readfds,
> +		    fd_set *__restrict __writefds,
> +		    fd_set *__restrict __exceptfds,
> +		    struct timeval *__restrict __timeout))
> +{
> +	return do_select(__nfds, __readfds, __writefds, __exceptfds, __timeout);
> +}
> 

-- 
Siemens AG, Foundational Technologies
Linux Expert Center
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.