xref: /aosp_15_r20/external/virglrenderer/server/main.c (revision bbecb9d118dfdb95f99bd754f8fa9be01f189df3)
1 /*
2  * Copyright 2021 Google LLC
3  * SPDX-License-Identifier: MIT
4  */
5 
6 #include "render_context.h"
7 #include "render_server.h"
8 
9 /* The main process is the server process.  It enters render_server_main and
10  * never returns except on fatal errors.
11  *
12  * The server process supports only one connection currently.  It creates a
13  * render_client to manage the connection.  There is a client process at the
14  * other end of the connection.  When the client process requests a new
15  * context to be created, the server process creates a worker.  It also sets
16  * up a socket pair, with one end owned by the worker and the other end sent
17  * to and owned by the client process.
18  *
19  * A worker can be a subprocess forked from the server process, or a thread
20  * created by the server process.  When a worker is a subprocess, the
21  * subprocess returns from render_server_main and enters render_context_main.
22  *
23  * When a worker is a thread, the thread enters render_context_main directly
24  * from its start function.  In this case, render_context_main must be
25  * thread-safe.
26  */
27 int
main(int argc,char ** argv)28 main(int argc, char **argv)
29 {
30    render_log_init();
31 
32    struct render_context_args ctx_args;
33    bool ok = render_server_main(argc, argv, &ctx_args);
34 
35    /* this is a subprocess */
36    if (ok && ctx_args.valid)
37       ok = render_context_main(&ctx_args);
38 
39    return ok ? 0 : -1;
40 }
41