Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Default build options. These are applied first and unconditionally.
#

build --cxxopt="-std=c++11"
build --cxxopt="-std=c++17"
# Use gnu11 for asm keyword.
build --conlyopt="-std=gnu11"

Expand Down
122 changes: 22 additions & 100 deletions .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ on:
paths-ignore:
- '**.md'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
proc_num: $(nproc)

jobs:
gcc-compile-with-make:
runs-on: ubuntu-20.04 # https://github.com/actions/runner-images
runs-on: ubuntu-24.04 # https://github.com/actions/runner-images
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v7
- uses: ./.github/actions/install-essential-dependences
- uses: ./.github/actions/init-make-config
with:
Expand All @@ -27,9 +31,9 @@ jobs:
make -j ${{env.proc_num}}

gcc-compile-with-cmake:
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v7
- uses: ./.github/actions/install-essential-dependences
- name: cmake
run: |
Expand All @@ -43,9 +47,9 @@ jobs:
make -j ${{env.proc_num}}

gcc-compile-with-bazel:
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v7
- name: install dependences
run: |
sudo apt-get update
Expand All @@ -56,9 +60,9 @@ jobs:
bazel build -j ${{env.proc_num}} -c opt --copt -DHAVE_ZLIB=1 //...

gcc-compile-with-make-all-options:
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v7
- uses: ./.github/actions/install-all-dependences
- uses: ./.github/actions/init-make-config
with:
Expand All @@ -68,9 +72,9 @@ jobs:
make -j ${{env.proc_num}}

gcc-compile-with-cmake-all-options:
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v7
- uses: ./.github/actions/install-all-dependences
- name: cmake
run: |
Expand All @@ -84,9 +88,9 @@ jobs:
make -j ${{env.proc_num}}

gcc-compile-with-bazel-all-options:
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v7
- name: install dependences
run: |
sudo apt-get update
Expand All @@ -96,100 +100,18 @@ jobs:
export CC=gcc && export CXX=g++
bazel build -j 12 -c opt --define with_mesalink=false --define with_glog=true --define with_thrift=true --copt -DHAVE_ZLIB=1 //...


clang-compile-with-make:
runs-on: ubuntu-20.04
gcc-unittest:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v7
- uses: ./.github/actions/install-essential-dependences
- uses: ./.github/actions/init-make-config
with:
options: --cc=clang --cxx=clang++
- name: compile
run: |
make -j ${{env.proc_num}}

clang-compile-with-cmake:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/install-essential-dependences
- name: cmake
run: |
export CC=clang && export CXX=clang++
mkdir build
cd build
cmake ..
- name: compile
run: |
cd build
make -j ${{env.proc_num}}

clang-compile-with-bazel:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: install dependences
- name: install test dependencies
run: |
sudo apt-get update
sudo apt-get install libibverbs-dev
- name: compile
run: |
export CC=clang && export CXX=clang++
bazel build -j ${{env.proc_num}} -c opt --copt -DHAVE_ZLIB=1 //...

clang-compile-with-make-all-options:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/install-all-dependences
sudo apt-get install -y gdb libgtest-dev
- uses: ./.github/actions/init-make-config
with:
options: --cc=clang --cxx=clang++ --with-thrift --with-glog
- name: compile
run: |
make -j ${{env.proc_num}}

clang-compile-with-cmake-all-options:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/install-all-dependences
- name: cmake
run: |
export CC=clang && export CXX=clang++
mkdir build
cd build
cmake -DWITH_MESALINK=OFF -DWITH_GLOG=ON -DWITH_THRIFT=ON ..
- name: compile
run: |
cd build
make -j ${{env.proc_num}}

clang-compile-with-bazel-all-options:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: install dependences
run: |
sudo apt-get update
sudo apt-get install libibverbs-dev
- name: compile
run: |
export CC=clang && export CXX=clang++
bazel build -j ${{env.proc_num}} -c opt --define with_mesalink=false --define with_glog=true --define with_thrift=true --copt -DHAVE_ZLIB=1 //...

clang-unittest:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/install-essential-dependences
- name: install gtest
run: |
sudo apt-get install -y cmake libgtest-dev && cd /usr/src/gtest && sudo cmake . && sudo make && sudo mv lib/libgtest* /usr/lib/
- uses: ./.github/actions/init-make-config
with:
options: --cc=clang --cxx=clang++
options: --cc=gcc --cxx=g++
- name: compile tests
run: |
cd test
Expand Down
58 changes: 0 additions & 58 deletions .github/workflows/ci-macos.yml

This file was deleted.

7 changes: 6 additions & 1 deletion .github/workflows/license-eyes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ on:
push:
branches:
- master

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
license-check:
name: "License Check"
runs-on: ubuntu-latest
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v2
uses: actions/checkout@v7
- name: Check License
uses: apache/skywalking-eyes@v0.4.0
env:
Expand Down
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ http_archive(
sha256 = "5347464af5b14ac54bb945dc68f1dd7c56f0dad7262816b956138fc53bcc0131",
strip_prefix = "boost_1_77_0",
urls = [
"https://boostorg.jfrog.io/artifactory/main/release/1.77.0/source/boost_1_77_0.tar.gz",
"https://archives.boost.io/release/1.77.0/source/boost_1_77_0.tar.gz",
],
)

Expand Down
24 changes: 18 additions & 6 deletions src/butil/fast_rand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "butil/macros.h"
#include "butil/time.h" // gettimeofday_us()
#include "butil/fast_rand.h"
#include "butil/numerics/safe_conversions.h" // safe_abs

namespace butil {

Expand Down Expand Up @@ -110,20 +111,31 @@ int64_t fast_rand_in_64(int64_t min, int64_t max) {
if (need_init(_tls_seed)) {
init_fast_rand_seed(&_tls_seed);
}
if (min >= max) {
if (BAIDU_UNLIKELY(min >= max)) {
if (min == max) {
return min;
}
const int64_t tmp = min;
min = max;
max = tmp;
std::swap(min, max);
}
uint64_t range;
if (min >= 0) {
// Always safe to do subtraction.
range = (uint64_t)(max - min) + 1;
return min + (int64_t)fast_rand_impl(range, &_tls_seed);
}

uint64_t abs_min = safe_abs(min);
if (max >= 0) {
range = abs_min + (uint64_t)(max) + 1;
} else {
range = abs_min - safe_abs(max) + 1;
}
int64_t range = max - min + 1;
if (range == 0) {
// max = INT64_MAX, min = INT64_MIN
return (int64_t)xorshift128_next(&_tls_seed);
}
return min + (int64_t)fast_rand_impl(max - min + 1, &_tls_seed);
uint64_t r = fast_rand_impl(range, &_tls_seed);
return r >= abs_min ? (int64_t)(r - abs_min) : -((int64_t)(abs_min - r));
}

uint64_t fast_rand_in_u64(uint64_t min, uint64_t max) {
Expand Down
25 changes: 25 additions & 0 deletions src/butil/numerics/safe_conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,31 @@ inline Dst saturated_cast(Src value) {
return static_cast<Dst>(value);
}

inline uint64_t safe_abs(uint64_t x) {
return x;
}

inline uint64_t safe_abs(int64_t x) {
return (x >= 0) ? (uint64_t)x : ((~(uint64_t)(x)) + 1);
}

inline uint32_t safe_abs(uint32_t x) {
return x;
}

inline uint32_t safe_abs(int32_t x) {
return (uint32_t)safe_abs((int64_t)x);
}

#if defined(__APPLE__)
inline unsigned long safe_abs(unsigned long x) {
return x;
}
inline unsigned long safe_abs(long x) {
return (x >= 0) ? (unsigned long)x : ((~(unsigned long)(x)) + 1);
}
#endif

} // namespace butil

#endif // BUTIL_SAFE_CONVERSIONS_H_
Loading