mirror of
https://github.com/FeralInteractive/gamemode.git
synced 2025-08-06 05:08:29 +02:00
Apply clang format to files
Also add brackets for all scopes at the same time
This commit is contained in:
@@ -29,8 +29,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
#include "gamemode.h"
|
||||
#include "logging.h"
|
||||
#include "governors.h"
|
||||
#include "logging.h"
|
||||
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
@@ -49,8 +49,8 @@ static void start_alarm_timer();
|
||||
// Must be called after init_game_mode
|
||||
static void enter_game_mode()
|
||||
{
|
||||
LOG_MSG( "Entering Game Mode...\n" );
|
||||
set_governors( "performance" );
|
||||
LOG_MSG("Entering Game Mode...\n");
|
||||
set_governors("performance");
|
||||
|
||||
// Set up the alarm callback
|
||||
start_alarm_timer();
|
||||
@@ -60,45 +60,45 @@ static void enter_game_mode()
|
||||
// Must be called after an equivelant call to enter_game_mode
|
||||
static void leave_game_mode()
|
||||
{
|
||||
LOG_MSG( "Leaving Game Mode...\n" );
|
||||
set_governors( NULL );
|
||||
LOG_MSG("Leaving Game Mode...\n");
|
||||
set_governors(NULL);
|
||||
}
|
||||
|
||||
// Set up an alarm callback to check for current process ids
|
||||
static void alarm_handler( int sig )
|
||||
static void alarm_handler(int sig)
|
||||
{
|
||||
// Quick return if no games, and don't register another callback
|
||||
if( num_games == 0 )
|
||||
if (num_games == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if games are alive at all
|
||||
for( int i = 0; i < num_games; )
|
||||
{
|
||||
for (int i = 0; i < num_games;) {
|
||||
int game = game_pids[i];
|
||||
|
||||
if( kill( game, 0 ) != 0 )
|
||||
{
|
||||
LOG_MSG( "Removing expired game [%i]...\n", game );
|
||||
memmove( &game_pids[i], &game_pids[i+1], MAX_GAMES - (i+1) );
|
||||
if (kill(game, 0) != 0) {
|
||||
LOG_MSG("Removing expired game [%i]...\n", game);
|
||||
memmove(&game_pids[i], &game_pids[i + 1], MAX_GAMES - (i + 1));
|
||||
num_games--;
|
||||
}
|
||||
else
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
// Either trigger another alarm, or reset the governors
|
||||
if( num_games )
|
||||
if (num_games) {
|
||||
start_alarm_timer();
|
||||
else
|
||||
} else {
|
||||
leave_game_mode();
|
||||
}
|
||||
}
|
||||
|
||||
// Call to trigger starting the alarm timer for pid checks
|
||||
static void start_alarm_timer()
|
||||
{
|
||||
// Set up process check alarms
|
||||
signal( SIGALRM, alarm_handler );
|
||||
alarm( wakeup_timer );
|
||||
signal(SIGALRM, alarm_handler);
|
||||
alarm(wakeup_timer);
|
||||
}
|
||||
|
||||
// Intialise any game mode needs
|
||||
@@ -106,72 +106,68 @@ void init_game_mode()
|
||||
{
|
||||
// Read current governer state before setting up any message handling
|
||||
update_initial_gov_state();
|
||||
LOG_MSG( "governor is set to [%s]\n", get_initial_governor() );
|
||||
LOG_MSG("governor is set to [%s]\n", get_initial_governor());
|
||||
}
|
||||
|
||||
// Called on exit to clean up the governors if appropriate
|
||||
void term_game_mode()
|
||||
{
|
||||
if( num_games )
|
||||
if (num_games) {
|
||||
leave_game_mode();
|
||||
}
|
||||
}
|
||||
|
||||
// Register a game pid with the game mode
|
||||
// Will trigger enter game mode if appropriate
|
||||
void register_game( int pid )
|
||||
void register_game(int pid)
|
||||
{
|
||||
// Check for duplicates
|
||||
for( int i = 0; i < num_games; i++ )
|
||||
{
|
||||
if( game_pids[i] == pid )
|
||||
{
|
||||
LOG_ERROR( "Addition requested for already known process [%i]\n", pid );
|
||||
for (int i = 0; i < num_games; i++) {
|
||||
if (game_pids[i] == pid) {
|
||||
LOG_ERROR("Addition requested for already known process [%i]\n", pid);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Check we've not already hit max
|
||||
if( num_games == MAX_GAMES )
|
||||
{
|
||||
LOG_ERROR( "Max games (%i) reached, could not add [%i]\n", MAX_GAMES, pid );
|
||||
if (num_games == MAX_GAMES) {
|
||||
LOG_ERROR("Max games (%i) reached, could not add [%i]\n", MAX_GAMES, pid);
|
||||
return;
|
||||
}
|
||||
|
||||
// Add the game to the database
|
||||
LOG_MSG( "Adding game: %i\n", pid );
|
||||
LOG_MSG("Adding game: %i\n", pid);
|
||||
game_pids[num_games] = pid;
|
||||
num_games++;
|
||||
|
||||
if( num_games == 1 )
|
||||
if (num_games == 1) {
|
||||
enter_game_mode();
|
||||
}
|
||||
}
|
||||
|
||||
// Remove a game from game mode
|
||||
// Will exit game mode if appropriate
|
||||
void unregister_game( int pid )
|
||||
void unregister_game(int pid)
|
||||
{
|
||||
bool found = false;
|
||||
|
||||
// Check list even contains this entry
|
||||
for( int i = 0; i < num_games; i++ )
|
||||
{
|
||||
if( game_pids[i] == pid )
|
||||
{
|
||||
LOG_MSG( "Removing game: %i\n", pid );
|
||||
memmove( &game_pids[i], &game_pids[i+1], MAX_GAMES - (i+1) );
|
||||
for (int i = 0; i < num_games; i++) {
|
||||
if (game_pids[i] == pid) {
|
||||
LOG_MSG("Removing game: %i\n", pid);
|
||||
memmove(&game_pids[i], &game_pids[i + 1], MAX_GAMES - (i + 1));
|
||||
num_games--;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( !found )
|
||||
{
|
||||
LOG_ERROR( "Removal requested for unknown process [%i]\n", pid );
|
||||
if (!found) {
|
||||
LOG_ERROR("Removal requested for unknown process [%i]\n", pid);
|
||||
return;
|
||||
}
|
||||
|
||||
// Leave game mode if needed
|
||||
if( num_games == 0 )
|
||||
if (num_games == 0) {
|
||||
leave_game_mode();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user