Explorar o código

gamemode: Optimize detection of dupe registers

GameMode can do a pretty expensive lookup function now for the exe.
Let's spare some CPU cycles by detecting a duplicate PID early. Nothing
makes use of the exe path at this stage.

Signed-off-by: Kai Krakow <kai@kaishome.de>
Kai Krakow %!s(int64=6) %!d(string=hai) anos
pai
achega
8214f93630
Modificáronse 1 ficheiros con 6 adicións e 3 borrados
  1. 6 3
      daemon/gamemode.c

+ 6 - 3
daemon/gamemode.c

@@ -454,15 +454,18 @@ bool game_mode_context_register(GameModeContext *self, pid_t client)
 		fputs("OOM\n", stderr);
 		return false;
 	}
-	cl->executable = game_mode_context_find_exe(client);
-	if (!cl->executable)
-		goto error_cleanup;
 
+	/* Check the PID first to spare a potentially expensive lookup for the exe */
 	if (game_mode_context_has_client(self, client)) {
 		LOG_ERROR("Addition requested for already known process [%d]\n", client);
 		goto error_cleanup;
 	}
 
+	/* Lookup the executable */
+	cl->executable = game_mode_context_find_exe(client);
+	if (!cl->executable)
+		goto error_cleanup;
+
 	/* Check our blacklist and whitelist */
 	if (!config_get_client_whitelisted(self->config, cl->executable)) {
 		LOG_MSG("Client [%s] was rejected (not in whitelist)\n", cl->executable);