1#!/bin/bash 2# Copyright (c) 2021-2022 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 15set -e 16 17FILE="$1" 18PATTERNS=( 19 '<mutex>' 'pthread' '<shared_mutex>' '<condition_variable>' '<future>' '<stop_token>' 'this_thread' 20 'std::mutex' 'recursive_mutex' 'lock_guard' 21) 22 23if [[ "$FILE" == *"libpandabase/os"* ]]; then 24 # Do not check files with primitives wrappers. 25 exit 0 26fi 27 28if [[ "$FILE" == *"libopenjdkpandavm/"* ]]; then 29 # Do not check files with primitives wrappers. 30 exit 0 31fi 32 33if [[ "$FILE" == *"runtime/tests"* ]]; then 34 # Usage of this_thread::sleep 35 exit 0 36fi 37 38if [[ "$FILE" == *"runtime/profilesaver"* ]]; then 39 # Usage of this_thread::sleep 40 exit 0 41fi 42 43if [[ "$FILE" == *"runtime/methodtrace/trace"* ]]; then 44 # Usage of specific UNIX functions: clock_gettime(), pthread_getcpuclockid() 45 exit 0 46fi 47 48if [[ "$FILE" == *"java/runtime/java_signal_catcher.cpp"* ]]; then 49 # Usage of specific UNIX functions: pthread_kill() 50 exit 0 51fi 52 53if [[ "$FILE" == *"compiler/optimizer/code_generator/disassembly.cpp"* ]]; then 54 # Usage of std::call_once 55 exit 0 56fi 57 58for pattern in "${PATTERNS[@]}"; do 59 if grep ${pattern} ${FILE}; then 60 echo "File ${FILE} contains '${pattern}' usage. Please use wrapper functions from 'os/mutex.h' instead." 61 exit 1 62 fi 63done 64