17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*1d2738a5Sraf * Common Development and Distribution License (the "License"). 6*1d2738a5Sraf * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 2159e63b6eSraf 227c478bd9Sstevel@tonic-gate /* 2359e63b6eSraf * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _MTLIB_H 287c478bd9Sstevel@tonic-gate #define _MTLIB_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <thread.h> 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #ifdef __cplusplus 357c478bd9Sstevel@tonic-gate extern "C" { 367c478bd9Sstevel@tonic-gate #endif 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate /* these are private to the library */ 397c478bd9Sstevel@tonic-gate extern int primary_link_map; 407c478bd9Sstevel@tonic-gate extern int _private_mutex_init(mutex_t *, int, void *); 417c478bd9Sstevel@tonic-gate extern int _private_mutex_destroy(mutex_t *); 427c478bd9Sstevel@tonic-gate extern int _private_mutex_lock(mutex_t *); 437c478bd9Sstevel@tonic-gate extern int _private_mutex_trylock(mutex_t *); 447c478bd9Sstevel@tonic-gate extern int _private_mutex_unlock(mutex_t *); 457c478bd9Sstevel@tonic-gate #define rmutex_lock _private_mutex_lock 467c478bd9Sstevel@tonic-gate #define rmutex_trylock _private_mutex_trylock 477c478bd9Sstevel@tonic-gate #define rmutex_unlock _private_mutex_unlock 487c478bd9Sstevel@tonic-gate extern void lmutex_lock(mutex_t *); 497c478bd9Sstevel@tonic-gate extern void lmutex_unlock(mutex_t *); 507c478bd9Sstevel@tonic-gate extern int __rwlock_init(rwlock_t *, int, void *); 517c478bd9Sstevel@tonic-gate extern int __rwlock_destroy(rwlock_t *); 527c478bd9Sstevel@tonic-gate extern int __rw_rdlock(rwlock_t *); 537c478bd9Sstevel@tonic-gate extern int __rw_wrlock(rwlock_t *); 547c478bd9Sstevel@tonic-gate extern int __rw_tryrdlock(rwlock_t *); 557c478bd9Sstevel@tonic-gate extern int __rw_trywrlock(rwlock_t *); 567c478bd9Sstevel@tonic-gate extern int __rw_unlock(rwlock_t *); 577c478bd9Sstevel@tonic-gate extern void lrw_rdlock(rwlock_t *); 587c478bd9Sstevel@tonic-gate extern void lrw_wrlock(rwlock_t *); 597c478bd9Sstevel@tonic-gate extern void lrw_unlock(rwlock_t *); 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate /* the rest are public functions */ 627c478bd9Sstevel@tonic-gate extern int _mutex_init(mutex_t *, int, void *); 637c478bd9Sstevel@tonic-gate extern int _mutex_destroy(mutex_t *); 647c478bd9Sstevel@tonic-gate extern int _mutex_lock(mutex_t *); 657c478bd9Sstevel@tonic-gate extern int _mutex_trylock(mutex_t *); 667c478bd9Sstevel@tonic-gate extern int _mutex_unlock(mutex_t *); 677c478bd9Sstevel@tonic-gate extern int __mutex_init(mutex_t *, int, void *); 687c478bd9Sstevel@tonic-gate extern int __mutex_destroy(mutex_t *); 697c478bd9Sstevel@tonic-gate extern int __mutex_lock(mutex_t *); 707c478bd9Sstevel@tonic-gate extern int __mutex_trylock(mutex_t *); 717c478bd9Sstevel@tonic-gate extern int __mutex_unlock(mutex_t *); 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate extern int _cond_init(cond_t *, int, void *); 747c478bd9Sstevel@tonic-gate extern int _cond_destroy(cond_t *); 757c478bd9Sstevel@tonic-gate extern int _cond_wait(cond_t *, mutex_t *); 767c478bd9Sstevel@tonic-gate extern int _cond_timedwait(cond_t *, mutex_t *, const timespec_t *); 777c478bd9Sstevel@tonic-gate extern int _cond_reltimedwait(cond_t *, mutex_t *, const timespec_t *); 787c478bd9Sstevel@tonic-gate extern int _cond_signal(cond_t *); 797c478bd9Sstevel@tonic-gate extern int _cond_broadcast(cond_t *); 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate extern int _rwlock_init(rwlock_t *, int, void *); 827c478bd9Sstevel@tonic-gate extern int _rwlock_destroy(rwlock_t *); 837c478bd9Sstevel@tonic-gate extern int _rw_rdlock(rwlock_t *); 847c478bd9Sstevel@tonic-gate extern int _rw_wrlock(rwlock_t *); 857c478bd9Sstevel@tonic-gate extern int _rw_tryrdlock(rwlock_t *); 867c478bd9Sstevel@tonic-gate extern int _rw_trywrlock(rwlock_t *); 877c478bd9Sstevel@tonic-gate extern int _rw_unlock(rwlock_t *); 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate extern int _thr_main(void); 907c478bd9Sstevel@tonic-gate extern thread_t _thr_self(void); 917c478bd9Sstevel@tonic-gate extern void _thr_exit(void *); 927c478bd9Sstevel@tonic-gate extern size_t _thr_min_stack(void); 937c478bd9Sstevel@tonic-gate extern int _thr_kill(thread_t, int); 947c478bd9Sstevel@tonic-gate extern int _thr_keycreate(thread_key_t *, void (*)(void *)); 957c478bd9Sstevel@tonic-gate extern int _thr_setspecific(thread_key_t, void *); 967c478bd9Sstevel@tonic-gate extern int _thr_getspecific(thread_key_t, void **); 977c478bd9Sstevel@tonic-gate extern void *_pthread_getspecific(thread_key_t); 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate #if defined(THREAD_DEBUG) 1007c478bd9Sstevel@tonic-gate extern void assert_no_libc_locks_held(void); 1017c478bd9Sstevel@tonic-gate #else 1027c478bd9Sstevel@tonic-gate #define assert_no_libc_locks_held() 1037c478bd9Sstevel@tonic-gate #endif 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate #define _FWRITE _fwrite_unlocked 10659e63b6eSraf #define FILENO(s) _fileno(s) 10759e63b6eSraf #define FERROR(s) ferror(s) 1087c478bd9Sstevel@tonic-gate #define GETC(s) _getc_unlocked(s) 1097c478bd9Sstevel@tonic-gate #define UNGETC(c, s) _ungetc_unlocked(c, s) 1107c478bd9Sstevel@tonic-gate #define PUTC(c, s) _putc_unlocked(c, s) 1117c478bd9Sstevel@tonic-gate #define GETWC(s) getwc(s) 1127c478bd9Sstevel@tonic-gate #define PUTWC(c, s) putwc(c, s) 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate /* 1157c478bd9Sstevel@tonic-gate * Cheap check to tell if stdio needs to lock for MT progs. 1167c478bd9Sstevel@tonic-gate * Referenced directly in port/stdio/flush.c and FLOCKFILE and 117*1d2738a5Sraf * FUNLOCKFILE macros. __libc_threaded gets set to 1 when the first 1187c478bd9Sstevel@tonic-gate * thread (beyond the main thread) is created in _thrp_create(). 1197c478bd9Sstevel@tonic-gate */ 120*1d2738a5Sraf extern int __libc_threaded; 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate #define FILELOCKING(iop) (GET_IONOLOCK(iop) == 0) 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate #define FLOCKFILE(lk, iop) \ 1257c478bd9Sstevel@tonic-gate { \ 126*1d2738a5Sraf if (__libc_threaded && FILELOCKING(iop)) \ 1277c478bd9Sstevel@tonic-gate lk = _flockget((iop)); \ 1287c478bd9Sstevel@tonic-gate else \ 1297c478bd9Sstevel@tonic-gate lk = NULL; \ 1307c478bd9Sstevel@tonic-gate } 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate #define FUNLOCKFILE(lk) \ 1337c478bd9Sstevel@tonic-gate { \ 1347c478bd9Sstevel@tonic-gate if (lk != NULL) \ 1357c478bd9Sstevel@tonic-gate _flockrel(lk); \ 1367c478bd9Sstevel@tonic-gate } 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate #define FLOCKRETURN(iop, ret) \ 1397c478bd9Sstevel@tonic-gate { int r; \ 1407c478bd9Sstevel@tonic-gate rmutex_t *lk; \ 1417c478bd9Sstevel@tonic-gate FLOCKFILE(lk, iop); \ 1427c478bd9Sstevel@tonic-gate r = (ret); \ 1437c478bd9Sstevel@tonic-gate FUNLOCKFILE(lk); \ 1447c478bd9Sstevel@tonic-gate return (r); \ 1457c478bd9Sstevel@tonic-gate } 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1487c478bd9Sstevel@tonic-gate } 1497c478bd9Sstevel@tonic-gate #endif 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate #endif /* _MTLIB_H */ 152