xref: /onnv-gate/usr/src/lib/libc/inc/mtlib.h (revision 6812:febeba71273d)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51672Sraf  * Common Development and Distribution License (the "License").
61672Sraf  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211343Sraf 
220Sstevel@tonic-gate /*
235891Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #ifndef	_MTLIB_H
280Sstevel@tonic-gate #define	_MTLIB_H
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <thread.h>
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #ifdef	__cplusplus
350Sstevel@tonic-gate extern "C" {
360Sstevel@tonic-gate #endif
370Sstevel@tonic-gate 
380Sstevel@tonic-gate /* these are private to the library */
390Sstevel@tonic-gate extern	int	primary_link_map;
400Sstevel@tonic-gate extern	void	lmutex_lock(mutex_t *);
410Sstevel@tonic-gate extern	void	lmutex_unlock(mutex_t *);
420Sstevel@tonic-gate extern	void	lrw_rdlock(rwlock_t *);
430Sstevel@tonic-gate extern	void	lrw_wrlock(rwlock_t *);
440Sstevel@tonic-gate extern	void	lrw_unlock(rwlock_t *);
452248Sraf extern	void	sig_mutex_lock(mutex_t *);
462248Sraf extern	void	sig_mutex_unlock(mutex_t *);
472248Sraf extern	int	sig_mutex_trylock(mutex_t *);
482248Sraf extern	int	sig_cond_wait(cond_t *, mutex_t *);
492248Sraf extern	int	sig_cond_reltimedwait(cond_t *, mutex_t *, const timespec_t *);
505891Sraf extern	void	cancel_safe_mutex_lock(mutex_t *);
515891Sraf extern	void	cancel_safe_mutex_unlock(mutex_t *);
525891Sraf extern	int	cancel_safe_mutex_trylock(mutex_t *);
535891Sraf extern	int	cancel_active(void);
54*6812Sraf extern	int	_thrp_cancelled(void);
552248Sraf 
562248Sraf /* the private libc thread-safe allocator */
572248Sraf extern	void	*lmalloc(size_t);
582248Sraf extern	void	lfree(void *, size_t);
590Sstevel@tonic-gate 
600Sstevel@tonic-gate #if defined(THREAD_DEBUG)
610Sstevel@tonic-gate extern	void	assert_no_libc_locks_held(void);
620Sstevel@tonic-gate #else
630Sstevel@tonic-gate #define	assert_no_libc_locks_held()
640Sstevel@tonic-gate #endif
650Sstevel@tonic-gate 
660Sstevel@tonic-gate #define	_FWRITE _fwrite_unlocked
671343Sraf #define	FILENO(s) _fileno(s)
681343Sraf #define	FERROR(s) ferror(s)
690Sstevel@tonic-gate #define	GETC(s) _getc_unlocked(s)
700Sstevel@tonic-gate #define	UNGETC(c, s) _ungetc_unlocked(c, s)
710Sstevel@tonic-gate #define	PUTC(c, s) _putc_unlocked(c, s)
720Sstevel@tonic-gate #define	GETWC(s) getwc(s)
730Sstevel@tonic-gate #define	PUTWC(c, s) putwc(c, s)
740Sstevel@tonic-gate 
750Sstevel@tonic-gate /*
760Sstevel@tonic-gate  * Cheap check to tell if stdio needs to lock for MT progs.
770Sstevel@tonic-gate  * Referenced directly in port/stdio/flush.c and FLOCKFILE and
781672Sraf  * FUNLOCKFILE macros.  __libc_threaded gets set to 1 when the first
790Sstevel@tonic-gate  * thread (beyond the main thread) is created in _thrp_create().
800Sstevel@tonic-gate  */
811672Sraf extern	int	__libc_threaded;
820Sstevel@tonic-gate 
830Sstevel@tonic-gate #define	FILELOCKING(iop)	(GET_IONOLOCK(iop) == 0)
840Sstevel@tonic-gate 
850Sstevel@tonic-gate #define	FLOCKFILE(lk, iop) \
860Sstevel@tonic-gate 	{ \
871672Sraf 		if (__libc_threaded && FILELOCKING(iop)) \
880Sstevel@tonic-gate 			lk = _flockget((iop)); \
890Sstevel@tonic-gate 		else \
900Sstevel@tonic-gate 			lk = NULL; \
910Sstevel@tonic-gate 	}
920Sstevel@tonic-gate 
930Sstevel@tonic-gate #define	FUNLOCKFILE(lk) \
940Sstevel@tonic-gate 	{ \
950Sstevel@tonic-gate 		if (lk != NULL) \
960Sstevel@tonic-gate 			_flockrel(lk); \
970Sstevel@tonic-gate 	}
980Sstevel@tonic-gate 
990Sstevel@tonic-gate #define	FLOCKRETURN(iop, ret) \
1000Sstevel@tonic-gate 	{	int r; \
1010Sstevel@tonic-gate 		rmutex_t *lk; \
1020Sstevel@tonic-gate 		FLOCKFILE(lk, iop); \
1030Sstevel@tonic-gate 		r = (ret); \
1040Sstevel@tonic-gate 		FUNLOCKFILE(lk); \
1050Sstevel@tonic-gate 		return (r); \
1060Sstevel@tonic-gate 	}
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate #ifdef	__cplusplus
1090Sstevel@tonic-gate }
1100Sstevel@tonic-gate #endif
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate #endif	/* _MTLIB_H */
113