thr_autoinit.c revision 112918
1112918Sjeff/* 2112918Sjeff * Copyright (c) 2002 Alfred Perlstein <alfred@freebsd.org>. 3112918Sjeff * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. 4112918Sjeff * All rights reserved. 5112918Sjeff * 6112918Sjeff * Redistribution and use in source and binary forms, with or without 7112918Sjeff * modification, are permitted provided that the following conditions 8112918Sjeff * are met: 9112918Sjeff * 1. Redistributions of source code must retain the above copyright 10112918Sjeff * notice, this list of conditions and the following disclaimer. 11112918Sjeff * 2. Redistributions in binary form must reproduce the above copyright 12112918Sjeff * notice, this list of conditions and the following disclaimer in the 13112918Sjeff * documentation and/or other materials provided with the distribution. 14112918Sjeff * 3. All advertising materials mentioning features or use of this software 15112918Sjeff * must display the following acknowledgement: 16112918Sjeff * This product includes software developed by John Birrell. 17112918Sjeff * 4. Neither the name of the author nor the names of any co-contributors 18112918Sjeff * may be used to endorse or promote products derived from this software 19112918Sjeff * without specific prior written permission. 20112918Sjeff * 21112918Sjeff * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 22112918Sjeff * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23112918Sjeff * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24112918Sjeff * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 25112918Sjeff * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26112918Sjeff * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27112918Sjeff * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28112918Sjeff * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29112918Sjeff * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30112918Sjeff * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31112918Sjeff * SUCH DAMAGE. 32112918Sjeff * 33112918Sjeff * $FreeBSD: head/lib/libthr/thread/thr_autoinit.c 112918 2003-04-01 03:46:29Z jeff $ 34112918Sjeff */ 35112918Sjeff 36112918Sjeff/* 37112918Sjeff * This module uses GCC extentions to initialize the 38112918Sjeff * threads package at program start-up time. 39112918Sjeff */ 40112918Sjeff 41112918Sjeffvoid _thread_init_hack(void) __attribute__ ((constructor)); 42112918Sjeff 43112918Sjeffvoid 44112918Sjeff_thread_init_hack(void) 45112918Sjeff{ 46112918Sjeff 47112918Sjeff _thread_init(); 48112918Sjeff} 49112918Sjeff 50112918Sjeff/* 51112918Sjeff * For the shared version of the threads library, the above is sufficient. 52112918Sjeff * But for the archive version of the library, we need a little bit more. 53112918Sjeff * Namely, we must arrange for this particular module to be pulled in from 54112918Sjeff * the archive library at link time. To accomplish that, we define and 55112918Sjeff * initialize a variable, "_thread_autoinit_dummy_decl". This variable is 56112918Sjeff * referenced (as an extern) from libc/stdlib/exit.c. This will always 57112918Sjeff * create a need for this module, ensuring that it is present in the 58112918Sjeff * executable. 59112918Sjeff */ 60112918Sjeffextern int _thread_autoinit_dummy_decl; 61112918Sjeffint _thread_autoinit_dummy_decl = 0; 62