if(CMAKE_ENABLE_UNIT_TEST) | if(CMAKE_ENABLE_UNIT_TEST) | ||||
add_subdirectory(tutorial) | add_subdirectory(tutorial) | ||||
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/tutorial ALL_TUTORIAL_FILES) | |||||
add_executable(test_librf | |||||
${CMAKE_CURRENT_SOURCE_DIR}/test_librf.cpp | |||||
${CMAKE_CURRENT_SOURCE_DIR}/benchmark/benchmark_async_mem.cpp | |||||
${CMAKE_CURRENT_SOURCE_DIR}/benchmark/benchmark_channel_passing_next.cpp | |||||
${ALL_TUTORIAL_FILES}) | |||||
target_link_libraries(test_librf PUBLIC librf) | |||||
#add_subdirectory(benchmark) | #add_subdirectory(benchmark) | ||||
endif() | endif() | ||||
add_executable(${BENCHMARK_FILE_NAME} ${BENCHMARK_FILE_PATH}) | add_executable(${BENCHMARK_FILE_NAME} ${BENCHMARK_FILE_PATH}) | ||||
target_link_libraries(${BENCHMARK_FILE_NAME} PUBLIC librf) | target_link_libraries(${BENCHMARK_FILE_NAME} PUBLIC librf) | ||||
target_compile_definitions(${TUTORIAL_FILE_NAME} | |||||
PRIVATE LIBRF_TUTORIAL_STAND_ALONE=1 | |||||
) | |||||
endforeach(BENCHMARK_FILE_PATH) | endforeach(BENCHMARK_FILE_PATH) |
| | ||||
#include <iostream> | #include <iostream> | ||||
#include "librf.h" | |||||
#include "librf/librf.h" | |||||
#include <asio.hpp> | #include <asio.hpp> | ||||
#include "../asio/asio_task.h" | #include "../asio/asio_task.h" | ||||
#include <string> | #include <string> | ||||
#include <thread> | #include <thread> | ||||
#include "librf.h" | |||||
#include "librf/librf.h" | |||||
const size_t N = 5000000; | const size_t N = 5000000; | ||||
const size_t LOOP_COUNT = 50; | const size_t LOOP_COUNT = 50; | ||||
//clang : 平均 210字节 | //clang : 平均 210字节 | ||||
//msvc : 平均600字节 | //msvc : 平均600字节 | ||||
#if LIBRF_TUTORIAL_STAND_ALONE | |||||
int main() | int main() | ||||
{ | { | ||||
resumable_main_benchmark_mem(false); | resumable_main_benchmark_mem(false); | ||||
return 0; | return 0; | ||||
} | } | ||||
#endif |
#include <deque> | #include <deque> | ||||
#include <mutex> | #include <mutex> | ||||
#include "librf.h" | |||||
#include "librf/librf.h" | |||||
using namespace librf; | using namespace librf; | ||||
using namespace std::chrono; | using namespace std::chrono; | ||||
this_scheduler()->run_until_notask(); | this_scheduler()->run_until_notask(); | ||||
} | } | ||||
#if LIBRF_TUTORIAL_STAND_ALONE | |||||
int main() | int main() | ||||
{ | { | ||||
benchmark_main_channel_passing_next(); | benchmark_main_channel_passing_next(); | ||||
return 0; | return 0; | ||||
} | } | ||||
#endif |
#include <iostream> | #include <iostream> | ||||
#include "../../cinatra/include/cinatra.hpp" | #include "../../cinatra/include/cinatra.hpp" | ||||
#include "librf.h" | |||||
#include "librf/librf.h" | |||||
#include "use_librf.h" | #include "use_librf.h" | ||||
using namespace librf; | using namespace librf; |
} | } | ||||
#ifndef DOXYGEN_SKIP_PROPERTY | #ifndef DOXYGEN_SKIP_PROPERTY | ||||
LIBRF_API void add_generator(state_base_t* sptr); | |||||
LIBRF_API void del_final(state_base_t* sptr); | |||||
void add_generator(state_base_t* sptr); | |||||
void del_final(state_base_t* sptr); | |||||
LIBRF_API std::unique_ptr<task_t> del_switch(state_base_t* sptr); | LIBRF_API std::unique_ptr<task_t> del_switch(state_base_t* sptr); | ||||
LIBRF_API void add_switch(std::unique_ptr<task_t> task); | |||||
LIBRF_API task_t* find_task(state_base_t* sptr) const noexcept; | |||||
void add_switch(std::unique_ptr<task_t> task); | |||||
task_t* find_task(state_base_t* sptr) const noexcept; | |||||
friend struct local_scheduler_t; | friend struct local_scheduler_t; | ||||
protected: | protected: |
} | } | ||||
scheduler_t* get_scheduler() const | scheduler_t* get_scheduler() const | ||||
{ | { | ||||
return get_root()->_scheduler; | |||||
return _scheduler ? _scheduler : get_root()->_scheduler; | |||||
} | } | ||||
}; | }; | ||||
Subproject commit 678558b0339e490b7c9624d22afca1ab0367fb3e | |||||
Subproject commit afe1a6bd4e98ccbb4177ecf90b6335520c85ddff |
add_executable(${TUTORIAL_FILE_NAME} ${TUTORIAL_FILE_PATH}) | add_executable(${TUTORIAL_FILE_NAME} ${TUTORIAL_FILE_PATH}) | ||||
target_link_libraries(${TUTORIAL_FILE_NAME} PUBLIC librf) | target_link_libraries(${TUTORIAL_FILE_NAME} PUBLIC librf) | ||||
target_compile_definitions(${TUTORIAL_FILE_NAME} | |||||
PRIVATE LIBRF_TUTORIAL_STAND_ALONE=1 | |||||
) | |||||
endforeach(TUTORIAL_FILE_PATH) | endforeach(TUTORIAL_FILE_PATH) |
this_scheduler()->run_until_notask(); | this_scheduler()->run_until_notask(); | ||||
} | } | ||||
#if LIBRF_TUTORIAL_STAND_ALONE | |||||
int main() | int main() | ||||
{ | { | ||||
resumable_main_cb(); | resumable_main_cb(); | ||||
return 0; | return 0; | ||||
} | } | ||||
#endif |
test_channel_performance_double_thread(1000); | test_channel_performance_double_thread(1000); | ||||
} | } | ||||
#if LIBRF_TUTORIAL_STAND_ALONE | |||||
int main() | int main() | ||||
{ | { | ||||
resumable_main_channel(); | resumable_main_channel(); | ||||
return 0; | return 0; | ||||
} | } | ||||
#endif |
std::cout << "OK: counter = " << gcounter.load() << std::endl; | std::cout << "OK: counter = " << gcounter.load() << std::endl; | ||||
} | } | ||||
#if LIBRF_TUTORIAL_STAND_ALONE | |||||
int main() | int main() | ||||
{ | { | ||||
resumable_main_channel_mult_thread(); | resumable_main_channel_mult_thread(); | ||||
return 0; | return 0; | ||||
} | } | ||||
#endif |
test_dynamic_go(); | test_dynamic_go(); | ||||
} | } | ||||
#if LIBRF_TUTORIAL_STAND_ALONE | |||||
int main() | int main() | ||||
{ | { | ||||
resumable_main_dynamic_go(); | resumable_main_dynamic_go(); | ||||
return 0; | return 0; | ||||
} | } | ||||
#endif |
std::cout << std::endl; | std::cout << std::endl; | ||||
} | } | ||||
#if LIBRF_TUTORIAL_STAND_ALONE | |||||
int main() | int main() | ||||
{ | { | ||||
resumable_main_event(); | resumable_main_event(); | ||||
return 0; | return 0; | ||||
} | } | ||||
#endif |
std::cout << std::endl; | std::cout << std::endl; | ||||
} | } | ||||
#if LIBRF_TUTORIAL_STAND_ALONE | |||||
int main() | int main() | ||||
{ | { | ||||
resumable_main_event_timeout(); | resumable_main_event_timeout(); | ||||
return 0; | return 0; | ||||
} | } | ||||
#endif |
std::cout << std::endl; | std::cout << std::endl; | ||||
} | } | ||||
#if LIBRF_TUTORIAL_STAND_ALONE | |||||
int main() | int main() | ||||
{ | { | ||||
resumable_main_event_v2(); | resumable_main_event_v2(); | ||||
return 0; | return 0; | ||||
} | } | ||||
#endif |
} | } | ||||
} | } | ||||
#if LIBRF_TUTORIAL_STAND_ALONE | |||||
int main() | int main() | ||||
{ | { | ||||
resumable_main_exception(true); | resumable_main_exception(true); | ||||
return 0; | return 0; | ||||
} | } | ||||
#endif |
std::cout << __FUNCTION__ << " - end" << std::endl; | std::cout << __FUNCTION__ << " - end" << std::endl; | ||||
} | } | ||||
#if LIBRF_TUTORIAL_STAND_ALONE | |||||
int main() | int main() | ||||
{ | { | ||||
resumable_main_layout(); | resumable_main_layout(); | ||||
return 0; | return 0; | ||||
} | } | ||||
#endif |
example_librf(); | example_librf(); | ||||
} | } | ||||
#if LIBRF_TUTORIAL_STAND_ALONE | |||||
int main() | int main() | ||||
{ | { | ||||
resumable_main_modern_cb(); | resumable_main_modern_cb(); | ||||
return 0; | return 0; | ||||
} | } | ||||
#endif |
scheduler_t::g_scheduler.run_until_notask(); | scheduler_t::g_scheduler.run_until_notask(); | ||||
} | } | ||||
#if LIBRF_TUTORIAL_STAND_ALONE | |||||
int main() | int main() | ||||
{ | { | ||||
resumable_main_multi_thread(); | resumable_main_multi_thread(); | ||||
return 0; | return 0; | ||||
} | } | ||||
#endif |
resumable_mutex_lock_range(); | resumable_mutex_lock_range(); | ||||
} | } | ||||
#if LIBRF_TUTORIAL_STAND_ALONE | |||||
int main() | int main() | ||||
{ | { | ||||
resumable_main_mutex(); | resumable_main_mutex(); | ||||
return 0; | return 0; | ||||
} | } | ||||
#endif |
*/ | */ | ||||
} | } | ||||
#if LIBRF_TUTORIAL_STAND_ALONE | |||||
int main() | int main() | ||||
{ | { | ||||
resumable_main_resumable(); | resumable_main_resumable(); | ||||
return 0; | return 0; | ||||
} | } | ||||
#endif |
this_scheduler()->run_until_notask(); | this_scheduler()->run_until_notask(); | ||||
} | } | ||||
#if LIBRF_TUTORIAL_STAND_ALONE | |||||
int main() | int main() | ||||
{ | { | ||||
resumable_main_routine(); | resumable_main_routine(); | ||||
return 0; | return 0; | ||||
} | } | ||||
#endif |
std::cout << std::endl; | std::cout << std::endl; | ||||
} | } | ||||
#if LIBRF_TUTORIAL_STAND_ALONE | |||||
int main() | int main() | ||||
{ | { | ||||
resumable_main_sleep(); | resumable_main_sleep(); | ||||
return 0; | return 0; | ||||
} | } | ||||
#endif |
std::cout << "OK - stop_token!" << std::endl; | std::cout << "OK - stop_token!" << std::endl; | ||||
} | } | ||||
#if LIBRF_TUTORIAL_STAND_ALONE | |||||
int main() | int main() | ||||
{ | { | ||||
resumable_main_stop_token(); | resumable_main_stop_token(); | ||||
return 0; | return 0; | ||||
} | } | ||||
#endif |
test_loop_sleep<7> -> 0000016B847726C0 | test_loop_sleep<7> -> 0000016B847726C0 | ||||
*/ | */ | ||||
#if LIBRF_TUTORIAL_STAND_ALONE | |||||
int main() | int main() | ||||
{ | { | ||||
resumable_main_suspend_always(); | resumable_main_suspend_always(); | ||||
return 0; | return 0; | ||||
} | } | ||||
#endif |
other.join(); | other.join(); | ||||
} | } | ||||
#if LIBRF_TUTORIAL_STAND_ALONE | |||||
int main() | int main() | ||||
{ | { | ||||
resumable_main_switch_scheduler(); | resumable_main_switch_scheduler(); | ||||
return 0; | return 0; | ||||
} | } | ||||
#endif |
th2.stop(); //but th2 is invalid | th2.stop(); //but th2 is invalid | ||||
} | } | ||||
#if LIBRF_TUTORIAL_STAND_ALONE | |||||
int main() | int main() | ||||
{ | { | ||||
resumable_main_timer(); | resumable_main_timer(); | ||||
return 0; | return 0; | ||||
} | } | ||||
#endif |
#endif | #endif | ||||
} | } | ||||
#if LIBRF_TUTORIAL_STAND_ALONE | |||||
int main() | int main() | ||||
{ | { | ||||
resumable_main_when_all(); | resumable_main_when_all(); | ||||
return 0; | return 0; | ||||
} | } | ||||
#endif |
this_scheduler()->run_until_notask(); | this_scheduler()->run_until_notask(); | ||||
} | } | ||||
#if LIBRF_TUTORIAL_STAND_ALONE | |||||
int main() | int main() | ||||
{ | { | ||||
resumable_main_yield_return(); | resumable_main_yield_return(); | ||||
return 0; | return 0; | ||||
} | } | ||||
#endif |