4 * Copyright(c) 2015 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef _PTHREAD_SHIM_H_
35 #define _PTHREAD_SHIM_H_
37 #include <rte_lcore.h>
40 * This pthread shim is an example that demonstrates how legacy code
41 * that makes use of POSIX pthread services can make use of lthreads
42 * with reduced porting effort.
44 * N.B. The example is not a complete implementation, only a subset of
45 * pthread APIs sufficient to demonstrate the principle of operation
48 * In general pthread attribute objects do not have equivalent functions
49 * in lthreads, and are ignored.
51 * There is one exception and that is the use of attr to specify a
52 * core affinity in calls to pthread_create.
54 * The shim operates as follows:-
56 * On initialisation a constructor function uses dlsym to obtain and
57 * save the loaded address of the full set of pthread APIs that will
60 * For each function there is a stub provided that will invoke either
61 * the genuine pthread library function saved saved by the constructor,
62 * or else the corresponding equivalent lthread function.
64 * The stub functions are implemented in pthread_shim.c
66 * The stub will take care of adapting parameters, and any police
67 * any constraints where lthread functionality differs.
69 * The initial thread must always be a pure lthread.
71 * The decision whether to invoke the real library function or the lthread
72 * function is controlled by a per pthread flag that can be switched
73 * on of off by the pthread_override_set() API described below. Typcially
74 * this should be done as the first action of the initial lthread.
76 * N.B In general it would be poor practice to revert to invoke a real
77 * pthread function when running as an lthread, since these may block and
78 * effectively stall the lthread scheduler.
84 * An exiting lthread must not terminate the pthread it is running in
85 * since this would mean terminating the lthread scheduler.
86 * We override pthread_exit() with a macro because it is typically declared with
87 * __attribute__((noreturn))
89 void pthread_exit_override(void *v);
91 #define pthread_exit(v) do { \
92 pthread_exit_override((v)); \
97 * Enable/Disable pthread override
102 void pthread_override_set(int state);
106 * Return pthread override state
111 int pthread_override_get(void);
114 #endif /* _PTHREAD_SHIM_H_ */