Crossfire Server, Trunk  R20513
Functions
swap.c File Reference

Functions that deal with swapping maps to disk to reclaim memory. More...

#include "global.h"
#include <string.h>
#include "object.h"
#include "output_file.h"
#include "sproto.h"
Include dependency graph for swap.c:

Go to the source code of this file.

Functions

void check_active_maps (void)
 Finds maps in memory to reset. More...
 
void flush_old_maps (void)
 Removes tmp-files of maps which are going to be reset next time they are visited. More...
 
static mapstructmap_least_timeout (const char *except_level)
 Returns the map with the lowest timeout variable (not 0). More...
 
int players_on_map (mapstruct *m, int show_all)
 Returns the count of players on a map, calculated from player list. More...
 
void read_map_log (void)
 Reads temporary maps information from disk. More...
 
void swap_below_max (const char *except_level)
 Tries to swap out maps which are still in memory, because of MAP_TIMEOUT until used objects is below MAX_OBJECTS or there are no more maps to swap. More...
 
int swap_map (mapstruct *map)
 Swaps a map to disk. More...
 
static void write_map_log (void)
 Writes out information on all the temporary maps. More...
 

Detailed Description

Functions that deal with swapping maps to disk to reclaim memory.

Definition in file swap.c.

Function Documentation

void check_active_maps ( void  )

Finds maps in memory to reset.

Todo:
The check for MAX_OBJECTS_LWM is wrongly placed, and should be moved elsewhere.

Definition at line 195 of file swap.c.

References first_map, mapdef::in_memory, MAP_IN_MEMORY, mapdef::next, swap_map(), and mapdef::timeout.

Referenced by server_main().

Here is the call graph for this function:

Here is the caller graph for this function:

void flush_old_maps ( void  )

Removes tmp-files of maps which are going to be reset next time they are visited.

This is very useful if the tmp-disk is very full.

Definition at line 294 of file swap.c.

References clean_tmp_map(), delete_map(), EVENT_MAPRESET, execute_global_event(), first_map, mapdef::in_memory, mapdef::is_template, llevDebug, LOG(), MAP_IN_MEMORY, MAP_SWAPPED, mapdef::next, mapdef::path, players_on_map(), seconds(), set_map_timeout(), mapdef::timeout, mapdef::tmpname, TRUE, and mapdef::unique.

Referenced by block_until_new_connection(), command_reset(), and do_specials().

Here is the call graph for this function:

Here is the caller graph for this function:

static mapstruct* map_least_timeout ( const char *  except_level)
static

Returns the map with the lowest timeout variable (not 0).

Parameters
except_levelpath of map to ignore for reset. Musn't be NULL.
Returns
map, or NULL if no map is ready for reset.

Definition at line 221 of file swap.c.

References first_map, mapdef::in_memory, MAP_IN_MEMORY, MAP_MAXTIMEOUT, mapdef::next, mapdef::path, and mapdef::timeout.

Referenced by swap_below_max().

Here is the caller graph for this function:

int players_on_map ( mapstruct m,
int  show_all 
)

Returns the count of players on a map, calculated from player list.

Parameters
mmap we want the count of players on.
show_allif true, show everyone. If not, don't show hidden players (dms)
Returns
player count.
Todo:
this doesn't take into account transports. Should be removed when mapstruct::players is valid.

Definition at line 276 of file swap.c.

References first_player, FLAG_REMOVED, pl::hidden, obj::map, pl::next, pl::ob, and QUERY_FLAG.

Referenced by flush_old_maps(), and map_info().

Here is the caller graph for this function:

void read_map_log ( void  )

Reads temporary maps information from disk.

Will LOG() in case of error.

Definition at line 70 of file swap.c.

References mapdef::darkness, mapdef::difficulty, get_linked_map(), mapdef::in_memory, llevDebug, Settings::localdir, LOG(), MAP_MAXRESET, MAP_SWAPPED, MAX_BUF, mapdef::path, mapdef::reset_time, safe_strncpy, seconds(), settings, snprintf, split_string(), strdup_local, mapdef::timeout, and mapdef::tmpname.

Referenced by init().

Here is the call graph for this function:

Here is the caller graph for this function:

void swap_below_max ( const char *  except_level)

Tries to swap out maps which are still in memory, because of MAP_TIMEOUT until used objects is below MAX_OBJECTS or there are no more maps to swap.

Parameters
except_levelpath of map to ignore for reset. Musn't be NULL.

Definition at line 242 of file swap.c.

References llevDebug, LOG(), map_least_timeout(), MAX_OBJECTS, nrofallocobjects, nroffreeobjects, mapdef::path, swap_map(), and mapdef::timeout.

Referenced by enter_map().

Here is the call graph for this function:

Here is the caller graph for this function:

int swap_map ( mapstruct map)
static void write_map_log ( void  )
static

Writes out information on all the temporary maps.

It is called by swap_map().

Will LOG() in case of error.

Definition at line 33 of file swap.c.

References mapdef::darkness, mapdef::difficulty, first_map, mapdef::in_memory, Settings::localdir, MAP_IN_MEMORY, MAX_BUF, mapdef::next, of_close(), of_open(), mapdef::path, mapdef::reset_time, settings, snprintf, and mapdef::tmpname.

Referenced by swap_map().

Here is the call graph for this function:

Here is the caller graph for this function: