no message
parent
df54fd094b
commit
85b23f1b5b
|
@ -9,37 +9,18 @@ add_library(generallib STATIC $<TARGET_OBJECTS:General> ${SRC_SDK})
|
||||||
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")
|
||||||
#message("using clang")
|
message("clang compiler \r\n")
|
||||||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||||
#message("using gcc")
|
message("gcc compiler \r\n")
|
||||||
#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
|
|
||||||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
|
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
|
||||||
message("using asm")
|
message("using asm")
|
||||||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||||
message("using msvc")
|
message("using msvc compiler")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# copy header files
|
# copy header files
|
||||||
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/obj)
|
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/obj)
|
||||||
|
|
||||||
set(COPYITEM inc)
|
set(COPYITEM inc)
|
||||||
file(GLOB INCLUDES ${PROJECT_SOURCE_DIR}/inc/*)
|
file(GLOB INCLUDES ${PROJECT_SOURCE_DIR}/inc/*)
|
||||||
file(COPY ${INCLUDES} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc
|
file(COPY ${INCLUDES} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc
|
||||||
|
|
|
@ -3,6 +3,21 @@
|
||||||
//
|
//
|
||||||
#include "debug.h"
|
#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){
|
int PrintDumpObjvoid (void *dst,int rowNum,int num,bool ifAsii){
|
||||||
char out [2048] = {0};
|
char out [2048] = {0};
|
||||||
int row = num / rowNum;
|
int row = num / rowNum;
|
||||||
|
|
|
@ -75,9 +75,6 @@ void Timer::stop()
|
||||||
gettimeofday(&endCount, NULL);
|
gettimeofday(&endCount, NULL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// compute elapsed time in micro-second resolution.
|
// compute elapsed time in micro-second resolution.
|
||||||
// other getElapsedTime will call this first, then convert to correspond resolution.
|
// other getElapsedTime will call this first, then convert to correspond resolution.
|
||||||
|
@ -100,9 +97,6 @@ double Timer::getElapsedTimeInMicroSec()
|
||||||
|
|
||||||
return endTimeInMicroSec - startTimeInMicroSec;
|
return endTimeInMicroSec - startTimeInMicroSec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// divide elapsedTimeInMicroSec by 1000
|
// divide elapsedTimeInMicroSec by 1000
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -13,6 +13,7 @@ public:
|
||||||
RingBuffer(uint64_t size);
|
RingBuffer(uint64_t size);
|
||||||
int Add(T *data,uint64_t len);
|
int Add(T *data,uint64_t len);
|
||||||
int Take(T *data,uint64_t len);
|
int Take(T *data,uint64_t len);
|
||||||
|
void SetEmpty();
|
||||||
uint32_t CanReadCount();
|
uint32_t CanReadCount();
|
||||||
uint32_t CanWriteCount();
|
uint32_t CanWriteCount();
|
||||||
uint32_t Size();
|
uint32_t Size();
|
||||||
|
@ -46,6 +47,11 @@ template<typename T>
|
||||||
RingBuffer<T>::~RingBuffer(){
|
RingBuffer<T>::~RingBuffer(){
|
||||||
delete[] mData;
|
delete[] mData;
|
||||||
}
|
}
|
||||||
|
template<typename T>
|
||||||
|
void RingBuffer<T>::SetEmpty(){
|
||||||
|
this->mCurrentHead = this->mCurrentTail;
|
||||||
|
this->mRemain = this->mSize;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
uint32_t RingBuffer<T>::Size(){
|
uint32_t RingBuffer<T>::Size(){
|
||||||
|
@ -76,7 +82,8 @@ int RingBuffer<T>::Add(T *data,uint64_t len){
|
||||||
if(mCurrentTail == mCurrentHead){
|
if(mCurrentTail == mCurrentHead){
|
||||||
/// |start also head also tail|...|end|
|
/// |start also head also tail|...|end|
|
||||||
if(mCurrentHead == 0){
|
if(mCurrentHead == 0){
|
||||||
memcpy(mData,data,bytes_write);
|
memcpy(mData,data,bytes_write*sizeof(T));
|
||||||
|
mCurrentTail = bytes_write;
|
||||||
}else{
|
}else{
|
||||||
/// |start |...| head also tail|...|end|
|
/// |start |...| head also tail|...|end|
|
||||||
if(mCurrentTail + bytes_write < mSize){
|
if(mCurrentTail + bytes_write < mSize){
|
||||||
|
@ -84,7 +91,8 @@ int RingBuffer<T>::Add(T *data,uint64_t len){
|
||||||
mCurrentTail += bytes_write;
|
mCurrentTail += bytes_write;
|
||||||
}else{
|
}else{
|
||||||
memcpy(&mData[mCurrentTail],data,(mSize - mCurrentTail)*sizeof(T));
|
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;
|
mCurrentTail = (mCurrentTail + bytes_write)%mSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,26 @@
|
||||||
|
|
||||||
#include "utils.h"
|
#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)
|
string itos(int x)
|
||||||
{
|
{
|
||||||
char buf[100] = {0};
|
char buf[100] = {0};
|
||||||
|
@ -16,7 +36,7 @@ string itos(int x)
|
||||||
|
|
||||||
inline ENV_SYS CurrentEnvSys() {
|
inline ENV_SYS CurrentEnvSys() {
|
||||||
#ifdef linux
|
#ifdef linux
|
||||||
return ENV_LINUX
|
return ENV_LINUX;
|
||||||
#endif
|
#endif
|
||||||
#ifdef _WINDOWS
|
#ifdef _WINDOWS
|
||||||
return ENV_WINDOWS
|
return ENV_WINDOWS
|
||||||
|
|
|
@ -10,4 +10,5 @@ link_directories("./third/jsoncpp/lib/")
|
||||||
link_libraries(jsoncpp)
|
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")
|
||||||
|
include_directories("../../../obj/inc/")
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
void thread_set_promise(std::promise<int>& promiseObj) {
|
void thread_set_promise(std::promise<int>& promiseObj) {
|
||||||
std::cout << "In a thread, making data. wait for 10 seconds"<<std::endl;
|
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);
|
promiseObj.set_value(9);
|
||||||
std::cout<<"end"<<std::endl;
|
std::cout<<"end"<<std::endl;
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,7 @@ void TestPromiseFutureBefore(){
|
||||||
std::promise<int> promiseObj;
|
std::promise<int> promiseObj;
|
||||||
std::future<int> futureObj = promiseObj.get_future();
|
std::future<int> futureObj = promiseObj.get_future();
|
||||||
std::thread t(&thread_set_promise, std::ref(promiseObj));
|
std::thread t(&thread_set_promise, std::ref(promiseObj));
|
||||||
|
if (std::future_status::timeout == futureObj.wait_for(std::chrono::milliseconds(4000))){
|
||||||
while (std::future_status::timeout == futureObj.wait_for(std::chrono::milliseconds(1000))){
|
|
||||||
static uint32_t times = 0;
|
static uint32_t times = 0;
|
||||||
times ++;
|
times ++;
|
||||||
std::cout<<"time out "<< times <<std::endl;
|
std::cout<<"time out "<< times <<std::endl;
|
||||||
|
@ -159,7 +158,7 @@ public:
|
||||||
Json::Value root1;
|
Json::Value root1;
|
||||||
Json::Value root2;
|
Json::Value root2;
|
||||||
|
|
||||||
for (int i = 0;i < ; i ++){
|
for (int i = 0;i < 10; i ++){
|
||||||
reader.parse(strValue, root);
|
reader.parse(strValue, root);
|
||||||
reader1.parse(strValue, root1);
|
reader1.parse(strValue, root1);
|
||||||
reader2.parse(strValue, root2);
|
reader2.parse(strValue, root2);
|
||||||
|
|
Loading…
Reference in New Issue