Project

General

Profile

Feature #469 ยป 0053-timing.c-Replace-NULLs-with-nullptrs.patch

Marko Lindqvist, 04/18/2024 05:28 PM

View differences:

utility/timing.c
struct timer *timer_new(enum timer_timetype type, enum timer_use use,
const char *name)
{
return timer_renew(NULL, type, use, name);
return timer_renew(nullptr, type, use, name);
}
/*******************************************************************//**
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
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 = NULL;
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));
......
struct timer *timer_renew(struct timer *t, enum timer_timetype type,
enum timer_use use, const char *name)
{
if (t == NULL) {
if (t == nullptr) {
t = (struct timer *)fc_malloc(sizeof(struct timer));
#ifdef FREECIV_DEBUG
t->name = NULL;
t->name = nullptr;
#endif
}
t->type = type;
t->use = use;
#ifdef FREECIV_DEBUG
if (name != NULL) {
if (t->name != NULL) {
if (name != nullptr) {
if (t->name != nullptr) {
free(t->name);
}
t->name = fc_strdup(name);
}
#endif
#endif /* FREECIV_DEBUG */
timer_clear(t);
return t;
......
***********************************************************************/
void timer_destroy(struct timer *t)
{
if (t != NULL) {
if (t != nullptr) {
#ifdef FREECIV_DEBUG
if (t->name != NULL) {
if (t->name != nullptr) {
free(t->name);
}
#endif /* FREECIV_DEBUG */
......
}
/*******************************************************************//**
Return name of the timer, or some placeholder string (never NULL)
Return name of the timer, or some placeholder string (never nullptr)
***********************************************************************/
static char *timer_name(struct timer *t)
{
#ifdef FREECIV_DEBUG
if (t->name != NULL) {
if (t->name != nullptr) {
return t->name;
} else {
return "Nameless";
......
/*******************************************************************//**
Return whether timer is in use.
t may be NULL, in which case returns FALSE
t may be nullptr, in which case returns FALSE
***********************************************************************/
bool timer_in_use(struct timer *t)
{
return (t != NULL && t->use != TIMER_IGNORE);
return (t != nullptr && t->use != TIMER_IGNORE);
}
/*******************************************************************//**
......
***********************************************************************/
void timer_clear(struct timer *t)
{
fc_assert_ret(NULL != t);
fc_assert_ret(t != nullptr);
t->state = TIMER_STOPPED;
t->sec = 0.0;
t->usec = 0;
......
***********************************************************************/
void timer_start(struct timer *t)
{
fc_assert_ret(NULL != t);
fc_assert_ret(t != nullptr);
if (t->use == TIMER_IGNORE) {
return;
......
}
} else {
#ifdef HAVE_GETTIMEOFDAY
int ret = gettimeofday(&t->start.tv, NULL);
int ret = gettimeofday(&t->start.tv, nullptr);
if (ret == -1) {
report_gettimeofday_failed(t);
......
#elif defined HAVE_FTIME
ftime(&t->start.tp);
#else
t->start.t = time(NULL);
t->start.t = time(nullptr);
if (t->start.t == (time_t) -1) {
report_time_failed(t);
return;
......
***********************************************************************/
void timer_stop(struct timer *t)
{
fc_assert_ret(NULL != t);
fc_assert_ret(t != nullptr);
if (t->use == TIMER_IGNORE) {
return;
......
} else {
#ifdef HAVE_GETTIMEOFDAY
struct timeval now;
int ret = gettimeofday(&now, NULL);
int ret = gettimeofday(&now, nullptr);
if (ret == -1) {
report_gettimeofday_failed(t);
......
}
t->start.tp = now;
#else
time_t now = time(NULL);
time_t now = time(nullptr);
if (now == (time_t) -1) {
report_time_failed(t);
......
***********************************************************************/
double timer_read_seconds(struct timer *t)
{
fc_assert_ret_val(NULL != t, -1.0);
fc_assert_ret_val(t != nullptr, -1.0);
if (t->use == TIMER_IGNORE) {
return 0.0;
......
long elapsed_usec;
long wait_usec;
fc_assert_ret(NULL != t);
fc_assert_ret(t != nullptr);
ret = gettimeofday(&tv_now, NULL);
ret = gettimeofday(&tv_now, nullptr);
if ((ret == -1)
|| (t->type != TIMER_USER)
|| (t->use != TIMER_ACTIVE)
|| (t->state != TIMER_STARTED)) {
fc_usleep(usec);
return;
}
    (1-1/1)