@@ -139,6 +139,15 @@ endif() | |||
if(CMAKE_ENABLE_UNIT_TEST) | |||
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) | |||
endif() | |||
@@ -7,4 +7,7 @@ foreach(BENCHMARK_FILE_PATH ${BENCHMARK_FILES}) | |||
add_executable(${BENCHMARK_FILE_NAME} ${BENCHMARK_FILE_PATH}) | |||
target_link_libraries(${BENCHMARK_FILE_NAME} PUBLIC librf) | |||
target_compile_definitions(${TUTORIAL_FILE_NAME} | |||
PRIVATE LIBRF_TUTORIAL_STAND_ALONE=1 | |||
) | |||
endforeach(BENCHMARK_FILE_PATH) |
@@ -1,7 +1,7 @@ | |||
| |||
#include <iostream> | |||
#include "librf.h" | |||
#include "librf/librf.h" | |||
#include <asio.hpp> | |||
#include "../asio/asio_task.h" | |||
@@ -4,7 +4,7 @@ | |||
#include <string> | |||
#include <thread> | |||
#include "librf.h" | |||
#include "librf/librf.h" | |||
const size_t N = 5000000; | |||
const size_t LOOP_COUNT = 50; | |||
@@ -39,8 +39,10 @@ void resumable_main_benchmark_mem(bool wait_key) | |||
//clang : 平均 210字节 | |||
//msvc : 平均600字节 | |||
#if LIBRF_TUTORIAL_STAND_ALONE | |||
int main() | |||
{ | |||
resumable_main_benchmark_mem(false); | |||
return 0; | |||
} | |||
#endif |
@@ -6,7 +6,7 @@ | |||
#include <deque> | |||
#include <mutex> | |||
#include "librf.h" | |||
#include "librf/librf.h" | |||
using namespace librf; | |||
using namespace std::chrono; | |||
@@ -74,8 +74,10 @@ void benchmark_main_channel_passing_next() | |||
this_scheduler()->run_until_notask(); | |||
} | |||
#if LIBRF_TUTORIAL_STAND_ALONE | |||
int main() | |||
{ | |||
benchmark_main_channel_passing_next(); | |||
return 0; | |||
} | |||
#endif |
@@ -4,7 +4,7 @@ | |||
#include <iostream> | |||
#include "../../cinatra/include/cinatra.hpp" | |||
#include "librf.h" | |||
#include "librf/librf.h" | |||
#include "use_librf.h" | |||
using namespace librf; |
@@ -93,11 +93,11 @@ namespace librf | |||
} | |||
#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 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; | |||
protected: |
@@ -60,7 +60,7 @@ namespace librf | |||
} | |||
scheduler_t* get_scheduler() const | |||
{ | |||
return get_root()->_scheduler; | |||
return _scheduler ? _scheduler : get_root()->_scheduler; | |||
} | |||
}; | |||
@@ -1 +1 @@ | |||
Subproject commit 678558b0339e490b7c9624d22afca1ab0367fb3e | |||
Subproject commit afe1a6bd4e98ccbb4177ecf90b6335520c85ddff |
@@ -7,4 +7,7 @@ foreach(TUTORIAL_FILE_PATH ${TUTORIAL_FILES}) | |||
add_executable(${TUTORIAL_FILE_NAME} ${TUTORIAL_FILE_PATH}) | |||
target_link_libraries(${TUTORIAL_FILE_NAME} PUBLIC librf) | |||
target_compile_definitions(${TUTORIAL_FILE_NAME} | |||
PRIVATE LIBRF_TUTORIAL_STAND_ALONE=1 | |||
) | |||
endforeach(TUTORIAL_FILE_PATH) |
@@ -105,8 +105,10 @@ void resumable_main_cb() | |||
this_scheduler()->run_until_notask(); | |||
} | |||
#if LIBRF_TUTORIAL_STAND_ALONE | |||
int main() | |||
{ | |||
resumable_main_cb(); | |||
return 0; | |||
} | |||
#endif |
@@ -182,8 +182,10 @@ void resumable_main_channel() | |||
test_channel_performance_double_thread(1000); | |||
} | |||
#if LIBRF_TUTORIAL_STAND_ALONE | |||
int main() | |||
{ | |||
resumable_main_channel(); | |||
return 0; | |||
} | |||
#endif |
@@ -113,8 +113,10 @@ void resumable_main_channel_mult_thread() | |||
std::cout << "OK: counter = " << gcounter.load() << std::endl; | |||
} | |||
#if LIBRF_TUTORIAL_STAND_ALONE | |||
int main() | |||
{ | |||
resumable_main_channel_mult_thread(); | |||
return 0; | |||
} | |||
#endif |
@@ -60,8 +60,10 @@ void resumable_main_dynamic_go() | |||
test_dynamic_go(); | |||
} | |||
#if LIBRF_TUTORIAL_STAND_ALONE | |||
int main() | |||
{ | |||
resumable_main_dynamic_go(); | |||
return 0; | |||
} | |||
#endif |
@@ -195,8 +195,10 @@ void resumable_main_event() | |||
std::cout << std::endl; | |||
} | |||
#if LIBRF_TUTORIAL_STAND_ALONE | |||
int main() | |||
{ | |||
resumable_main_event(); | |||
return 0; | |||
} | |||
#endif |
@@ -183,8 +183,10 @@ void resumable_main_event_timeout() | |||
std::cout << std::endl; | |||
} | |||
#if LIBRF_TUTORIAL_STAND_ALONE | |||
int main() | |||
{ | |||
resumable_main_event_timeout(); | |||
return 0; | |||
} | |||
#endif |
@@ -112,8 +112,10 @@ void resumable_main_event_v2() | |||
std::cout << std::endl; | |||
} | |||
#if LIBRF_TUTORIAL_STAND_ALONE | |||
int main() | |||
{ | |||
resumable_main_event_v2(); | |||
return 0; | |||
} | |||
#endif |
@@ -90,8 +90,10 @@ void resumable_main_exception(bool bomb) | |||
} | |||
} | |||
#if LIBRF_TUTORIAL_STAND_ALONE | |||
int main() | |||
{ | |||
resumable_main_exception(true); | |||
return 0; | |||
} | |||
#endif |
@@ -141,8 +141,10 @@ void resumable_main_layout() | |||
std::cout << __FUNCTION__ << " - end" << std::endl; | |||
} | |||
#if LIBRF_TUTORIAL_STAND_ALONE | |||
int main() | |||
{ | |||
resumable_main_layout(); | |||
return 0; | |||
} | |||
#endif |
@@ -175,8 +175,10 @@ void resumable_main_modern_cb() | |||
example_librf(); | |||
} | |||
#if LIBRF_TUTORIAL_STAND_ALONE | |||
int main() | |||
{ | |||
resumable_main_modern_cb(); | |||
return 0; | |||
} | |||
#endif |
@@ -87,8 +87,10 @@ void resumable_main_multi_thread() | |||
scheduler_t::g_scheduler.run_until_notask(); | |||
} | |||
#if LIBRF_TUTORIAL_STAND_ALONE | |||
int main() | |||
{ | |||
resumable_main_multi_thread(); | |||
return 0; | |||
} | |||
#endif |
@@ -215,8 +215,10 @@ void resumable_main_mutex() | |||
resumable_mutex_lock_range(); | |||
} | |||
#if LIBRF_TUTORIAL_STAND_ALONE | |||
int main() | |||
{ | |||
resumable_main_mutex(); | |||
return 0; | |||
} | |||
#endif |
@@ -78,8 +78,10 @@ void resumable_main_resumable() | |||
*/ | |||
} | |||
#if LIBRF_TUTORIAL_STAND_ALONE | |||
int main() | |||
{ | |||
resumable_main_resumable(); | |||
return 0; | |||
} | |||
#endif |
@@ -44,8 +44,10 @@ void resumable_main_routine() | |||
this_scheduler()->run_until_notask(); | |||
} | |||
#if LIBRF_TUTORIAL_STAND_ALONE | |||
int main() | |||
{ | |||
resumable_main_routine(); | |||
return 0; | |||
} | |||
#endif |
@@ -74,8 +74,10 @@ void resumable_main_sleep() | |||
std::cout << std::endl; | |||
} | |||
#if LIBRF_TUTORIAL_STAND_ALONE | |||
int main() | |||
{ | |||
resumable_main_sleep(); | |||
return 0; | |||
} | |||
#endif |
@@ -96,8 +96,10 @@ void resumable_main_stop_token() | |||
std::cout << "OK - stop_token!" << std::endl; | |||
} | |||
#if LIBRF_TUTORIAL_STAND_ALONE | |||
int main() | |||
{ | |||
resumable_main_stop_token(); | |||
return 0; | |||
} | |||
#endif |
@@ -93,8 +93,10 @@ test_loop_sleep<6> -> 0000016B847726C0 | |||
test_loop_sleep<7> -> 0000016B847726C0 | |||
*/ | |||
#if LIBRF_TUTORIAL_STAND_ALONE | |||
int main() | |||
{ | |||
resumable_main_suspend_always(); | |||
return 0; | |||
} | |||
#endif |
@@ -133,8 +133,10 @@ void resumable_main_switch_scheduler() | |||
other.join(); | |||
} | |||
#if LIBRF_TUTORIAL_STAND_ALONE | |||
int main() | |||
{ | |||
resumable_main_switch_scheduler(); | |||
return 0; | |||
} | |||
#endif |
@@ -34,8 +34,10 @@ void resumable_main_timer() | |||
th2.stop(); //but th2 is invalid | |||
} | |||
#if LIBRF_TUTORIAL_STAND_ALONE | |||
int main() | |||
{ | |||
resumable_main_timer(); | |||
return 0; | |||
} | |||
#endif |
@@ -240,8 +240,10 @@ void resumable_main_when_all() | |||
#endif | |||
} | |||
#if LIBRF_TUTORIAL_STAND_ALONE | |||
int main() | |||
{ | |||
resumable_main_when_all(); | |||
return 0; | |||
} | |||
#endif |
@@ -89,8 +89,10 @@ void resumable_main_yield_return() | |||
this_scheduler()->run_until_notask(); | |||
} | |||
#if LIBRF_TUTORIAL_STAND_ALONE | |||
int main() | |||
{ | |||
resumable_main_yield_return(); | |||
return 0; | |||
} | |||
#endif |