xref: /illumos-gate/usr/src/cmd/scadm/sparc/mpxu/common/smq.h (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
1*03831d35Sstevel /*
2*03831d35Sstevel  * CDDL HEADER START
3*03831d35Sstevel  *
4*03831d35Sstevel  * The contents of this file are subject to the terms of the
5*03831d35Sstevel  * Common Development and Distribution License, Version 1.0 only
6*03831d35Sstevel  * (the "License").  You may not use this file except in compliance
7*03831d35Sstevel  * with the License.
8*03831d35Sstevel  *
9*03831d35Sstevel  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*03831d35Sstevel  * or http://www.opensolaris.org/os/licensing.
11*03831d35Sstevel  * See the License for the specific language governing permissions
12*03831d35Sstevel  * and limitations under the License.
13*03831d35Sstevel  *
14*03831d35Sstevel  * When distributing Covered Code, include this CDDL HEADER in each
15*03831d35Sstevel  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*03831d35Sstevel  * If applicable, add the following below this CDDL HEADER, with the
17*03831d35Sstevel  * fields enclosed by brackets "[]" replaced with your own identifying
18*03831d35Sstevel  * information: Portions Copyright [yyyy] [name of copyright owner]
19*03831d35Sstevel  *
20*03831d35Sstevel  * CDDL HEADER END
21*03831d35Sstevel  */
22*03831d35Sstevel /*
23*03831d35Sstevel  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
24*03831d35Sstevel  * Use is subject to license terms.
25*03831d35Sstevel  */
26*03831d35Sstevel 
27*03831d35Sstevel #ifndef _SMQ_H
28*03831d35Sstevel #define	_SMQ_H
29*03831d35Sstevel 
30*03831d35Sstevel #ifdef	__cplusplus
31*03831d35Sstevel extern "C" {
32*03831d35Sstevel #endif
33*03831d35Sstevel 
34*03831d35Sstevel #include <sys/types.h>
35*03831d35Sstevel #include <time.h>
36*03831d35Sstevel 
37*03831d35Sstevel #include "xsem.h"
38*03831d35Sstevel 
39*03831d35Sstevel /* THIS IS CURRENTLY ONLY WRITTEN TO HANDLE A SINGLE PRODUCER, SINGLE */
40*03831d35Sstevel /* CONSUMER !!!!!!!!!!!!!!!! */
41*03831d35Sstevel 
42*03831d35Sstevel /* Simple message queue */
43*03831d35Sstevel /* This package allows threads to pass simple messages through shared	*/
44*03831d35Sstevel /* local memory.  The goal is to keep it simple and somewhat fast	*/
45*03831d35Sstevel 
46*03831d35Sstevel /* smq_init() creates a simple message queue structure.  It returns	*/
47*03831d35Sstevel /* 0 on success.  You pass it a descriptor, the location of the buffer	*/
48*03831d35Sstevel /* where the messages will be stored, and the size of the buffer	*/
49*03831d35Sstevel /* (the number of messages that can be stored).  The memory allocation	*/
50*03831d35Sstevel /* of the simple message buffer is the programmers responsibility.	*/
51*03831d35Sstevel 
52*03831d35Sstevel /* smq_destroy() deativates a message queue structure */
53*03831d35Sstevel 
54*03831d35Sstevel /* smq_receive() retrieves a message off of the simple message queue.	*/
55*03831d35Sstevel /* The message will be  removed from the queue when this routine	*/
56*03831d35Sstevel /* returns.  It suspends the thread until a message is received.	*/
57*03831d35Sstevel 
58*03831d35Sstevel /* smq_send() places a message on the specified simple message queue. */
59*03831d35Sstevel /* It returns 0 on success. If the simple message queue is full, */
60*03831d35Sstevel /* SMQ_FULL is returned. */
61*03831d35Sstevel 
62*03831d35Sstevel /* smq_pendingmsgs() returns the number of pending messages currently */
63*03831d35Sstevel /* on the queue. It returns 0 on success. */
64*03831d35Sstevel 
65*03831d35Sstevel /* smq_depth() returns the depth of the queue. It returns 0 on */
66*03831d35Sstevel /* success. */
67*03831d35Sstevel 
68*03831d35Sstevel /* smq_timedreceive() retrieves a message off of the simple message */
69*03831d35Sstevel /* queue. The message will be  removed from the queue when this  */
70*03831d35Sstevel /* routine returns.  It suspends the thread until a message is  */
71*03831d35Sstevel /* received or until 'timeout' has expired. It returns 0 on success */
72*03831d35Sstevel /* and SMQ_TIMEOUT if timeout has expired. */
73*03831d35Sstevel 
74*03831d35Sstevel 
75*03831d35Sstevel #define	SMQ_INVALID		-1
76*03831d35Sstevel #define	SMQ_FULL		-2
77*03831d35Sstevel #define	SMQ_NOT_IMPLEMENTED	-3
78*03831d35Sstevel #define	SMQ_TIMEOUT		-4
79*03831d35Sstevel #define	SMQ_ETIME		-5
80*03831d35Sstevel #define	SMQ_ERROR		-127
81*03831d35Sstevel 
82*03831d35Sstevel /* Do NOT read or write to these structures directly. They are  */
83*03831d35Sstevel /* implementation dependent and may change over time */
84*03831d35Sstevel /* Be sure to declare any instantiation of these to be static if */
85*03831d35Sstevel /* you are alocating them on the stack */
86*03831d35Sstevel typedef uint32_t	smq_msg_t;
87*03831d35Sstevel typedef struct
88*03831d35Sstevel {
89*03831d35Sstevel 	int		smq_control;
90*03831d35Sstevel 	int		smq_depth;	/* maximum message count */
91*03831d35Sstevel 	int		smq_count;	/* current message count */
92*03831d35Sstevel 	smq_msg_t	*smq_msgBuffer;
93*03831d35Sstevel 	xsem_t		smq_msgAvail;
94*03831d35Sstevel 	smq_msg_t	*smq_head;
95*03831d35Sstevel 	smq_msg_t	*smq_tail;
96*03831d35Sstevel } smq_t;
97*03831d35Sstevel 
98*03831d35Sstevel 
99*03831d35Sstevel int smq_init(smq_t *smq, smq_msg_t *msgbuffer, int depth);
100*03831d35Sstevel int smq_destroy(smq_t *smq);
101*03831d35Sstevel int smq_receive(smq_t *smq, smq_msg_t *msg);
102*03831d35Sstevel int smq_send(smq_t *smq, smq_msg_t *msg);
103*03831d35Sstevel int smq_pendingmsgs(smq_t *smq, int *num);
104*03831d35Sstevel int smq_depth(smq_t *smq, int *depth);
105*03831d35Sstevel int smq_xreceive(smq_t *smq, timestruc_t *timeout, smq_msg_t *msg);
106*03831d35Sstevel 
107*03831d35Sstevel #ifdef	__cplusplus
108*03831d35Sstevel }
109*03831d35Sstevel #endif
110*03831d35Sstevel 
111*03831d35Sstevel #endif /* _SMQ_H */
112