Skip to content
Open
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
1 change: 1 addition & 0 deletions .github/workflows/auto-pr-autodelete.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.AUTOPR_SECRET }}

- name: set git config
run: |
Expand Down
59 changes: 56 additions & 3 deletions .github/workflows/ci.linux.arm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
branches: [ "main", "release/*" ]

jobs:
gcc921:
runs-on: [self-hosted, Linux, ARM64]
arm-linux-build-and-test:
runs-on: ubuntu-24.04-arm

container:
image: ghcr.io/alibaba/photon-ut-base:latest
Expand All @@ -23,7 +23,7 @@ jobs:

- uses: actions/checkout@v4

- name: Build
- name: Build-Debug-921-C++14
run: |
source /opt/rh/gcc-toolset-9/enable
cmake -B build -D CMAKE_BUILD_TYPE=MinSizeRel \
Expand All @@ -36,6 +36,7 @@ jobs:
-D PHOTON_ENABLE_EXTFS=ON
cmake --build build -j $(nproc)

<<<<<<< HEAD
- name: Test
run: |
cd build
Expand All @@ -50,11 +51,15 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Build
=======
- name: Build-Debug-921-C++17
>>>>>>> aaabc01 (make it compiles with C++17/20/23)
run: |
dnf install -y 'dnf-command(config-manager)'
dnf config-manager --set-enabled powertools
dnf -q -y install git gcc-c++ cmake gcc-toolset-9-gcc-c++ nasm
source /opt/rh/gcc-toolset-9/enable
<<<<<<< HEAD
cmake -B build -D CMAKE_BUILD_TYPE=Debug \
-D PHOTON_BUILD_DEPENDENCIES=ON \
-D PHOTON_BUILD_TESTING=ON \
Expand All @@ -65,3 +70,51 @@ jobs:
-D PHOTON_ENABLE_LIBCURL=OFF \
-D PHOTON_ENABLE_EXTFS=OFF
cmake --build build -j $(nproc)
=======
rm -fr build
cmake -B build \
-D PHOTON_CXX_STANDARD=17 \
-D CMAKE_BUILD_TYPE=Debug \
-D PHOTON_ENABLE_ECOSYSTEM=ON \
-D PHOTON_BUILD_TESTING=ON \
-D PHOTON_ENABLE_SASL=ON \
-D PHOTON_ENABLE_FUSE=ON \
-D PHOTON_ENABLE_LIBCURL=ON \
-D PHOTON_ENABLE_EXTFS=ON
cmake --build build -j $(nproc) -- VERBOSE=1

- name: Build-Debug-1121-C++20
run: |
source /opt/rh/gcc-toolset-11/enable
rm -fr build
cmake -B build \
-D PHOTON_CXX_STANDARD=20 \
-D CMAKE_BUILD_TYPE=Debug \
-D PHOTON_ENABLE_ECOSYSTEM=ON \
-D PHOTON_BUILD_TESTING=ON \
-D PHOTON_ENABLE_SASL=ON \
-D PHOTON_ENABLE_FUSE=ON \
-D PHOTON_ENABLE_LIBCURL=ON \
-D PHOTON_ENABLE_EXTFS=ON
cmake --build build -j $(nproc) -- VERBOSE=1

- name: Build-Debug-1211-C++23
run: |
source /opt/rh/gcc-toolset-12/enable
rm -fr build
cmake -B build \
-D PHOTON_CXX_STANDARD=23 \
-D CMAKE_BUILD_TYPE=Debug \
-D PHOTON_ENABLE_ECOSYSTEM=ON \
-D PHOTON_BUILD_TESTING=ON \
-D PHOTON_ENABLE_SASL=ON \
-D PHOTON_ENABLE_FUSE=ON \
-D PHOTON_ENABLE_LIBCURL=ON \
-D PHOTON_ENABLE_EXTFS=ON
cmake --build build -j $(nproc) -- VERBOSE=1

- name: Test
run: |
cd build
ctest -E test-lockfree --timeout 3600 -V
>>>>>>> aaabc01 (make it compiles with C++17/20/23)
8 changes: 4 additions & 4 deletions common/consistent-hash-map.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ class consistent_hash_map
const allocator_type& alloc = allocator_type()) :
m_comp(comp), m_vector(alloc) { }

using reference = typename allocator_type::reference;
using const_reference = typename allocator_type::const_reference;
using pointer = typename allocator_type::pointer;
using const_pointer = typename allocator_type::const_pointer;
using reference = mapped_type&;
using const_reference = const mapped_type&;
using pointer = mapped_type*;
using const_pointer = const mapped_type*;
using container_type = std::vector<value_type, allocator_type>;
using iterator = typename container_type::iterator;
using const_iterator = typename container_type::const_iterator;
Expand Down
5 changes: 5 additions & 0 deletions common/enumerable.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ struct Enumerable
if (obj && !obj->valid())
this->obj = nullptr;
}
#if __cplusplus < 201703L
using R = typename std::result_of<decltype(&T::get)(T)>::type;
#else
using R = typename std::invoke_result<decltype(&T::get), T>::type;
#endif

R operator*() { return obj ? obj->get() : R{}; }
bool operator==(const iterator& rhs) const { return obj == rhs.obj; }
bool operator!=(const iterator& rhs) const { return !(*this == rhs); }
Expand Down
8 changes: 8 additions & 0 deletions common/executor/executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ class Executor {

template <
typename Context = AutoContext, typename Func,
#if __cplusplus < 201703L
typename R = typename std::result_of<Func()>::type,
#else
typename R = typename std::invoke_result<Func>::type,
#endif
typename _ = typename std::enable_if<!std::is_void<R>::value, R>::type>
R perform(Func &&act) {
R result;
Expand All @@ -60,7 +64,11 @@ class Executor {

template <
typename Context = AutoContext, typename Func,
#if __cplusplus < 201703L
typename R = typename std::result_of<Func()>::type,
#else
typename R = typename std::invoke_result<Func>::type,
#endif
typename _ = typename std::enable_if<std::is_void<R>::value, R>::type>
void perform(Func &&act) {
Awaiter<Context> aop;
Expand Down
1 change: 1 addition & 0 deletions common/expirecontainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,4 @@ class ObjectCache<KeyType, intrusive_list<NodeType>>
Base::release(typename Base::Item(key), recycle, destroy));
}
};

6 changes: 3 additions & 3 deletions common/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ TEST(iovector, test1)
EXPECT_EQ(iov.sum(), 0);
EXPECT_TRUE(iov.empty());
EXPECT_EQ(iov.front_free_iovcnt(), IOVector::default_preserve);
EXPECT_EQ(iov.back_free_iovcnt(), IOVector::capacity - IOVector::default_preserve);
EXPECT_EQ(iov.back_free_iovcnt(), (uint16_t)IOVector::capacity - (uint16_t)IOVector::default_preserve);
EXPECT_EQ(iov.begin(), iov.iovec());

iovec v{nullptr, 33}, v2{nullptr, 44};
Expand All @@ -525,7 +525,7 @@ TEST(iovector, test1)
EXPECT_EQ(iov.back(), v);
EXPECT_EQ(iov.iovcnt(), 3);
EXPECT_EQ(iov.front_free_iovcnt(), IOVector::default_preserve - 3);
EXPECT_EQ(iov.back_free_iovcnt(), IOVector::capacity - IOVector::default_preserve);
EXPECT_EQ(iov.back_free_iovcnt(), (uint16_t)IOVector::capacity - (uint16_t)IOVector::default_preserve);
EXPECT_EQ(iov.sum(), 44+55+33);

iov.push_back(77);
Expand All @@ -540,7 +540,7 @@ TEST(iovector, test1)
EXPECT_EQ(iov.back(), v);
EXPECT_EQ(iov.iovcnt(), 6);
EXPECT_EQ(iov.front_free_iovcnt(), IOVector::default_preserve - 3);
EXPECT_EQ(iov.back_free_iovcnt(), IOVector::capacity - IOVector::default_preserve - 3);
EXPECT_EQ(iov.back_free_iovcnt(), (uint16_t)IOVector::capacity - (uint16_t)IOVector::default_preserve - 3);
EXPECT_EQ(iov.sum(), 44+55+33 + 77+44+33);

EXPECT_EQ(iov.pop_front(), 44);
Expand Down
1 change: 1 addition & 0 deletions common/test/test_objcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ limitations under the License.

#undef private
#undef protected

#include <thread>
#include <gtest/gtest.h>
#include <photon/thread/thread.h>
Expand Down
12 changes: 11 additions & 1 deletion common/timeout.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,19 @@ limitations under the License.
*/

#pragma once
#include <chrono>
#include <cinttypes>
#include <photon/common/utility.h>
#ifdef private
#define _PHOTON_UNIT_TEST
#undef private
#undef protected
#endif
#include <chrono>
#ifdef _PHOTON_UNIT_TEST
#undef _PHOTON_UNIT_TEST
#define private public
#define protected public
#endif

namespace photon {

Expand Down
4 changes: 2 additions & 2 deletions examples/sync-primitive/sync-primitive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ int main() {
message.sem.wait(1);
auto end = std::chrono::steady_clock::now();
auto duration_us = std::chrono::duration_cast<std::chrono::nanoseconds>(end - message.start).count();
latency.fetch_add(duration_us, std::memory_order::memory_order_relaxed);
qps.fetch_add(1, std::memory_order::memory_order_relaxed);
latency.fetch_add(duration_us, std::memory_order_relaxed);
qps.fetch_add(1, std::memory_order_relaxed);
}
}));
}
Expand Down
4 changes: 4 additions & 0 deletions fs/async_filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ namespace fs
{
public:
template<typename IF, typename Func, typename...ARGS,
#if __cplusplus < 201703L
typename R = typename std::result_of<Func(IF*, ARGS...)>::type >
#else
typename R = typename std::invoke_result<Func, IF*, ARGS...>::type>
#endif
R perform(IF* _if, Func func, ARGS...args)
{
return th_performer<R>().call(_if, func, args...);
Expand Down
5 changes: 5 additions & 0 deletions fs/exportfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,13 @@ namespace fs
__attribute__((visibility("hidden"))) Delegate<void> ExportBase::op;
__attribute__((visibility("hidden"))) ThreadPoolBase* ExportBase::pool = nullptr;

#if __cplusplus > 202000L
#define PERFORM(ID, expr) \
perform(timeout, new auto([=, this]() { do_callback(ID, expr, done); }));
#else
#define PERFORM(ID, expr) \
perform(timeout, new auto([=]() { do_callback(ID, expr, done); }));
#endif

class ExportAsAsyncFile : public ExportBase, public IAsyncFile, public IAsyncFileXAttr
{
Expand Down
15 changes: 10 additions & 5 deletions fs/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,12 +571,17 @@ TEST(AsyncFS, AsyncFS)
tafs.do_test(f);
}

#if __cplusplus < 202000
#define CAPTURE =
#else
#define CAPTURE =,this
#endif
class AFile : public ExampleAsyncFile
{
public:
OVERRIDE_ASYNC(ssize_t, pread, void *buf, size_t count, off_t offset)
{
std::thread t([=]()
std::thread t([CAPTURE]()
{
::sleep(1);
callback_umimplemented<ssize_t>(done);
Expand All @@ -588,7 +593,7 @@ class AFile : public ExampleAsyncFile
{
LOG_DEBUG("into afile pwrite `", timeout);

std::thread t([=]()
std::thread t([CAPTURE]()
{
::usleep(timeout);
//only return count/2 for timeout fired
Expand All @@ -604,7 +609,7 @@ class ExampleAsyncDir: public AsyncDIR {
OVERRIDE_ASYNC0(int, closedir) {
}
OVERRIDE_ASYNC0(dirent*, get) {
std::thread t([=]()
std::thread t([CAPTURE]()
{
::usleep(timeout);
AsyncResult<dirent*> r;
Expand All @@ -631,7 +636,7 @@ class AFS : public ExampleAsyncFileSystem {
public:
OVERRIDE_ASYNC(IAsyncFile*, open, const char *pathname, int flags)
{
std::thread t([=]()
std::thread t([CAPTURE]()
{
callback(done, UINT32_MAX, exampleAfile, 0);
});
Expand All @@ -640,7 +645,7 @@ class AFS : public ExampleAsyncFileSystem {

OVERRIDE_ASYNC(AsyncDIR*, opendir, const char *name)
{
std::thread t([=]()
std::thread t([CAPTURE]()
{
::usleep(timeout);
if (name[0] == 's') {
Expand Down
1 change: 1 addition & 0 deletions net/http/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ class ClientImpl : public Client {
resp.reset((char *)buf, kMinimalHeadersSize, true, sock.release(), true, req.verb());
}
if (op->resp.receive_header(tmo.timeout()) != 0) {
sock->close();
req.reset_status();
LOG_ERROR_RETURN(0, ROUNDTRIP_NEED_RETRY, "read response header failed");
}
Expand Down
51 changes: 50 additions & 1 deletion thread/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,54 @@ namespace photon
void* _ptr;
};

<<<<<<< HEAD
=======
#if defined(__has_feature)
# if __has_feature(address_sanitizer) // for clang
# define __SANITIZE_ADDRESS__ // GCC already sets this
# endif
#endif

#ifdef __SANITIZE_ADDRESS__
extern "C" {
// Check out sanitizer/asan-interface.h in compiler-rt for documentation.
void __sanitizer_start_switch_fiber(void** fake_stack_save, const void* bottom,
size_t size);
void __sanitizer_finish_switch_fiber(void* fake_stack_save,
const void** bottom_old, size_t* size_old);
}

static void asan_start(void** save, thread* to) {
void* bottom = to->buf ? to->buf : to->stackful_alloc_top;
__sanitizer_start_switch_fiber(save, bottom,
to->stack_size);
}

static void asan_finish(void* save) {
__sanitizer_finish_switch_fiber(save, nullptr, nullptr);
}

#define ASAN_START() asan_finish((void*)nullptr);

#define ASAN_SWITCH(to) \
void* __save; \
asan_start(&__save, to); \
DEFER({ asan_finish(__save); });

#define ASAN_DIE_SWITCH(to) \
asan_start(nullptr, to);

#else
#define ASAN_START(ptr)
#define ASAN_SWITCH(to)
#define ASAN_DIE_SWITCH(to)
#endif

static void _asan_start() asm("_asan_start");

__attribute__((used)) static void _asan_start() { ASAN_START(); }

>>>>>>> aaabc01 (make it compiles with C++17/20/23)
struct thread_list;
struct thread : public intrusive_list_node<thread> {
volatile vcpu_t* vcpu;
Expand Down Expand Up @@ -680,7 +728,8 @@ namespace photon
inline void prepare_switch(thread* from, thread* to) {
assert(from->vcpu == to->vcpu);
assert(to->state == states::RUNNING);
to->get_vcpu()->switch_count++;
auto& cnt = to->get_vcpu()->switch_count;
(*(uint64_t*)&cnt)++; // increment of volatile variable is deprecated
}

#pragma GCC diagnostic push
Expand Down
4 changes: 2 additions & 2 deletions thread/workerpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class WorkPool::impl {
auto task = ring.recv(running_tasks.load() ? 0 : QUEUE_YIELD_COUNT,
QUEUE_YIELD_US);
if (!task) break;
running_tasks.fetch_add(std::memory_order_acq_rel);
running_tasks.fetch_add(1, std::memory_order_acq_rel);
TaskLB tasklb{task, &running_tasks};
if (mode < 0) {
delegate_helper(&tasklb);
Expand All @@ -143,7 +143,7 @@ class WorkPool::impl {
// must copy to keep tasklb alive
TaskLB tasklb = *(TaskLB*)arg;
tasklb.task();
tasklb.count->fetch_sub(std::memory_order_acq_rel);
tasklb.count->fetch_sub(1, std::memory_order_acq_rel);
return nullptr;
}

Expand Down
Loading