-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmanticore-3.6.0-e2k.patch
153 lines (141 loc) · 4.18 KB
/
manticore-3.6.0-e2k.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
From 1e81413bb6f7821b4ae091e7283c2bc5e7f510cb Mon Sep 17 00:00:00 2001
From: Ilya Kurdyukov <[email protected]>
Date: Tue, 31 Aug 2021 16:52:12 +0700
Subject: [PATCH] manticore-3.6.0 e2k support
---
src/coroutine.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++-
src/searchd.cpp | 2 +-
2 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/src/coroutine.cpp b/src/coroutine.cpp
index 5dd688f..068a143 100644
--- a/src/coroutine.cpp
+++ b/src/coroutine.cpp
@@ -24,7 +24,18 @@
#endif
#endif
+#ifdef __e2k__
+#define USE_UCONTEXT
+#endif
+
+#ifdef USE_UCONTEXT
+#ifdef BOOST_USE_VALGRIND
+#undef BOOST_USE_VALGRIND
+#endif
+#include <ucontext.h>
+#else
#include <boost/context/detail/fcontext.hpp>
+#endif
#if BOOST_USE_VALGRIND
#include <valgrind/valgrind.h>
@@ -53,7 +64,9 @@ size_t GetDefaultCoroStackSize()
//////////////////////////////////////////////////////////////
/// Coroutine - uses boost::context to switch between jobs
+#ifndef USE_UCONTEXT
using namespace boost::context::detail;
+#endif
class CoRoutine_c
{
enum class State_e
@@ -70,15 +83,27 @@ class CoRoutine_c
unsigned m_uValgrindStackID = 0;
#endif
+#ifdef USE_UCONTEXT
+ using Ctx_t = ucontext_t;
+#else
using Ctx_t = fcontext_t;
+#endif
Ctx_t m_tCoroutineContext;
Ctx_t m_tExternalContext;
friend StringBuilder_c & operator<< ( StringBuilder_c &, CoRoutine_c::State_e);
private:
+#ifdef USE_UCONTEXT
+ static void ucontext_wrapper( CoRoutine_c *data ) {
+ data->WorkerLowest ();
+ }
+ void WorkerLowest ()
+ {
+#else
void WorkerLowest ( Ctx_t tCtx )
{
m_tExternalContext = tCtx;
+#endif
m_eState = State_e::Running;
m_fnHandler ();
m_eState = State_e::Finished;
@@ -88,7 +113,12 @@ private:
// goto back to external context
void YieldLowest ()
{
+#ifdef USE_UCONTEXT
+ int swapcontext_ret = swapcontext ( &m_tCoroutineContext, &m_tExternalContext );
+ assert ( swapcontext_ret >= 0 );
+#else
m_tExternalContext = jump_fcontext ( m_tExternalContext, nullptr ).fctx;
+#endif
}
inline void ValgrindRegisterStack()
@@ -111,10 +141,25 @@ private:
{
m_fnHandler = std::move ( fnHandler );
m_dStack = dStack;
+#ifdef USE_UCONTEXT
+ int getcontext_ret = getcontext ( &m_tCoroutineContext );
+ assert ( getcontext_ret >= 0 );
+ m_tCoroutineContext.uc_stack.ss_sp = m_dStack.begin ();
+ m_tCoroutineContext.uc_stack.ss_size = m_dStack.GetLength ();
+ m_tCoroutineContext.uc_stack.ss_flags = 0;
+ m_tCoroutineContext.uc_link = nullptr;
+#ifdef __e2k__
+ int makecontext_ret = makecontext_e2k ( &m_tCoroutineContext, (void(*)())ucontext_wrapper, 1, this );
+ assert ( makecontext_ret >= 0 );
+#else
+ makecontext (&m_tCoroutineContext, (void(*)())ucontext_wrapper, 1, this);
+#endif
+#else
ValgrindRegisterStack ();
m_tCoroutineContext = make_fcontext ( &m_dStack.Last (), m_dStack.GetLength (), [] ( transfer_t pT ) {
static_cast<CoRoutine_c *>(pT.data)->WorkerLowest ( pT.fctx );
} );
+#endif
}
public:
@@ -129,7 +174,12 @@ public:
CreateContext ( std::move ( fnHandler ), dStack );
}
-#if BOOST_USE_VALGRIND
+#ifdef __e2k
+ ~CoRoutine_c()
+ {
+ freecontext_e2k( &m_tCoroutineContext );
+ }
+#elif BOOST_USE_VALGRIND
~CoRoutine_c()
{
ValgrindDeregisterStack ();
@@ -140,7 +190,12 @@ public:
{
LOG( DEBUGV, CORO ) << "Run";
assert ( m_eState==State_e::Paused );
+#ifdef USE_UCONTEXT
+ int swapcontext_ret = swapcontext ( &m_tExternalContext, &m_tCoroutineContext );
+ assert ( swapcontext_ret >= 0 );
+#else
m_tCoroutineContext = jump_fcontext ( m_tCoroutineContext, static_cast<void*>(this) ).fctx;
+#endif
}
bool IsFinished () const
diff --git a/src/searchd.cpp b/src/searchd.cpp
index c66b437..2ca8b44 100644
--- a/src/searchd.cpp
+++ b/src/searchd.cpp
@@ -733,7 +733,7 @@ void Shutdown () REQUIRES ( MainThread ) NO_THREAD_SAFETY_ANALYSIS
// unlock indexes and release locks if needed
for ( RLockedServedIt_c it ( g_pLocalIndexes ); it.Next(); )
{
- auto pIdx = (const ServedDesc_t *) it.Get(); // breaks any access, but we're finishing, that's ok.
+ auto pIdx = (const ServedDesc_t *) (const ServedIndex_c *) it.Get(); // breaks any access, but we're finishing, that's ok.
if ( pIdx && pIdx->m_pIndex )
pIdx->m_pIndex->Unlock();
}
--
2.17.1