Skip to content

Commit

Permalink
Merge pull request #7 from zerbina/support-disabling-valgrind
Browse files Browse the repository at this point in the history
support disabling valgrind
  • Loading branch information
disruptek authored Apr 13, 2024
2 parents a311185 + 037fbf8 commit 95191a5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ for all the actors to terminate and clean up all the resources used.



### Valgrind

To make the library aware of being run with helgrind, the program needs to be
built with `-d:usesValgrind`, otherwise false positives could be reported.


### More to come

Sure.
Expand Down
2 changes: 0 additions & 2 deletions actors/pool.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import isisolated
import mallinfo
import valgrind

{.emit:"#include <valgrind/helgrind.h>".}

type

Pool* = object
Expand Down
36 changes: 21 additions & 15 deletions actors/valgrind.nim
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@

{.emit:"#include <valgrind/helgrind.h>".}
const
usesValgrind {.booldefine.} = false

template valgrind_annotate_happens_before*(x) =
block:
let y {.exportc,inject.} = x
{.emit:"ANNOTATE_HAPPENS_BEFORE(y);".}
when usesValgrind:
const header = "<valgrind/helgrind.h>"

template valgrind_annotate_happens_after*(x) =
block:
let y {.exportc,inject.} = x
{.emit:"ANNOTATE_HAPPENS_AFTER(y);".}
proc valgrind_annotate_happens_before*(x: pointer) {.
header: header, importc: "ANNOTATE_HAPPENS_BEFORE".}
proc valgrind_annotate_happens_after*(x: pointer) {.
header: header, importc: "ANNOTATE_HAPPENS_AFTER".}
proc valgrind_annotate_happens_before_forget_all*(x: pointer) {.
header: header, importc: "ANNOTATE_HAPPENS_BEFORE_FORGET_ALL".}

template valgrind_annotate_happens_before_forget_all*(x) =
block:
let y {.exportc,inject.} = x
{.emit:"ANNOTATE_HAPPENS_BEFORE_FORGET_ALL(y);".}
let enabled {.header: header, importc: "RUNNING_ON_VALGRIND".}: bool

proc running_on_valgrind*(): bool =
{.emit: "result = RUNNING_ON_VALGRIND;".}
proc running_on_valgrind*(): bool =
{.cast(noSideEffect), cast(gcSafe).}:
result = enabled

else:
proc valgrind_annotate_happens_before*(x: pointer) = discard
proc valgrind_annotate_happens_after*(x: pointer) = discard
proc valgrind_annotate_happens_before_forget_all*(x: pointer) = discard

template running_on_valgrind*(): bool = false
1 change: 1 addition & 0 deletions tests/nim.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--define:usesValgrind

0 comments on commit 95191a5

Please sign in to comment.