xref: /titanic_52/usr/src/cmd/scadm/sparc/mpxu/common/smq.h (revision 03831d35f7499c87d51205817c93e9a8d42c4bae)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*03831d35Sstevel 
32*03831d35Sstevel #ifdef	__cplusplus
33*03831d35Sstevel extern "C" {
34*03831d35Sstevel #endif
35*03831d35Sstevel 
36*03831d35Sstevel #include <sys/types.h>
37*03831d35Sstevel #include <time.h>
38*03831d35Sstevel 
39*03831d35Sstevel #include "xsem.h"
40*03831d35Sstevel 
41*03831d35Sstevel /* THIS IS CURRENTLY ONLY WRITTEN TO HANDLE A SINGLE PRODUCER, SINGLE */
42*03831d35Sstevel /* CONSUMER !!!!!!!!!!!!!!!! */
43*03831d35Sstevel 
44*03831d35Sstevel /* Simple message queue */
45*03831d35Sstevel /* This package allows threads to pass simple messages through shared	*/
46*03831d35Sstevel /* local memory.  The goal is to keep it simple and somewhat fast	*/
47*03831d35Sstevel 
48*03831d35Sstevel /* smq_init() creates a simple message queue structure.  It returns	*/
49*03831d35Sstevel /* 0 on success.  You pass it a descriptor, the location of the buffer	*/
50*03831d35Sstevel /* where the messages will be stored, and the size of the buffer	*/
51*03831d35Sstevel /* (the number of messages that can be stored).  The memory allocation	*/
52*03831d35Sstevel /* of the simple message buffer is the programmers responsibility.	*/
53*03831d35Sstevel 
54*03831d35Sstevel /* smq_destroy() deativates a message queue structure */
55*03831d35Sstevel 
56*03831d35Sstevel /* smq_receive() retrieves a message off of the simple message queue.	*/
57*03831d35Sstevel /* The message will be  removed from the queue when this routine	*/
58*03831d35Sstevel /* returns.  It suspends the thread until a message is received.	*/
59*03831d35Sstevel 
60*03831d35Sstevel /* smq_send() places a message on the specified simple message queue. */
61*03831d35Sstevel /* It returns 0 on success. If the simple message queue is full, */
62*03831d35Sstevel /* SMQ_FULL is returned. */
63*03831d35Sstevel 
64*03831d35Sstevel /* smq_pendingmsgs() returns the number of pending messages currently */
65*03831d35Sstevel /* on the queue. It returns 0 on success. */
66*03831d35Sstevel 
67*03831d35Sstevel /* smq_depth() returns the depth of the queue. It returns 0 on */
68*03831d35Sstevel /* success. */
69*03831d35Sstevel 
70*03831d35Sstevel /* smq_timedreceive() retrieves a message off of the simple message */
71*03831d35Sstevel /* queue. The message will be  removed from the queue when this  */
72*03831d35Sstevel /* routine returns.  It suspends the thread until a message is  */
73*03831d35Sstevel /* received or until 'timeout' has expired. It returns 0 on success */
74*03831d35Sstevel /* and SMQ_TIMEOUT if timeout has expired. */
75*03831d35Sstevel 
76*03831d35Sstevel 
77*03831d35Sstevel #define	SMQ_INVALID		-1
78*03831d35Sstevel #define	SMQ_FULL		-2
79*03831d35Sstevel #define	SMQ_NOT_IMPLEMENTED	-3
80*03831d35Sstevel #define	SMQ_TIMEOUT		-4
81*03831d35Sstevel #define	SMQ_ETIME		-5
82*03831d35Sstevel #define	SMQ_ERROR		-127
83*03831d35Sstevel 
84*03831d35Sstevel /* Do NOT read or write to these structures directly. They are  */
85*03831d35Sstevel /* implementation dependent and may change over time */
86*03831d35Sstevel /* Be sure to declare any instantiation of these to be static if */
87*03831d35Sstevel /* you are alocating them on the stack */
88*03831d35Sstevel typedef uint32_t	smq_msg_t;
89*03831d35Sstevel typedef struct
90*03831d35Sstevel {
91*03831d35Sstevel 	int		smq_control;
92*03831d35Sstevel 	int		smq_depth;	/* maximum message count */
93*03831d35Sstevel 	int		smq_count;	/* current message count */
94*03831d35Sstevel 	smq_msg_t	*smq_msgBuffer;
95*03831d35Sstevel 	xsem_t		smq_msgAvail;
96*03831d35Sstevel 	smq_msg_t	*smq_head;
97*03831d35Sstevel 	smq_msg_t	*smq_tail;
98*03831d35Sstevel } smq_t;
99*03831d35Sstevel 
100*03831d35Sstevel 
101*03831d35Sstevel int smq_init(smq_t *smq, smq_msg_t *msgbuffer, int depth);
102*03831d35Sstevel int smq_destroy(smq_t *smq);
103*03831d35Sstevel int smq_receive(smq_t *smq, smq_msg_t *msg);
104*03831d35Sstevel int smq_send(smq_t *smq, smq_msg_t *msg);
105*03831d35Sstevel int smq_pendingmsgs(smq_t *smq, int *num);
106*03831d35Sstevel int smq_depth(smq_t *smq, int *depth);
107*03831d35Sstevel int smq_xreceive(smq_t *smq, timestruc_t *timeout, smq_msg_t *msg);
108*03831d35Sstevel 
109*03831d35Sstevel #ifdef	__cplusplus
110*03831d35Sstevel }
111*03831d35Sstevel #endif
112*03831d35Sstevel 
113*03831d35Sstevel #endif /* _SMQ_H */
114