Skip to content

Commit 5037dc0

Browse files
committed
update examples
1 parent df4da4d commit 5037dc0

File tree

4 files changed

+38
-33
lines changed

4 files changed

+38
-33
lines changed

CMakeLists.txt

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,11 @@
11
cmake_minimum_required(VERSION 3.10)
22
project(debugio CXX)
33

4-
enable_testing()
5-
#SET (CMAKE_VERBOSE_MAKEFILE 1)
6-
74
set(CMAKE_CXX_STANDARD 20)
5+
#SET (CMAKE_VERBOSE_MAKEFILE 1)
86

9-
set(EXAMPLE_READER_SOURCES example/reader.cpp)
10-
set(EXAMPLE_WRITER_SOURCES example/writer.cpp)
7+
option(BUILD_EXAMPLE "Build the example tree." ON)
118

12-
if(WIN32)
13-
set(EXAMPLE_READER_SOURCES
14-
${EXAMPLE_READER_SOURCES}
15-
windows/debugio_impl.cpp
16-
)
17-
set(EXAMPLE_WRITER_SOURCES
18-
${EXAMPLE_READER_SOURCES}
19-
windows/debugio_impl.cpp
20-
)
21-
else()
22-
set(ADD_LINK_LIBRARIES pthread rt)
23-
set(EXAMPLE_READER_SOURCES
24-
${EXAMPLE_READER_SOURCES}
25-
linux/debugio_impl.cpp
26-
)
27-
set(EXAMPLE_WRITER_SOURCES
28-
${EXAMPLE_READER_SOURCES}
29-
linux/debugio_impl.cpp
30-
)
9+
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_EXAMPLE)
10+
add_subdirectory(example)
3111
endif()
32-
33-
add_executable(example_reader ${EXAMPLE_READER_SOURCES})
34-
target_link_libraries(example_reader ${EXAMPLE_READER_LIBRARIES})
35-
36-
add_executable(example_writer ${EXAMPLE_WRITER_SOURCES})
37-
target_link_libraries(example_writer ${EXAMPLE_WRITER_LIBRARIES})

example/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
project(debugio-example CXX)
3+
4+
if(WIN32)
5+
set(ADD_LINK_LIBRARIES Advapi32)
6+
else()
7+
set(ADD_LINK_LIBRARIES pthread rt)
8+
endif()
9+
10+
set(READER_SOURCE reader.cpp)
11+
set(WRITER_SOURCE writer.cpp)
12+
13+
add_executable(example-reader ${READER_SOURCE})
14+
target_link_libraries(example-reader ${ADD_LINK_LIBRARIES})
15+
16+
add_executable(example-writer ${WRITER_SOURCE})
17+
target_link_libraries(example-writer ${ADD_LINK_LIBRARIES})

example/reader.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2+
#pragma warning(disable : 4267)
3+
#pragma warning(disable : 4996)
4+
15
#include "../include/debugio.h"
26

37
#include <chrono>
@@ -9,15 +13,19 @@ int main()
913
using std::this_thread::sleep_for;
1014
using namespace std::literals::chrono_literals;
1115

16+
//::SetPriorityClass(::GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
17+
//::SetThreadPriority(hMonitorThread, THREAD_PRIORITY_TIME_CRITICAL);
18+
1219
debugio::Monitor monitor;
1320

1421
monitor.start([](debugio::Buffer* buf) -> int {
1522
fprintf(stderr, "[READ] pid=%d msg=%s\n", buf->processID, buf->data);
1623
return 0;
1724
});
1825

19-
sleep_for(500ms);
20-
26+
sleep_for(2000ms);
2127
monitor.stop();
28+
29+
fprintf(stderr, "Reader process Finished\n");
2230
return 0;
2331
}

example/writer.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#pragma warning(disable : 4267)
2+
#pragma warning(disable : 4996)
3+
14
#include "../include/debugio.h"
25

36
#ifdef _MSC_VER
@@ -28,8 +31,11 @@ int main()
2831
debugio::write_string(msg.c_str());
2932
fprintf(stderr, "[WRITE] %s\n", msg.c_str());
3033

31-
sleep_for(500ms);
34+
sleep_for(100ms);
3235
}
3336

37+
sleep_for(100ms);
38+
39+
fprintf(stderr, "Writer process Finished\n");
3440
return 0;
3541
}

0 commit comments

Comments
 (0)