thread_safe.h 564 B

123456789101112131415161718192021222324252627282930
  1. //
  2. // thread_safe.h
  3. // shared_random_generator
  4. //
  5. // Created by Sam Jaffe on 3/19/23.
  6. // Copyright © 2023 Sam Jaffe. All rights reserved.
  7. //
  8. #pragma once
  9. #include <mutex>
  10. #include <random/device.h>
  11. namespace engine::random {
  12. class ThreadSafeDevice : public Device {
  13. private:
  14. std::mutex mutex_;
  15. std::unique_ptr<Device> impl_;
  16. public:
  17. ThreadSafeDevice(std::unique_ptr<Device> impl);
  18. int32_t inclusive(int32_t min, int32_t max) final;
  19. uint32_t inclusive(uint32_t min, uint32_t max) final;
  20. double exclusive(double min, double max) final;
  21. };
  22. }