Importing in main tree this library which used to be in tests tree
[mmondor.git] / mmsoftware / pthread_util / mm_pthread_msg.h
CommitLineData
c6268fe8
MM
1/* $Id: mm_pthread_msg.h,v 1.1 2007/03/13 19:37:22 mmondor Exp $ */
2
3/*
4 * Copyright (C) 2005, Matthew Mondor
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Matthew Mondor.
18 * 4. The name of Matthew Mondor may not be used to endorse or promote
19 * products derived from this software without specific prior written
20 * permission.
21 * 5. Redistribution of source code may not be released under the terms of
22 * any GNU Public License derivate.
23 *
24 * THIS SOFTWARE IS PROVIDED BY MATTHEW MONDOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL MATTHEW MONDOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36
37
38#ifndef MM_PTHREAD_MSG_H
39#define MM_PTHREAD_MSG_H
40
41
42
43#include <pthread.h>
44
45#include <mmtypes.h>
46#include <mmlist.h>
47
48
49
50#define PRING_MAGIC 0x50524e47
51#define PPORT_MAGIC 0x50505254
52#define PMESG_MAGIC 0x504d5347
53
54typedef struct {
55 u_int32_t magic;
56 pthread_cond_t cond;
57 pthread_mutex_t mutex;
58 int mode;
59 int event;
60 int mevent;
61} pthread_ring_t;
62
63enum pthread_ring_modes {
64 PTHREAD_RMOD_NOWAIT,
65 PTHREAD_RMOD_CONDWAIT,
66 PTHREAD_RMOD_FDWAIT
67};
68
69typedef struct {
70 u_int32_t magic;
71 pthread_ring_t *ring;
72 pthread_mutex_t lock;
73 list_t messages;
74} pthread_port_t;
75
76typedef struct {
77 node_t node;
78 u_int32_t magic;
79 pthread_port_t *reply;
80 size_t size;
81 void *message;
82} pthread_msg_t;
83
84
85
86extern int pthread_ring_init(pthread_ring_t *);
87extern int pthread_ring_valid(pthread_ring_t *);
88extern int pthread_ring_destroy(pthread_ring_t *);
89extern int pthread_ring_wait(pthread_ring_t *,
90 const struct timespec *);
91extern int pthread_ring_notify(pthread_ring_t *);
92
93extern int pthread_port_init(pthread_port_t *);
94extern int pthread_port_valid(pthread_port_t *);
95extern int pthread_port_destroy(pthread_port_t *);
96extern int pthread_port_set_ring(pthread_port_t *,
97 pthread_ring_t *);
98extern int pthread_msg_init(pthread_msg_t *,
99 pthread_port_t *);
100extern int pthread_msg_valid(pthread_msg_t *);
101extern int pthread_msg_destroy(pthread_msg_t *);
102extern pthread_msg_t *pthread_msg_get(pthread_port_t *);
103extern int pthread_msg_put(pthread_port_t *,
104 pthread_msg_t *);
105extern int pthread_msg_reply(pthread_msg_t *);
106extern int pthread_port_pending(pthread_port_t *);
107
108
109
110#endif