Freeciv-3.3: /fast/freeciv/nightly/main/utility/timing.c File Reference

Freeciv-3.3

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 timer * | timer_new (enum timer_timetype type, enum timer_use use, const char *name)
struct timer * | timer_renew (struct timer *t, enum timer_timetype type, enum timer_use use, const char *name)
void | timer_destroy (struct timer *t)
static char * | timer_name (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

enum 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 113 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 144 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 252 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 | ) |

Free the memory associated with a timer.

Definition at line 208 of file timing.c.

Referenced by adv_workers_free(), agents_free(), autosaves_callback(), cm_free(), connection_common_close(), dai_manage_taxes(), incoming_client_packets(), load_command(), mapimg_create(), save_game(), savegame3_save(), savegame_load(), send_server_info_to_metaserver(), server_make_connection(), server_quit(), signal_timer_free(), srv_running(), and timing_log_free().

## ◆ timer_in_use()

bool timer_in_use | ( | struct timer * | t | ) |

Return whether timer is in use. t may be nullptr, in which case returns FALSE

Definition at line 242 of file timing.c.

Referenced by auto_workers_player().

## ◆ timer_name()

static char * timer_name | ( | struct timer * | t | ) |

static

Return name of the timer, or some placeholder string (never nullptr)

Definition at line 225 of file timing.c.

Referenced by timer_start(), and timer_stop().

## ◆ timer_new()

struct timer * timer_new | ( | enum timer_timetype | type,
|  | enum timer_use | use,
|  | const char * | name
| ) |  |

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

Definition at line 160 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 | ) |

Read value from timer. If the timer is not stopped, this stops the timer, reads it (and accumulates), and then restarts it. Returns 0.0 for unused timers.

Definition at line 384 of file timing.c.

Referenced by auto_workers_player(), blink_active_unit(), blink_turn_done_button(), cut_lagging_connection(), dai_manage_taxes(), handle_conn_pong(), incoming_client_packets(), increase_timeout_because_unit_moved(), load_command(), mapimg_create(), move_unit_map_canvas(), real_timer_callback(), save_game(), savegame3_save(), savegame_load(), send_game_info(), send_server_info_to_metaserver(), server_sniff_all_input(), set_mapview_origin(), sg_save_game(), srv_running(), update_animation(), and wait_for_requests().

## ◆ timer_renew()

struct timer * timer_renew | ( | struct timer * | t,
|  | enum timer_timetype | type,
|  | enum timer_use | use,
|  | const char * | name
| ) |  |

Allocate a new timer, or reuse t, with specified "type" and "use". The timer is created as cleared, and stopped. If t is nullptr, 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 = nullptr; t = timer_renew(t, TIMER_CPU, TIMER_USE, "example"); ... stuff ... log_verbose("That took %g seconds.", timer_read_seconds(t)); ... never free t ... }

Definition at line 180 of file timing.c.

Referenced by anim_timer_renew(), auto_workers_player(), autosaves_callback(), begin_phase(), blink_active_unit(), blink_turn_done_button(), cma_init(), incoming_client_packets(), server_sniff_all_input(), set_seconds_to_turndone(), srv_running(), start_turn_change_wait(), timer_new(), and write_socket_data().

## ◆ timer_start()

void timer_start | ( | struct timer * | t | ) |

Start timing, adding to previous accumulated time if timer has not been cleared. A warning is printed if the timer is already started.

Definition at line 264 of file timing.c.

Referenced by anim_timer_renew(), auto_workers_player(), autosaves_callback(), begin_phase(), begin_search(), blink_active_unit(), blink_turn_done_button(), connection_ping(), dai_manage_taxes(), incoming_client_packets(), load_command(), mapimg_create(), save_game(), savegame3_save(), savegame_load(), send_server_info_to_metaserver(), server_make_connection(), server_sniff_all_input(), set_seconds_to_turndone(), srv_running(), start_turn_change_wait(), timing_log_real(), wait_for_requests(), and write_socket_data().

## ◆ 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 308 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 405 of file timing.c.

Referenced by decrease_unit_hp_smooth().