Loading...
Searching...
No Matches
utils
// vi:set ft=cpp: -*- Mode: C++ -*-
/*
* Copyright (C) 2013 Technische Universität Dresden.
*
* License: see LICENSE.spdx (in this directory or the directories above)
*/
#pragma once
namespace cxx {
template< typename T > inline
T access_once(T const *a)
{
#if 1
__asm__ __volatile__ ( "" : "=m"(*const_cast<T*>(a)));
T tmp = *a;
__asm__ __volatile__ ( "" : "=m"(*const_cast<T*>(a)));
return tmp;
#else
return *static_cast<T const volatile *>(a);
#endif
}
template< typename T, typename VAL > inline
void write_now(T *a, VAL &&val)
{
__asm__ __volatile__ ( "" : "=m"(*a));
*a = val;
__asm__ __volatile__ ( "" : : "m"(*a));
}
}
cxx
Our C++ library.
Definition arith:11
cxx::write_now
void write_now(T *a, VAL &&val)
Write a value at an address exactly once.
Definition utils:71
cxx::access_once
T access_once(T const *a)
Read the value at an address at most once.
Definition utils:40