mirror of
https://github.com/FeralInteractive/gamemode.git
synced 2025-08-05 20:58:29 +02:00
Add gamemode_query_status and teach gamemoded '-s'
This allows the client to query the daemon about the status of gamemode. Returns the following: 0 if gamemode is inactive 1 if gamemode is active 2 if gamemode is active and this client is registered -1 if the query failed Passing -s to gamemoded will simply query and print the current status. Allows for more comprehensive testing when using 'gamemoded -r' as well as more reactionary program behaviour
This commit is contained in:
@@ -366,6 +366,40 @@ bool game_mode_context_unregister(GameModeContext *self, pid_t client)
|
||||
return true;
|
||||
}
|
||||
|
||||
int game_mode_context_query_status(GameModeContext *self, pid_t client)
|
||||
{
|
||||
GameModeClient *cl = NULL;
|
||||
int ret = 0;
|
||||
|
||||
/*
|
||||
* Check the current refcount on gamemode, this equates to whether gamemode is active or not,
|
||||
* see game_mode_context_register and game_mode_context_unregister
|
||||
*/
|
||||
if (atomic_load_explicit(&self->refcount, memory_order_seq_cst)) {
|
||||
ret++;
|
||||
|
||||
/* Check if the current client is registered */
|
||||
|
||||
/* Requires locking. */
|
||||
pthread_rwlock_rdlock(&self->rwlock);
|
||||
|
||||
for (cl = self->client; cl; cl = cl->next) {
|
||||
if (cl->pid != client) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Found it */
|
||||
ret++;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Unlock here, potentially yielding */
|
||||
pthread_rwlock_unlock(&self->rwlock);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new GameModeClient for the given process ID
|
||||
*
|
||||
|
Reference in New Issue
Block a user