xref: /illumos-gate/usr/src/lib/libc/port/rt/sigev_thread.h (revision 86d949f9497332fe19be6b5d711d265eb957439f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SIGEV_THREAD_H
28 #define	_SIGEV_THREAD_H
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #include <signal.h>
35 #include <port.h>
36 #include <mqueue.h>
37 #include <time.h>
38 #include <limits.h>
39 #include <semaphore.h>
40 #include <thread_pool.h>
41 
42 #define	SIGEV_THREAD_TERM	1
43 
44 typedef enum {TIMER = 1, MQ, AIO} subsystem_t;	/* Calling sub-system */
45 
46 typedef struct {
47 	void (*std_func)(union sigval);	/* User-defined notification function */
48 	union sigval std_arg;	/* Parameter of user-defined notification fct */
49 } sigev_thread_data_t;
50 
51 typedef struct thread_communication_data {
52 	struct thread_communication_data *tcd_next;
53 	struct sigevent	tcd_notif;	/* encapsulates usr fct and usr vals */
54 	pthread_attr_t	tcd_user_attr;	/* copy of caller's attributes */
55 	pthread_attr_t	*tcd_attrp;	/* NULL if caller passed NULL */
56 	int		tcd_port;	/* port this spawner is controlling */
57 	thread_t	tcd_server_id;	/* thread id of server thread */
58 	subsystem_t	tcd_subsystem;	/* event generating subsystem */
59 	tpool_t		*tcd_poolp;	/* worker thread pool */
60 	/* for creation/termination synchronization protocol */
61 	mutex_t		tcd_lock;
62 	cond_t		tcd_cv;
63 	/* subsystem-specific data */
64 	union {
65 		struct {
66 			int	overruns;	/* number of overruns */
67 		} timer;
68 		struct {
69 			int	msg_enabled;	/* notification enabled */
70 			int	msg_closing;	/* mq_close() is waiting */
71 			sem_t	*msg_avail;	/* wait for message available */
72 			void	*msg_object;	/* mqd_t */
73 			void	*msg_userval;	/* notification user value */
74 		} mqueue;
75 	} tcd_object;
76 } thread_communication_data_t;
77 
78 #define	tcd_overruns	tcd_object.timer.overruns
79 
80 #define	tcd_msg_enabled	tcd_object.mqueue.msg_enabled
81 #define	tcd_msg_closing	tcd_object.mqueue.msg_closing
82 #define	tcd_msg_avail	tcd_object.mqueue.msg_avail
83 #define	tcd_msg_object	tcd_object.mqueue.msg_object
84 #define	tcd_msg_userval	tcd_object.mqueue.msg_userval
85 
86 /* Generic functions common to all entities */
87 extern thread_communication_data_t *setup_sigev_handler(
88 		const struct sigevent *, subsystem_t);
89 extern void free_sigev_handler(thread_communication_data_t *);
90 extern int launch_spawner(thread_communication_data_t *);
91 extern void tcd_teardown(thread_communication_data_t *);
92 
93 /* Additional functions for different entities */
94 extern void *timer_spawner(void *);
95 extern int del_sigev_timer(timer_t);
96 extern int sigev_timer_getoverrun(timer_t);
97 extern void *mqueue_spawner(void *);
98 extern void del_sigev_mq(thread_communication_data_t *);
99 extern void *aio_spawner(void *);
100 
101 /* Private interfaces elsewhere in libc */
102 extern int pthread_attr_clone(pthread_attr_t *, const pthread_attr_t *);
103 extern int pthread_attr_equal(const pthread_attr_t *, const pthread_attr_t *);
104 extern int _port_dispatch(int, int, int, int, uintptr_t, void *);
105 
106 extern thread_communication_data_t *sigev_aio_tcd;
107 
108 extern int timer_max;
109 extern thread_communication_data_t **timer_tcd;
110 
111 #ifdef	__cplusplus
112 }
113 #endif
114 
115 #endif	/* _SIGEV_THREAD_H */
116