Interface Documentation
Version: invalid
privilege.hh
Go to the documentation of this file.
1 /*
2  @@@@@@@@ @@ @@@@@@ @@@@@@@@ @@
3  /@@///// /@@ @@////@@ @@////// /@@
4  /@@ /@@ @@@@@ @@ // /@@ /@@
5  /@@@@@@@ /@@ @@///@@/@@ /@@@@@@@@@/@@
6  /@@//// /@@/@@@@@@@/@@ ////////@@/@@
7  /@@ /@@/@@//// //@@ @@ /@@/@@
8  /@@ @@@//@@@@@@ //@@@@@@ @@@@@@@@ /@@
9  // /// ////// ////// //////// //
10 
11  Copyright (c) 2016, Triad National Security, LLC
12  All rights reserved.
13  */
14 #pragma once
15 
18 #if !defined(__FLECSI_PRIVATE__)
19 #error Do not include this file directly!
20 #endif
21 
22 #include "flecsi/util/bitutils.hh"
23 
24 #include <cstddef>
25 #include <tuple>
26 #include <utility>
27 
28 namespace flecsi {
29 
44 enum partition_privilege_t : size_t {
45  nu = 0b00,
46  ro = 0b01,
47  wo = 0b10,
48  rw = 0b11
49 }; // enum partition_privilege_t
50 
51 inline constexpr short privilege_bits = 2;
52 
61 template<partition_privilege_t... PP>
62 inline constexpr size_t privilege_pack = [] {
63  static_assert(((PP < 1 << privilege_bits) && ...));
64  std::size_t ret = 1; // nonzero to allow recovering sizeof...(PP)
65  ((ret <<= privilege_bits, ret |= PP), ...);
66  return ret;
67 }();
68 
75 constexpr size_t
76 privilege_count(std::size_t PACK) {
77  return (util::bit_width(PACK) - 1) / privilege_bits;
78 } // privilege_count
79 
87 constexpr partition_privilege_t
88 get_privilege(std::size_t i, std::size_t pack) {
89  return partition_privilege_t(
90  pack >> (privilege_count(pack) - 1 - i) * privilege_bits &
91  ((1 << privilege_bits) - 1));
92 } // get_privilege
93 
94 constexpr bool
95 privilege_write(std::size_t pack) noexcept {
96  for(auto i = privilege_count(pack); i--;)
97  if(get_privilege(i, pack) > ro)
98  return true;
99  return false;
100 }
101 
102 } // namespace flecsi
constexpr size_t privilege_pack
Definition: privilege.hh:62
constexpr partition_privilege_t get_privilege(std::size_t i, std::size_t pack)
Definition: privilege.hh:88
partition_privilege_t
Definition: privilege.hh:44
constexpr size_t privilege_count(std::size_t PACK)
Definition: privilege.hh:76
Definition: control.hh:31