xref: /dflybsd-src/lib/libthread_xu/thread/thr_main_np.c (revision 71b3fa151e714295cd932238bb91973cd4a02c55)
1*71b3fa15SDavid Xu /*
2*71b3fa15SDavid Xu  * Copyright (c) 2001 Alfred Perlstein
3*71b3fa15SDavid Xu  * Author: Alfred Perlstein <alfred@FreeBSD.org>
4*71b3fa15SDavid Xu  * All rights reserved.
5*71b3fa15SDavid Xu  *
6*71b3fa15SDavid Xu  * Redistribution and use in source and binary forms, with or without
7*71b3fa15SDavid Xu  * modification, are permitted provided that the following conditions
8*71b3fa15SDavid Xu  * are met:
9*71b3fa15SDavid Xu  * 1. Redistributions of source code must retain the above copyright
10*71b3fa15SDavid Xu  *    notice, this list of conditions and the following disclaimer.
11*71b3fa15SDavid Xu  * 2. Redistributions in binary form must reproduce the above copyright
12*71b3fa15SDavid Xu  *    notice, this list of conditions and the following disclaimer in the
13*71b3fa15SDavid Xu  *    documentation and/or other materials provided with the distribution.
14*71b3fa15SDavid Xu  *
15*71b3fa15SDavid Xu  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16*71b3fa15SDavid Xu  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17*71b3fa15SDavid Xu  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18*71b3fa15SDavid Xu  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19*71b3fa15SDavid Xu  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*71b3fa15SDavid Xu  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21*71b3fa15SDavid Xu  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*71b3fa15SDavid Xu  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*71b3fa15SDavid Xu  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*71b3fa15SDavid Xu  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25*71b3fa15SDavid Xu  * SUCH DAMAGE.
26*71b3fa15SDavid Xu  *
27*71b3fa15SDavid Xu  * $FreeBSD: src/lib/libpthread/thread/thr_main_np.c,v 1.5 2003/04/18 05:04:16 deischen Exp $
28*71b3fa15SDavid Xu  * $DragonFly: src/lib/libthread_xu/thread/thr_main_np.c,v 1.1 2005/02/01 12:38:27 davidxu Exp $
29*71b3fa15SDavid Xu  */
30*71b3fa15SDavid Xu 
31*71b3fa15SDavid Xu #include <pthread.h>
32*71b3fa15SDavid Xu #include <pthread_np.h>
33*71b3fa15SDavid Xu #include "thr_private.h"
34*71b3fa15SDavid Xu 
35*71b3fa15SDavid Xu __weak_reference(_pthread_main_np, pthread_main_np);
36*71b3fa15SDavid Xu 
37*71b3fa15SDavid Xu /*
38*71b3fa15SDavid Xu  * Provide the equivelant to Solaris thr_main() function
39*71b3fa15SDavid Xu  */
40*71b3fa15SDavid Xu int
41*71b3fa15SDavid Xu _pthread_main_np()
42*71b3fa15SDavid Xu {
43*71b3fa15SDavid Xu 
44*71b3fa15SDavid Xu 	if (!_thr_initial)
45*71b3fa15SDavid Xu 		return (-1);
46*71b3fa15SDavid Xu 	else
47*71b3fa15SDavid Xu 		return (pthread_equal(pthread_self(), _thr_initial) ? 1 : 0);
48*71b3fa15SDavid Xu }
49