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