local_tasks.h 347 B

1234567891011121314151617181920212223
  1. #pragma once
  2. #include <library/cpp/deprecated/atomic/atomic.h>
  3. class TLocalTasks {
  4. private:
  5. TAtomic GotTasks;
  6. public:
  7. TLocalTasks()
  8. : GotTasks(0)
  9. {
  10. }
  11. void AddTask() {
  12. AtomicSet(GotTasks, 1);
  13. }
  14. bool FetchTask() {
  15. bool gotTasks = AtomicCas(&GotTasks, 0, 1);
  16. return gotTasks;
  17. }
  18. };