1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FFRT_QOS_H 17 #define FFRT_QOS_H 18 19 #include "ffrt_inner.h" 20 21 namespace ffrt { 22 class QoS { 23 public: 24 QoS(int qos = qos_default) 25 { 26 if (qos < qos_inherit) { 27 qos = qos_inherit; 28 } else if (qos > qos_max) { 29 qos = qos_max; 30 } 31 32 qos_ = qos; 33 } 34 QoS(const QoS & qos)35 QoS(const QoS& qos) : qos_(qos()) 36 { 37 } 38 operator()39 int operator()() const 40 { 41 return qos_; 42 } 43 44 QoS& operator=(int qos) 45 { 46 qos_ = qos; 47 return *this; 48 } 49 50 QoS& operator=(const QoS& qos) 51 { 52 if (this != &qos) { 53 qos_ = qos(); 54 } 55 return *this; 56 } 57 58 bool operator==(int qos) const 59 { 60 return qos_ == qos; 61 } 62 63 bool operator==(const QoS& qos) const 64 { 65 return qos_ == qos(); 66 } 67 68 bool operator!=(int qos) const 69 { 70 return !(*this == qos); 71 } 72 73 bool operator!=(const QoS& qos) const 74 { 75 return !(*this == qos); 76 } 77 78 operator int() const 79 { 80 return qos_; 81 } 82 Min()83 static constexpr int Min() 84 { 85 return qos_background; 86 } 87 Max()88 static constexpr int Max() 89 { 90 return qos_max + 1; 91 } 92 93 private: 94 int qos_; 95 }; 96 }; // namespace ffrt 97 #endif