lwlock.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* Declarations for lightweight locks.
  2. This file is part of xrcu.
  3. xrcu is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>. */
  13. #ifndef __XRCU_LWLOCK_HPP__
  14. #define __XRCU_LWLOCK_HPP__ 1
  15. #include <cstdint>
  16. namespace xrcu
  17. {
  18. /* Lightweight lock used when including <mutex> is overkill. Should be just as
  19. * performant in certain platforms (i.e: Those that support something akin to
  20. * Linux's futexes), but much lighter space-wise. */
  21. struct lwlock
  22. {
  23. uintptr_t lock = 0;
  24. void acquire ();
  25. void release ();
  26. lwlock () = default;
  27. lwlock (const lwlock&) = delete;
  28. void operator= (const lwlock&) = delete;
  29. };
  30. }
  31. #endif