xref: /freebsd/lib/libthr/thread/thr_main_np.c (revision f8bbbce458194ff4312c610d32a64ff4a3a71d45)
15e53a4f9SPedro F. Giffuni /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
35e53a4f9SPedro F. Giffuni  *
4bb535300SJeff Roberson  * Copyright (c) 2001 Alfred Perlstein
5bb535300SJeff Roberson  * Author: Alfred Perlstein <alfred@FreeBSD.org>
6bb535300SJeff Roberson  * All rights reserved.
7bb535300SJeff Roberson  *
8bb535300SJeff Roberson  * Redistribution and use in source and binary forms, with or without
9bb535300SJeff Roberson  * modification, are permitted provided that the following conditions
10bb535300SJeff Roberson  * are met:
11bb535300SJeff Roberson  * 1. Redistributions of source code must retain the above copyright
12bb535300SJeff Roberson  *    notice, this list of conditions and the following disclaimer.
13bb535300SJeff Roberson  * 2. Redistributions in binary form must reproduce the above copyright
14bb535300SJeff Roberson  *    notice, this list of conditions and the following disclaimer in the
15bb535300SJeff Roberson  *    documentation and/or other materials provided with the distribution.
16bb535300SJeff Roberson  *
17bb535300SJeff Roberson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18bb535300SJeff Roberson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19bb535300SJeff Roberson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20bb535300SJeff Roberson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21bb535300SJeff Roberson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22bb535300SJeff Roberson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23bb535300SJeff Roberson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24bb535300SJeff Roberson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25bb535300SJeff Roberson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26bb535300SJeff Roberson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27bb535300SJeff Roberson  * SUCH DAMAGE.
28bb535300SJeff Roberson  */
29bb535300SJeff Roberson 
3037a6356bSDavid Xu #include "namespace.h"
31bb535300SJeff Roberson #include <pthread.h>
32bb535300SJeff Roberson #include <pthread_np.h>
3337a6356bSDavid Xu #include "un-namespace.h"
34a091d823SDavid Xu 
35bb535300SJeff Roberson #include "thr_private.h"
36bb535300SJeff Roberson 
370ab1bfc7SKonstantin Belousov __weak_reference(_thr_main_np, pthread_main_np);
380ab1bfc7SKonstantin Belousov __weak_reference(_thr_main_np, _pthread_main_np);
39bb535300SJeff Roberson 
40bb535300SJeff Roberson /*
415c43c9a1SKonstantin Belousov  * Provide the equivalent to Solaris thr_main() function.
42bb535300SJeff Roberson  */
43bb535300SJeff Roberson int
_thr_main_np(void)440ab1bfc7SKonstantin Belousov _thr_main_np(void)
45bb535300SJeff Roberson {
46bb535300SJeff Roberson 
47a091d823SDavid Xu 	if (!_thr_initial)
48bb535300SJeff Roberson 		return (-1);
49bb535300SJeff Roberson 	else
5037a6356bSDavid Xu 		return (_pthread_equal(_pthread_self(), _thr_initial) ? 1 : 0);
51bb535300SJeff Roberson }
52