Skip to content

Commit

Permalink
for #2, support valgrind, use macro to enable it
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Sep 4, 2016
1 parent 1dbd539 commit 4cca7a0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
15 changes: 15 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
19 changes: 19 additions & 0 deletions sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
#include <errno.h>
#include "common.h"

/* merge from https://github.com/toffaletti/state-threads/commit/7f57fc9acc05e657bca1223f1e5b9b1a45ed929b */
#ifndef NVALGRIND
#include <valgrind/valgrind.h>
#endif


/* Global data */
_st_vp_t _st_this_vp; /* This VP */
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 4cca7a0

Please sign in to comment.