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 
9 namespace cxx {
10 
11 template< typename T >
12 T access_once(T const *a)
13 {
14 #if 1
15   __asm__ __volatile__ ( "" : "=m"(*const_cast<T*>(a)));
16   T tmp = *a;
17   __asm__ __volatile__ ( "" : "=m"(*const_cast<T*>(a)));
18   return tmp;
19 #else
20   return *static_cast<T const volatile *>(a);
21 #endif
22 }
23 
24 template< typename T >
25 void write_now(T *a, T const &val)
26 {
27   __asm__ __volatile__ ( "" : "=m"(*a));
28   *a = val;
29   __asm__ __volatile__ ( "" : : "m"(*a));
30 }
31 
32 
33 }
34 
35