NAME

counterCreateAtomic - creates a new atomic counter with the specified name.

SYNOPSIS

#include <game-carrier/server.h>

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

typedef struct counterCreateAtomic {
    /* ... Some fields ... */
    CounterCreateAtomic counterCreateAtomic;
    /* ... Some fields ... */
}

Parameters:

  • name GCT_CSTR The name of the new atomic counter.

RETURN VALUE

Returns the unique identifier of the counter upon success.

Returns ‘-1’ on failure.

DESCRIPTION

The counterCreateAtomic function creates a new atomic counter with the specified name. The application does not need to ensure thread safety, since atomic counters are thread-safe.

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 atomic 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.counterCreateAtomic("MyCounter");
    if (my_counter_id == -1)
    {
        return -1;
    }

    /* Continue application initialization */
    return 0;
}

SEE ALSO

counterCreate, counterOpen, counterGetNames, counterAdd, counterSet