summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
Diffstat (limited to 'src/base')
-rw-r--r--src/base/fiber.cc13
-rw-r--r--src/base/fiber.hh5
2 files changed, 17 insertions, 1 deletions
diff --git a/src/base/fiber.cc b/src/base/fiber.cc
index f10f1fbfd..eac1d9394 100644
--- a/src/base/fiber.cc
+++ b/src/base/fiber.cc
@@ -29,6 +29,10 @@
#include "base/fiber.hh"
+#if HAVE_VALGRIND
+#include <valgrind/valgrind.h>
+#endif
+
#include <cerrno>
#include <cstring>
@@ -71,7 +75,11 @@ Fiber::Fiber(size_t stack_size) :
link(primaryFiber()),
stack(stack_size ? new uint8_t[stack_size] : nullptr),
stackSize(stack_size), started(false), _finished(false)
-{}
+{
+#if HAVE_VALGRIND
+ valgrindStackId = VALGRIND_STACK_REGISTER(stack, stack + stack_size);
+#endif
+}
Fiber::Fiber(Fiber *link, size_t stack_size) :
link(link), stack(stack_size ? new uint8_t[stack_size] : nullptr),
@@ -81,6 +89,9 @@ Fiber::Fiber(Fiber *link, size_t stack_size) :
Fiber::~Fiber()
{
panic_if(stack && _currentFiber == this, "Fiber stack is in use.");
+#if HAVE_VALGRIND
+ VALGRIND_STACK_DEREGISTER(valgrindStackId);
+#endif
delete [] stack;
}
diff --git a/src/base/fiber.hh b/src/base/fiber.hh
index 5f7285b29..3d82075f0 100644
--- a/src/base/fiber.hh
+++ b/src/base/fiber.hh
@@ -44,6 +44,8 @@
#include <cstddef>
#include <cstdint>
+#include "config/have_valgrind.hh"
+
/**
* This class represents a fiber, which is a light weight sort of thread which
* is cooperatively scheduled and runs sequentially with other fibers, swapping
@@ -106,6 +108,9 @@ class Fiber
// The stack for this context, or a nullptr if allocated elsewhere.
uint8_t *stack;
size_t stackSize;
+#if HAVE_VALGRIND
+ unsigned valgrindStackId;
+#endif
bool started;
bool _finished;