Per-thread defaultLoop and uWS::run()

This commit is contained in:
Alex Hultman
2018-09-15 04:50:07 +02:00
parent f82603fd73
commit 527089c621
6 changed files with 110 additions and 71 deletions
-50
View File
@@ -1,50 +0,0 @@
#ifndef HUB_H
#define HUB_H
// this header needs fixing! should not depend on source files!
#include "new_design/LoopData.h"
#include <libusockets.h>
// Loop is a bit different, it holds the loop pointer, not as "this"
namespace uWS {
struct Loop {
us_loop *loop;
static void wakeupCb(us_loop *loop) {
}
static void preCb(us_loop *loop) {
}
static void postCb(us_loop *loop) {
}
Loop() : loop(us_create_loop(1, wakeupCb, preCb, postCb, sizeof(LoopData))) {
new (us_loop_ext(loop)) LoopData();
}
void run() {
us_loop_run(loop);
}
~Loop() {
// deconstruct the loopdata
}
};
// dessa måste ligga i en sourcefil
thread_local Loop defaultLoop;
static void run() {
defaultLoop.run();
}
}
#endif // HUB_H