1875bea1aSmrg/* 2875bea1aSmrg * Copyright © 2015 Tobias Nygren 3875bea1aSmrg * Copyright © 2013 Keith Packard 4875bea1aSmrg * 5875bea1aSmrg * Permission to use, copy, modify, distribute, and sell this software and its 6875bea1aSmrg * documentation for any purpose is hereby granted without fee, provided that 7875bea1aSmrg * the above copyright notice appear in all copies and that both that copyright 8875bea1aSmrg * notice and this permission notice appear in supporting documentation, and 9875bea1aSmrg * that the name of the copyright holders not be used in advertising or 10875bea1aSmrg * publicity pertaining to distribution of the software without specific, 11875bea1aSmrg * written prior permission. The copyright holders make no representations 12875bea1aSmrg * about the suitability of this software for any purpose. It is provided "as 13875bea1aSmrg * is" without express or implied warranty. 14875bea1aSmrg * 15875bea1aSmrg * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 16875bea1aSmrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 17875bea1aSmrg * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 18875bea1aSmrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 19875bea1aSmrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 20875bea1aSmrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 21875bea1aSmrg * OF THIS SOFTWARE. 22875bea1aSmrg */ 23875bea1aSmrg 24875bea1aSmrg#ifndef _XSHMFENCE_SEMAPHORE_H_ 25875bea1aSmrg#define _XSHMFENCE_SEMAPHORE_H_ 26875bea1aSmrg 27875bea1aSmrg#include <semaphore.h> 28875bea1aSmrg 29875bea1aSmrg#define LOCK_ALIGN __attribute__((aligned(128))) 30875bea1aSmrg#ifndef LIBXSHM_PAGESIZE 31875bea1aSmrg#error unknown machine page size 32875bea1aSmrg#endif 33875bea1aSmrg#define PAGE_ALIGN __attribute__((aligned(LIBXSHM_PAGESIZE))) 34875bea1aSmrg 35875bea1aSmrg/* 36875bea1aSmrg * the fence is divided into two memory pages: 37875bea1aSmrg * page 1 contains process shared state 38875bea1aSmrg * page 2 contains process local state 39875bea1aSmrg */ 40875bea1aSmrg 41875bea1aSmrgstruct xshmfence { 42875bea1aSmrg /* page 1 */ 43875bea1aSmrg int refcnt LOCK_ALIGN; 44875bea1aSmrg int triggered LOCK_ALIGN; 45875bea1aSmrg int waiting LOCK_ALIGN; 465a4966d2Stnn int wakeups LOCK_ALIGN; 475a4966d2Stnn char condname_w[16]; 485a4966d2Stnn char condname_t[16]; 49875bea1aSmrg /* page 2*/ 505a4966d2Stnn sem_t *cond_w PAGE_ALIGN; 515a4966d2Stnn sem_t *cond_t; 52875bea1aSmrg}; 53875bea1aSmrg 54875bea1aSmrgvoid 55875bea1aSmrgxshmfence_init(int fd); 56875bea1aSmrgvoid 57875bea1aSmrgxshmfence_open_semaphore(struct xshmfence *f); 58875bea1aSmrgvoid 59875bea1aSmrgxshmfence_close_semaphore(struct xshmfence *f); 60875bea1aSmrg 61875bea1aSmrg#endif /* _XSHMFENCE_SEMAPHORE_H_ */ 62