L4Re Operating System Framework – Interface and Usage Documentation
Loading...
Searching...
No Matches
utils
1// vi:set ft=cpp: -*- Mode: C++ -*-
2/* SPDX-License-Identifier: GPL-2.0-only or License-Ref-kk-custom */
3/*
4 * Copyright (C) 2013 Technische Universität Dresden.
5 */
6
7#pragma once
8
9namespace cxx {
10
38template< typename T > inline
39T access_once(T const *a)
40{
41#if 1
42 __asm__ __volatile__ ( "" : "=m"(*const_cast<T*>(a)));
43 T tmp = *a;
44 __asm__ __volatile__ ( "" : "=m"(*const_cast<T*>(a)));
45 return tmp;
46#else
47 return *static_cast<T const volatile *>(a);
48#endif
49}
50
69template< typename T, typename VAL > inline
70void write_now(T *a, VAL &&val)
71{
72 __asm__ __volatile__ ( "" : "=m"(*a));
73 *a = val;
74 __asm__ __volatile__ ( "" : : "m"(*a));
75}
76
77
78}
79
Our C++ library.
Definition arith:22
void write_now(T *a, VAL &&val)
Write a value at an address exactly once.
Definition utils:70
T access_once(T const *a)
Read the value at an address at most once.
Definition utils:39