Freeciv-3.1
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions
timing.c File Reference
#include <time.h>
#include "log.h"
#include "mem.h"
#include "shared.h"
#include "support.h"
#include "timing.h"

Go to the source code of this file.

Data Structures

struct  timer
 

Macros

#define CLOCKS_PER_SEC   1000000 /* wild guess!! */
 
#define N_USEC_PER_SEC   1000000L /* not 1000! :-) */
 

Enumerations

enum  timer_state { TIMER_STARTED , TIMER_STOPPED }
 

Functions

static void report_clock_failed (struct timer *t)
 
static void report_time_failed (struct timer *t)
 
struct timertimer_new (enum timer_timetype type, enum timer_use use)
 
struct timertimer_renew (struct timer *t, enum timer_timetype type, enum timer_use use)
 
void timer_destroy (struct timer *t)
 
bool timer_in_use (struct timer *t)
 
void timer_clear (struct timer *t)
 
void timer_start (struct timer *t)
 
void timer_stop (struct timer *t)
 
double timer_read_seconds (struct timer *t)
 
void timer_usleep_since_start (struct timer *t, long usec)
 

Macro Definition Documentation

◆ CLOCKS_PER_SEC

#define CLOCKS_PER_SEC   1000000 /* wild guess!! */

Definition at line 70 of file timing.c.

◆ N_USEC_PER_SEC

#define N_USEC_PER_SEC   1000000L /* not 1000! :-) */

Definition at line 74 of file timing.c.

Enumeration Type Documentation

◆ timer_state

Enumerator
TIMER_STARTED 
TIMER_STOPPED 

Definition at line 76 of file timing.c.

Function Documentation

◆ report_clock_failed()

static void report_clock_failed ( struct timer t)
static

Report if clock() returns -1, but only the first time. Ignore this timer from now on.

Definition at line 109 of file timing.c.

Referenced by timer_start(), and timer_stop().

◆ report_time_failed()

static void report_time_failed ( struct timer t)
static

Report if time() returns -1, but only the first time. Ignore this timer from now on.

Definition at line 140 of file timing.c.

Referenced by timer_start(), and timer_stop().

◆ timer_clear()

void timer_clear ( struct timer t)

Reset accumulated time to zero, and stop timer if going. That is, this may be called whether t is started or stopped; in either case the timer is in the stopped state after this function.

Definition at line 212 of file timing.c.

Referenced by send_server_info_to_metaserver(), srv_running(), timer_renew(), and timing_log_real().

◆ timer_destroy()

void timer_destroy ( struct timer t)

◆ timer_in_use()

bool timer_in_use ( struct timer t)

Return whether timer is in use. t may be NULL, in which case returns 0

Definition at line 202 of file timing.c.

Referenced by auto_settlers_player().

◆ timer_new()

struct timer * timer_new ( enum timer_timetype  type,
enum timer_use  use 
)

Allocate a new timer with specified "type" and "use". The timer is created as cleared, and stopped.

Definition at line 157 of file timing.c.

Referenced by cm_init(), connection_ping(), dai_manage_taxes(), load_command(), mapimg_create(), register_agent(), save_game(), savegame3_save(), savegame_load(), send_server_info_to_metaserver(), server_make_connection(), srv_prepare(), and timing_log_init().

◆ timer_read_seconds()

double timer_read_seconds ( struct timer t)

◆ timer_renew()

struct timer * timer_renew ( struct timer t,
enum timer_timetype  type,
enum timer_use  use 
)

Allocate a new timer, or reuse t, with specified "type" and "use". The timer is created as cleared, and stopped. If t is NULL, allocate and return a new timer, else just re-initialise t and return t. This is intended to be useful to allocate a static t just once, eg: { static struct timer *t = NULL; t = timer_renew(t, TIMER_CPU, TIMER_USE); ... stuff ... log_verbose("That took %g seconds.", timer_read_seconds(t)); ... never free t ... }

Definition at line 176 of file timing.c.

Referenced by animation_add(), auto_settlers_player(), autosaves_callback(), begin_phase(), blink_active_unit(), blink_turn_done_button(), cma_init(), decrease_unit_hp_smooth(), incoming_client_packets(), move_unit_map_canvas(), server_sniff_all_input(), set_mapview_origin(), set_seconds_to_turndone(), srv_running(), start_turn_change_wait(), timer_new(), update_animation(), and write_socket_data().

◆ timer_start()

void timer_start ( struct timer t)

◆ timer_stop()

void timer_stop ( struct timer t)

Stop timing, and accumulate time so far. (The current time is stored in t->start, so that timer_read_seconds can call this to take a point reading if the timer is active.) A warning is printed if the timer is already stopped.

Definition at line 268 of file timing.c.

Referenced by autosaves_callback(), dai_manage_taxes(), end_search(), savegame3_save(), savegame_load(), timer_read_seconds(), timing_log_real(), and wait_for_requests().

◆ timer_usleep_since_start()

void timer_usleep_since_start ( struct timer t,
long  usec 
)

Sleeps until the given number of microseconds have elapsed since the timer was started. Leaves the timer running. Must be called with an active, running user timer. (If timer is broken or in wrong state, just sleep for entire interval.)

Definition at line 364 of file timing.c.

Referenced by decrease_unit_hp_smooth().