no message

master
zcy 2021-05-15 01:25:01 +08:00
parent df54fd094b
commit 85b23f1b5b
7 changed files with 53 additions and 35 deletions

View File

@ -9,37 +9,18 @@ add_library(generallib STATIC $<TARGET_OBJECTS:General> ${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

View File

@ -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;

View File

@ -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
///////////////////////////////////////////////////////////////////////////////

View File

@ -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<typename T>
RingBuffer<T>::~RingBuffer(){
delete[] mData;
}
template<typename T>
void RingBuffer<T>::SetEmpty(){
this->mCurrentHead = this->mCurrentTail;
this->mRemain = this->mSize;
}
template<typename T>
uint32_t RingBuffer<T>::Size(){
@ -76,7 +82,8 @@ int RingBuffer<T>::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<T>::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;
}
}

View File

@ -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

View File

@ -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/")

View File

@ -2,7 +2,7 @@
void thread_set_promise(std::promise<int>& promiseObj) {
std::cout << "In a thread, making data. wait for 10 seconds"<<std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(800));
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
promiseObj.set_value(9);
std::cout<<"end"<<std::endl;
}
@ -11,8 +11,7 @@ void TestPromiseFutureBefore(){
std::promise<int> promiseObj;
std::future<int> 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 <<std::endl;
@ -159,7 +158,7 @@ public:
Json::Value root1;
Json::Value root2;
for (int i = 0;i < ; i ++){
for (int i = 0;i < 10; i ++){
reader.parse(strValue, root);
reader1.parse(strValue, root1);
reader2.parse(strValue, root2);