
| Current Path : /usr/include/gap/hpc/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : //usr/include/gap/hpc/guards.h |
#ifndef GAP_HPC_GUARD_H
#define GAP_HPC_GUARD_H
#include "hpc/region.h"
#include "hpc/tls.h"
#ifndef HPCGAP
#error This header is only meant to be used with HPC-GAP
#endif
#ifdef VERBOSE_GUARDS
void WriteGuardError(Bag bag,
const char *file, unsigned line, const char *func, const char *expr);
void ReadGuardError(Bag bag,
const char *file, unsigned line, const char *func, const char *expr);
#else
void WriteGuardError(Bag bag);
void ReadGuardError(Bag bag);
#endif
#ifdef VERBOSE_GUARDS
#define WriteGuard(bag) WriteGuardFull(bag, __FILE__, __LINE__, __FUNCTION__, #bag)
static ALWAYS_INLINE Bag WriteGuardFull(Bag bag,
const char *file, unsigned line, const char *func, const char *expr)
#else
static ALWAYS_INLINE Bag WriteGuard(Bag bag)
#endif
{
Region *region;
if (!IS_BAG_REF(bag))
return bag;
region = REGION(bag);
if (region && region->owner != GetTLS() && region->alt_owner != GetTLS())
WriteGuardError(bag
#ifdef VERBOSE_GUARDS
, file, line, func, expr
#endif
);
return bag;
}
static inline Bag ImpliedWriteGuard(Bag bag)
{
return bag;
}
static inline int CheckWriteAccess(Bag bag)
{
Region *region;
if (!IS_BAG_REF(bag))
return 1;
region = REGION(bag);
return !(region && region->owner != GetTLS() && region->alt_owner != GetTLS())
|| TLS(DisableGuards) >= 2;
}
static inline int CheckExclusiveWriteAccess(Bag bag)
{
Region *region;
if (!IS_BAG_REF(bag))
return 1;
region = REGION(bag);
if (!region)
return 0;
return region->owner == GetTLS() || region->alt_owner == GetTLS()
|| TLS(DisableGuards) >= 2;
}
#ifdef VERBOSE_GUARDS
#define ReadGuard(bag) ReadGuardFull(bag, __FILE__, __LINE__, __FUNCTION__, #bag)
static ALWAYS_INLINE Bag ReadGuardFull(Bag bag,
const char *file, unsigned line, const char *func, const char *expr)
#else
static ALWAYS_INLINE Bag ReadGuard(Bag bag)
#endif
{
Region *region;
if (!IS_BAG_REF(bag))
return bag;
region = REGION(bag);
if (region && region->owner != GetTLS() &&
!region->readers[TLS(threadID)] && region->alt_owner != GetTLS())
ReadGuardError(bag
#ifdef VERBOSE_GUARDS
, file, line, func, expr
#endif
);
return bag;
}
static ALWAYS_INLINE Bag ImpliedReadGuard(Bag bag)
{
return bag;
}
static ALWAYS_INLINE int CheckReadAccess(Bag bag)
{
Region *region;
if (!IS_BAG_REF(bag))
return 1;
region = REGION(bag);
return !(region && region->owner != GetTLS() &&
!region->readers[TLS(threadID)] && region->alt_owner != GetTLS())
|| TLS(DisableGuards) >= 2;
}
#endif // GAP_HPC_GUARD_H