pi mutex interface

Signed-off-by: liuchungang <liuchungang@hisilicon.com>
This commit is contained in:
Marquez_esta
2025-11-21 14:23:40 +08:00
committed by liuchungang
parent 11c6907043
commit 4ef2c59cde
2 changed files with 48 additions and 1 deletions
+2 -1
View File
@@ -63,7 +63,8 @@
"header": {
"header_base": "//foundation/resourceschedule/qos_manager/interfaces/inner_api/",
"header_files": [
"qos.h"
"qos.h",
"pi_mutex.h"
]
},
"name": "//foundation/resourceschedule/qos_manager/qos:qos"
+46
View File
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef QOS_PI_MUETX_H
#define QOS_PI_MUETX_H
#include <pthread.h>
#include <mutex>
#include <type_traits>
namespace OHOS {
namespace QOS {
class PiMutex : public std::mutex {
public:
PiMutex()
{
if constexpr (std::is_same_v<std::mutex::native_handle_type, pthread_mutex_t*>) {
std::mutex::native_handle_type handle = std::mutex::native_handle();
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT);
pthread_mutex_init(handle, &attr);
}
}
~PiMutex() = default;
PiMutex(const PiMutex&) = delete;
PiMutex& operator=(const PiMutex&) = delete;
};
} // namespace QOS
} // namespace OHOS
#endif // QOS_PI_MUETX_H