xref: /freebsd/lib/libthr/thread/thr_ctrdtr.c (revision a2f733abcff64628b7771a47089628b7327a88bd)
120fe2c94SAndrew Turner /*-
220fe2c94SAndrew Turner  * Copyright (C) 2003 Jake Burkholder <jake@freebsd.org>
320fe2c94SAndrew Turner  * Copyright (C) 2003 David Xu <davidxu@freebsd.org>
420fe2c94SAndrew Turner  * Copyright (c) 2001,2003 Daniel Eischen <deischen@freebsd.org>
520fe2c94SAndrew Turner  * All rights reserved.
620fe2c94SAndrew Turner  *
720fe2c94SAndrew Turner  * Redistribution and use in source and binary forms, with or without
820fe2c94SAndrew Turner  * modification, are permitted provided that the following conditions
920fe2c94SAndrew Turner  * are met:
1020fe2c94SAndrew Turner  * 1. Redistributions of source code must retain the above copyright
1120fe2c94SAndrew Turner  *    notice, this list of conditions and the following disclaimer.
1220fe2c94SAndrew Turner  * 2. Neither the name of the author nor the names of its contributors
1320fe2c94SAndrew Turner  *    may be used to endorse or promote products derived from this software
1420fe2c94SAndrew Turner  *    without specific prior written permission.
1520fe2c94SAndrew Turner  *
1620fe2c94SAndrew Turner  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1720fe2c94SAndrew Turner  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1820fe2c94SAndrew Turner  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1920fe2c94SAndrew Turner  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2020fe2c94SAndrew Turner  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2120fe2c94SAndrew Turner  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2220fe2c94SAndrew Turner  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2320fe2c94SAndrew Turner  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2420fe2c94SAndrew Turner  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2520fe2c94SAndrew Turner  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2620fe2c94SAndrew Turner  * SUCH DAMAGE.
2720fe2c94SAndrew Turner  */
2820fe2c94SAndrew Turner 
2920fe2c94SAndrew Turner #include <sys/types.h>
3020fe2c94SAndrew Turner #include <rtld_tls.h>
3120fe2c94SAndrew Turner 
3220fe2c94SAndrew Turner #include "thr_private.h"
3320fe2c94SAndrew Turner 
3420fe2c94SAndrew Turner struct tcb *
_tcb_ctor(struct pthread * thread,int initial)3520fe2c94SAndrew Turner _tcb_ctor(struct pthread *thread, int initial)
3620fe2c94SAndrew Turner {
3720fe2c94SAndrew Turner 	struct tcb *tcb;
3820fe2c94SAndrew Turner 
3920fe2c94SAndrew Turner 	if (initial)
4020fe2c94SAndrew Turner 		tcb = _tcb_get();
4120fe2c94SAndrew Turner 	else
42*8de1a813SJohn Baldwin 		tcb = _rtld_allocate_tls(NULL, TLS_TCB_SIZE, TLS_TCB_ALIGN);
4320fe2c94SAndrew Turner 	if (tcb)
4420fe2c94SAndrew Turner 		tcb->tcb_thread = thread;
4520fe2c94SAndrew Turner 	return (tcb);
4620fe2c94SAndrew Turner }
4720fe2c94SAndrew Turner 
4820fe2c94SAndrew Turner void
_tcb_dtor(struct tcb * tcb)4920fe2c94SAndrew Turner _tcb_dtor(struct tcb *tcb)
5020fe2c94SAndrew Turner {
5120fe2c94SAndrew Turner 
52*8de1a813SJohn Baldwin 	_rtld_free_tls(tcb, TLS_TCB_SIZE, TLS_TCB_ALIGN);
5320fe2c94SAndrew Turner }
54