mirror of
https://github.com/FeralInteractive/gamemode.git
synced 2025-06-07 16:17:23 +02:00
gamemode: Convert game_mode_context_has_client() to return the client
Returning a bool is not useful if we want to create some log information from this. It now returns NULL or a client pointer which is compatible with all of the current users. When dereferencing the returned pointer, a read lock must be acquired around using the returned result as the client may be deallocated from heap otherwise. Signed-off-by: Kai Krakow <kai@kaishome.de>
This commit is contained in:
parent
d023495a5d
commit
fd4166279b
@ -131,7 +131,7 @@ static volatile bool had_context_init = false;
|
|||||||
|
|
||||||
static GameModeClient *game_mode_client_new(pid_t pid, char *exe);
|
static GameModeClient *game_mode_client_new(pid_t pid, char *exe);
|
||||||
static void game_mode_client_free(GameModeClient *client);
|
static void game_mode_client_free(GameModeClient *client);
|
||||||
static bool game_mode_context_has_client(GameModeContext *self, pid_t client);
|
static const GameModeClient *game_mode_context_has_client(GameModeContext *self, pid_t client);
|
||||||
static int game_mode_context_num_clients(GameModeContext *self);
|
static int game_mode_context_num_clients(GameModeContext *self);
|
||||||
static void *game_mode_context_reaper(void *userdata);
|
static void *game_mode_context_reaper(void *userdata);
|
||||||
static void game_mode_context_enter(GameModeContext *self);
|
static void game_mode_context_enter(GameModeContext *self);
|
||||||
@ -439,15 +439,15 @@ static void game_mode_context_auto_expire(GameModeContext *self)
|
|||||||
/**
|
/**
|
||||||
* Determine if the client is already known to the context
|
* Determine if the client is already known to the context
|
||||||
*/
|
*/
|
||||||
static bool game_mode_context_has_client(GameModeContext *self, pid_t client)
|
static const GameModeClient *game_mode_context_has_client(GameModeContext *self, pid_t client)
|
||||||
{
|
{
|
||||||
bool found = false;
|
const GameModeClient *found = NULL;
|
||||||
pthread_rwlock_rdlock(&self->rwlock);
|
pthread_rwlock_rdlock(&self->rwlock);
|
||||||
|
|
||||||
/* Walk all clients and find a matching pid */
|
/* Walk all clients and find a matching pid */
|
||||||
for (GameModeClient *cl = self->client; cl; cl = cl->next) {
|
for (GameModeClient *cl = self->client; cl; cl = cl->next) {
|
||||||
if (cl->pid == client) {
|
if (cl->pid == client) {
|
||||||
found = true;
|
found = cl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user