From: Steinar H. Gunderson Date: Sat, 6 Apr 2013 13:29:11 +0000 (+0200) Subject: Fire off worker threads (that do nothing right now). X-Git-Tag: 1.0.0~225 X-Git-Url: https://git.sesse.net/?p=cubemap;a=commitdiff_plain;h=418ca367be670db5377ca99462906eb9c73d296b;hp=0a1c3b53713cdacc94c43ae1afb955468fff570f Fire off worker threads (that do nothing right now). --- diff --git a/cubemap.cpp b/cubemap.cpp index 6095ce5..9f5e42e 100644 --- a/cubemap.cpp +++ b/cubemap.cpp @@ -77,15 +77,52 @@ struct Stream { class Server { public: + Server(); + + // Start a new thread that handles clients. + void run(); void add_socket(int server_sock); void add_stream(const string &stream_id); void set_header(const string &stream_id, const string &header); void add_data(const string &stream_id, const char *data, size_t bytes); private: + pthread_mutex_t mutex; map streams; + + // Recover the this pointer, and call do_work(). + static void *do_work_thunk(void *arg); + + // The actual worker thread. + void do_work(); }; +Server::Server() +{ + pthread_mutex_init(&mutex, NULL); +} + +void Server::run() +{ + pthread_t thread; + pthread_create(&thread, NULL, Server::do_work_thunk, this); +} + +void *Server::do_work_thunk(void *arg) +{ + Server *server = static_cast(arg); + server->do_work(); + return NULL; +} + +void Server::do_work() +{ + for ( ;; ) { + printf("server thread running\n"); + sleep(1); + } +} + class Input { public: Input(); @@ -168,7 +205,7 @@ void Input::process_block(const char *data, uint32_t size, uint32_t flags) // TODO: treat it right here printf("Block: %d bytes, flags=0x%x\n", size, flags); } - + void Input::drop_pending_data(size_t num_bytes) { if (num_bytes == 0) { @@ -240,11 +277,13 @@ void *acceptor_thread_run(void *arg) } } +Server *servers = NULL; + int main(int argc, char **argv) { + servers = new Server[NUM_SERVERS]; for (int i = 0; i < NUM_SERVERS; ++i) { - Server *s = new Server; - //s->run(); + servers[i].run(); } int server_sock = create_server_socket(PORT);