no message

master
caiyuzheng 2021-03-19 17:31:22 +08:00
parent b06fa65636
commit 99793e8db9
9 changed files with 53 additions and 40 deletions

View File

@ -3,28 +3,9 @@ enable_language(CXX)
project(generallib) project(generallib)
add_subdirectory(general) add_subdirectory(general)
find_package(libevent REQUIRED)
set(EVENT__HAVE_LIBEVENT 1)
message(STATUS "PATH: " $ENV{CMAKE_MODULE_PATH})
message(STATUS "libevent include: " ${libevent_INCLUDE_DIRS})
message(STATUS "libevent lib: " ${libevent_INCLUDE_DIR})
message(STATUS "libevent lib Dirs: " ${libevent_LIB_DIRS})
SET(SRC_SDK sdk_main.c )# SET(SRC_SDK sdk_main.c )#
add_library(generallib STATIC $<TARGET_OBJECTS:General> ${SRC_SDK}) add_library(generallib STATIC $<TARGET_OBJECTS:General> ${SRC_SDK})
message("CMAKE_BINARY_DIR is " ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/libd)
link_directories(${libevent_LIB_DIRS})
set_target_properties(generallib PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(generallib public
-Wl,--whole-archive
libevent.a
-Wl,--no-whole-archive
)
message("current path is" ${CMAKE_CURRENT_SOURCE_DIR}) message("current path is" ${CMAKE_CURRENT_SOURCE_DIR})
IF (WIN32) IF (WIN32)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")

View File

@ -3,7 +3,6 @@ enable_language(CXX)
project(General) project(General)
message( "current compiler " ${CMAKE_CXX_COMPILER_ID}) message( "current compiler " ${CMAKE_CXX_COMPILER_ID})
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# using Clang # using Clang
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
@ -32,7 +31,11 @@ INCLUDE_DIRECTORIES (pattern)
include_directories(third/include) include_directories(third/include)
aux_source_directory(src DIRSRCS) aux_source_directory(src DIRSRCS)
aux_source_directory(src/pattern PaternSrc) aux_source_directory(src/pattern PaternSrc)
aux_source_directory(src/function FunctionSrc)
aux_source_directory(src/algorithm AlgorithmSrc)
aux_source_directory(src/net NetSrc)
aux_source_directory(src/encrypt EncryptSrc)
message("source file is " ${DIRSRCS} ${PaternSrc} ${EncryptSrc} ${NetSrc} ${FunctionSrc} ${AlgorithmSrc})
add_library(General OBJECT ${DIRSRCS} ${PaternSrc} src/pattern/signleton.hpp src/pattern/cmd.hpp src/pattern/Observer.hpp src/pattern/stratergy.hpp "src/pattern/adapter.hpp" src/encrypt/base64.cpp src/encrypt/base64.h src/encrypt/aes.cpp src/encrypt/aes.h src/encrypt/rsa.cpp add_library(General OBJECT ${DIRSRCS} ${PaternSrc} ${EncryptSrc} ${NetSrc} ${FunctionSrc} ${AlgorithmSrc} )
src/math/BigInt.hpp src/net/TcpClient.cpp src/net/TcpClient.h src/net/PackageReceiver.cpp src/net/PackageReceiver.h src/function/Timer.cpp src/function/btree.cpp src/function/btree.h src/algorithm/sorter.hpp)

View File

@ -1,13 +1,14 @@
cmake_minimum_required(VERSION 3.12) cmake_minimum_required(VERSION 3.12)
project(cpp11) project(cpp11)
add_definitions(-std=c++11)
message("current dir" ${CMAKE_CURRENT_SOURCE_DIR}) message("current dir" ${CMAKE_CURRENT_SOURCE_DIR})
# set(CMAKE_CXX_FLAGS "-fno-elide-constructors") # set(CMAKE_CXX_FLAGS "-fno-elide-constructors")
aux_source_directory(. SOURCE) aux_source_directory(. SOURCE)
message(info ${SOURCE}) message(info ${SOURCE})
link_directories("./third/jsoncpp/lib/")
link_libraries(jsoncpp)
add_executable(cpp11 ${SOURCE} ) add_executable(cpp11 ${SOURCE} )
include_directories("./third/jsoncpp/include/pkgsrc/include/json") include_directories("./third/jsoncpp/include/pkgsrc/include/json")
link_libraries("./third/jsoncpp/lib/")
add_library(jsoncpp STATIC IMPORTED)
# target_link_libraries(cpp11 "jsoncpp") # target_link_libraries(cpp11 "jsoncpp")

View File

@ -0,0 +1,4 @@
[requires]
jsoncpp/1.1.1
[imports]
.,* -> ./third @ folder=True, ignore_case=True, excludes=*.html *.jpeg

View File

@ -148,10 +148,22 @@ class TestTask : public general::Task
public: public:
void Run() void Run()
{ {
for(int i = 0;i < 50000; i++){ for (int i = 0;i < 100; i ++){
std::string strValue = "{\"key\":\"value1\",\
\"array\":[{\"arraykey\":1},{\"arraykey\":2}]}";
Json::Reader reader;
Json::Reader reader1;
Json::Reader reader2;
Json::Value root;
Json::Value root1;
Json::Value root2;
reader.parse(strValue, root);
reader1.parse(strValue, root1);
reader2.parse(strValue, root2);
} }
std::cout<<"end"<<std::endl;
} }
}; };
// 42973.6 // 42973.6
@ -160,14 +172,16 @@ int TestThreadPool()
{ {
//run code //run code
TestTask *t = new TestTask; TestTask *t = new TestTask;
general::ThreadPool pool(2); general::ThreadPool pool(1);
pool.Start(); pool.Start();
auto t1 = std::chrono::steady_clock::now(); auto t1 = std::chrono::steady_clock::now();
for(int i = 0;i < 20000;i++) for(int i = 0;i < 2000;i++){
pool.AddTask(t); pool.AddTask(t);
}
pool.StopAll(); pool.StopAll();
auto t2 = std::chrono::steady_clock::now(); auto t2 = std::chrono::steady_clock::now();
double dr_ms=std::chrono::duration<double,std::milli>(t2-t1).count(); double dr_ms = std::chrono::duration<double,std::milli>(t2-t1).count();
std::cout<<"count is "<<dr_ms<<std::endl; std::cout<<"count is "<<dr_ms<<std::endl;
getchar(); getchar();
} }

View File

@ -20,10 +20,7 @@ namespace general{
{ {
this->mThreadCnt = num; this->mThreadCnt = num;
mStarted = false; mStarted = false;
if (num < 2){
mThreadCnt = 2;
}
mStoping = false;
} }
int CThreadPool::AddTask(Task *t){ int CThreadPool::AddTask(Task *t){

View File

@ -2,17 +2,21 @@ cmake_minimum_required(VERSION 3.11)
project(tcptest) project(tcptest)
message("cmake module " $ENV{CMAKE_MODULE_PATH}) message("cmake module " $ENV{CMAKE_MODULE_PATH})
message("project dir " ${PROJECT_SOURCE_DIR}) message("project dir " ${PROJECT_SOURCE_DIR})
message("current dir " ${CMAKE_CURRENT_SOURCE_DIR}/../../../obj/inc)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../../obj/inc)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../obj/inc)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../build) link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../build)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../obj) link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../obj)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/third/lib)
link_libraries(libgenerallib.a) link_libraries(libgenerallib.a)
link_libraries(libevent.a)
link_libraries(libevent_core.a)
link_libraries(ws2_32) link_libraries(ws2_32)
link_libraries(libevent.la) link_libraries(bcrypt)
link_libraries(libevent_core.la) link_libraries(Iphlpapi.lib)
add_executable(tcptest tcpclient_test.cpp) add_executable(tcptest tcpclient_test.cpp)
target_include_directories(tcptest SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../../obj/inc/third/include()) target_include_directories(tcptest SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../../obj/inc/third/include)

View File

@ -0,0 +1,8 @@
[requires]
libevent/2.1.2
[imports]
lib, *.a -> ./third/lib # Copies all dll files from packages bin folder to my "bin" folder
include, *.h -> ./third/include # Copies all dll files from packages bin folder to my "bin" folder
include, *.hpp -> ./third/include # Copies all dll files from packages bin folder to my "bin" folder

View File

@ -5,4 +5,5 @@
using namespace std; using namespace std;
int main(){ int main(){
TcpClientLibevent mTcp("127.0.0.1",8443, nullptr); TcpClientLibevent mTcp("127.0.0.1",8443, nullptr);
} }