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