• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright (c) 2021 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" == *"runtime/tests"* ]]; then
29    # Usage of this_thread::sleep
30    exit 0
31fi
32
33if [[ "$FILE" == *"runtime/profilesaver"* ]]; then
34    # Usage of this_thread::sleep
35    exit 0
36fi
37
38for pattern in "${PATTERNS[@]}"; do
39    if grep ${pattern} ${FILE}; then
40        echo "File ${FILE} contains '${pattern}' usage. Please use wrapper functions from 'os/mutex.h' instead."
41        exit 1
42    fi
43done
44