Skip to content

Commit

Permalink
build a async task schedule framework
Browse files Browse the repository at this point in the history
  • Loading branch information
fs committed Mar 7, 2024
1 parent f046006 commit 1a6b1d2
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 0 deletions.
11 changes: 11 additions & 0 deletions c++/async_task/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.10)
project(async_task)

set(CMAKE_CXX_STANDARD 11)

# 添加src目录
add_subdirectory(src)

# 启用测试
# enable_testing()
# add_subdirectory(tests)
5 changes: 5 additions & 0 deletions c++/async_task/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## how to run
mkdir build
cd build && cmake .. && make

## how to test
6 changes: 6 additions & 0 deletions c++/async_task/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
file(GLOB_RECURSE SOURCE_FILES "*.cpp")

add_library(async_task SHARED ${SOURCE_FILES})

# 指定这个库的头文件路径
target_include_directories(async_task PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
45 changes: 45 additions & 0 deletions c++/async_task/src/task.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef ASYNC_TASK_H
#define ASYNC_TASK_H

#include <string>
#include <memory>
#include <functional>
#include <atomic>
#include "utils/utils_define.h"

namespace async_framework {
/**
* @brief 任务参数类
*
* 用于存储任务相关的参数。
*/
class TaskParam {
public:
virtual ~TaskParam() = default;
};

class VoidTaskParam : public TaskParam {
public:
VoidTaskParam() = default;
virtual ~VoidTaskParam() = default;

static VoidTaskParam& value() {
return *pointer();
}
static std::shared_ptr< VoidTaskParam > pointer() {
static std::shared_ptr< VoidTaskParam > s_void_param = std::make_shared< VoidTaskParam >();
return s_void_param;
}
private:
DISALLOW_COPY_AND_ASSIGN(VoidTaskParam);

};

class task {
public:
};

}


#endif
Empty file added c++/async_task/src/task.h
Empty file.
10 changes: 10 additions & 0 deletions c++/async_task/src/utils/utils_define.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef UTILS_DEFINE_H
#define UTILS_DEFINE_H

#ifndef DISALLOW_COPY_AND_ASSIGN
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&) = delete; \
TypeName& operator=(const TypeName&) = delete
#endif

#endif // BAIDU_AD2_SIM_FRAMEWORK_INLUCDE_GLOBAL_DEFINE_H

0 comments on commit 1a6b1d2

Please sign in to comment.