64 lines
1.4 KiB
C
64 lines
1.4 KiB
C
/*
|
|
Copyright (C) 2004, Wolfgang Hottgenroth
|
|
|
|
This file is part of smmapdfw.
|
|
|
|
smmapdfw is free software; you can redistribute it and/or modify it
|
|
under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
smmapdfw is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with smmapdfw. If not, write to the Free Software Foundation, 59
|
|
Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
|
|
|
|
#include "count.h"
|
|
|
|
void count_init(count_t *c) {
|
|
c->cnt = 0;
|
|
|
|
pthread_mutex_init(&c->mutex, NULL);
|
|
}
|
|
|
|
void count_destroy(count_t *c) {
|
|
pthread_mutex_destroy(&c->mutex);
|
|
}
|
|
|
|
int count_inc(count_t *c) {
|
|
int i;
|
|
|
|
pthread_mutex_lock(&c->mutex);
|
|
i = ++c->cnt;
|
|
pthread_mutex_unlock(&c->mutex);
|
|
|
|
return i;
|
|
}
|
|
|
|
int count_dec(count_t *c) {
|
|
int i;
|
|
|
|
pthread_mutex_lock(&c->mutex);
|
|
i = --c->cnt;
|
|
pthread_mutex_unlock(&c->mutex);
|
|
|
|
return i;
|
|
}
|
|
|
|
int count_get(count_t *c) {
|
|
int i;
|
|
|
|
pthread_mutex_lock(&c->mutex);
|
|
i = c->cnt;
|
|
pthread_mutex_unlock(&c->mutex);
|
|
|
|
return i;
|
|
}
|