comparison Platforms/Wasm/WasmDelayedCallExecutor.cpp @ 431:26b90b110719 am-vsol-upgrade

added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
author am@osimis.io
date Thu, 29 Nov 2018 19:25:15 +0100
parents
children 4f2416d519b4
comparison
equal deleted inserted replaced
430:b85f635f1eb5 431:26b90b110719
1 #include "WasmDelayedCallExecutor.h"
2 #include "json/value.h"
3 #include "json/writer.h"
4 #include <emscripten/emscripten.h>
5
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9
10 extern void WasmDelayedCallExecutor_Schedule(void* callable,
11 unsigned int timeoutInMs
12 /*void* payload*/);
13
14 void EMSCRIPTEN_KEEPALIVE WasmDelayedCallExecutor_ExecuteCallback(void* callable
15 //void* payload
16 )
17 {
18 if (callable == NULL)
19 {
20 throw;
21 }
22 else
23 {
24 reinterpret_cast<OrthancStone::MessageHandler<OrthancStone::IDelayedCallExecutor::TimeoutMessage>*>(callable)->
25 Apply(OrthancStone::IDelayedCallExecutor::TimeoutMessage()); // uri, reinterpret_cast<Orthanc::IDynamicObject*>(payload)));
26 }
27 }
28
29
30 #ifdef __cplusplus
31 }
32 #endif
33
34
35
36 namespace OrthancStone
37 {
38 MessageBroker* WasmDelayedCallExecutor::broker_ = NULL;
39
40
41 void WasmDelayedCallExecutor::Schedule(MessageHandler<IDelayedCallExecutor::TimeoutMessage>* callback,
42 unsigned int timeoutInMs)
43 {
44 WasmDelayedCallExecutor_Schedule(callback, timeoutInMs);
45 }
46 }