xref: /illumos-gate/usr/src/lib/libc/port/rt/sigev_thread.h (revision c61a1653a4d73dbc950dac7d96350fd6cb517486)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <signal.h>
37 #include <port.h>
38 #include <mqueue.h>
39 #include <time.h>
40 #include <limits.h>
41 #include <semaphore.h>
42 #include <thread_pool.h>
43 
44 #define	SIGEV_THREAD_TERM	1
45 
46 typedef enum {TIMER = 1, MQ, AIO} subsystem_t;	/* Calling sub-system */
47 
48 typedef struct {
49 	void (*std_func)(union sigval);	/* User-defined notification function */
50 	union sigval std_arg;	/* Parameter of user-defined notification fct */
51 } sigev_thread_data_t;
52 
53 typedef struct thread_communication_data {
54 	struct thread_communication_data *tcd_next;
55 	struct sigevent	tcd_notif;	/* encapsulates usr fct and usr vals */
56 	pthread_attr_t	tcd_user_attr;	/* copy of caller's attributes */
57 	pthread_attr_t	*tcd_attrp;	/* NULL if caller passed NULL */
58 	int		tcd_port;	/* port this spawner is controlling */
59 	thread_t	tcd_server_id;	/* thread id of server thread */
60 	subsystem_t	tcd_subsystem;	/* event generating subsystem */
61 	tpool_t		*tcd_poolp;	/* worker thread pool */
62 	/* for creation/termination synchronization protocol */
63 	mutex_t		tcd_lock;
64 	cond_t		tcd_cv;
65 	/* subsystem-specific data */
66 	union {
67 		struct {
68 			int	overruns;	/* number of overruns */
69 		} timer;
70 		struct {
71 			int	msg_enabled;	/* notification enabled */
72 			int	msg_closing;	/* mq_close() is waiting */
73 			sem_t	*msg_avail;	/* wait for message available */
74 			void	*msg_object;	/* mqd_t */
75 			void	*msg_userval;	/* notification user value */
76 		} mqueue;
77 	} tcd_object;
78 } thread_communication_data_t;
79 
80 #define	tcd_overruns	tcd_object.timer.overruns
81 
82 #define	tcd_msg_enabled	tcd_object.mqueue.msg_enabled
83 #define	tcd_msg_closing	tcd_object.mqueue.msg_closing
84 #define	tcd_msg_avail	tcd_object.mqueue.msg_avail
85 #define	tcd_msg_object	tcd_object.mqueue.msg_object
86 #define	tcd_msg_userval	tcd_object.mqueue.msg_userval
87 
88 /* Generic functions common to all entities */
89 extern thread_communication_data_t *setup_sigev_handler(
90 		const struct sigevent *, subsystem_t);
91 extern void free_sigev_handler(thread_communication_data_t *);
92 extern int launch_spawner(thread_communication_data_t *);
93 extern void tcd_teardown(thread_communication_data_t *);
94 
95 /* Additional functions for different entities */
96 extern void *timer_spawner(void *);
97 extern int del_sigev_timer(timer_t);
98 extern int sigev_timer_getoverrun(timer_t);
99 extern void *mqueue_spawner(void *);
100 extern void del_sigev_mq(thread_communication_data_t *);
101 extern void *aio_spawner(void *);
102 
103 /* Private interfaces elsewhere in libc */
104 extern int pthread_attr_clone(pthread_attr_t *, const pthread_attr_t *);
105 extern int pthread_attr_equal(const pthread_attr_t *, const pthread_attr_t *);
106 extern int _port_dispatch(int, int, int, int, uintptr_t, void *);
107 
108 extern thread_communication_data_t *sigev_aio_tcd;
109 
110 extern int timer_max;
111 extern thread_communication_data_t **timer_tcd;
112 
113 #ifdef	__cplusplus
114 }
115 #endif
116 
117 #endif	/* _SIGEV_THREAD_H */
118