NAME

counterCreate - creates a new counter with the specified name.

SYNOPSIS

#include <game-carrier/server.h>

typedef GCT_INT (GC_CORE_API *CounterCreate)(
    GCT_CSTR name);

typedef struct counterCreate {
    /* ... Some fields ... */
    CounterCreate counterCreate;
    /* ... Some fields ... */
}

Parameters:

  • name GCT_CSTR The name of the new counter.

RETURN VALUE

Returns the unique identifier of the counter upon success.

Returns ‘-1’ on failure.

DESCRIPTION

The counterCreate function creates a new counter with the specified name. It’s important to note that the created counter is not thread-safe, so it is the responsibility of the application to ensure thread safety if needed.

Counters are utilized to monitor and track various metrics within the application. It’s crucial to create counters only during the application_initialize event, as any attempts to create counters after this event will result in failure.

The counter identifier is unique for the entire GCS server, allowing applications on the same server to share and utilize the identifier when communicating with each other.

The name parameter represents the name of the new counter.

EXAMPLE

#include <game-carrier/server.h>

static struct core_api api;
static GCT_INT my_counter_id;

GC_ADAPTER_EVENT
GCT_INT adapter_initialize(
    GCT_INT adapter_id,
    struct core_api * core_api,
    GCT_CPTR load_path)
{
    api = *core_api;
    return 0;
}

GC_ADAPTER_EVENT
GCT_INT application_initialize(
    GCT_INT id,
    GCT_CSTR name,
    GCT_CSTR type_name,
    GCT_CSTR file_name)
{
    my_counter_id = api.counterCreate("MyCounter");
    if (my_counter_id == -1) {
        return -1;
    }

    /* Continue application initialization */
    return 0;
}

SEE ALSO

counterCreateAtomic, counterOpen, counterGetNames, counterAdd, counterSet