scheduler_cookie.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "scheduler_cookie.h"
  2. namespace NActors {
  3. class TSchedulerCookie2Way: public ISchedulerCookie {
  4. TAtomic Value;
  5. public:
  6. TSchedulerCookie2Way()
  7. : Value(2)
  8. {
  9. }
  10. bool IsArmed() noexcept override {
  11. return (AtomicGet(Value) == 2);
  12. }
  13. bool Detach() noexcept override {
  14. const ui64 x = AtomicDecrement(Value);
  15. if (x == 1)
  16. return true;
  17. if (x == 0) {
  18. delete this;
  19. return false;
  20. }
  21. Y_ABORT();
  22. }
  23. bool DetachEvent() noexcept override {
  24. Y_ABORT();
  25. }
  26. };
  27. ISchedulerCookie* ISchedulerCookie::Make2Way() {
  28. return new TSchedulerCookie2Way();
  29. }
  30. class TSchedulerCookie3Way: public ISchedulerCookie {
  31. TAtomic Value;
  32. public:
  33. TSchedulerCookie3Way()
  34. : Value(3)
  35. {
  36. }
  37. bool IsArmed() noexcept override {
  38. return (AtomicGet(Value) == 3);
  39. }
  40. bool Detach() noexcept override {
  41. const ui64 x = AtomicDecrement(Value);
  42. if (x == 2)
  43. return true;
  44. if (x == 1)
  45. return false;
  46. if (x == 0) {
  47. delete this;
  48. return false;
  49. }
  50. Y_ABORT();
  51. }
  52. bool DetachEvent() noexcept override {
  53. const ui64 x = AtomicDecrement(Value);
  54. if (x == 2)
  55. return false;
  56. if (x == 1)
  57. return true;
  58. if (x == 0) {
  59. delete this;
  60. return false;
  61. }
  62. Y_ABORT();
  63. }
  64. };
  65. ISchedulerCookie* ISchedulerCookie::Make3Way() {
  66. return new TSchedulerCookie3Way();
  67. }
  68. }