xref: /freebsd-src/lib/librt/sigev_thread.h (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
15e53a4f9SPedro F. Giffuni /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
35e53a4f9SPedro F. Giffuni  *
44acaec8fSDavid Xu  * Copyright (c) 2005 David Xu <davidxu@freebsd.org>
54acaec8fSDavid Xu  * All rights reserved.
64acaec8fSDavid Xu  *
74acaec8fSDavid Xu  * Redistribution and use in source and binary forms, with or without
84acaec8fSDavid Xu  * modification, are permitted provided that the following conditions
94acaec8fSDavid Xu  * are met:
104acaec8fSDavid Xu  * 1. Redistributions of source code must retain the above copyright
114acaec8fSDavid Xu  *    notice unmodified, this list of conditions, and the following
124acaec8fSDavid Xu  *    disclaimer.
134acaec8fSDavid Xu  * 2. Redistributions in binary form must reproduce the above copyright
144acaec8fSDavid Xu  *    notice, this list of conditions and the following disclaimer in the
154acaec8fSDavid Xu  *    documentation and/or other materials provided with the distribution.
164acaec8fSDavid Xu  *
174acaec8fSDavid Xu  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
184acaec8fSDavid Xu  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
194acaec8fSDavid Xu  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
204acaec8fSDavid Xu  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
214acaec8fSDavid Xu  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
224acaec8fSDavid Xu  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
234acaec8fSDavid Xu  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
244acaec8fSDavid Xu  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
254acaec8fSDavid Xu  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
264acaec8fSDavid Xu  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
274acaec8fSDavid Xu  *
284acaec8fSDavid Xu  */
294acaec8fSDavid Xu 
304acaec8fSDavid Xu #ifndef _SIGEV_THREAD_H_
314acaec8fSDavid Xu #define _SIGEV_THREAD_H_
324acaec8fSDavid Xu 
334acaec8fSDavid Xu #include <sys/types.h>
344acaec8fSDavid Xu #include <sys/queue.h>
354acaec8fSDavid Xu 
36c5a4f4efSDavid Xu struct sigev_thread;
374acaec8fSDavid Xu struct sigev_node;
384acaec8fSDavid Xu 
394acaec8fSDavid Xu typedef uintptr_t	sigev_id_t;
406348ace8SDavid Xu typedef void		(*sigev_dispatch_t)(struct sigev_node *);
414acaec8fSDavid Xu 
424acaec8fSDavid Xu struct sigev_node {
434acaec8fSDavid Xu 	LIST_ENTRY(sigev_node)		sn_link;
444acaec8fSDavid Xu 	int				sn_type;
454acaec8fSDavid Xu 	sigev_id_t			sn_id;
464acaec8fSDavid Xu 	sigev_dispatch_t		sn_dispatch;
474acaec8fSDavid Xu 	union sigval			sn_value;
484acaec8fSDavid Xu 	void 				*sn_func;
494acaec8fSDavid Xu 	int				sn_flags;
504acaec8fSDavid Xu 	int				sn_gen;
516348ace8SDavid Xu 	siginfo_t			sn_info;
52c5a4f4efSDavid Xu 	pthread_attr_t			sn_attr;
53c5a4f4efSDavid Xu 	struct sigev_thread		*sn_tn;
544acaec8fSDavid Xu };
554acaec8fSDavid Xu 
564acaec8fSDavid Xu 
57c5a4f4efSDavid Xu struct sigev_thread {
58c5a4f4efSDavid Xu 	LIST_ENTRY(sigev_thread)	tn_link;
594acaec8fSDavid Xu 	pthread_t			tn_thread;
604acaec8fSDavid Xu 	struct sigev_node		*tn_cur;
616348ace8SDavid Xu 	int				tn_refcount;
624acaec8fSDavid Xu 	long				tn_lwpid;
63c5a4f4efSDavid Xu 	pthread_cond_t			tn_cv;
644acaec8fSDavid Xu };
654acaec8fSDavid Xu 
664acaec8fSDavid Xu #define	SNF_WORKING		0x01
674acaec8fSDavid Xu #define	SNF_REMOVED		0x02
68c5a4f4efSDavid Xu #define	SNF_SYNC		0x04
694acaec8fSDavid Xu 
704acaec8fSDavid Xu int	__sigev_check_init();
716348ace8SDavid Xu struct sigev_node *__sigev_alloc(int, const struct sigevent *,
72c5a4f4efSDavid Xu 	struct sigev_node *, int);
734acaec8fSDavid Xu struct sigev_node *__sigev_find(int, sigev_id_t);
744acaec8fSDavid Xu void	__sigev_get_sigevent(struct sigev_node *, struct sigevent *,
754acaec8fSDavid Xu 		sigev_id_t);
764acaec8fSDavid Xu int	__sigev_register(struct sigev_node *);
774acaec8fSDavid Xu int	__sigev_delete(int, sigev_id_t);
784acaec8fSDavid Xu int	__sigev_delete_node(struct sigev_node *);
79c5a4f4efSDavid Xu void	__sigev_list_lock(void);
80c5a4f4efSDavid Xu void	__sigev_list_unlock(void);
814acaec8fSDavid Xu void	__sigev_free(struct sigev_node *);
824acaec8fSDavid Xu 
834acaec8fSDavid Xu #endif
84