L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
utils
1// vi:set ft=cpp: -*- Mode: C++ -*-
2/*
3 * Copyright (C) 2013 Technische Universität Dresden.
4 *
5 * License: see LICENSE.spdx (in this directory or the directories above)
6 */
7
8#pragma once
9
10namespace cxx {
11
39template< typename T > inline
40T access_once(T const *a)
41{
42#if 1
43 __asm__ __volatile__ ( "" : "=m"(*const_cast<T*>(a)));
44 T tmp = *a;
45 __asm__ __volatile__ ( "" : "=m"(*const_cast<T*>(a)));
46 return tmp;
47#else
48 return *static_cast<T const volatile *>(a);
49#endif
50}
51
70template< typename T, typename VAL > inline
71void write_now(T *a, VAL &&val)
72{
73 __asm__ __volatile__ ( "" : "=m"(*a));
74 *a = val;
75 __asm__ __volatile__ ( "" : : "m"(*a));
76}
77
78
79}
80
Our C++ library.
Definition arith:11
void write_now(T *a, VAL &&val)
Write a value at an address exactly once.
Definition utils:71
T access_once(T const *a)
Read the value at an address at most once.
Definition utils:40