
// this file is not final ..
// you need to add locking

#include "counter.h"
#include <pthread.h>

static int global_counter = 0;
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; 

/**************************************************/
/* Init                                           */
/*                                                */
/**************************************************/
void Counter_Init()
{
    global_counter = 0;
}

/**************************************************/
/*                                                */
/*                                                */
/**************************************************/
int Counter_GetValue()
{
    return global_counter;
}

/**************************************************/
/* increment                                      */
/*                                                */
/**************************************************/
void Counter_Increment()
{
    pthread_mutex_lock(&mutex1);	
    global_counter++;
    pthread_mutex_unlock(&mutex1);
}

/**************************************************/
/* decrement                                      */
/*                                                */
/**************************************************/
void Counter_Decrement()
{
    pthread_mutex_lock(&mutex1);
    global_counter--;
    pthread_mutex_unlock(&mutex1);
}

