xshmfence_semaphore.h revision 875bea1a
1/*
2 * Copyright © 2015 Tobias Nygren
3 * Copyright © 2013 Keith Packard
4 *
5 * Permission to use, copy, modify, distribute, and sell this software and its
6 * documentation for any purpose is hereby granted without fee, provided that
7 * the above copyright notice appear in all copies and that both that copyright
8 * notice and this permission notice appear in supporting documentation, and
9 * that the name of the copyright holders not be used in advertising or
10 * publicity pertaining to distribution of the software without specific,
11 * written prior permission.  The copyright holders make no representations
12 * about the suitability of this software for any purpose.  It is provided "as
13 * is" without express or implied warranty.
14 *
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
21 * OF THIS SOFTWARE.
22 */
23
24#ifndef _XSHMFENCE_SEMAPHORE_H_
25#define _XSHMFENCE_SEMAPHORE_H_
26
27#include <semaphore.h>
28
29#define LOCK_ALIGN __attribute__((aligned(128)))
30#ifndef LIBXSHM_PAGESIZE
31#error unknown machine page size
32#endif
33#define PAGE_ALIGN __attribute__((aligned(LIBXSHM_PAGESIZE)))
34
35/*
36 * the fence is divided into two memory pages:
37 * page 1 contains process shared state
38 * page 2 contains process local state
39 */
40
41struct xshmfence {
42	/* page 1 */
43	int refcnt LOCK_ALIGN;
44	int triggered LOCK_ALIGN;
45	int waiting LOCK_ALIGN;
46	char lockname[16];
47	char condname[16];
48	/* page 2*/
49	sem_t *lock PAGE_ALIGN;
50	sem_t *cond;
51};
52
53void
54xshmfence_init(int fd);
55void
56xshmfence_open_semaphore(struct xshmfence *f);
57void
58xshmfence_close_semaphore(struct xshmfence *f);
59
60#endif /* _XSHMFENCE_SEMAPHORE_H_ */
61