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
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.
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]
23 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
30 #pragma ident "%Z%%M% %I% %E% SMI"
36 #include <sys/types.h>
41 /* THIS IS CURRENTLY ONLY WRITTEN TO HANDLE A SINGLE PRODUCER, SINGLE */
42 /* CONSUMER !!!!!!!!!!!!!!!! */
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 */
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. */
54 /* smq_destroy() deativates a message queue structure */
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. */
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. */
64 /* smq_pendingmsgs() returns the number of pending messages currently */
65 /* on the queue. It returns 0 on success. */
67 /* smq_depth() returns the depth of the queue. It returns 0 on */
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. */
77 #define SMQ_INVALID -1
79 #define SMQ_NOT_IMPLEMENTED -3
80 #define SMQ_TIMEOUT -4
82 #define SMQ_ERROR -127
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
;
92 int smq_depth
; /* maximum message count */
93 int smq_count
; /* current message count */
94 smq_msg_t
*smq_msgBuffer
;
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
);