summaryrefslogtreecommitdiff
path: root/accel-pptpd/triton
diff options
context:
space:
mode:
authorKozlov Dmitry <dima@server>2010-11-29 13:01:18 +0300
committerKozlov Dmitry <dima@server>2010-11-29 13:01:18 +0300
commit369689ab48d7d213f66d338f5f090366b2bce56c (patch)
treebf0f6069c201f637ca645330c7fd5b410e11b40f /accel-pptpd/triton
parent43803998812ee949cbe02a121030888c51a9aad2 (diff)
downloadaccel-ppp-xebd-369689ab48d7d213f66d338f5f090366b2bce56c.tar.gz
accel-ppp-xebd-369689ab48d7d213f66d338f5f090366b2bce56c.zip
use atomic operation on statistics update operations
Diffstat (limited to 'accel-pptpd/triton')
-rw-r--r--accel-pptpd/triton/md.c1
-rw-r--r--accel-pptpd/triton/mempool.c18
-rw-r--r--accel-pptpd/triton/timer.c1
-rw-r--r--accel-pptpd/triton/triton.c24
4 files changed, 24 insertions, 20 deletions
diff --git a/accel-pptpd/triton/md.c b/accel-pptpd/triton/md.c
index 7833031..15ed9fc 100644
--- a/accel-pptpd/triton/md.c
+++ b/accel-pptpd/triton/md.c
@@ -86,6 +86,7 @@ static void *md_thread(void *arg)
if (!h->pending) {
list_add_tail(&h->entry2, &h->ctx->pending_handlers);
h->pending = 1;
+ __sync_add_and_fetch(&triton_stat.md_handler_pending, 1);
r = triton_queue_ctx(h->ctx);
} else
r = 0;
diff --git a/accel-pptpd/triton/mempool.c b/accel-pptpd/triton/mempool.c
index da11825..fb9db08 100644
--- a/accel-pptpd/triton/mempool.c
+++ b/accel-pptpd/triton/mempool.c
@@ -84,7 +84,7 @@ void __export *mempool_alloc(mempool_t *pool)
list_del(&it->entry);
spin_unlock(&p->lock);
- triton_stat.mempool_available -= size;
+ __sync_sub_and_fetch(&triton_stat.mempool_available, size);
it->magic1 = MAGIC1;
@@ -106,7 +106,7 @@ void __export *mempool_alloc(mempool_t *pool)
it->magic2 = p->magic;
*(uint64_t*)(it->data + p->size) = it->magic2;
- triton_stat.mempool_allocated += size;
+ __sync_add_and_fetch(&triton_stat.mempool_allocated, size);
return it->ptr;
}
@@ -128,7 +128,7 @@ void __export *mempool_alloc_md(mempool_t *pool, const char *fname, int line)
it->fname = fname;
it->line = line;
- triton_stat.mempool_available -= size;
+ __sync_sub_and_fetch(&triton_stat.mempool_available, size);
it->magic1 = MAGIC1;
@@ -156,7 +156,7 @@ void __export *mempool_alloc_md(mempool_t *pool, const char *fname, int line)
list_add(&it->entry, &p->ditems);
spin_unlock(&p->lock);
- triton_stat.mempool_allocated += size;
+ __sync_add_and_fetch(&triton_stat.mempool_allocated, size);
return it->ptr;
}
@@ -202,7 +202,7 @@ void __export mempool_free(void *ptr)
_free(it);
#endif
- triton_stat.mempool_available += size;
+ __sync_add_and_fetch(&triton_stat.mempool_available, size);
}
void __export mempool_clean(mempool_t *pool)
@@ -219,8 +219,8 @@ void __export mempool_clean(mempool_t *pool)
munmap(it, size);
else
_free(it);
- triton_stat.mempool_allocated -= size;
- triton_stat.mempool_available -= size;
+ __sync_sub_and_fetch(&triton_stat.mempool_allocated, size);
+ __sync_sub_and_fetch(&triton_stat.mempool_available, size);
}
spin_unlock(&p->lock);
}
@@ -257,8 +257,8 @@ void sigclean(int num)
munmap(it, size);
else
_free(it);
- triton_stat.mempool_allocated -= size;
- triton_stat.mempool_available -= size;
+ __sync_sub_and_fetch(&triton_stat.mempool_allocated, size);
+ __sync_sub_and_fetch(&triton_stat.mempool_available, size);
}
spin_unlock(&p->lock);
}
diff --git a/accel-pptpd/triton/timer.c b/accel-pptpd/triton/timer.c
index 95a540a..d6be1e4 100644
--- a/accel-pptpd/triton/timer.c
+++ b/accel-pptpd/triton/timer.c
@@ -92,6 +92,7 @@ void *timer_thread(void *arg)
if (!t->pending) {
list_add_tail(&t->entry2, &t->ctx->pending_timers);
t->pending = 1;
+ __sync_add_and_fetch(&triton_stat.timer_pending, 1);
r = triton_queue_ctx(t->ctx);
} else
r = 0;
diff --git a/accel-pptpd/triton/triton.c b/accel-pptpd/triton/triton.c
index a628fe1..426eefe 100644
--- a/accel-pptpd/triton/triton.c
+++ b/accel-pptpd/triton/triton.c
@@ -62,7 +62,7 @@ static void* triton_thread(struct _triton_thread_t *thread)
thread->ctx->thread = thread;
thread->ctx->queued = 0;
spin_unlock(&thread->ctx->lock);
- triton_stat.context_pending--;
+ __sync_sub_and_fetch(&triton_stat.context_pending, 1);
} else {
log_debug2("thread: %p: sleeping\n", thread);
if (!terminate)
@@ -71,11 +71,11 @@ static void* triton_thread(struct _triton_thread_t *thread)
if (terminate)
return NULL;
- triton_stat.thread_active--;
+ __sync_sub_and_fetch(&triton_stat.thread_active, 1);
//printf("thread %p: enter sigwait\n", thread);
sigwait(&set, &sig);
//printf("thread %p: exit sigwait\n", thread);
- triton_stat.thread_active++;
+ __sync_add_and_fetch(&triton_stat.thread_active, 1);
if (!thread->ctx)
continue;
@@ -141,6 +141,7 @@ static void ctx_thread(struct _triton_context_t *ctx)
list_del(&t->entry2);
t->pending = 0;
spin_unlock(&ctx->lock);
+ __sync_sub_and_fetch(&triton_stat.timer_pending, 1);
read(t->fd, &tt, sizeof(tt));
t->ud->expire(t->ud);
continue;
@@ -150,6 +151,7 @@ static void ctx_thread(struct _triton_context_t *ctx)
list_del(&h->entry2);
h->pending = 0;
spin_unlock(&ctx->lock);
+ __sync_sub_and_fetch(&triton_stat.md_handler_pending, 1);
if (h->trig_epoll_events & (EPOLLIN | EPOLLERR | EPOLLHUP))
if (h->ud && h->ud->read)
if (h->ud->read(h->ud))
@@ -197,8 +199,8 @@ struct _triton_thread_t *create_thread()
return NULL;
}
- triton_stat.thread_count++;
- triton_stat.thread_active++;
+ __sync_add_and_fetch(&triton_stat.thread_count, 1);
+ __sync_add_and_fetch(&triton_stat.thread_active, 1);
return thread;
}
@@ -218,7 +220,7 @@ int triton_queue_ctx(struct _triton_context_t *ctx)
spin_unlock(&threads_lock);
ctx->queued = 1;
log_debug2("ctx %p: queued\n", ctx);
- triton_stat.context_pending++;
+ __sync_add_and_fetch(&triton_stat.context_pending, 1);
return 0;
}
@@ -272,8 +274,8 @@ int __export triton_context_register(struct triton_context_t *ud, void *bf_arg)
list_add_tail(&ctx->entry, &ctx_list);
spin_unlock(&ctx_list_lock);
- triton_stat.context_sleeping++;
- triton_stat.context_count++;
+ __sync_add_and_fetch(&triton_stat.context_sleeping, 1);
+ __sync_add_and_fetch(&triton_stat.context_count, 1);
return 0;
}
@@ -322,7 +324,7 @@ void __export triton_context_unregister(struct triton_context_t *ud)
terminate = 1;
spin_unlock(&ctx_list_lock);
- triton_stat.context_count--;
+ __sync_sub_and_fetch(&triton_stat.context_count, 1);
if (terminate) {
list_for_each_entry(t, &threads, entry)
@@ -352,7 +354,7 @@ void __export triton_context_schedule(struct triton_context_t *ud)
ctx->thread = NULL;
spin_unlock(&ctx->lock);
- triton_stat.context_sleeping++;
+ __sync_add_and_fetch(&triton_stat.context_sleeping, 1);
log_debug2("ctx %p: enter schedule\n", ctx);
if (swapcontext(&ctx->uctx, uctx))
@@ -388,7 +390,7 @@ int __export triton_context_wakeup(struct triton_context_t *ud)
if (r)
triton_thread_wakeup(ctx->thread);
- triton_stat.context_sleeping--;
+ __sync_sub_and_fetch(&triton_stat.context_sleeping, 1);
return 0;
}