aboutsummaryrefslogtreecommitdiff
path: root/syspoll.h
blob: 68e48844ef5c0f30d9d963eca83c7fa42921ce9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
/*	  All Rights Reserved  	*/

/*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
/*	The copyright notice above does not evidence any   	*/
/*	actual or intended publication of such source code.	*/

/*
 * Copyright (c) 1995 by Sun Microsystems, Inc.
 * All rights reserved.
 */

#ifndef _SYS_POLL_H
#define	_SYS_POLL_H

#pragma ident	"@(#)poll.h	1.24	97/04/18 SMI"	/* SVr4.0 11.9 */

#ifdef	__cplusplus
extern "C" {
#endif

/*
 * Structure of file descriptor/event pairs supplied in
 * the poll arrays.
 */
typedef struct pollfd {
	int fd;				/* file desc to poll */
	short events;			/* events of interest on fd */
	short revents;			/* events that occurred on fd */
} pollfd_t;

typedef unsigned long	nfds_t;

/*
 * Testable select events
 */
#define	POLLIN		0x0001		/* fd is readable */
#define	POLLPRI		0x0002		/* high priority info at fd */
#define	POLLOUT		0x0004		/* fd is writeable (won't block) */
#define	POLLRDNORM	0x0040		/* normal data is readable */
#define	POLLWRNORM	POLLOUT
#define	POLLRDBAND	0x0080		/* out-of-band data is readable */
#define	POLLWRBAND	0x0100		/* out-of-band data is writeable */

#define	POLLNORM	POLLRDNORM

/*
 * Non-testable poll events (may not be specified in events field,
 * but may be returned in revents field).
 */
#define	POLLERR		0x0008		/* fd has error condition */
#define	POLLHUP		0x0010		/* fd has been hung up on */
#define	POLLNVAL	0x0020		/* invalid pollfd entry */

#ifdef _KERNEL

/*
 * Additional private poll flags supported only by strpoll().
 * Must be bit-wise distinct from the above POLL flags.
 */
#define	POLLRDDATA	0x200	/* Wait for M_DATA; ignore M_PROTO only msgs */
#define	POLLNOERR	0x400	/* Ignore POLLERR conditions */

#endif /* _KERNEL */

#if defined(_KERNEL) || defined(_KMEMUSER)

#include <sys/t_lock.h>
#include <sys/thread.h>

/*
 * Poll list head structure.  A pointer to this is passed to
 * pollwakeup() from the caller indicating an event has occurred.
 * Only the ph_list field is used, but for DDI compliance, we can't
 * change the size of the structure.
 */
typedef struct pollhead {
	struct polldat	*ph_list;	/* list of pollers */
	struct polldat	*ph_dummy;	/* unused -- see above */
	short		ph_events;	/* unused -- see above */
} pollhead_t;

/*
 * Data necessary to notify process sleeping in poll(2)
 * when an event has occurred.
 */
typedef struct polldat {
	kthread_t	*pd_thread;	/* thread doing poll */
	int		pd_events;	/* events being polled */
	struct polldat	*pd_next;	/* next in poll list */
	struct polldat	*pd_prev;	/* previous in poll list */
	struct pollhead	*pd_headp;	/* backpointer to head of list */
	struct pollhead	*pd_sphp;	/* stored pollhead struct pointer */
} polldat_t;

/*
 * State information kept by each polling thread
 */
typedef struct pollstate {
	int		ps_nfds;
	int		ps_flag;
	pollfd_t	*ps_pollfd;
	polldat_t	*ps_polldat;
	kmutex_t	ps_lock;	/* mutex for the polling thread */
	kmutex_t	ps_no_exit;	/* protects ps_busy*, can't be nested */
	int		ps_busy;	/* can only exit when its 0 */
	kcondvar_t	ps_busy_cv;	/* cv to wait on if ps_busy != 0 */
	kcondvar_t	ps_cv;		/* cv to wait on if needed */
} pollstate_t;

/* ps_flag */
#define	T_POLLTIME	0x01	/* poll timeout pending */
#define	T_POLLWAKE	0x02	/* pollwakeup() occurred */

#if defined(_KERNEL)

/*
 * Routine called to notify a process of the occurrence
 * of an event.
 */
extern void pollwakeup(pollhead_t *, short);
/*
 * pollwakeup_safe will replace pollwakeup when the support
 * for unsafe drivers is removed.
 */
extern void pollwakeup_safe(pollhead_t *, short);

/*
 * Internal routines.
 */
extern void polltime(kthread_t *);
extern void pollrun(kthread_t *);
extern void polldel(pollstate_t *);
extern void polllock(pollhead_t *, kmutex_t *);
extern int pollunlock(pollhead_t *);
extern void pollrelock(pollhead_t *, int);
extern void pollcleanup(kthread_t *);

extern void ppwaitemptylist(pollhead_t *);

#endif /* defined(_KERNEL) */

#endif /* defined(_KERNEL) || defined(_KMEMUSER) */

#if defined(__STDC__) && !defined(_KERNEL)
int poll(struct pollfd *, nfds_t, int);
#endif

#ifdef	__cplusplus
}
#endif

#endif	/* _SYS_POLL_H */