## dzl-counter dzl-counter |

## Functions

guint | dzl_get_current_cpu_rdtscp ()
#define | dzl_get_current_cpu
#define | DZL_DEFINE_COUNTER()
#define | DZL_COUNTER_INC()
#define | DZL_COUNTER_DEC()
#define | DZL_COUNTER_SUB()
#define | DZL_COUNTER_ADD()
void | (*DzlCounterForeachFunc) ()

## Types and Values

#define | DZL_COUNTER_REQUIRES_ATOMIC
| DzlCounter
| DzlCounterArena
| DzlCounterValue

## Description

## Functions

### dzl_get_current_cpu_rdtscp ()

    guint
    dzl_get_current_cpu_rdtscp (void);

### dzl_get_current_cpu

    # define dzl_get_current_cpu() dzl_get_current_cpu_rdtscp()

### DZL_DEFINE_COUNTER()

    #define             DZL_DEFINE_COUNTER(Identifier, Category, Name, Description)

    1
    DZL_DEFINE_COUNTER (my_counter, "My", "Counter", "My Counter Description");

#### Parameters

Identifier | The symbol name of the counter |
Category | A string category for the counter. |
Name | A string name for the counter. |
Description | A string description for the counter. |

### DZL_COUNTER_INC()

    #define DZL_COUNTER_INC(Identifier) DZL_COUNTER_ADD(Identifier, G_GINT64_CONSTANT(1))

Increments the counter `Identifier` by 1.

#### Parameters

Identifier | The identifier of the counter. |

### DZL_COUNTER_DEC()

    #define DZL_COUNTER_DEC(Identifier) DZL_COUNTER_SUB(Identifier, G_GINT64_CONSTANT(1))

Decrements the counter `Identifier` by 1.

#### Parameters

Identifier | The identifier of the counter. |

### DZL_COUNTER_SUB()

    #define DZL_COUNTER_SUB(Identifier, Count) DZL_COUNTER_ADD(Identifier, (-(Count)))

Subtracts from the counter identified by `Identifier` by `Count` .

#### Parameters

Identifier | The identifier of the counter. |
Count | the amount to subtract. |

### DZL_COUNTER_ADD()

    #define             DZL_COUNTER_ADD(Identifier, Count)

Adds `Count` to `Identifier` .

This operation is not guaranteed to have full correctness. It tries to find a happy medium between fast, and accurate. When possible, the `rdtscp` instruction is used to get a cacheline owned by the executing CPU, to avoid collisions. However, this is not guaranteed as the thread could be swapped between the calls to `rdtscp` and `addq` (on 64-bit Intel).

Other platforms have fallbacks which may give different guarantees, such as using atomic operations (and therefore, memory barriers).

See DzlCounter for more information.

#### Parameters

Identifier | The identifier of the counter. |
Count | the amount to add to the counter. |

### DzlCounterForeachFunc ()

    void
    (*DzlCounterForeachFunc) (DzlCounter *counter,
                              gpointer user_data);

Function prototype for callbacks provided to `dzl_counter_arena_foreach()`.

#### Parameters

counter | the counter. |
user_data | data supplied to `dzl_counter_arena_foreach()`. |

## Types and Values

### DZL_COUNTER_REQUIRES_ATOMIC

    # define DZL_COUNTER_REQUIRES_ATOMIC 1

### DzlCounter

    typedef struct _DzlCounter DzlCounter;

### DzlCounterArena

    typedef struct _DzlCounterArena DzlCounterArena;

### DzlCounterValue

    typedef struct _DzlCounterValue DzlCounterValue;