Skip to content

Commit 81a33f0

Browse files
committed
refactor: removed some useless member from TimeTaskData
1 parent ea79585 commit 81a33f0

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

src/legacy/engine/TimeTaskSystem.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,13 @@ std::atomic_uint timeTaskId = 0;
1515
std::mutex locker;
1616

1717
struct TimeTaskData {
18-
uint64 taskId;
1918
script::Global<Function> func;
2019
std::vector<script::Global<Value>> paras;
2120
script::Global<String> code;
2221
ScriptEngine* engine;
23-
inline void swap(TimeTaskData& rhs) {
24-
std::swap(rhs.taskId, taskId);
25-
std::swap(rhs.engine, engine);
26-
rhs.code.swap(code);
27-
rhs.paras.swap(paras);
28-
rhs.func.swap(func);
29-
}
3022
};
3123

32-
std::unordered_map<int, TimeTaskData> timeTaskMap;
24+
std::unordered_map<uint64, ScriptEngine*> timeTaskMap;
3325

3426
#define TIMETASK_CATCH(TASK_TYPE) \
3527
catch (const Exception& e) { \
@@ -77,7 +69,7 @@ int NewTimeout(Local<Function> func, std::vector<Local<Value>> paras, int timeou
7769
}).launch(ll::thread::ServerThreadExecutor::getDefault());
7870

7971
std::lock_guard lock(locker);
80-
timeTaskMap[tid] = data;
72+
timeTaskMap[tid] = data.engine;
8173
return tid;
8274
}
8375

@@ -105,7 +97,7 @@ int NewTimeout(Local<String> func, int timeout) {
10597
}).launch(ll::thread::ServerThreadExecutor::getDefault());
10698

10799
std::lock_guard lock(locker);
108-
timeTaskMap[tid] = data;
100+
timeTaskMap[tid] = data.engine;
109101
return tid;
110102
}
111103

@@ -146,7 +138,7 @@ int NewInterval(Local<Function> func, std::vector<Local<Value>> paras, int timeo
146138
}).launch(ll::thread::ServerThreadExecutor::getDefault());
147139

148140
std::lock_guard lock(locker);
149-
timeTaskMap[tid] = data;
141+
timeTaskMap[tid] = data.engine;
150142
return tid;
151143
}
152144

@@ -179,7 +171,7 @@ int NewInterval(Local<String> func, int timeout) {
179171
}).launch(ll::thread::ServerThreadExecutor::getDefault());
180172

181173
std::lock_guard lock(locker);
182-
timeTaskMap[tid] = data;
174+
timeTaskMap[tid] = data.engine;
183175
return tid;
184176
}
185177

@@ -202,11 +194,12 @@ bool ClearTimeTask(int const& id) {
202194
}
203195

204196
void LLSERemoveTimeTaskData(ScriptEngine* engine) {
197+
// enter scope to prevent script::Global::~Global() from crashing
205198
EngineScope enter(engine);
206199
try {
207200
std::lock_guard lock(locker);
208201
for (auto it = timeTaskMap.begin(); it != timeTaskMap.end();) {
209-
if (it->second.engine == engine) {
202+
if (it->second == engine) {
210203
it = timeTaskMap.erase(it);
211204
} else {
212205
++it;

0 commit comments

Comments
 (0)