CNDP  22.08.0
cthread.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2019-2022 Intel Corporation
3  */
4 
5 /*
6  * Some portions of this software is derived from the
7  * https://github.com/halayli/lthread which carrys the following license.
8  *
9  * Copyright (c) 2012, Hasan Alayli <halayli@gmail.com>
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in the
18  * documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32 
33 #ifndef _CTHREAD_H_
34 #define _CTHREAD_H_
35 
36 #include <cne_atomic.h>
37 #include <bsd/string.h>
38 
39 #include <cne_per_thread.h>
40 #include <cne_system.h>
41 #include <cne_timer.h>
42 
43 #include <cthread_api.h>
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 struct cthread;
50 struct cthread_sched;
51 
52 /* function to be called when a context function returns */
53 typedef void (*cthread_exit_func)(struct cthread *);
54 
55 void _cthread_exit_handler(struct cthread *ct);
56 
57 void _cthread_sched_busy_sleep(struct cthread *ct, uint64_t nsecs);
58 
59 int _cthread_desched_sleep(struct cthread *ct);
60 
61 void _cthread_free(struct cthread *ct);
62 
63 struct cthread_stack *_stack_alloc(void);
64 
65 void _stack_free(struct cthread_stack *s);
66 
67 void cthread_list(FILE *f, int tid);
68 
69 int cthread_id_get(struct cthread *c);
70 
71 #ifdef __cplusplus
72 }
73 #endif
74 
75 #endif /* _CTHREAD_H_ */