summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2011-03-30 22:01:09 +0200
committerGravatar waker <wakeroid@gmail.com>2011-03-30 22:01:09 +0200
commitd995a2ec11a36793a4f143b2343a71343ddb2bb6 (patch)
tree5c264886ffa42273304b385c68eb8845f51aaa9f
parent8fdbe02975e7b7b8176e538c113a6c58db71624b (diff)
moved RPC server loop into separate thread, and added select with timeout for better RPC responsiveness
-rw-r--r--main.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/main.c b/main.c
index ae962c71..636542ac 100644
--- a/main.c
+++ b/main.c
@@ -63,9 +63,8 @@
#define USE_ABSTRACT_NAME 0
#endif
-#define trace(...) { fprintf(stderr, __VA_ARGS__); }
-//#define trace(fmt,...)
-
+//#define trace(...) { fprintf(stderr, __VA_ARGS__); }
+#define trace(fmt,...)
// some common global variables
char sys_install_path[PATH_MAX]; // see deadbeef->get_prefix
@@ -358,16 +357,34 @@ server_update (void) {
return 0;
}
+static uintptr_t server_tid;
+static int server_terminate;
+
void
-player_mainloop (void) {
- for (;;) {
- static int srvupd_count = 0;
- if (--srvupd_count <= 0) {
- srvupd_count = 10;
+server_loop (void *ctx) {
+ fd_set rds;
+ int ret;
+ struct timeval timeout = {0, 0};
+
+ FD_ZERO(&rds);
+ while (!server_terminate) {
+ FD_SET(srv_socket, &rds);
+ timeout.tv_usec = 50000;
+ if ((ret = select(srv_socket + 1, &rds, NULL, NULL, &timeout)) < 0 && errno != EINTR) {
+ perror("select");
+ exit (-1);
+ }
+ if (ret > 0) {
if (server_update () < 0) {
messagepump_push (M_TERMINATE, 0, 0, 0);
}
}
+ }
+}
+
+void
+player_mainloop (void) {
+ for (;;) {
uint32_t msg;
uintptr_t ctx;
uint32_t p1;
@@ -809,8 +826,15 @@ main (int argc, char *argv[]) {
restore_resume_state ();
}
+ server_tid = thread_start (server_loop, NULL);
// this runs in main thread (blocks right here)
player_mainloop ();
+ // terminate server and wait for completion
+ if (server_tid) {
+ server_terminate = 1;
+ thread_join (server_tid);
+ server_tid = 0;
+ }
save_resume_state ();