Add one stage pipeline to /ok
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "ThreadPipeline.h"
|
||||
#include "connection.hpp"
|
||||
#include "connection_handler.hpp"
|
||||
#include "perfetto_categories.hpp"
|
||||
#include "server.hpp"
|
||||
#include <llhttp.h>
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
|
||||
/**
|
||||
* HTTP routes supported by WeaselDB server.
|
||||
@@ -57,8 +61,34 @@ struct HttpConnectionState {
|
||||
* Supports the WeaselDB REST API endpoints with enum-based routing.
|
||||
*/
|
||||
class HttpHandler : public ConnectionHandler {
|
||||
ThreadPipeline<std::unique_ptr<Connection>> ok_pipeline{10, {1}};
|
||||
std::thread ok_thread{[this]() {
|
||||
pthread_setname_np(pthread_self(), "stage-0");
|
||||
for (;;) {
|
||||
auto guard = ok_pipeline.acquire(0, 0);
|
||||
for (auto &c : guard.batch) {
|
||||
if (!c) {
|
||||
return;
|
||||
}
|
||||
auto *state = static_cast<HttpConnectionState *>(c->user_data);
|
||||
TRACE_EVENT("http", "pipeline thread",
|
||||
perfetto::Flow::Global(state->request_id));
|
||||
Server::releaseBackToServer(std::move(c));
|
||||
}
|
||||
}
|
||||
}};
|
||||
|
||||
public:
|
||||
HttpHandler() = default;
|
||||
~HttpHandler() {
|
||||
{
|
||||
auto guard = ok_pipeline.push(1, true);
|
||||
for (auto &c : guard.batch) {
|
||||
c = {};
|
||||
}
|
||||
}
|
||||
ok_thread.join();
|
||||
}
|
||||
|
||||
void on_connection_established(Connection &conn) override;
|
||||
void on_connection_closed(Connection &conn) override;
|
||||
|
||||
Reference in New Issue
Block a user