You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

cond_var.h 1.6 kB

6 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * Copyright 2019 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_COND_VAR_H_
  17. #define MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_COND_VAR_H_
  18. #include <condition_variable>
  19. #include <functional>
  20. #include <memory>
  21. #include <mutex>
  22. #include <string>
  23. #include "minddata/dataset/util/intrp_resource.h"
  24. #include "minddata/dataset/util/intrp_service.h"
  25. #include "minddata/dataset/util/status.h"
  26. namespace mindspore {
  27. namespace dataset {
  28. class CondVar : public IntrpResource {
  29. public:
  30. CondVar();
  31. ~CondVar() noexcept;
  32. Status Wait(std::unique_lock<std::mutex> *lck, const std::function<bool()> &pred);
  33. void Interrupt() override;
  34. void NotifyOne() noexcept;
  35. void NotifyAll() noexcept;
  36. Status Register(std::shared_ptr<IntrpService> svc);
  37. std::string my_name() const;
  38. Status Deregister();
  39. protected:
  40. std::condition_variable cv_;
  41. std::shared_ptr<IntrpService> svc_;
  42. private:
  43. std::string my_name_;
  44. };
  45. } // namespace dataset
  46. } // namespace mindspore
  47. #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_COND_VAR_H_