1a9643ea8Slogwang /*-
2a9643ea8Slogwang  *   BSD LICENSE
3a9643ea8Slogwang  *
4a9643ea8Slogwang  *   Copyright(c) 2015 Intel Corporation. All rights reserved.
5a9643ea8Slogwang  *   All rights reserved.
6a9643ea8Slogwang  *
7a9643ea8Slogwang  *   Redistribution and use in source and binary forms, with or without
8a9643ea8Slogwang  *   modification, are permitted provided that the following conditions
9a9643ea8Slogwang  *   are met:
10a9643ea8Slogwang  *
11a9643ea8Slogwang  *     * Redistributions of source code must retain the above copyright
12a9643ea8Slogwang  *       notice, this list of conditions and the following disclaimer.
13a9643ea8Slogwang  *     * Redistributions in binary form must reproduce the above copyright
14a9643ea8Slogwang  *       notice, this list of conditions and the following disclaimer in
15a9643ea8Slogwang  *       the documentation and/or other materials provided with the
16a9643ea8Slogwang  *       distribution.
17a9643ea8Slogwang  *     * Neither the name of Intel Corporation nor the names of its
18a9643ea8Slogwang  *       contributors may be used to endorse or promote products derived
19a9643ea8Slogwang  *       from this software without specific prior written permission.
20a9643ea8Slogwang  *
21a9643ea8Slogwang  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22a9643ea8Slogwang  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23a9643ea8Slogwang  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24a9643ea8Slogwang  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25a9643ea8Slogwang  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26a9643ea8Slogwang  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27a9643ea8Slogwang  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28a9643ea8Slogwang  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29a9643ea8Slogwang  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30a9643ea8Slogwang  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31a9643ea8Slogwang  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32a9643ea8Slogwang  */
33a9643ea8Slogwang 
34a9643ea8Slogwang /*
35a9643ea8Slogwang  * Some portions of this software is derived from the
36a9643ea8Slogwang  * https://github.com/halayli/lthread which carrys the following license.
37a9643ea8Slogwang  *
38a9643ea8Slogwang  * Copyright (C) 2012, Hasan Alayli <[email protected]>
39a9643ea8Slogwang  *
40a9643ea8Slogwang  * Redistribution and use in source and binary forms, with or without
41a9643ea8Slogwang  * modification, are permitted provided that the following conditions
42a9643ea8Slogwang  * are met:
43a9643ea8Slogwang  * 1. Redistributions of source code must retain the above copyright
44a9643ea8Slogwang  *    notice, this list of conditions and the following disclaimer.
45a9643ea8Slogwang  * 2. Redistributions in binary form must reproduce the above copyright
46a9643ea8Slogwang  *    notice, this list of conditions and the following disclaimer in the
47a9643ea8Slogwang  *    documentation and/or other materials provided with the distribution.
48a9643ea8Slogwang  *
49a9643ea8Slogwang  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
50a9643ea8Slogwang  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51a9643ea8Slogwang  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52a9643ea8Slogwang  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
53a9643ea8Slogwang  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54a9643ea8Slogwang  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55a9643ea8Slogwang  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56a9643ea8Slogwang  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57a9643ea8Slogwang  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58a9643ea8Slogwang  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59a9643ea8Slogwang  * SUCH DAMAGE.
60a9643ea8Slogwang  */
61a9643ea8Slogwang 
62a9643ea8Slogwang #ifndef LTHREAD_H_
63a9643ea8Slogwang #define LTHREAD_H_
64a9643ea8Slogwang 
65*2bfe3f2eSlogwang #ifdef __cplusplus
66*2bfe3f2eSlogwang extern "C" {
67*2bfe3f2eSlogwang #endif
68*2bfe3f2eSlogwang 
69a9643ea8Slogwang #include <rte_per_lcore.h>
70a9643ea8Slogwang 
71a9643ea8Slogwang #include "lthread_api.h"
72a9643ea8Slogwang #include "lthread_diag.h"
73a9643ea8Slogwang 
74a9643ea8Slogwang struct lthread;
75a9643ea8Slogwang struct lthread_sched;
76a9643ea8Slogwang 
77a9643ea8Slogwang /* function to be called when a context function returns */
78a9643ea8Slogwang typedef void (*lthread_exit_func) (struct lthread *);
79a9643ea8Slogwang 
80a9643ea8Slogwang void _lthread_exit_handler(struct lthread *lt);
81a9643ea8Slogwang 
82a9643ea8Slogwang void lthread_set_funcname(const char *f);
83a9643ea8Slogwang 
84a9643ea8Slogwang void _lthread_sched_busy_sleep(struct lthread *lt, uint64_t nsecs);
85a9643ea8Slogwang 
86a9643ea8Slogwang int _lthread_desched_sleep(struct lthread *lt);
87a9643ea8Slogwang 
88a9643ea8Slogwang void _lthread_free(struct lthread *lt);
89a9643ea8Slogwang 
90*2bfe3f2eSlogwang struct lthread_sched *_lthread_sched_get(unsigned int lcore_id);
91a9643ea8Slogwang 
92a9643ea8Slogwang struct lthread_stack *_stack_alloc(void);
93a9643ea8Slogwang 
94a9643ea8Slogwang struct
95a9643ea8Slogwang lthread_sched *_lthread_sched_create(size_t stack_size);
96a9643ea8Slogwang 
97a9643ea8Slogwang void
98a9643ea8Slogwang _lthread_init(struct lthread *lt,
99a9643ea8Slogwang 	      lthread_func_t fun, void *arg, lthread_exit_func exit_handler);
100a9643ea8Slogwang 
101a9643ea8Slogwang void _lthread_set_stack(struct lthread *lt, void *stack, size_t stack_size);
102a9643ea8Slogwang 
103*2bfe3f2eSlogwang #ifdef __cplusplus
104*2bfe3f2eSlogwang }
105*2bfe3f2eSlogwang #endif
106*2bfe3f2eSlogwang 
107a9643ea8Slogwang #endif				/* LTHREAD_H_ */
108