Skip to content

Commit

Permalink
Initial work on tracking spurious guard errors with unward.
Browse files Browse the repository at this point in the history
  • Loading branch information
rbehrends committed Sep 20, 2018
1 parent 9190768 commit e97e1dd
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/gasman.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@

#include "system.h"

#ifdef HPCGAP
#include "hpc/region.h"
#include "hpc/tls.h"
#endif


/****************************************************************************
**
Expand Down Expand Up @@ -299,13 +304,64 @@ static inline UInt SIZE_BAG_CONTENTS(const void *ptr) {
** the application must inform {\Gasman} that it has changed the bag, by
** calling 'CHANGED_BAG(old)' in the above example (see "CHANGED_BAG").
*/
#ifdef HPCGAP
#define PURE_FUNC __attribute__((pure))
static inline PURE_FUNC int ReadCheck(Bag bag)
{
Region *region;
if (!IS_BAG_REF(bag))
return 1;
region = REGION(bag);
if (!region)
return 1;
if (region->owner == GetTLS())
return 1;
if (region->readers[TLS(threadID)])
return 1;
return 0;
}

static inline PURE_FUNC int WriteCheck(Bag bag)
{
Region *region;
if (!IS_BAG_REF(bag))
return 1;
region = REGION(bag);
return !region || region->owner == GetTLS();
}
#endif // HPCGAP

static inline Bag *PTR_BAG(Bag bag)
{
GAP_ASSERT(bag != 0);
#ifdef HPCGAP
extern PURE_FUNC int HandleWriteGuardError(Bag);
extern volatile int GuardDummy;
if (!WriteCheck(bag))
GuardDummy = HandleWriteGuardError(bag);
#endif
return *(Bag**)bag;
}

static inline Bag *UNSAFE_PTR_BAG(Bag bag)
{
GAP_ASSERT(bag != 0);
return *(Bag**)bag;
}

static inline const Bag *CONST_PTR_BAG(Bag bag)
{
GAP_ASSERT(bag != 0);
#ifdef HPCGAP
extern PURE_FUNC int HandleReadGuardError(Bag);
extern volatile int GuardDummy;
if (!ReadCheck(bag))
GuardDummy = HandleReadGuardError(bag);
#endif
return *(const Bag**)bag;
}

static inline const Bag *UNSAFE_CONST_PTR_BAG(Bag bag)
{
GAP_ASSERT(bag != 0);
return *(const Bag**)bag;
Expand Down
16 changes: 16 additions & 0 deletions src/hpc/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -1270,4 +1270,20 @@ void ReadGuardError(Obj o)
}
#endif

// These are temporary debugging functions.

Int NumReadErrors = 0;
Int NumWriteErrors = 0;
volatile int GuardDummy;

PURE_FUNC int HandleReadGuardError(Bag bag) {
NumReadErrors++;
return 0;
}

PURE_FUNC int HandleWriteGuardError(Bag bag) {
NumWriteErrors++;
return 0;
}

#endif

0 comments on commit e97e1dd

Please sign in to comment.