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