xref: /freebsd-src/lib/libthr/thread/thr_concurrency.c (revision f8bbbce458194ff4312c610d32a64ff4a3a71d45)
1*df57947fSPedro F. Giffuni /*-
2*df57947fSPedro F. Giffuni  * SPDX-License-Identifier: BSD-4-Clause
3*df57947fSPedro F. Giffuni  *
48c0d4b5fSJohn Polstra  * Copyright (c) 2003 Sergey Osokin <osa@FreeBSD.org.ru>.
58c0d4b5fSJohn Polstra  * All rights reserved.
68c0d4b5fSJohn Polstra  *
78c0d4b5fSJohn Polstra  * Redistribution and use in source and binary forms, with or without
88c0d4b5fSJohn Polstra  * modification, are permitted provided that the following conditions
98c0d4b5fSJohn Polstra  * are met:
108c0d4b5fSJohn Polstra  * 1. Redistributions of source code must retain the above copyright
118c0d4b5fSJohn Polstra  *    notice, this list of conditions and the following disclaimer.
128c0d4b5fSJohn Polstra  * 2. Redistributions in binary form must reproduce the above copyright
138c0d4b5fSJohn Polstra  *    notice, this list of conditions and the following disclaimer in the
148c0d4b5fSJohn Polstra  *    documentation and/or other materials provided with the distribution.
158c0d4b5fSJohn Polstra  * 3. All advertising materials mentioning features or use of this software
168c0d4b5fSJohn Polstra  *    must display the following acknowledgement:
178c0d4b5fSJohn Polstra  *      This product includes software developed by Sergey Osokin.
188c0d4b5fSJohn Polstra  * 4. Neither the name of the author nor the names of any co-contributors
198c0d4b5fSJohn Polstra  *    may be used to endorse or promote products derived from this software
208c0d4b5fSJohn Polstra  *    without specific prior written permission.
218c0d4b5fSJohn Polstra  *
228c0d4b5fSJohn Polstra  * THIS SOFTWARE IS PROVIDED BY SERGEY OSOKIN AND CONTRIBUTORS ``AS IS'' AND
238c0d4b5fSJohn Polstra  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
248c0d4b5fSJohn Polstra  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
258c0d4b5fSJohn Polstra  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
268c0d4b5fSJohn Polstra  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
278c0d4b5fSJohn Polstra  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
288c0d4b5fSJohn Polstra  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
298c0d4b5fSJohn Polstra  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
308c0d4b5fSJohn Polstra  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
318c0d4b5fSJohn Polstra  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
328c0d4b5fSJohn Polstra  * SUCH DAMAGE.
338c0d4b5fSJohn Polstra  */
348c0d4b5fSJohn Polstra 
3537a6356bSDavid Xu #include "namespace.h"
368c0d4b5fSJohn Polstra #include <errno.h>
37a091d823SDavid Xu #include <pthread.h>
3837a6356bSDavid Xu #include "un-namespace.h"
39a091d823SDavid Xu 
40a091d823SDavid Xu #include "thr_private.h"
418c0d4b5fSJohn Polstra 
428c0d4b5fSJohn Polstra static int current_concurrency = 0;
438c0d4b5fSJohn Polstra 
448c0d4b5fSJohn Polstra __weak_reference(_pthread_getconcurrency, pthread_getconcurrency);
458c0d4b5fSJohn Polstra __weak_reference(_pthread_setconcurrency, pthread_setconcurrency);
468c0d4b5fSJohn Polstra 
478c0d4b5fSJohn Polstra int
_pthread_getconcurrency(void)488c0d4b5fSJohn Polstra _pthread_getconcurrency(void)
498c0d4b5fSJohn Polstra {
508c0d4b5fSJohn Polstra 	return current_concurrency;
518c0d4b5fSJohn Polstra }
528c0d4b5fSJohn Polstra 
538c0d4b5fSJohn Polstra int
_pthread_setconcurrency(int new_level)548c0d4b5fSJohn Polstra _pthread_setconcurrency(int new_level)
558c0d4b5fSJohn Polstra {
568c0d4b5fSJohn Polstra 	int ret;
578c0d4b5fSJohn Polstra 
588c0d4b5fSJohn Polstra 	if (new_level < 0) {
598c0d4b5fSJohn Polstra 		ret = EINVAL;
608c0d4b5fSJohn Polstra 	} else {
618c0d4b5fSJohn Polstra 		current_concurrency = new_level;
628c0d4b5fSJohn Polstra 		ret = 0;
638c0d4b5fSJohn Polstra 	}
648c0d4b5fSJohn Polstra 	return (ret);
658c0d4b5fSJohn Polstra }
66