From 4ccc3634b36b92e350e5cdc5b209f78c6108abd5 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Wed, 25 Mar 2015 23:50:46 +0100 Subject: [PATCH] net/ng_pktdump: manage stack internally --- sys/include/net/ng_pktdump.h | 34 ++++++++++++++++------ sys/net/crosslayer/ng_pktdump/ng_pktdump.c | 25 ++++++++++++++-- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/sys/include/net/ng_pktdump.h b/sys/include/net/ng_pktdump.h index bd1dff8de4..afaac00913 100644 --- a/sys/include/net/ng_pktdump.h +++ b/sys/include/net/ng_pktdump.h @@ -35,19 +35,35 @@ extern "C" { #define NG_PKTDUMP_MSG_QUEUE_SIZE (8U) #endif +/** + * @brief Priority of the pktdump thread + */ +#ifndef NG_PKTDUMP_PRIO +#define NG_PKTDUMP_PRIO (PRIORITY_MIN - 1) +#endif + +/** + * @brief Stack size used for the pktdump thread + */ +#ifndef NG_PKTDUMP_STACKSIZE +#define NG_PKTDUMP_STACKSIZE (KERNEL_CONF_STACKSIZE_MAIN) +#endif + +/** + * @brief Get the PID of the pktdump thread + * + * @return PID of the pktdump thread + * @return @ref KERNEL_PID_UNDEF if not initialized + */ +kernel_pid_t ng_pktdump_getpid(void); + /** * @brief Start the packet dump thread and listening for incoming packets * - * @param[in] stack stack for the packet dump thread - * @param[in] stacksize size of @p stack - * @param[in] priority priority of the packet dump thread - * @param[in] name name for the packet dump thread - * - * @return PID of newly created task on success - * @return negative value on error + * @return PID of the pktdump thread + * @return negative value on error */ -kernel_pid_t ng_pktdump_init(char *stack, int stacksize, - char priority, char *name); +kernel_pid_t ng_pktdump_init(void); #ifdef __cplusplus } diff --git a/sys/net/crosslayer/ng_pktdump/ng_pktdump.c b/sys/net/crosslayer/ng_pktdump/ng_pktdump.c index 6e066f7ced..d9e7478a51 100644 --- a/sys/net/crosslayer/ng_pktdump/ng_pktdump.c +++ b/sys/net/crosslayer/ng_pktdump/ng_pktdump.c @@ -22,9 +22,20 @@ #include "thread.h" #include "msg.h" +#include "kernel.h" #include "net/ng_pktdump.h" #include "net/ng_netbase.h" +/** + * @brief PID of the pktdump thread + */ +static kernel_pid_t _pid = KERNEL_PID_UNDEF; + +/** + * @brief Stack for the pktdump thread + */ +static char _stack[NG_PKTDUMP_STACKSIZE]; + void _dump_type(ng_nettype_t type) { switch (type) { @@ -117,8 +128,16 @@ void *_eventloop(void *arg) return NULL; } -kernel_pid_t ng_pktdump_init(char *stack, int stacksize, - char priority, char *name) +kernel_pid_t ng_pktdump_getpid(void) { - return thread_create(stack, stacksize, priority, 0, _eventloop, NULL, name); + return _pid; +} + +kernel_pid_t ng_pktdump_init(void) +{ + if (_pid == KERNEL_PID_UNDEF) { + _pid = thread_create(_stack, sizeof(_stack), NG_PKTDUMP_PRIO, + 0, _eventloop, NULL, "pktdump"); + } + return _pid; }