xref: /freebsd/cddl/contrib/opensolaris/tools/ctf/cvt/barrier.h (revision 98e0ffaefb0f241cda3a72395d3be04192ae0d47)
11673e404SJohn Birrell /*
21673e404SJohn Birrell  * CDDL HEADER START
31673e404SJohn Birrell  *
41673e404SJohn Birrell  * The contents of this file are subject to the terms of the
51673e404SJohn Birrell  * Common Development and Distribution License, Version 1.0 only
61673e404SJohn Birrell  * (the "License").  You may not use this file except in compliance
71673e404SJohn Birrell  * with the License.
81673e404SJohn Birrell  *
91673e404SJohn Birrell  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
101673e404SJohn Birrell  * or http://www.opensolaris.org/os/licensing.
111673e404SJohn Birrell  * See the License for the specific language governing permissions
121673e404SJohn Birrell  * and limitations under the License.
131673e404SJohn Birrell  *
141673e404SJohn Birrell  * When distributing Covered Code, include this CDDL HEADER in each
151673e404SJohn Birrell  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
161673e404SJohn Birrell  * If applicable, add the following below this CDDL HEADER, with the
171673e404SJohn Birrell  * fields enclosed by brackets "[]" replaced with your own identifying
181673e404SJohn Birrell  * information: Portions Copyright [yyyy] [name of copyright owner]
191673e404SJohn Birrell  *
201673e404SJohn Birrell  * CDDL HEADER END
211673e404SJohn Birrell  */
221673e404SJohn Birrell /*
231673e404SJohn Birrell  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
241673e404SJohn Birrell  * Use is subject to license terms.
251673e404SJohn Birrell  */
261673e404SJohn Birrell 
271673e404SJohn Birrell #ifndef _BARRIER_H
281673e404SJohn Birrell #define	_BARRIER_H
291673e404SJohn Birrell 
301673e404SJohn Birrell #pragma ident	"%Z%%M%	%I%	%E% SMI"
311673e404SJohn Birrell 
321673e404SJohn Birrell /*
331673e404SJohn Birrell  * APIs for the barrier synchronization primitive.
341673e404SJohn Birrell  */
351673e404SJohn Birrell 
36*bc96366cSSteven Hartland #ifdef illumos
371673e404SJohn Birrell #include <synch.h>
384cc75139SJohn Birrell #else
394cc75139SJohn Birrell #include <semaphore.h>
404cc75139SJohn Birrell typedef sem_t	sema_t;
414cc75139SJohn Birrell #endif
421673e404SJohn Birrell 
431673e404SJohn Birrell #ifdef __cplusplus
441673e404SJohn Birrell extern "C" {
451673e404SJohn Birrell #endif
461673e404SJohn Birrell 
471673e404SJohn Birrell typedef struct barrier {
481673e404SJohn Birrell 	pthread_mutex_t bar_lock;	/* protects bar_numin */
491673e404SJohn Birrell 	int bar_numin;			/* current number of waiters */
501673e404SJohn Birrell 
511673e404SJohn Birrell 	sema_t bar_sem;			/* where everyone waits */
521673e404SJohn Birrell 	int bar_nthr;			/* # of waiters to trigger release */
531673e404SJohn Birrell } barrier_t;
541673e404SJohn Birrell 
551673e404SJohn Birrell extern void barrier_init(barrier_t *, int);
561673e404SJohn Birrell extern int barrier_wait(barrier_t *);
571673e404SJohn Birrell 
581673e404SJohn Birrell #ifdef __cplusplus
591673e404SJohn Birrell }
601673e404SJohn Birrell #endif
611673e404SJohn Birrell 
621673e404SJohn Birrell #endif /* _BARRIER_H */
63