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 constexpr unsigned char NR_QOS = 6; 22 23 namespace ffrt { 24 struct QoSMap { 25 QoSMap(int _qos = qos_default) 26 { 27 if (_qos <= static_cast<int>(qos_inherit)) { 28 m_qos = qos_inherit; 29 } else if (_qos >= static_cast<int>(qos_background) && _qos <= static_cast<int>(qos_max)) { 30 m_qos = _qos; 31 } else { 32 m_qos = qos_default; 33 } 34 } 35 int m_qos; 36 }; 37 class QoS { 38 public: 39 QoS(int qos = qos_default) 40 { 41 if (qos < static_cast<int>(qos_inherit)) { 42 qos = qos_inherit; 43 } else if (qos > static_cast<int>(qos_max)) { 44 qos = qos_max; 45 } 46 qos_ = qos; 47 } 48 QoS(const QoSMap & qosattr)49 QoS(const QoSMap& qosattr) 50 { 51 qos_ = qosattr.m_qos; 52 } 53 QoS(const QoS & qos)54 QoS(const QoS& qos) : qos_(qos()) 55 { 56 } 57 operator()58 int operator()() const 59 { 60 return qos_; 61 } 62 63 QoS& operator=(int qos) 64 { 65 qos_ = qos; 66 return *this; 67 } 68 69 QoS& operator=(const QoS& qos) 70 { 71 if (this != &qos) { 72 qos_ = qos(); 73 } 74 return *this; 75 } 76 77 bool operator==(int qos) const 78 { 79 return qos_ == qos; 80 } 81 82 bool operator==(const QoS& qos) const 83 { 84 return qos_ == qos(); 85 } 86 87 bool operator!=(int qos) const 88 { 89 return !(*this == qos); 90 } 91 92 bool operator!=(const QoS& qos) const 93 { 94 return !(*this == qos); 95 } 96 97 operator int() const 98 { 99 return qos_; 100 } 101 Min()102 static constexpr int Min() 103 { 104 return qos_background; 105 } 106 Max()107 static constexpr int Max() 108 { 109 return qos_max + 1; 110 } 111 112 private: 113 int qos_; 114 }; 115 }; // namespace ffrt 116 #endif