Skip to content
This repository has been archived by the owner on Oct 31, 2020. It is now read-only.

Commit

Permalink
add valgrind support to state-threads
Browse files Browse the repository at this point in the history
  • Loading branch information
toffaletti committed Oct 19, 2010
1 parent e150dbf commit 7f57fc9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ set(CMAKE_C_FLAGS

add_definitions(-DMD_HAVE_EPOLL -DLINUX)

# check for valgrind. this should really be in FindValgrind.cmake
# http://www.itk.org/Wiki/CMake:How_To_Find_Installed_Software
find_file(VALGRIND_H valgrind.h /usr/include/valgrind /usr/local/include/valgrind)
message("valgrind headers: ${VALGRIND_H}")
if(NOT VALGRIND_H)
# this will remove valgrind stack tracking support from state-threads
add_definitions(-DNVALGRIND)
endif(NOT VALGRIND_H)

exec_program(${CMAKE_COMMAND} ARGS -E copy ${CMAKE_CURRENT_SOURCE_DIR}/public.h ${CMAKE_CURRENT_BINARY_DIR}/st.h)
# use gcc for the asm file because it needs to be
# pre-processed by cpp first
Expand All @@ -22,3 +31,6 @@ add_library(st STATIC md.S event.c io.c key.c sched.c stk.c sync.c)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
#add_executable(server examples/server.c examples/error.c)
#target_link_libraries(server st)

add_executable(lookupdns examples/lookupdns.c examples/res.c)
target_link_libraries(lookupdns st resolv)
5 changes: 5 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ typedef struct _st_stack {
#ifdef __ia64__
void *bsp; /* Register stack backing store pointer */
#endif
#ifndef NVALGRIND
/* id returned by VALGRIND_STACK_REGISTER */
/* http://valgrind.org/docs/manual/manual-core-adv.html */
unsigned int valgrind_stack_id;
#endif
} _st_stack_t;


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

#ifndef NVALGRIND
#include <valgrind/valgrind.h>
#endif

/* Global data */
_st_vp_t _st_this_vp; /* This VP */
Expand Down Expand Up @@ -263,6 +266,12 @@ void st_thread_exit(void *retval)
_ST_DEL_THREADQ(thread);
#endif

#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 @@ -610,6 +619,11 @@ _st_thread_t *st_thread_create(void *(*start)(void *arg), void *arg,
_ST_ADD_THREADQ(thread);
#endif

#ifndef NVALGRIND
thread->stack->valgrind_stack_id =
VALGRIND_STACK_REGISTER(thread->stack->stk_top, thread->stack->stk_bottom);
#endif

return thread;
}

Expand Down

1 comment on commit 7f57fc9

@winlinvip
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍
Merged to ossrs/state-threads#2, thanks very much~

Please sign in to comment.