summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--accel-pptpd/ctrl/l2tp/l2tp.c16
-rw-r--r--accel-pptpd/ctrl/pppoe/pppoe.c10
-rw-r--r--accel-pptpd/ctrl/pptp/pptp.c16
-rw-r--r--accel-pptpd/log.c2
-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
8 files changed, 46 insertions, 42 deletions
diff --git a/accel-pptpd/ctrl/l2tp/l2tp.c b/accel-pptpd/ctrl/l2tp/l2tp.c
index b4b7b742..d7aeae8f 100644
--- a/accel-pptpd/ctrl/l2tp/l2tp.c
+++ b/accel-pptpd/ctrl/l2tp/l2tp.c
@@ -119,11 +119,11 @@ static void l2tp_disconnect(struct l2tp_conn_t *conn)
triton_timer_del(&conn->hello_timer);
if (conn->state == STATE_PPP) {
- stat_active--;
+ __sync_sub_and_fetch(&stat_active, 1);
conn->state = STATE_FIN;
ppp_terminate(&conn->ppp, TERM_USER_REQUEST, 1);
} else if (conn->state != STATE_FIN)
- stat_starting--;
+ __sync_sub_and_fetch(&stat_starting, 1);
pthread_mutex_lock(&l2tp_lock);
l2tp_conn[conn->tid] = NULL;
@@ -201,7 +201,7 @@ static void l2tp_ppp_finished(struct ppp_t *ppp)
log_ppp_debug("l2tp: ppp finished\n");
if (conn->state != STATE_FIN) {
- stat_active--;
+ __sync_sub_and_fetch(&stat_active, 1);
if (l2tp_terminate(conn, 0, 0))
triton_context_call(&conn->ctx, (triton_event_func)l2tp_disconnect, conn);
}
@@ -212,7 +212,7 @@ static void l2tp_conn_close(struct triton_context_t *ctx)
struct l2tp_conn_t *conn = container_of(ctx, typeof(*conn), ctx);
if (conn->state == STATE_PPP) {
- stat_active--;
+ __sync_sub_and_fetch(&stat_active, 1);
conn->state = STATE_FIN;
ppp_terminate(&conn->ppp, TERM_ADMIN_RESET, 1);
}
@@ -357,7 +357,7 @@ static int l2tp_tunnel_alloc(struct l2tp_serv_t *serv, struct l2tp_packet_t *pac
triton_context_call(&conn->ctx, (triton_event_func)l2tp_send_SCCRP, conn);
- stat_starting++;
+ __sync_add_and_fetch(&stat_starting, 1);
return 0;
@@ -419,8 +419,8 @@ static int l2tp_connect(struct l2tp_conn_t *conn)
if (establish_ppp(&conn->ppp))
return -1;
- stat_starting--;
- stat_active++;
+ __sync_sub_and_fetch(&stat_starting, 1);
+ __sync_add_and_fetch(&stat_active, 1);
conn->state = STATE_PPP;
@@ -835,7 +835,7 @@ static int l2tp_recv_CDN(struct l2tp_conn_t *conn, struct l2tp_packet_t *pack)
}
if (conn->state == STATE_PPP) {
- stat_active--;
+ __sync_sub_and_fetch(&stat_active, 1);
conn->state = STATE_FIN;
ppp_terminate(&conn->ppp, TERM_USER_REQUEST, 1);
}
diff --git a/accel-pptpd/ctrl/pppoe/pppoe.c b/accel-pptpd/ctrl/pppoe/pppoe.c
index daa07b76..24d2405d 100644
--- a/accel-pptpd/ctrl/pppoe/pppoe.c
+++ b/accel-pptpd/ctrl/pppoe/pppoe.c
@@ -82,7 +82,7 @@ void pppoe_server_free(struct pppoe_serv_t *serv);
static void disconnect(struct pppoe_conn_t *conn)
{
if (conn->ppp_started) {
- stat_active--;
+ __sync_sub_and_fetch(&stat_active, 1);
conn->ppp_started = 0;
ppp_terminate(&conn->ppp, TERM_USER_REQUEST, 1);
}
@@ -132,7 +132,7 @@ static void ppp_finished(struct ppp_t *ppp)
log_ppp_debug("pppoe: ppp finished\n");
if (conn->ppp_started) {
- stat_active--;
+ __sync_sub_and_fetch(&stat_active, 1);
conn->ppp_started = 0;
triton_context_call(&conn->ctx, (triton_event_func)disconnect, conn);
}
@@ -546,7 +546,7 @@ static void free_delayed_pado(struct delayed_pado_t *pado)
{
triton_timer_del(&pado->timer);
- stat_delayed_pado--;
+ __sync_sub_and_fetch(&stat_delayed_pado, 1);
list_del(&pado->entry);
if (pado->host_uniq)
@@ -655,7 +655,7 @@ static void pppoe_recv_PADI(struct pppoe_serv_t *serv, uint8_t *pack, int size)
triton_timer_add(&serv->ctx, &pado->timer, 0);
list_add_tail(&pado->entry, &serv->pado_list);
- stat_delayed_pado++;
+ __sync_add_and_fetch(&stat_delayed_pado, 1);
} else
pppoe_send_PADO(serv, ethhdr->h_source, host_uniq_tag, relay_sid_tag, service_name_tag);
}
@@ -756,7 +756,7 @@ static void pppoe_recv_PADR(struct pppoe_serv_t *serv, uint8_t *pack, int size)
if (connect_channel(conn))
disconnect(conn);
else {
- stat_active++;
+ __sync_add_and_fetch(&stat_active, 1);
conn->ppp_started = 1;
}
}
diff --git a/accel-pptpd/ctrl/pptp/pptp.c b/accel-pptpd/ctrl/pptp/pptp.c
index 608be306..1523d99d 100644
--- a/accel-pptpd/ctrl/pptp/pptp.c
+++ b/accel-pptpd/ctrl/pptp/pptp.c
@@ -82,11 +82,11 @@ static void disconnect(struct pptp_conn_t *conn)
triton_timer_del(&conn->echo_timer);
if (conn->state == STATE_PPP) {
- stat_active--;
+ __sync_sub_and_fetch(&stat_active, 1);
conn->state = STATE_CLOSE;
ppp_terminate(&conn->ppp, TERM_USER_REQUEST, 1);
} else if (conn->state != STATE_CLOSE)
- stat_starting--;
+ __sync_sub_and_fetch(&stat_starting, 1);
triton_event_fire(EV_CTRL_FINISHED, &conn->ppp);
@@ -329,8 +329,8 @@ static int pptp_out_call_rqst(struct pptp_conn_t *conn)
return -1;
}
conn->state = STATE_PPP;
- stat_starting--;
- stat_active++;
+ __sync_sub_and_fetch(&stat_starting, 1);
+ __sync_add_and_fetch(&stat_active, 1);
if (conn->timeout_timer.tpd)
triton_timer_del(&conn->timeout_timer);
@@ -367,7 +367,7 @@ static int pptp_call_clear_rqst(struct pptp_conn_t *conn)
log_ppp_info("recv [PPTP Call-Clear-Request <Call-ID %x>]\n", ntohs(rqst->call_id));
if (conn->state == STATE_PPP) {
- stat_active--;
+ __sync_sub_and_fetch(&stat_active, 1);
conn->state = STATE_CLOSE;
ppp_terminate(&conn->ppp, TERM_USER_REQUEST, 1);
}
@@ -549,7 +549,7 @@ static void pptp_close(struct triton_context_t *ctx)
{
struct pptp_conn_t *conn = container_of(ctx, typeof(*conn), ctx);
if (conn->state == STATE_PPP) {
- stat_active--;
+ __sync_sub_and_fetch(&stat_active, 1);
conn->state = STATE_CLOSE;
ppp_terminate(&conn->ppp, TERM_ADMIN_RESET, 1);
if (send_pptp_call_disconnect_notify(conn, 3)) {
@@ -579,7 +579,7 @@ static void ppp_finished(struct ppp_t *ppp)
if (conn->state != STATE_CLOSE) {
log_ppp_debug("pptp: ppp finished\n");
conn->state = STATE_CLOSE;
- stat_active--;
+ __sync_sub_and_fetch(&stat_active, 1);
if (send_pptp_call_disconnect_notify(conn, 3))
triton_context_call(&conn->ctx, (void (*)(void*))disconnect, conn);
@@ -667,7 +667,7 @@ static int pptp_connect(struct triton_md_handler_t *h)
triton_event_fire(EV_CTRL_STARTING, &conn->ppp);
- stat_starting++;
+ __sync_add_and_fetch(&stat_starting, 1);
}
return 0;
}
diff --git a/accel-pptpd/log.c b/accel-pptpd/log.c
index d92ab125..582c250c 100644
--- a/accel-pptpd/log.c
+++ b/accel-pptpd/log.c
@@ -260,7 +260,7 @@ static struct log_msg_t *clone_msg(struct _log_msg_t *msg)
m->timestamp = msg->timestamp;
m->level = msg->level;
- msg->refs++;
+ __sync_add_and_fetch(&msg->refs, 1);
//printf("clone msg %p\n", m);
return m;
diff --git a/accel-pptpd/triton/md.c b/accel-pptpd/triton/md.c
index 78330316..15ed9fcd 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 da11825c..fb9db089 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 95a540a6..d6be1e42 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 a628fe16..426eefe5 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;
}