thread_safe.cxx 716 B

1234567891011121314151617181920212223242526272829
  1. //
  2. // thread_safe.cpp
  3. // shared_random_generator
  4. //
  5. // Created by Sam Jaffe on 3/19/23.
  6. // Copyright © 2023 Sam Jaffe. All rights reserved.
  7. //
  8. #include "random/thread_safe.h"
  9. namespace engine::random {
  10. ThreadSafeDevice::ThreadSafeDevice(std::unique_ptr<Device> impl)
  11. : impl_(std::move(impl)) {}
  12. int32_t ThreadSafeDevice::inclusive(int32_t min, int32_t max) {
  13. std::lock_guard lock(mutex_);
  14. return impl_->exclusive(min, max);
  15. }
  16. uint32_t ThreadSafeDevice::inclusive(uint32_t min, uint32_t max) {
  17. std::lock_guard lock(mutex_);
  18. return impl_->exclusive(min, max);
  19. }
  20. double ThreadSafeDevice::exclusive(double min, double max) {
  21. std::lock_guard lock(mutex_);
  22. return impl_->exclusive(min, max);
  23. }
  24. }