• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_INTRP_RESOURCE_H_
17 #define MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_INTRP_RESOURCE_H_
18 
19 #include <atomic>
20 #include "minddata/dataset/util/status.h"
21 
22 namespace mindspore {
23 namespace dataset {
24 class IntrpResource {
25  public:
26   enum class State : int { kRunning, kInterrupted };
27 
IntrpResource()28   IntrpResource() : st_(State::kRunning) {}
29 
30   virtual ~IntrpResource() = default;
31 
Interrupt()32   virtual void Interrupt() { st_ = State::kInterrupted; }
33 
ResetIntrpState()34   virtual void ResetIntrpState() { st_ = State::kRunning; }
35 
CurState()36   State CurState() const { return st_; }
37 
Interrupted()38   bool Interrupted() const { return CurState() == State::kInterrupted; }
39 
GetInterruptStatus()40   virtual Status GetInterruptStatus() const {
41     if (Interrupted()) {
42       return Status(StatusCode::kMDInterrupted);
43     }
44     return Status::OK();
45   }
46 
47  protected:
48   std::atomic<State> st_;
49 };
50 }  // namespace dataset
51 }  // namespace mindspore
52 #endif  // MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_INTRP_RESOURCE_H_
53