summaryrefslogtreecommitdiff
path: root/accel-pptpd/triton
diff options
context:
space:
mode:
authorKozlov Dmitry <dima@server>2010-09-11 14:27:27 +0400
committerKozlov Dmitry <dima@server>2010-09-11 14:27:27 +0400
commit417ef849f1adcb3b655fbb2382e126b0b17aabbe (patch)
tree560cba379463fc8e912c7f73b54676b7c1582062 /accel-pptpd/triton
parentd0c060a39d3bf6f675666a1400b533511e24a26c (diff)
downloadaccel-ppp-417ef849f1adcb3b655fbb2382e126b0b17aabbe.tar.gz
accel-ppp-417ef849f1adcb3b655fbb2382e126b0b17aabbe.zip
log: implemented extensible loggin engine with per-session logging support
log: implemented log_file logging target with per-user/per-session support
Diffstat (limited to 'accel-pptpd/triton')
-rw-r--r--accel-pptpd/triton/CMakeLists.txt1
-rw-r--r--accel-pptpd/triton/mempool.c8
-rw-r--r--accel-pptpd/triton/mempool.h10
-rw-r--r--accel-pptpd/triton/spinlock.h2
-rw-r--r--accel-pptpd/triton/timer.c1
-rw-r--r--accel-pptpd/triton/triton.c10
-rw-r--r--accel-pptpd/triton/triton.h3
-rw-r--r--accel-pptpd/triton/triton_p.h7
8 files changed, 26 insertions, 16 deletions
diff --git a/accel-pptpd/triton/CMakeLists.txt b/accel-pptpd/triton/CMakeLists.txt
index 41339d9..95ab416 100644
--- a/accel-pptpd/triton/CMakeLists.txt
+++ b/accel-pptpd/triton/CMakeLists.txt
@@ -10,7 +10,6 @@ SET(sources_c
event.c
)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
-ADD_DEFINITIONS("-DUSE_SPINLOCK")
ADD_LIBRARY(${target} SHARED ${sources_c})
diff --git a/accel-pptpd/triton/mempool.c b/accel-pptpd/triton/mempool.c
index dacb611..6d9172a 100644
--- a/accel-pptpd/triton/mempool.c
+++ b/accel-pptpd/triton/mempool.c
@@ -20,7 +20,7 @@ struct _item_t
char ptr[0];
};
-mempool_t *mempool_create(int size)
+__export mempool_t *mempool_create(int size)
{
struct _mempool_t *p = malloc(sizeof(*p));
@@ -33,7 +33,7 @@ mempool_t *mempool_create(int size)
return (mempool_t *)p;
}
-void *mempool_alloc(mempool_t *pool)
+__export void *mempool_alloc(mempool_t *pool)
{
struct _mempool_t *p = (struct _mempool_t *)pool;
struct _item_t *it;
@@ -48,7 +48,7 @@ void *mempool_alloc(mempool_t *pool)
spin_unlock(&p->lock);
it = malloc(sizeof(*it) + p->size);
if (!it) {
- triton_log_error("out of memory\n");
+ triton_log_error("mempool: out of memory\n");
return NULL;
}
it->owner = p;
@@ -56,7 +56,7 @@ void *mempool_alloc(mempool_t *pool)
return it->ptr;
}
-void mempool_free(void *ptr)
+__export void mempool_free(void *ptr)
{
struct _item_t *it = container_of(ptr, typeof(*it), ptr);
diff --git a/accel-pptpd/triton/mempool.h b/accel-pptpd/triton/mempool.h
new file mode 100644
index 0000000..e8bcaf6
--- /dev/null
+++ b/accel-pptpd/triton/mempool.h
@@ -0,0 +1,10 @@
+#ifndef __TRITON_MEMPOOL_H
+#define __TRITON_MEMPOOL_H
+
+typedef void * mempool_t;
+mempool_t *mempool_create(int size);
+void *mempool_alloc(mempool_t*);
+void mempool_free(void*);
+
+#endif
+
diff --git a/accel-pptpd/triton/spinlock.h b/accel-pptpd/triton/spinlock.h
index b6d1656..5ef9c48 100644
--- a/accel-pptpd/triton/spinlock.h
+++ b/accel-pptpd/triton/spinlock.h
@@ -1,7 +1,7 @@
#ifndef __TRITON_SPINLOCK_H
#define __TRITON_SPINLOCK_H
-#ifdef USE_SPINLOCK
+#ifdef GCC_SPINLOCK
typedef unsigned char spinlock_t;
#define spin_lock(l) {while(__sync_lock_test_and_set(l,1));}
#define spin_unlock(l) __sync_lock_release(l)
diff --git a/accel-pptpd/triton/timer.c b/accel-pptpd/triton/timer.c
index e9fd66a..d224978 100644
--- a/accel-pptpd/triton/timer.c
+++ b/accel-pptpd/triton/timer.c
@@ -164,5 +164,6 @@ void __export triton_timer_del(struct triton_timer_t *ud)
spin_unlock(&t->ctx->lock);
sched_yield();
mempool_free(t);
+ ud->tpd = NULL;
}
diff --git a/accel-pptpd/triton/triton.c b/accel-pptpd/triton/triton.c
index 8b25f03..b0aedbc 100644
--- a/accel-pptpd/triton/triton.c
+++ b/accel-pptpd/triton/triton.c
@@ -43,9 +43,10 @@ static void* triton_thread(struct _triton_thread_t *thread)
sigwait(&set, &sig);
cont:
- if (swapcontext(&thread->uctx, &thread->ctx->uctx)) {
+ if (thread->ctx->ud->before_switch)
+ thread->ctx->ud->before_switch(thread->ctx->ud, thread->ctx->bf_arg);
+ if (swapcontext(&thread->uctx, &thread->ctx->uctx))
triton_log_error("swapcontext: %s\n", strerror(errno));
- }
if (thread->ctx->need_free)
mempool_free(thread->ctx);
@@ -164,7 +165,7 @@ int triton_queue_ctx(struct _triton_context_t *ctx)
return 1;
}
-int __export triton_context_register(struct triton_context_t *ud)
+int __export triton_context_register(struct triton_context_t *ud, void *bf_arg)
{
struct _triton_context_t *ctx = mempool_alloc(ctx_pool);
@@ -173,6 +174,7 @@ int __export triton_context_register(struct triton_context_t *ud)
memset(ctx, 0, sizeof(*ctx));
ctx->ud = ud;
+ ctx->bf_arg = bf_arg;
spinlock_init(&ctx->lock);
INIT_LIST_HEAD(&ctx->handlers);
INIT_LIST_HEAD(&ctx->timers);
@@ -299,7 +301,7 @@ int __export triton_init(const char *conf_file, const char *mod_sect)
fprintf(stderr,"cann't allocate memory\n");
return -1;
}
- triton_context_register(default_ctx);
+ triton_context_register(default_ctx, NULL);
if (conf_load(conf_file))
return -1;
diff --git a/accel-pptpd/triton/triton.h b/accel-pptpd/triton/triton.h
index d9baa7d..b1df497 100644
--- a/accel-pptpd/triton/triton.h
+++ b/accel-pptpd/triton/triton.h
@@ -10,6 +10,7 @@ struct triton_context_t
const void *tpd; // triton private data, don't touch!
void (*close)(struct triton_context_t*);
void (*free)(struct triton_context_t*);
+ void (*before_switch)(struct triton_context_t *ctx, void *arg);
};
struct triton_md_handler_t
@@ -41,7 +42,7 @@ struct conf_sect_t
struct list_head items;
};
-int triton_context_register(struct triton_context_t *);
+int triton_context_register(struct triton_context_t *, void *arg);
void triton_context_unregister(struct triton_context_t *);
void triton_context_schedule(struct triton_context_t *);
void triton_context_wakeup(struct triton_context_t *);
diff --git a/accel-pptpd/triton/triton_p.h b/accel-pptpd/triton/triton_p.h
index 5e498fc..ec2eb84 100644
--- a/accel-pptpd/triton/triton_p.h
+++ b/accel-pptpd/triton/triton_p.h
@@ -8,6 +8,7 @@
#include "triton.h"
#include "list.h"
#include "spinlock.h"
+#include "mempool.h"
#define CTX_STACK_SIZE 8196
@@ -43,6 +44,7 @@ struct _triton_context_t
int need_free:1;
struct triton_context_t *ud;
+ void *bf_arg;
};
struct _triton_md_handler_t
@@ -80,11 +82,6 @@ struct _triton_ctx_call_t
void (*func)(void *);
};
-typedef void * mempool_t;
-mempool_t *mempool_create(int size);
-void *mempool_alloc(mempool_t*);
-void mempool_free(void*);
-
int log_init(void);
int md_init();
int timer_init();