1b1994897Sopenharmony_ci#!/bin/bash 2b1994897Sopenharmony_ci# Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3b1994897Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 4b1994897Sopenharmony_ci# you may not use this file except in compliance with the License. 5b1994897Sopenharmony_ci# You may obtain a copy of the License at 6b1994897Sopenharmony_ci# 7b1994897Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 8b1994897Sopenharmony_ci# 9b1994897Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software 10b1994897Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 11b1994897Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12b1994897Sopenharmony_ci# See the License for the specific language governing permissions and 13b1994897Sopenharmony_ci# limitations under the License. 14b1994897Sopenharmony_ci 15b1994897Sopenharmony_ciset -e 16b1994897Sopenharmony_ci 17b1994897Sopenharmony_ciFILE="$1" 18b1994897Sopenharmony_ciPATTERNS=( 19b1994897Sopenharmony_ci '<mutex>' 'pthread' '<shared_mutex>' '<condition_variable>' '<future>' '<stop_token>' 'this_thread' 20b1994897Sopenharmony_ci 'std::mutex' 'recursive_mutex' 'lock_guard' 21b1994897Sopenharmony_ci) 22b1994897Sopenharmony_ci 23b1994897Sopenharmony_ciif [[ "$FILE" == *"libpandabase/os"* ]]; then 24b1994897Sopenharmony_ci # Do not check files with primitives wrappers. 25b1994897Sopenharmony_ci exit 0 26b1994897Sopenharmony_cifi 27b1994897Sopenharmony_ci 28b1994897Sopenharmony_ciif [[ "$FILE" == *"libopenjdkpandavm/"* ]]; then 29b1994897Sopenharmony_ci # Do not check files with primitives wrappers. 30b1994897Sopenharmony_ci exit 0 31b1994897Sopenharmony_cifi 32b1994897Sopenharmony_ci 33b1994897Sopenharmony_ciif [[ "$FILE" == *"runtime/tests"* ]]; then 34b1994897Sopenharmony_ci # Usage of this_thread::sleep 35b1994897Sopenharmony_ci exit 0 36b1994897Sopenharmony_cifi 37b1994897Sopenharmony_ci 38b1994897Sopenharmony_ciif [[ "$FILE" == *"runtime/profilesaver"* ]]; then 39b1994897Sopenharmony_ci # Usage of this_thread::sleep 40b1994897Sopenharmony_ci exit 0 41b1994897Sopenharmony_cifi 42b1994897Sopenharmony_ci 43b1994897Sopenharmony_ciif [[ "$FILE" == *"runtime/methodtrace/trace"* ]]; then 44b1994897Sopenharmony_ci # Usage of specific UNIX functions: clock_gettime(), pthread_getcpuclockid() 45b1994897Sopenharmony_ci exit 0 46b1994897Sopenharmony_cifi 47b1994897Sopenharmony_ci 48b1994897Sopenharmony_ciif [[ "$FILE" == *"java/runtime/java_signal_catcher.cpp"* ]]; then 49b1994897Sopenharmony_ci # Usage of specific UNIX functions: pthread_kill() 50b1994897Sopenharmony_ci exit 0 51b1994897Sopenharmony_cifi 52b1994897Sopenharmony_ci 53b1994897Sopenharmony_ciif [[ "$FILE" == *"compiler/optimizer/code_generator/disassembly.cpp"* ]]; then 54b1994897Sopenharmony_ci # Usage of std::call_once 55b1994897Sopenharmony_ci exit 0 56b1994897Sopenharmony_cifi 57b1994897Sopenharmony_ci 58b1994897Sopenharmony_cifor pattern in "${PATTERNS[@]}"; do 59b1994897Sopenharmony_ci if grep ${pattern} ${FILE}; then 60b1994897Sopenharmony_ci echo "File ${FILE} contains '${pattern}' usage. Please use wrapper functions from 'os/mutex.h' instead." 61b1994897Sopenharmony_ci exit 1 62b1994897Sopenharmony_ci fi 63b1994897Sopenharmony_cidone 64