Browse Source

Use atomic refcount operations

personal/stbuehler/wip
Stefan Bühler 14 years ago
parent
commit
dbc9859ce8
  1. 8
      src/actions.c
  2. 8
      src/chunk.c
  3. 16
      src/condition.c
  4. 7
      src/log.c

8
src/actions.c

@ -14,8 +14,8 @@ struct action_stack_element {
void action_release(server *srv, action *a) {
if (!a) return;
guint i;
assert(a->refcount > 0);
if (!(--a->refcount)) {
assert(g_atomic_int_get(&a->refcount) > 0);
if (g_atomic_int_dec_and_test(&a->refcount)) {
switch (a->type) {
case ACTION_TSETTING:
release_option(srv, &a->value.setting);
@ -42,8 +42,8 @@ void action_release(server *srv, action *a) {
}
void action_acquire(action *a) {
assert(a->refcount > 0);
a->refcount++;
assert(g_atomic_int_get(&a->refcount) > 0);
g_atomic_int_inc(&a->refcount);
}
action *action_new_setting(option_set setting) {

8
src/chunk.c

@ -21,14 +21,14 @@ static chunkfile *chunkfile_new(GString *name, int fd, gboolean is_temp) {
}
static void chunkfile_acquire(chunkfile *cf) {
assert(cf->refcount > 0);
cf->refcount++;
assert(g_atomic_int_get(&cf->refcount) > 0);
g_atomic_int_inc(&cf->refcount);
}
static void chunkfile_release(chunkfile *cf) {
if (!cf) return;
assert(cf->refcount > 0);
if (!(--cf->refcount)) {
assert(g_atomic_int_get(&cf->refcount) > 0);
if (g_atomic_int_dec_and_test(&cf->refcount)) {
if (-1 != cf->fd) close(cf->fd);
cf->fd = -1;
if (cf->is_temp) unlink(cf->name->str);

16
src/condition.c

@ -55,14 +55,14 @@ condition_lvalue* condition_lvalue_new(cond_lvalue_t type, GString *key) {
}
void condition_lvalue_acquire(condition_lvalue *lvalue) {
assert(lvalue->refcount > 0);
lvalue->refcount++;
assert(g_atomic_int_get(&lvalue->refcount) > 0);
g_atomic_int_inc(&lvalue->refcount);
}
void condition_lvalue_release(condition_lvalue *lvalue) {
if (!lvalue) return;
assert(lvalue->refcount > 0);
if (!(--lvalue->refcount)) {
assert(g_atomic_int_get(&lvalue->refcount) > 0);
if (g_atomic_int_dec_and_test(&lvalue->refcount)) {
if (lvalue->key) g_string_free(lvalue->key, TRUE);
g_slice_free(condition_lvalue, lvalue);
}
@ -194,15 +194,15 @@ static void condition_free(condition *c) {
}
void condition_acquire(condition *c) {
assert(c->refcount > 0);
c->refcount++;
assert(g_atomic_int_get(&c->refcount) > 0);
g_atomic_int_inc(&c->refcount);
}
void condition_release(server *srv, condition* c) {
UNUSED(srv);
if (!c) return;
assert(c->refcount > 0);
if (!(--c->refcount)) {
assert(g_atomic_int_get(&c->refcount) > 0);
if (g_atomic_int_dec_and_test(&c->refcount)) {
condition_free(c);
}
}

7
src/log.c

@ -190,9 +190,8 @@ void log_rotate_logs(server *srv) {
void log_ref(server *srv, log_t *log) {
g_mutex_lock(srv->log_mutex);
log->refcount++;
g_mutex_unlock(srv->log_mutex);
UNUSED(srv);
g_atomic_int_inc(&log->refcount);
}
void log_unref(server *srv, log_t *log) {
@ -264,7 +263,7 @@ log_t *log_new(server *srv, log_type_t type, GString *path) {
/* log already open, inc refcount */
if (log != NULL)
{
log->refcount++;
g_atomic_int_inc(&log->refcount);
g_mutex_unlock(srv->log_mutex);
return log;
}

Loading…
Cancel
Save