diff --git a/CMakeLists.txt b/CMakeLists.txt index f0af8d2..24c7b7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,37 +9,18 @@ add_library(generallib STATIC $ ${SRC_SDK}) message("current path is" ${CMAKE_CURRENT_SOURCE_DIR}) IF (WIN32) if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - #message("using clang") + message("clang compiler \r\n") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - #message("using gcc") - #add_custom_command ( - # TARGET generallib POST_BUILD - # COMMAND ar -x - # ${CMAKE_CURRENT_SOURCE_DIR}/libd/libevent.a - # COMMENT "package library ar -x ${CMAKE_CURRENT_SOURCE_DIR}/libd/libevent.a " - #) - #add_custom_command ( - # TARGET generallib POST_BUILD - # COMMAND ar rc libgeneral.a *.obj - # COMMENT "package library ar rc *.o " - #) - #add_custom_command( - # TARGET generallib POST_BUILD - # COMMAND del *.o *.obj - # COMMENT "remove all step library" - #) - # using GCC + message("gcc compiler \r\n") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") message("using asm") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") - message("using msvc") + message("using msvc compiler") endif() - endif() # copy header files SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/obj) - set(COPYITEM inc) file(GLOB INCLUDES ${PROJECT_SOURCE_DIR}/inc/*) file(COPY ${INCLUDES} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc diff --git a/general/src/debug.cpp b/general/src/debug.cpp index 09ed05a..9d78901 100644 --- a/general/src/debug.cpp +++ b/general/src/debug.cpp @@ -3,6 +3,21 @@ // #include "debug.h" +#ifdef linux +void itoa(int i,char* string) +{ + int power,j; + j=i; + for(power=1;j>=10;j/=10) + power*=10; + for(;power>0;power/=10) + { + *string++='0'+i/power; + i%=power; + } + *string='\0'; +} +#endif int PrintDumpObjvoid (void *dst,int rowNum,int num,bool ifAsii){ char out [2048] = {0}; int row = num / rowNum; diff --git a/general/src/function/Timer.cpp b/general/src/function/Timer.cpp index 84bd80c..764ce44 100644 --- a/general/src/function/Timer.cpp +++ b/general/src/function/Timer.cpp @@ -75,9 +75,6 @@ void Timer::stop() gettimeofday(&endCount, NULL); #endif } - - - /////////////////////////////////////////////////////////////////////////////// // compute elapsed time in micro-second resolution. // other getElapsedTime will call this first, then convert to correspond resolution. @@ -100,9 +97,6 @@ double Timer::getElapsedTimeInMicroSec() return endTimeInMicroSec - startTimeInMicroSec; } - - - /////////////////////////////////////////////////////////////////////////////// // divide elapsedTimeInMicroSec by 1000 /////////////////////////////////////////////////////////////////////////////// diff --git a/general/src/pattern/ringbuffer.hpp b/general/src/pattern/ringbuffer.hpp index 09c44fb..295bcb3 100644 --- a/general/src/pattern/ringbuffer.hpp +++ b/general/src/pattern/ringbuffer.hpp @@ -13,6 +13,7 @@ public: RingBuffer(uint64_t size); int Add(T *data,uint64_t len); int Take(T *data,uint64_t len); + void SetEmpty(); uint32_t CanReadCount(); uint32_t CanWriteCount(); uint32_t Size(); @@ -46,6 +47,11 @@ template RingBuffer::~RingBuffer(){ delete[] mData; } +template +void RingBuffer::SetEmpty(){ + this->mCurrentHead = this->mCurrentTail; + this->mRemain = this->mSize; +} template uint32_t RingBuffer::Size(){ @@ -76,7 +82,8 @@ int RingBuffer::Add(T *data,uint64_t len){ if(mCurrentTail == mCurrentHead){ /// |start also head also tail|...|end| if(mCurrentHead == 0){ - memcpy(mData,data,bytes_write); + memcpy(mData,data,bytes_write*sizeof(T)); + mCurrentTail = bytes_write; }else{ /// |start |...| head also tail|...|end| if(mCurrentTail + bytes_write < mSize){ @@ -84,7 +91,8 @@ int RingBuffer::Add(T *data,uint64_t len){ mCurrentTail += bytes_write; }else{ memcpy(&mData[mCurrentTail],data,(mSize - mCurrentTail)*sizeof(T)); - memcpy(&mData[0],data,(mCurrentTail + bytes_write)%mSize); + std::cout<<"\r\n"<<(mCurrentTail + bytes_write)%mSize<<"\r\n"; + memcpy(&mData[0],&data[mSize - mCurrentTail],(mCurrentTail + bytes_write)%mSize*sizeof(T)); mCurrentTail = (mCurrentTail + bytes_write)%mSize; } } diff --git a/general/src/utils.cpp b/general/src/utils.cpp index 636d03c..e1330d7 100644 --- a/general/src/utils.cpp +++ b/general/src/utils.cpp @@ -7,6 +7,26 @@ #include "utils.h" +#ifdef linux + +int itoa(int n ,char * const s,int radix){ + if(nullptr == s){ + return -1; + } + if (radix == 10){ + sprintf(s,"%d",n); + } + if(radix == 8){ + sprintf(s,"%o",n); + } + if(radix == 16){ + sprintf(s,"%x",n); + } + return 0; + +} +#endif + string itos(int x) { char buf[100] = {0}; @@ -16,7 +36,7 @@ string itos(int x) inline ENV_SYS CurrentEnvSys() { #ifdef linux - return ENV_LINUX + return ENV_LINUX; #endif #ifdef _WINDOWS return ENV_WINDOWS diff --git a/test/src/cpp11/CMakeLists.txt b/test/src/cpp11/CMakeLists.txt index 9b225c8..00fe11b 100644 --- a/test/src/cpp11/CMakeLists.txt +++ b/test/src/cpp11/CMakeLists.txt @@ -10,4 +10,5 @@ link_directories("./third/jsoncpp/lib/") link_libraries(jsoncpp) add_executable(cpp11 ${SOURCE} ) include_directories("./third/jsoncpp/include/pkgsrc/include/json") +include_directories("../../../obj/inc/") diff --git a/test/src/cpp11/thread_usage.cpp b/test/src/cpp11/thread_usage.cpp index ad1af8a..60346b6 100644 --- a/test/src/cpp11/thread_usage.cpp +++ b/test/src/cpp11/thread_usage.cpp @@ -2,7 +2,7 @@ void thread_set_promise(std::promise& promiseObj) { std::cout << "In a thread, making data. wait for 10 seconds"< promiseObj; std::future futureObj = promiseObj.get_future(); std::thread t(&thread_set_promise, std::ref(promiseObj)); - - while (std::future_status::timeout == futureObj.wait_for(std::chrono::milliseconds(1000))){ + if (std::future_status::timeout == futureObj.wait_for(std::chrono::milliseconds(4000))){ static uint32_t times = 0; times ++; std::cout<<"time out "<< times <