diff --git a/README.md b/README.md index c568b59..f1b4e41 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The branch [srs](https://github.com/ossrs/state-threads/tree/srs) will be patche - [x] Patch [st.disable.examples.patch](https://github.com/ossrs/srs/blob/2.0release/trunk/3rdparty/patches/4.st.disable.examples.patch), for ubuntu. - [x] [Refine TAB of code](https://github.com/ossrs/state-threads/compare/c2001d30ca58f55d72a6cc6b9b6c70391eaf14db...d2101b26988b0e0db0aabc53ddf452068c1e2cbc). - [x] Merge from [michaeltalyansky](https://github.com/michaeltalyansky/state-threads) and [xzh3836598](https://github.com/ossrs/state-threads/commit/9a17dec8f9c2814d93761665df7c5575a4d2d8a3), support [ARM](https://github.com/ossrs/state-threads/issues/1). -- [ ] Merge from [toffaletti](https://github.com/toffaletti/state-threads), support [valgrind](https://github.com/ossrs/state-threads/issues/2) for ST. +- [x] Merge from [toffaletti](https://github.com/toffaletti/state-threads), support [valgrind](https://github.com/ossrs/state-threads/issues/2) for ST. ## Usage @@ -30,4 +30,19 @@ For osx: make darwin-debug EXTRA_CFLAGS="-DMD_HAVE_KQUEUE" ``` +Linux with valgrind: + +``` +make linux-debug EXTRA_CFLAGS="-DMD_VALGRIND -I/usr/local/include" +``` + +> Remark: User must install valgrind, for instance, in centos6 `sudo yum install -y valgrind valgrind-devel`. +> Remark: User must define the macro `-DMD_VALGRIND` and the valgrind header files dir `-I/usr/local/include`. + +Linux with valgrind and epoll: + +``` +make linux-debug EXTRA_CFLAGS="-DMD_HAVE_EPOLL -DMD_VALGRIND -I/usr/local/include" +``` + Winlin 2016 diff --git a/common.h b/common.h index e436811..0c0685b 100644 --- a/common.h +++ b/common.h @@ -67,6 +67,15 @@ #include "public.h" #include "md.h" +/* merge from https://github.com/toffaletti/state-threads/commit/7f57fc9acc05e657bca1223f1e5b9b1a45ed929b */ +#ifndef MD_VALGRIND + #ifndef NVALGRIND + #define NVALGRIND + #endif +#else + #undef NVALGRIND +#endif + /***************************************** * Circular linked list definitions @@ -148,6 +157,12 @@ typedef struct _st_stack { void *sp; /* Stack pointer from C's point of view */ #ifdef __ia64__ void *bsp; /* Register stack backing store pointer */ +#endif + /* merge from https://github.com/toffaletti/state-threads/commit/7f57fc9acc05e657bca1223f1e5b9b1a45ed929b */ +#ifndef NVALGRIND + /* id returned by VALGRIND_STACK_REGISTER */ + /* http://valgrind.org/docs/manual/manual-core-adv.html */ + unsigned long valgrind_stack_id; #endif } _st_stack_t; diff --git a/sched.c b/sched.c index 545853a..8751582 100644 --- a/sched.c +++ b/sched.c @@ -47,6 +47,11 @@ #include #include "common.h" +/* merge from https://github.com/toffaletti/state-threads/commit/7f57fc9acc05e657bca1223f1e5b9b1a45ed929b */ +#ifndef NVALGRIND +#include +#endif + /* Global data */ _st_vp_t _st_this_vp; /* This VP */ @@ -261,6 +266,13 @@ void st_thread_exit(void *retval) _ST_DEL_THREADQ(thread); #endif + /* merge from https://github.com/toffaletti/state-threads/commit/7f57fc9acc05e657bca1223f1e5b9b1a45ed929b */ +#ifndef NVALGRIND + if (!(thread->flags & _ST_FL_PRIMORDIAL)) { + VALGRIND_STACK_DEREGISTER(thread->stack->valgrind_stack_id); + } +#endif + if (!(thread->flags & _ST_FL_PRIMORDIAL)) _st_stack_free(thread->stack); @@ -624,6 +636,13 @@ _st_thread_t *st_thread_create(void *(*start)(void *arg), void *arg, int joinabl _ST_ADD_THREADQ(thread); #endif + /* merge from https://github.com/toffaletti/state-threads/commit/7f57fc9acc05e657bca1223f1e5b9b1a45ed929b */ +#ifndef NVALGRIND + if (!(thread->flags & _ST_FL_PRIMORDIAL)) { + thread->stack->valgrind_stack_id = VALGRIND_STACK_REGISTER(thread->stack->stk_top, thread->stack->stk_bottom); + } +#endif + return thread; }