Merge remote-tracking branch 'origin/3.0' into feature/shm
This commit is contained in:
commit
40b3c0d376
|
@ -85,11 +85,7 @@ typedef struct taosField {
|
|||
int32_t bytes;
|
||||
} TAOS_FIELD;
|
||||
|
||||
#ifdef _TD_GO_DLL_
|
||||
#define DLL_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define DLL_EXPORT
|
||||
#endif
|
||||
|
||||
typedef void (*__taos_async_fn_t)(void *param, TAOS_RES *, int code);
|
||||
|
||||
|
|
|
@ -54,25 +54,28 @@ typedef struct SColumnDataAgg {
|
|||
} SColumnDataAgg;
|
||||
|
||||
typedef struct SDataBlockInfo {
|
||||
STimeWindow window;
|
||||
int32_t rows;
|
||||
int32_t rowSize;
|
||||
int16_t numOfCols;
|
||||
int16_t hasVarCol;
|
||||
union {int64_t uid; int64_t blockId;};
|
||||
STimeWindow window;
|
||||
int32_t rows;
|
||||
int32_t rowSize;
|
||||
int16_t numOfCols;
|
||||
int16_t hasVarCol;
|
||||
union {
|
||||
int64_t uid;
|
||||
int64_t blockId;
|
||||
};
|
||||
} SDataBlockInfo;
|
||||
|
||||
//typedef struct SConstantItem {
|
||||
// SColumnInfo info;
|
||||
// int32_t startRow; // run-length-encoding to save the space for multiple rows
|
||||
// int32_t endRow;
|
||||
// SVariant value;
|
||||
//} SConstantItem;
|
||||
// typedef struct SConstantItem {
|
||||
// SColumnInfo info;
|
||||
// int32_t startRow; // run-length-encoding to save the space for multiple rows
|
||||
// int32_t endRow;
|
||||
// SVariant value;
|
||||
// } SConstantItem;
|
||||
|
||||
// info.numOfCols = taosArrayGetSize(pDataBlock) + taosArrayGetSize(pConstantList);
|
||||
typedef struct SSDataBlock {
|
||||
SColumnDataAgg *pBlockAgg;
|
||||
SArray *pDataBlock; // SArray<SColumnInfoData>
|
||||
SColumnDataAgg* pBlockAgg;
|
||||
SArray* pDataBlock; // SArray<SColumnInfoData>
|
||||
SDataBlockInfo info;
|
||||
} SSDataBlock;
|
||||
|
||||
|
@ -98,23 +101,37 @@ void* blockDataDestroy(SSDataBlock* pBlock);
|
|||
int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlock);
|
||||
void* tDecodeDataBlock(const void* buf, SSDataBlock* pBlock);
|
||||
|
||||
static FORCE_INLINE void tDeleteSSDataBlock(SSDataBlock* pBlock) {
|
||||
if (pBlock == NULL) {
|
||||
return;
|
||||
static FORCE_INLINE void blockDestroyInner(SSDataBlock* pBlock) {
|
||||
// WARNING: do not use info.numOfCols,
|
||||
// sometimes info.numOfCols != array size
|
||||
int32_t numOfOutput = taosArrayGetSize(pBlock->pDataBlock);
|
||||
for (int32_t i = 0; i < numOfOutput; ++i) {
|
||||
SColumnInfoData* pColInfoData = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, i);
|
||||
if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
|
||||
tfree(pColInfoData->varmeta.offset);
|
||||
} else {
|
||||
tfree(pColInfoData->nullbitmap);
|
||||
}
|
||||
|
||||
tfree(pColInfoData->pData);
|
||||
}
|
||||
blockDataDestroy(pBlock);
|
||||
|
||||
taosArrayDestroy(pBlock->pDataBlock);
|
||||
tfree(pBlock->pBlockAgg);
|
||||
}
|
||||
|
||||
static FORCE_INLINE void tDeleteSSDataBlock(SSDataBlock* pBlock) { blockDestroyInner(pBlock); }
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSMqPollRsp(void** buf, const SMqPollRsp* pRsp) {
|
||||
int32_t tlen = 0;
|
||||
int32_t sz = 0;
|
||||
tlen += taosEncodeFixedI64(buf, pRsp->consumerId);
|
||||
// tlen += taosEncodeFixedI64(buf, pRsp->consumerId);
|
||||
tlen += taosEncodeFixedI64(buf, pRsp->reqOffset);
|
||||
tlen += taosEncodeFixedI64(buf, pRsp->rspOffset);
|
||||
tlen += taosEncodeFixedI32(buf, pRsp->skipLogNum);
|
||||
tlen += taosEncodeFixedI32(buf, pRsp->numOfTopics);
|
||||
if (pRsp->numOfTopics == 0) return tlen;
|
||||
tlen += tEncodeSSchemaWrapper(buf, pRsp->schemas);
|
||||
tlen += tEncodeSSchemaWrapper(buf, pRsp->schema);
|
||||
if (pRsp->pBlockData) {
|
||||
sz = taosArrayGetSize(pRsp->pBlockData);
|
||||
}
|
||||
|
@ -128,15 +145,15 @@ static FORCE_INLINE int32_t tEncodeSMqPollRsp(void** buf, const SMqPollRsp* pRsp
|
|||
|
||||
static FORCE_INLINE void* tDecodeSMqPollRsp(void* buf, SMqPollRsp* pRsp) {
|
||||
int32_t sz;
|
||||
buf = taosDecodeFixedI64(buf, &pRsp->consumerId);
|
||||
// buf = taosDecodeFixedI64(buf, &pRsp->consumerId);
|
||||
buf = taosDecodeFixedI64(buf, &pRsp->reqOffset);
|
||||
buf = taosDecodeFixedI64(buf, &pRsp->rspOffset);
|
||||
buf = taosDecodeFixedI32(buf, &pRsp->skipLogNum);
|
||||
buf = taosDecodeFixedI32(buf, &pRsp->numOfTopics);
|
||||
if (pRsp->numOfTopics == 0) return buf;
|
||||
pRsp->schemas = (SSchemaWrapper*)calloc(1, sizeof(SSchemaWrapper));
|
||||
if (pRsp->schemas == NULL) return NULL;
|
||||
buf = tDecodeSSchemaWrapper(buf, pRsp->schemas);
|
||||
pRsp->schema = (SSchemaWrapper*)calloc(1, sizeof(SSchemaWrapper));
|
||||
if (pRsp->schema == NULL) return NULL;
|
||||
buf = tDecodeSSchemaWrapper(buf, pRsp->schema);
|
||||
buf = taosDecodeFixedI32(buf, &sz);
|
||||
pRsp->pBlockData = taosArrayInit(sz, sizeof(SSDataBlock));
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
|
@ -148,13 +165,13 @@ static FORCE_INLINE void* tDecodeSMqPollRsp(void* buf, SMqPollRsp* pRsp) {
|
|||
}
|
||||
|
||||
static FORCE_INLINE void tDeleteSMqConsumeRsp(SMqPollRsp* pRsp) {
|
||||
if (pRsp->schemas) {
|
||||
if (pRsp->schemas->nCols) {
|
||||
tfree(pRsp->schemas->pSchema);
|
||||
if (pRsp->schema) {
|
||||
if (pRsp->schema->nCols) {
|
||||
tfree(pRsp->schema->pSchema);
|
||||
}
|
||||
free(pRsp->schemas);
|
||||
free(pRsp->schema);
|
||||
}
|
||||
taosArrayDestroyEx(pRsp->pBlockData, (void (*)(void*))tDeleteSSDataBlock);
|
||||
taosArrayDestroyEx(pRsp->pBlockData, (void (*)(void*))blockDestroyInner);
|
||||
pRsp->pBlockData = NULL;
|
||||
}
|
||||
|
||||
|
@ -196,7 +213,7 @@ typedef struct SGroupbyExpr {
|
|||
|
||||
typedef struct SFunctParam {
|
||||
int32_t type;
|
||||
SColumn *pCol;
|
||||
SColumn* pCol;
|
||||
SVariant param;
|
||||
} SFunctParam;
|
||||
|
||||
|
@ -214,12 +231,12 @@ typedef struct SResSchame {
|
|||
typedef struct SExprBasicInfo {
|
||||
SResSchema resSchema;
|
||||
int16_t numOfParams; // argument value of each function
|
||||
SFunctParam *pParam;
|
||||
SFunctParam* pParam;
|
||||
} SExprBasicInfo;
|
||||
|
||||
typedef struct SExprInfo {
|
||||
struct SExprBasicInfo base;
|
||||
struct tExprNode *pExpr;
|
||||
struct SExprBasicInfo base;
|
||||
struct tExprNode* pExpr;
|
||||
} SExprInfo;
|
||||
|
||||
typedef struct SStateWindow {
|
||||
|
|
|
@ -1282,7 +1282,7 @@ static FORCE_INLINE SMqRebSubscribe* tNewSMqRebSubscribe(const char* key) {
|
|||
if (pRebSub == NULL) {
|
||||
goto _err;
|
||||
}
|
||||
pRebSub->key = key;
|
||||
pRebSub->key = strdup(key);
|
||||
pRebSub->lostConsumers = taosArrayInit(0, sizeof(int64_t));
|
||||
if (pRebSub->lostConsumers == NULL) {
|
||||
goto _err;
|
||||
|
@ -2116,25 +2116,16 @@ typedef struct {
|
|||
int8_t mqMsgType;
|
||||
int32_t code;
|
||||
int32_t epoch;
|
||||
int64_t consumerId;
|
||||
} SMqRspHead;
|
||||
|
||||
typedef struct {
|
||||
int64_t consumerId;
|
||||
SSchemaWrapper* schemas;
|
||||
int64_t reqOffset;
|
||||
int64_t rspOffset;
|
||||
int32_t skipLogNum;
|
||||
int32_t numOfTopics;
|
||||
SArray* pBlockData; // SArray<SSDataBlock>
|
||||
} SMqPollRsp;
|
||||
|
||||
// one req for one vg+topic
|
||||
typedef struct {
|
||||
SMsgHead head;
|
||||
|
||||
int64_t consumerId;
|
||||
int64_t blockingTime;
|
||||
int32_t epoch;
|
||||
int8_t withSchema;
|
||||
char cgroup[TSDB_CGROUP_LEN];
|
||||
|
||||
int64_t currentOffset;
|
||||
|
@ -2153,19 +2144,22 @@ typedef struct {
|
|||
} SMqSubTopicEp;
|
||||
|
||||
typedef struct {
|
||||
int64_t consumerId;
|
||||
char cgroup[TSDB_CGROUP_LEN];
|
||||
SArray* topics; // SArray<SMqSubTopicEp>
|
||||
} SMqCMGetSubEpRsp;
|
||||
SMqRspHead head;
|
||||
int64_t reqOffset;
|
||||
int64_t rspOffset;
|
||||
int32_t skipLogNum;
|
||||
// TODO: replace with topic name
|
||||
int32_t numOfTopics;
|
||||
// TODO: remove from msg
|
||||
SSchemaWrapper* schema;
|
||||
SArray* pBlockData; // SArray<SSDataBlock>
|
||||
} SMqPollRsp;
|
||||
|
||||
typedef struct {
|
||||
SMqRspHead head;
|
||||
union {
|
||||
SMqPollRsp consumeRsp;
|
||||
SMqCMGetSubEpRsp getEpRsp;
|
||||
};
|
||||
void* extra;
|
||||
} SMqMsgWrapper;
|
||||
char cgroup[TSDB_CGROUP_LEN];
|
||||
SArray* topics; // SArray<SMqSubTopicEp>
|
||||
} SMqCMGetSubEpRsp;
|
||||
|
||||
typedef struct {
|
||||
int32_t curBlock;
|
||||
|
@ -2173,11 +2167,13 @@ typedef struct {
|
|||
void** uData;
|
||||
} SMqRowIter;
|
||||
|
||||
struct tmq_message_t_v1 {
|
||||
SMqPollRsp rsp;
|
||||
struct tmq_message_t {
|
||||
SMqPollRsp msg;
|
||||
void* vg;
|
||||
SMqRowIter iter;
|
||||
};
|
||||
|
||||
#if 0
|
||||
struct tmq_message_t {
|
||||
SMqRspHead head;
|
||||
union {
|
||||
|
@ -2189,6 +2185,7 @@ struct tmq_message_t {
|
|||
int32_t curRow;
|
||||
void** uData;
|
||||
};
|
||||
#endif
|
||||
|
||||
static FORCE_INLINE void tDeleteSMqSubTopicEp(SMqSubTopicEp* pSubTopicEp) { taosArrayDestroy(pSubTopicEp->vgs); }
|
||||
|
||||
|
@ -2241,8 +2238,7 @@ static FORCE_INLINE void* tDecodeSMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicE
|
|||
|
||||
static FORCE_INLINE int32_t tEncodeSMqCMGetSubEpRsp(void** buf, const SMqCMGetSubEpRsp* pRsp) {
|
||||
int32_t tlen = 0;
|
||||
tlen += taosEncodeFixedI64(buf, pRsp->consumerId);
|
||||
tlen += taosEncodeString(buf, pRsp->cgroup);
|
||||
// tlen += taosEncodeString(buf, pRsp->cgroup);
|
||||
int32_t sz = taosArrayGetSize(pRsp->topics);
|
||||
tlen += taosEncodeFixedI32(buf, sz);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
|
@ -2253,8 +2249,7 @@ static FORCE_INLINE int32_t tEncodeSMqCMGetSubEpRsp(void** buf, const SMqCMGetSu
|
|||
}
|
||||
|
||||
static FORCE_INLINE void* tDecodeSMqCMGetSubEpRsp(void* buf, SMqCMGetSubEpRsp* pRsp) {
|
||||
buf = taosDecodeFixedI64(buf, &pRsp->consumerId);
|
||||
buf = taosDecodeStringTo(buf, pRsp->cgroup);
|
||||
// buf = taosDecodeStringTo(buf, pRsp->cgroup);
|
||||
int32_t sz;
|
||||
buf = taosDecodeFixedI32(buf, &sz);
|
||||
pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
|
||||
|
@ -2275,8 +2270,8 @@ enum {
|
|||
};
|
||||
|
||||
typedef struct {
|
||||
void* inputHandle;
|
||||
void** executor;
|
||||
void* inputHandle;
|
||||
void* executor[4];
|
||||
} SStreamTaskParRunner;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -20,337 +20,96 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
#define atomic_load_8(ptr) (*(char volatile*)(ptr))
|
||||
#define atomic_load_16(ptr) (*(short volatile*)(ptr))
|
||||
#define atomic_load_32(ptr) (*(long volatile*)(ptr))
|
||||
#define atomic_load_64(ptr) (*(__int64 volatile*)(ptr))
|
||||
#define atomic_load_ptr(ptr) (*(void* volatile*)(ptr))
|
||||
|
||||
#define atomic_store_8(ptr, val) ((*(char volatile*)(ptr)) = (char)(val))
|
||||
#define atomic_store_16(ptr, val) ((*(short volatile*)(ptr)) = (short)(val))
|
||||
#define atomic_store_32(ptr, val) ((*(long volatile*)(ptr)) = (long)(val))
|
||||
#define atomic_store_64(ptr, val) ((*(__int64 volatile*)(ptr)) = (__int64)(val))
|
||||
#define atomic_store_ptr(ptr, val) ((*(void* volatile*)(ptr)) = (void*)(val))
|
||||
|
||||
#define atomic_exchange_8(ptr, val) _InterlockedExchange8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_exchange_16(ptr, val) _InterlockedExchange16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_exchange_32(ptr, val) _InterlockedExchange((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_exchange_64(ptr, val) _InterlockedExchange64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#ifdef _WIN64
|
||||
#define atomic_exchange_ptr(ptr, val) _InterlockedExchangePointer((void* volatile*)(ptr), (void*)(val))
|
||||
#else
|
||||
#define atomic_exchange_ptr(ptr, val) _InlineInterlockedExchangePointer((void* volatile*)(ptr), (void*)(val))
|
||||
#endif
|
||||
|
||||
#ifdef _TD_GO_DLL_
|
||||
#define atomic_val_compare_exchange_8 __sync_val_compare_and_swap
|
||||
#else
|
||||
#define atomic_val_compare_exchange_8(ptr, oldval, newval) _InterlockedCompareExchange8((char volatile*)(ptr), (char)(newval), (char)(oldval))
|
||||
#endif
|
||||
#define atomic_val_compare_exchange_16(ptr, oldval, newval) _InterlockedCompareExchange16((short volatile*)(ptr), (short)(newval), (short)(oldval))
|
||||
#define atomic_val_compare_exchange_32(ptr, oldval, newval) _InterlockedCompareExchange((long volatile*)(ptr), (long)(newval), (long)(oldval))
|
||||
#define atomic_val_compare_exchange_64(ptr, oldval, newval) _InterlockedCompareExchange64((__int64 volatile*)(ptr), (__int64)(newval), (__int64)(oldval))
|
||||
#define atomic_val_compare_exchange_ptr(ptr, oldval, newval) _InterlockedCompareExchangePointer((void* volatile*)(ptr), (void*)(newval), (void*)(oldval))
|
||||
|
||||
char interlocked_add_fetch_8(char volatile *ptr, char val);
|
||||
short interlocked_add_fetch_16(short volatile *ptr, short val);
|
||||
long interlocked_add_fetch_32(long volatile *ptr, long val);
|
||||
__int64 interlocked_add_fetch_64(__int64 volatile *ptr, __int64 val);
|
||||
|
||||
char interlocked_and_fetch_8(char volatile* ptr, char val);
|
||||
short interlocked_and_fetch_16(short volatile* ptr, short val);
|
||||
long interlocked_and_fetch_32(long volatile* ptr, long val);
|
||||
__int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val);
|
||||
|
||||
__int64 interlocked_fetch_and_64(__int64 volatile* ptr, __int64 val);
|
||||
|
||||
char interlocked_or_fetch_8(char volatile* ptr, char val);
|
||||
short interlocked_or_fetch_16(short volatile* ptr, short val);
|
||||
long interlocked_or_fetch_32(long volatile* ptr, long val);
|
||||
__int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val);
|
||||
|
||||
char interlocked_xor_fetch_8(char volatile* ptr, char val);
|
||||
short interlocked_xor_fetch_16(short volatile* ptr, short val);
|
||||
long interlocked_xor_fetch_32(long volatile* ptr, long val);
|
||||
__int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val);
|
||||
|
||||
__int64 interlocked_fetch_xor_64(__int64 volatile* ptr, __int64 val);
|
||||
|
||||
#define atomic_add_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_add_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_add_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_add_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#ifdef _TD_GO_DLL_
|
||||
#define atomic_fetch_add_8 __sync_fetch_and_ad
|
||||
#define atomic_fetch_add_16 __sync_fetch_and_add
|
||||
#else
|
||||
#define atomic_fetch_add_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_fetch_add_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), (short)(val))
|
||||
#endif
|
||||
#define atomic_fetch_add_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_fetch_add_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_fetch_add_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_fetch_add_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
|
||||
#define atomic_sub_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), -(char)(val))
|
||||
#define atomic_sub_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), -(short)(val))
|
||||
#define atomic_sub_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), -(long)(val))
|
||||
#define atomic_sub_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), -(__int64)(val))
|
||||
|
||||
#define atomic_fetch_sub_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), -(char)(val))
|
||||
#define atomic_fetch_sub_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), -(short)(val))
|
||||
#define atomic_fetch_sub_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), -(long)(val))
|
||||
#define atomic_fetch_sub_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), -(__int64)(val))
|
||||
|
||||
#define atomic_and_fetch_8(ptr, val) interlocked_and_fetch_8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_and_fetch_16(ptr, val) interlocked_and_fetch_16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_and_fetch_32(ptr, val) interlocked_and_fetch_32((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_and_fetch_64(ptr, val) interlocked_and_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
|
||||
#define atomic_fetch_and_8(ptr, val) _InterlockedAnd8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_fetch_and_16(ptr, val) _InterlockedAnd16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_fetch_and_32(ptr, val) _InterlockedAnd((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_fetch_and_64(ptr, val) interlocked_fetch_and_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
|
||||
#define atomic_or_fetch_8(ptr, val) interlocked_or_fetch_8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_or_fetch_16(ptr, val) interlocked_or_fetch_16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_or_fetch_32(ptr, val) interlocked_or_fetch_32((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_or_fetch_64(ptr, val) interlocked_or_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
|
||||
#define atomic_fetch_or_8(ptr, val) _InterlockedOr8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_fetch_or_16(ptr, val) _InterlockedOr16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_fetch_or_32(ptr, val) _InterlockedOr((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_fetch_or_64(ptr, val) interlocked_fetch_or_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
|
||||
#define atomic_xor_fetch_8(ptr, val) interlocked_xor_fetch_8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_xor_fetch_16(ptr, val) interlocked_xor_fetch_16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_xor_fetch_32(ptr, val) interlocked_xor_fetch_32((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_xor_fetch_64(ptr, val) interlocked_xor_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
|
||||
#define atomic_fetch_xor_8(ptr, val) _InterlockedXor8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_fetch_xor_16(ptr, val) _InterlockedXor16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_fetch_xor_32(ptr, val) _InterlockedXor((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_fetch_xor_64(ptr, val) interlocked_fetch_xor_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
|
||||
#ifdef _WIN64
|
||||
#define atomic_add_fetch_ptr atomic_add_fetch_64
|
||||
#define atomic_fetch_add_ptr atomic_fetch_add_64
|
||||
#define atomic_sub_fetch_ptr atomic_sub_fetch_64
|
||||
#define atomic_fetch_sub_ptr atomic_fetch_sub_64
|
||||
#define atomic_and_fetch_ptr atomic_and_fetch_64
|
||||
#define atomic_fetch_and_ptr atomic_fetch_and_64
|
||||
#define atomic_or_fetch_ptr atomic_or_fetch_64
|
||||
#define atomic_fetch_or_ptr atomic_fetch_or_64
|
||||
#define atomic_xor_fetch_ptr atomic_xor_fetch_64
|
||||
#define atomic_fetch_xor_ptr atomic_fetch_xor_64
|
||||
#else
|
||||
#define atomic_add_fetch_ptr atomic_add_fetch_32
|
||||
#define atomic_fetch_add_ptr atomic_fetch_add_32
|
||||
#define atomic_sub_fetch_ptr atomic_sub_fetch_32
|
||||
#define atomic_fetch_sub_ptr atomic_fetch_sub_32
|
||||
#define atomic_and_fetch_ptr atomic_and_fetch_32
|
||||
#define atomic_fetch_and_ptr atomic_fetch_and_32
|
||||
#define atomic_or_fetch_ptr atomic_or_fetch_32
|
||||
#define atomic_fetch_or_ptr atomic_fetch_or_32
|
||||
#define atomic_xor_fetch_ptr atomic_xor_fetch_32
|
||||
#define atomic_fetch_xor_ptr atomic_fetch_xor_32
|
||||
#endif
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
/*
|
||||
* type __sync_fetch_and_add (type *ptr, type value);
|
||||
* type __sync_fetch_and_sub (type *ptr, type value);
|
||||
* type __sync_fetch_and_or (type *ptr, type value);
|
||||
* type __sync_fetch_and_and (type *ptr, type value);
|
||||
* type __sync_fetch_and_xor (type *ptr, type value);
|
||||
* type __sync_fetch_and_nand (type *ptr, type value);
|
||||
* type __sync_add_and_fetch (type *ptr, type value);
|
||||
* type __sync_sub_and_fetch (type *ptr, type value);
|
||||
* type __sync_or_and_fetch (type *ptr, type value);
|
||||
* type __sync_and_and_fetch (type *ptr, type value);
|
||||
* type __sync_xor_and_fetch (type *ptr, type value);
|
||||
* type __sync_nand_and_fetch (type *ptr, type value);
|
||||
*
|
||||
* bool __sync_bool_compare_and_swap (type*ptr, type oldval, type newval, ...)
|
||||
* type __sync_val_compare_and_swap (type *ptr, type oldval, ?type newval, ...)
|
||||
* */
|
||||
|
||||
#define atomic_load_8(ptr) __sync_fetch_and_add((ptr), 0)
|
||||
#define atomic_load_16(ptr) __sync_fetch_and_add((ptr), 0)
|
||||
#define atomic_load_32(ptr) __sync_fetch_and_add((ptr), 0)
|
||||
#define atomic_load_64(ptr) __sync_fetch_and_add((ptr), 0)
|
||||
#define atomic_load_ptr(ptr) __sync_fetch_and_add((ptr), 0)
|
||||
|
||||
#define atomic_store_8(ptr, val) (*(ptr)=(val))
|
||||
#define atomic_store_16(ptr, val) (*(ptr)=(val))
|
||||
#define atomic_store_32(ptr, val) (*(ptr)=(val))
|
||||
#define atomic_store_64(ptr, val) (*(ptr)=(val))
|
||||
#define atomic_store_ptr(ptr, val) (*(ptr)=(val))
|
||||
|
||||
int8_t atomic_exchange_8_impl(int8_t* ptr, int8_t val );
|
||||
int16_t atomic_exchange_16_impl(int16_t* ptr, int16_t val );
|
||||
int32_t atomic_exchange_32_impl(int32_t* ptr, int32_t val );
|
||||
int64_t atomic_exchange_64_impl(int64_t* ptr, int64_t val );
|
||||
void* atomic_exchange_ptr_impl( void **ptr, void *val );
|
||||
|
||||
#define atomic_exchange_8(ptr, val) atomic_exchange_8_impl((int8_t*)ptr, (int8_t)val)
|
||||
#define atomic_exchange_16(ptr, val) atomic_exchange_16_impl((int16_t*)ptr, (int16_t)val)
|
||||
#define atomic_exchange_32(ptr, val) atomic_exchange_32_impl((int32_t*)ptr, (int32_t)val)
|
||||
#define atomic_exchange_64(ptr, val) atomic_exchange_64_impl((int64_t*)ptr, (int64_t)val)
|
||||
#define atomic_exchange_ptr(ptr, val) atomic_exchange_ptr_impl((void **)ptr, (void*)val)
|
||||
|
||||
#define atomic_val_compare_exchange_8 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_16 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_32 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_64 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_ptr __sync_val_compare_and_swap
|
||||
|
||||
#define atomic_add_fetch_8(ptr, val) __sync_add_and_fetch((ptr), (val))
|
||||
#define atomic_add_fetch_16(ptr, val) __sync_add_and_fetch((ptr), (val))
|
||||
#define atomic_add_fetch_32(ptr, val) __sync_add_and_fetch((ptr), (val))
|
||||
#define atomic_add_fetch_64(ptr, val) __sync_add_and_fetch((ptr), (val))
|
||||
#define atomic_add_fetch_ptr(ptr, val) __sync_add_and_fetch((ptr), (val))
|
||||
|
||||
#define atomic_fetch_add_8(ptr, val) __sync_fetch_and_add((ptr), (val))
|
||||
#define atomic_fetch_add_16(ptr, val) __sync_fetch_and_add((ptr), (val))
|
||||
#define atomic_fetch_add_32(ptr, val) __sync_fetch_and_add((ptr), (val))
|
||||
#define atomic_fetch_add_64(ptr, val) __sync_fetch_and_add((ptr), (val))
|
||||
#define atomic_fetch_add_ptr(ptr, val) __sync_fetch_and_add((ptr), (val))
|
||||
|
||||
#define atomic_sub_fetch_8(ptr, val) __sync_sub_and_fetch((ptr), (val))
|
||||
#define atomic_sub_fetch_16(ptr, val) __sync_sub_and_fetch((ptr), (val))
|
||||
#define atomic_sub_fetch_32(ptr, val) __sync_sub_and_fetch((ptr), (val))
|
||||
#define atomic_sub_fetch_64(ptr, val) __sync_sub_and_fetch((ptr), (val))
|
||||
#define atomic_sub_fetch_ptr(ptr, val) __sync_sub_and_fetch((ptr), (val))
|
||||
|
||||
#define atomic_fetch_sub_8(ptr, val) __sync_fetch_and_sub((ptr), (val))
|
||||
#define atomic_fetch_sub_16(ptr, val) __sync_fetch_and_sub((ptr), (val))
|
||||
#define atomic_fetch_sub_32(ptr, val) __sync_fetch_and_sub((ptr), (val))
|
||||
#define atomic_fetch_sub_64(ptr, val) __sync_fetch_and_sub((ptr), (val))
|
||||
#define atomic_fetch_sub_ptr(ptr, val) __sync_fetch_and_sub((ptr), (val))
|
||||
|
||||
#define atomic_and_fetch_8(ptr, val) __sync_and_and_fetch((ptr), (val))
|
||||
#define atomic_and_fetch_16(ptr, val) __sync_and_and_fetch((ptr), (val))
|
||||
#define atomic_and_fetch_32(ptr, val) __sync_and_and_fetch((ptr), (val))
|
||||
#define atomic_and_fetch_64(ptr, val) __sync_and_and_fetch((ptr), (val))
|
||||
#define atomic_and_fetch_ptr(ptr, val) __sync_and_and_fetch((ptr), (val))
|
||||
|
||||
#define atomic_fetch_and_8(ptr, val) __sync_fetch_and_and((ptr), (val))
|
||||
#define atomic_fetch_and_16(ptr, val) __sync_fetch_and_and((ptr), (val))
|
||||
#define atomic_fetch_and_32(ptr, val) __sync_fetch_and_and((ptr), (val))
|
||||
#define atomic_fetch_and_64(ptr, val) __sync_fetch_and_and((ptr), (val))
|
||||
#define atomic_fetch_and_ptr(ptr, val) __sync_fetch_and_and((ptr), (val))
|
||||
|
||||
#define atomic_or_fetch_8(ptr, val) __sync_or_and_fetch((ptr), (val))
|
||||
#define atomic_or_fetch_16(ptr, val) __sync_or_and_fetch((ptr), (val))
|
||||
#define atomic_or_fetch_32(ptr, val) __sync_or_and_fetch((ptr), (val))
|
||||
#define atomic_or_fetch_64(ptr, val) __sync_or_and_fetch((ptr), (val))
|
||||
#define atomic_or_fetch_ptr(ptr, val) __sync_or_and_fetch((ptr), (val))
|
||||
|
||||
#define atomic_fetch_or_8(ptr, val) __sync_fetch_and_or((ptr), (val))
|
||||
#define atomic_fetch_or_16(ptr, val) __sync_fetch_and_or((ptr), (val))
|
||||
#define atomic_fetch_or_32(ptr, val) __sync_fetch_and_or((ptr), (val))
|
||||
#define atomic_fetch_or_64(ptr, val) __sync_fetch_and_or((ptr), (val))
|
||||
#define atomic_fetch_or_ptr(ptr, val) __sync_fetch_and_or((ptr), (val))
|
||||
|
||||
#define atomic_xor_fetch_8(ptr, val) __sync_xor_and_fetch((ptr), (val))
|
||||
#define atomic_xor_fetch_16(ptr, val) __sync_xor_and_fetch((ptr), (val))
|
||||
#define atomic_xor_fetch_32(ptr, val) __sync_xor_and_fetch((ptr), (val))
|
||||
#define atomic_xor_fetch_64(ptr, val) __sync_xor_and_fetch((ptr), (val))
|
||||
#define atomic_xor_fetch_ptr(ptr, val) __sync_xor_and_fetch((ptr), (val))
|
||||
|
||||
#define atomic_fetch_xor_8(ptr, val) __sync_fetch_and_xor((ptr), (val))
|
||||
#define atomic_fetch_xor_16(ptr, val) __sync_fetch_and_xor((ptr), (val))
|
||||
#define atomic_fetch_xor_32(ptr, val) __sync_fetch_and_xor((ptr), (val))
|
||||
#define atomic_fetch_xor_64(ptr, val) __sync_fetch_and_xor((ptr), (val))
|
||||
#define atomic_fetch_xor_ptr(ptr, val) __sync_fetch_and_xor((ptr), (val))
|
||||
|
||||
#else
|
||||
#define atomic_load_8(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_16(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_32(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_64(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_ptr(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_store_8(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_store_16(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_store_32(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_store_64(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_store_ptr(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_exchange_8(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_exchange_16(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_exchange_32(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_exchange_64(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_exchange_ptr(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_val_compare_exchange_8 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_16 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_32 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_64 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_ptr __sync_val_compare_and_swap
|
||||
|
||||
#define atomic_add_fetch_8(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_add_fetch_16(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_add_fetch_32(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_add_fetch_64(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_add_fetch_ptr(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_add_8(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_16(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_32(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_64(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_ptr(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_sub_fetch_8(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_sub_fetch_16(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_sub_fetch_32(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_sub_fetch_64(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_sub_fetch_ptr(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_sub_8(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_16(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_32(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_64(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_ptr(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_and_fetch_8(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_and_fetch_16(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_and_fetch_32(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_and_fetch_64(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_and_fetch_ptr(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_and_8(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_16(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_32(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_64(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_ptr(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_or_fetch_8(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_or_fetch_16(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_or_fetch_32(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_or_fetch_64(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_or_fetch_ptr(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_or_8(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_16(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_32(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_64(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_ptr(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_xor_fetch_8(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_xor_fetch_16(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_xor_fetch_32(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_xor_fetch_64(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_xor_fetch_ptr(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_xor_8(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_16(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_32(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_64(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_ptr(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||
// When you want to use this feature, you should find or add the same function in the following section.
|
||||
#ifndef ALLOW_FORBID_FUNC
|
||||
#define __atomic_load_n __ATOMIC_LOAD_N_FUNC_TAOS_FORBID
|
||||
#define __atomic_store_n __ATOMIC_STORE_N_FUNC_TAOS_FORBID
|
||||
#define __atomic_exchange_n __ATOMIC_EXCHANGE_N_FUNC_TAOS_FORBID
|
||||
#define __sync_val_compare_and_swap __SYNC_VAL_COMPARE_AND_SWAP_FUNC_TAOS_FORBID
|
||||
#define __atomic_add_fetch __ATOMIC_ADD_FETCH_FUNC_TAOS_FORBID
|
||||
#define __atomic_fetch_add __ATOMIC_FETCH_ADD_FUNC_TAOS_FORBID
|
||||
#define __atomic_sub_fetch __ATOMIC_SUB_FETCH_FUNC_TAOS_FORBID
|
||||
#define __atomic_fetch_sub __ATOMIC_FETCH_SUB_FUNC_TAOS_FORBID
|
||||
#define __atomic_and_fetch __ATOMIC_AND_FETCH_FUNC_TAOS_FORBID
|
||||
#define __atomic_fetch_and __ATOMIC_FETCH_AND_FUNC_TAOS_FORBID
|
||||
#define __atomic_or_fetch __ATOMIC_OR_FETCH_FUNC_TAOS_FORBID
|
||||
#define __atomic_fetch_or __ATOMIC_FETCH_OR_FUNC_TAOS_FORBID
|
||||
#define __atomic_xor_fetch __ATOMIC_XOR_FETCH_FUNC_TAOS_FORBID
|
||||
#define __atomic_fetch_xor __ATOMIC_FETCH_XOR_FUNC_TAOS_FORBID
|
||||
#endif
|
||||
|
||||
int8_t atomic_load_8(int8_t volatile *ptr);
|
||||
int16_t atomic_load_16(int16_t volatile *ptr);
|
||||
int32_t atomic_load_32(int32_t volatile *ptr);
|
||||
int64_t atomic_load_64(int64_t volatile *ptr);
|
||||
void* atomic_load_ptr(void *ptr);
|
||||
void atomic_store_8(int8_t volatile *ptr, int8_t val);
|
||||
void atomic_store_16(int16_t volatile *ptr, int16_t val);
|
||||
void atomic_store_32(int32_t volatile *ptr, int32_t val);
|
||||
void atomic_store_64(int64_t volatile *ptr, int64_t val);
|
||||
void atomic_store_ptr(void *ptr, void *val);
|
||||
int8_t atomic_exchange_8(int8_t volatile *ptr, int8_t val);
|
||||
int16_t atomic_exchange_16(int16_t volatile *ptr, int16_t val);
|
||||
int32_t atomic_exchange_32(int32_t volatile *ptr, int32_t val);
|
||||
int64_t atomic_exchange_64(int64_t volatile *ptr, int64_t val);
|
||||
void* atomic_exchange_ptr(void *ptr, void *val);
|
||||
int8_t atomic_val_compare_exchange_8(int8_t volatile *ptr, int8_t oldval, int8_t newval);
|
||||
int16_t atomic_val_compare_exchange_16(int16_t volatile *ptr, int16_t oldval, int16_t newval);
|
||||
int32_t atomic_val_compare_exchange_32(int32_t volatile *ptr, int32_t oldval, int32_t newval);
|
||||
int64_t atomic_val_compare_exchange_64(int64_t volatile *ptr, int64_t oldval, int64_t newval);
|
||||
void* atomic_val_compare_exchange_ptr(void *ptr, void *oldval, void *newval);
|
||||
int8_t atomic_add_fetch_8(int8_t volatile *ptr, int8_t val);
|
||||
int16_t atomic_add_fetch_16(int16_t volatile *ptr, int16_t val);
|
||||
int32_t atomic_add_fetch_32(int32_t volatile *ptr, int32_t val);
|
||||
int64_t atomic_add_fetch_64(int64_t volatile *ptr, int64_t val);
|
||||
void* atomic_add_fetch_ptr(void *ptr, int32_t val);
|
||||
int8_t atomic_fetch_add_8(int8_t volatile *ptr, int8_t val);
|
||||
int16_t atomic_fetch_add_16(int16_t volatile *ptr, int16_t val);
|
||||
int32_t atomic_fetch_add_32(int32_t volatile *ptr, int32_t val);
|
||||
int64_t atomic_fetch_add_64(int64_t volatile *ptr, int64_t val);
|
||||
void* atomic_fetch_add_ptr(void *ptr, int32_t val);
|
||||
int8_t atomic_sub_fetch_8(int8_t volatile *ptr, int8_t val);
|
||||
int16_t atomic_sub_fetch_16(int16_t volatile *ptr, int16_t val);
|
||||
int32_t atomic_sub_fetch_32(int32_t volatile *ptr, int32_t val);
|
||||
int64_t atomic_sub_fetch_64(int64_t volatile *ptr, int64_t val);
|
||||
void* atomic_sub_fetch_ptr(void *ptr, int32_t val);
|
||||
int8_t atomic_fetch_sub_8(int8_t volatile *ptr, int8_t val);
|
||||
int16_t atomic_fetch_sub_16(int16_t volatile *ptr, int16_t val);
|
||||
int32_t atomic_fetch_sub_32(int32_t volatile *ptr, int32_t val);
|
||||
int64_t atomic_fetch_sub_64(int64_t volatile *ptr, int64_t val);
|
||||
void* atomic_fetch_sub_ptr(void *ptr, int32_t val);
|
||||
int8_t atomic_and_fetch_8(int8_t volatile *ptr, int8_t val);
|
||||
int16_t atomic_and_fetch_16(int16_t volatile *ptr, int16_t val);
|
||||
int32_t atomic_and_fetch_32(int32_t volatile *ptr, int32_t val);
|
||||
int64_t atomic_and_fetch_64(int64_t volatile *ptr, int64_t val);
|
||||
void* atomic_and_fetch_ptr(void *ptr, void *val);
|
||||
int8_t atomic_fetch_and_8(int8_t volatile *ptr, int8_t val);
|
||||
int16_t atomic_fetch_and_16(int16_t volatile *ptr, int16_t val);
|
||||
int32_t atomic_fetch_and_32(int32_t volatile *ptr, int32_t val);
|
||||
int64_t atomic_fetch_and_64(int64_t volatile *ptr, int64_t val);
|
||||
void* atomic_fetch_and_ptr(void *ptr, void *val);
|
||||
int8_t atomic_or_fetch_8(int8_t volatile *ptr, int8_t val);
|
||||
int16_t atomic_or_fetch_16(int16_t volatile *ptr, int16_t val);
|
||||
int32_t atomic_or_fetch_32(int32_t volatile *ptr, int32_t val);
|
||||
int64_t atomic_or_fetch_64(int64_t volatile *ptr, int64_t val);
|
||||
void* atomic_or_fetch_ptr(void *ptr, void *val);
|
||||
int8_t atomic_fetch_or_8(int8_t volatile *ptr, int8_t val);
|
||||
int16_t atomic_fetch_or_16(int16_t volatile *ptr, int16_t val);
|
||||
int32_t atomic_fetch_or_32(int32_t volatile *ptr, int32_t val);
|
||||
int64_t atomic_fetch_or_64(int64_t volatile *ptr, int64_t val);
|
||||
void* atomic_fetch_or_ptr(void *ptr, void *val);
|
||||
int8_t atomic_xor_fetch_8(int8_t volatile *ptr, int8_t val);
|
||||
int16_t atomic_xor_fetch_16(int16_t volatile *ptr, int16_t val);
|
||||
int32_t atomic_xor_fetch_32(int32_t volatile *ptr, int32_t val);
|
||||
int64_t atomic_xor_fetch_64(int64_t volatile *ptr, int64_t val);
|
||||
void* atomic_xor_fetch_ptr(void *ptr, void *val);
|
||||
int8_t atomic_fetch_xor_8(int8_t volatile *ptr, int8_t val);
|
||||
int16_t atomic_fetch_xor_16(int16_t volatile *ptr, int16_t val);
|
||||
int32_t atomic_fetch_xor_32(int32_t volatile *ptr, int32_t val);
|
||||
int64_t atomic_fetch_xor_64(int64_t volatile *ptr, int64_t val);
|
||||
void* atomic_fetch_xor_ptr(void *ptr, void *val);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#define _TD_OS_DIR_H_
|
||||
|
||||
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||
// When you want to use this feature, you should find or add the same function in the following section.
|
||||
#ifndef ALLOW_FORBID_FUNC
|
||||
#define opendir OPENDIR_FUNC_TAOS_FORBID
|
||||
#define readdir READDIR_FUNC_TAOS_FORBID
|
||||
|
|
|
@ -23,6 +23,7 @@ extern "C" {
|
|||
#include "osSocket.h"
|
||||
|
||||
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||
// When you want to use this feature, you should find or add the same function in the following sectio
|
||||
#ifndef ALLOW_FORBID_FUNC
|
||||
#define open OPEN_FUNC_TAOS_FORBID
|
||||
#define fopen FOPEN_FUNC_TAOS_FORBID
|
||||
|
|
|
@ -23,6 +23,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||
// When you want to use this feature, you should find or add the same function in the following section.
|
||||
#ifndef ALLOW_FORBID_FUNC
|
||||
#define setlocale SETLOCALE_FUNC_TAOS_FORBID
|
||||
#endif
|
||||
|
|
|
@ -21,6 +21,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||
// When you want to use this feature, you should find or add the same function in the following section.
|
||||
#ifndef ALLOW_FORBID_FUNC
|
||||
#define rand RAND_FUNC_TAOS_FORBID
|
||||
#define srand SRAND_FUNC_TAOS_FORBID
|
||||
|
|
|
@ -21,6 +21,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||
// When you want to use this feature, you should find or add the same function in the following section.
|
||||
#ifndef ALLOW_FORBID_FUNC
|
||||
#define Sleep SLEEP_FUNC_TAOS_FORBID
|
||||
#define sleep SLEEP_FUNC_TAOS_FORBID
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#define _TD_OS_SOCKET_H_
|
||||
|
||||
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||
// When you want to use this feature, you should find or add the same function in the following section.
|
||||
#ifndef ALLOW_FORBID_FUNC
|
||||
#define socket SOCKET_FUNC_TAOS_FORBID
|
||||
#define bind BIND_FUNC_TAOS_FORBID
|
||||
|
@ -52,9 +53,6 @@ extern "C" {
|
|||
|
||||
#if (defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
|
||||
#define htobe64 htonll
|
||||
#if defined(_TD_GO_DLL_)
|
||||
uint64_t htonll(uint64_t val);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(_TD_DARWIN_64)
|
||||
|
|
|
@ -24,6 +24,7 @@ typedef wchar_t TdWchar;
|
|||
typedef int32_t TdUcs4;
|
||||
|
||||
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||
// When you want to use this feature, you should find or add the same function in the following section.
|
||||
#ifndef ALLOW_FORBID_FUNC
|
||||
#define iconv_open ICONV_OPEN_FUNC_TAOS_FORBID
|
||||
#define iconv_close ICONV_CLOSE_FUNC_TAOS_FORBID
|
||||
|
|
|
@ -21,6 +21,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||
// When you want to use this feature, you should find or add the same function in the following section.
|
||||
#ifndef ALLOW_FORBID_FUNC
|
||||
#define popen POPEN_FUNC_TAOS_FORBID
|
||||
#define pclose PCLOSE_FUNC_TAOS_FORBID
|
||||
|
|
|
@ -37,6 +37,7 @@ typedef pthread_condattr_t TdThreadCondAttr;
|
|||
#define taosThreadCleanupPop pthread_cleanup_pop
|
||||
|
||||
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||
// When you want to use this feature, you should find or add the same function in the following section.
|
||||
#ifndef ALLOW_FORBID_FUNC
|
||||
#define pthread_t PTHREAD_T_TYPE_TAOS_FORBID
|
||||
#define pthread_spinlock_t PTHREAD_SPINLOCK_T_TYPE_TAOS_FORBID
|
||||
|
|
|
@ -21,6 +21,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||
// When you want to use this feature, you should find or add the same function in the following section.
|
||||
#ifndef ALLOW_FORBID_FUNC
|
||||
#define strptime STRPTIME_FUNC_TAOS_FORBID
|
||||
#define gettimeofday GETTIMEOFDAY_FUNC_TAOS_FORBID
|
||||
|
@ -33,11 +34,7 @@ extern "C" {
|
|||
|
||||
#define CLOCK_REALTIME 0
|
||||
|
||||
#ifdef _TD_GO_DLL_
|
||||
#define MILLISECOND_PER_SECOND (1000LL)
|
||||
#else
|
||||
#define MILLISECOND_PER_SECOND (1000i64)
|
||||
#endif
|
||||
#define MILLISECOND_PER_SECOND (1000i64)
|
||||
#else
|
||||
#define MILLISECOND_PER_SECOND ((int64_t)1000L)
|
||||
#endif
|
||||
|
|
|
@ -21,6 +21,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||
// When you want to use this feature, you should find or add the same function in the following section.
|
||||
#ifndef ALLOW_FORBID_FUNC
|
||||
#define timer_create TIMER_CREATE_FUNC_TAOS_FORBID
|
||||
#define timer_settime TIMER_SETTIME_FUNC_TAOS_FORBID
|
||||
|
|
|
@ -21,6 +21,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||
// When you want to use this feature, you should find or add the same function in the following section.
|
||||
#ifndef ALLOW_FORBID_FUNC
|
||||
#define tzset TZSET_FUNC_TAOS_FORBID
|
||||
#endif
|
||||
|
|
|
@ -48,8 +48,8 @@ static void registerRequest(SRequestObj *pRequest) {
|
|||
if (pTscObj->pAppInfo) {
|
||||
SInstanceSummary *pSummary = &pTscObj->pAppInfo->summary;
|
||||
|
||||
int32_t total = atomic_add_fetch_32(&pSummary->totalRequests, 1);
|
||||
int32_t currentInst = atomic_add_fetch_32(&pSummary->currentRequests, 1);
|
||||
int32_t total = atomic_add_fetch_64(&pSummary->totalRequests, 1);
|
||||
int32_t currentInst = atomic_add_fetch_64(&pSummary->currentRequests, 1);
|
||||
tscDebug("0x%" PRIx64 " new Request from connObj:0x%" PRIx64
|
||||
", current:%d, app current:%d, total:%d, reqId:0x%" PRIx64,
|
||||
pRequest->self, pRequest->pTscObj->id, num, currentInst, total, pRequest->requestId);
|
||||
|
@ -62,7 +62,7 @@ static void deregisterRequest(SRequestObj *pRequest) {
|
|||
STscObj * pTscObj = pRequest->pTscObj;
|
||||
SInstanceSummary *pActivity = &pTscObj->pAppInfo->summary;
|
||||
|
||||
int32_t currentInst = atomic_sub_fetch_32(&pActivity->currentRequests, 1);
|
||||
int32_t currentInst = atomic_sub_fetch_64(&pActivity->currentRequests, 1);
|
||||
int32_t num = atomic_sub_fetch_32(&pTscObj->numOfReqs, 1);
|
||||
|
||||
int64_t duration = taosGetTimestampMs() - pRequest->metric.start;
|
||||
|
|
|
@ -681,7 +681,7 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) {
|
|||
|
||||
int32_t tmqGetSkipLogNum(tmq_message_t* tmq_message) {
|
||||
if (tmq_message == NULL) return 0;
|
||||
SMqPollRsp* pRsp = &tmq_message->consumeRsp;
|
||||
SMqPollRsp* pRsp = &tmq_message->msg;
|
||||
return pRsp->skipLogNum;
|
||||
}
|
||||
|
||||
|
@ -690,15 +690,15 @@ void tmqShowMsg(tmq_message_t* tmq_message) {
|
|||
|
||||
static bool noPrintSchema;
|
||||
char pBuf[128];
|
||||
SMqPollRsp* pRsp = &tmq_message->consumeRsp;
|
||||
int32_t colNum = pRsp->schemas->nCols;
|
||||
SMqPollRsp* pRsp = &tmq_message->msg;
|
||||
int32_t colNum = pRsp->schema->nCols;
|
||||
if (!noPrintSchema) {
|
||||
printf("|");
|
||||
for (int32_t i = 0; i < colNum; i++) {
|
||||
if (i == 0)
|
||||
printf(" %25s |", pRsp->schemas->pSchema[i].name);
|
||||
printf(" %25s |", pRsp->schema->pSchema[i].name);
|
||||
else
|
||||
printf(" %15s |", pRsp->schemas->pSchema[i].name);
|
||||
printf(" %15s |", pRsp->schema->pSchema[i].name);
|
||||
}
|
||||
printf("\n");
|
||||
printf("===============================================\n");
|
||||
|
@ -735,7 +735,7 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
SMqClientVg* pVg = pParam->pVg;
|
||||
tmq_t* tmq = pParam->tmq;
|
||||
if (code != 0) {
|
||||
printf("msg discard\n");
|
||||
printf("msg discard %x\n", code);
|
||||
goto WRITE_QUEUE_FAIL;
|
||||
}
|
||||
|
||||
|
@ -778,19 +778,19 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
goto WRITE_QUEUE_FAIL;
|
||||
}
|
||||
memcpy(pRsp, pMsg->pData, sizeof(SMqRspHead));
|
||||
tDecodeSMqPollRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pRsp->consumeRsp);
|
||||
pRsp->curBlock = 0;
|
||||
pRsp->curRow = 0;
|
||||
tDecodeSMqPollRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pRsp->msg);
|
||||
pRsp->iter.curBlock = 0;
|
||||
pRsp->iter.curRow = 0;
|
||||
// TODO: alloc mem
|
||||
/*pRsp->*/
|
||||
/*printf("rsp commit off:%ld rsp off:%ld has data:%d\n", pRsp->committedOffset, pRsp->rspOffset, pRsp->numOfTopics);*/
|
||||
if (pRsp->consumeRsp.numOfTopics == 0) {
|
||||
if (pRsp->msg.numOfTopics == 0) {
|
||||
/*printf("no data\n");*/
|
||||
taosFreeQitem(pRsp);
|
||||
goto WRITE_QUEUE_FAIL;
|
||||
}
|
||||
|
||||
pRsp->extra = pParam->pVg;
|
||||
pRsp->vg = pParam->pVg;
|
||||
taosWriteQitem(tmq->mqueue, pRsp);
|
||||
atomic_add_fetch_32(&tmq->readyRequest, 1);
|
||||
tsem_post(&tmq->rspSem);
|
||||
|
@ -860,14 +860,14 @@ int32_t tmqAskEpCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
}
|
||||
tDeleteSMqCMGetSubEpRsp(&rsp);
|
||||
} else {
|
||||
tmq_message_t* pRsp = taosAllocateQitem(sizeof(tmq_message_t));
|
||||
SMqCMGetSubEpRsp* pRsp = taosAllocateQitem(sizeof(SMqCMGetSubEpRsp));
|
||||
if (pRsp == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = -1;
|
||||
goto END;
|
||||
}
|
||||
memcpy(pRsp, pMsg->pData, sizeof(SMqRspHead));
|
||||
tDecodeSMqCMGetSubEpRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pRsp->getEpRsp);
|
||||
tDecodeSMqCMGetSubEpRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), pRsp);
|
||||
|
||||
taosWriteQitem(tmq->mqueue, pRsp);
|
||||
tsem_post(&tmq->rspSem);
|
||||
|
@ -983,6 +983,7 @@ SMqPollReq* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t blockingTime, SMqClientTo
|
|||
return pReq;
|
||||
}
|
||||
|
||||
#if 0
|
||||
tmq_message_t* tmqSyncPollImpl(tmq_t* tmq, int64_t blockingTime) {
|
||||
tmq_message_t* msg = NULL;
|
||||
for (int i = 0; i < taosArrayGetSize(tmq->clientTopics); i++) {
|
||||
|
@ -1050,6 +1051,7 @@ tmq_message_t* tmqSyncPollImpl(tmq_t* tmq, int64_t blockingTime) {
|
|||
}
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) {
|
||||
/*printf("call poll\n");*/
|
||||
|
@ -1111,11 +1113,12 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) {
|
|||
}
|
||||
|
||||
// return
|
||||
int32_t tmqHandleRes(tmq_t* tmq, tmq_message_t* rspMsg, bool* pReset) {
|
||||
if (rspMsg->head.mqMsgType == TMQ_MSG_TYPE__EP_RSP) {
|
||||
int32_t tmqHandleRes(tmq_t* tmq, SMqRspHead* rspHead, bool* pReset) {
|
||||
if (rspHead->mqMsgType == TMQ_MSG_TYPE__EP_RSP) {
|
||||
/*printf("ep %d %d\n", rspMsg->head.epoch, tmq->epoch);*/
|
||||
if (rspMsg->head.epoch > atomic_load_32(&tmq->epoch)) {
|
||||
tmqUpdateEp(tmq, rspMsg->head.epoch, &rspMsg->getEpRsp);
|
||||
if (rspHead->epoch > atomic_load_32(&tmq->epoch)) {
|
||||
SMqCMGetSubEpRsp* rspMsg = (SMqCMGetSubEpRsp*)rspHead;
|
||||
tmqUpdateEp(tmq, rspHead->epoch, rspMsg);
|
||||
tmqClearUnhandleMsg(tmq);
|
||||
*pReset = true;
|
||||
} else {
|
||||
|
@ -1129,21 +1132,22 @@ int32_t tmqHandleRes(tmq_t* tmq, tmq_message_t* rspMsg, bool* pReset) {
|
|||
|
||||
tmq_message_t* tmqHandleAllRsp(tmq_t* tmq, int64_t blockingTime, bool pollIfReset) {
|
||||
while (1) {
|
||||
tmq_message_t* rspMsg = NULL;
|
||||
taosGetQitem(tmq->qall, (void**)&rspMsg);
|
||||
if (rspMsg == NULL) {
|
||||
SMqRspHead* rspHead = NULL;
|
||||
taosGetQitem(tmq->qall, (void**)&rspHead);
|
||||
if (rspHead == NULL) {
|
||||
taosReadAllQitems(tmq->mqueue, tmq->qall);
|
||||
taosGetQitem(tmq->qall, (void**)&rspMsg);
|
||||
if (rspMsg == NULL) return NULL;
|
||||
taosGetQitem(tmq->qall, (void**)&rspHead);
|
||||
if (rspHead == NULL) return NULL;
|
||||
}
|
||||
|
||||
if (rspMsg->head.mqMsgType == TMQ_MSG_TYPE__POLL_RSP) {
|
||||
if (rspHead->mqMsgType == TMQ_MSG_TYPE__POLL_RSP) {
|
||||
tmq_message_t* rspMsg = (tmq_message_t*)rspHead;
|
||||
atomic_sub_fetch_32(&tmq->readyRequest, 1);
|
||||
/*printf("handle poll rsp %d\n", rspMsg->head.mqMsgType);*/
|
||||
if (rspMsg->head.epoch == atomic_load_32(&tmq->epoch)) {
|
||||
if (rspMsg->msg.head.epoch == atomic_load_32(&tmq->epoch)) {
|
||||
/*printf("epoch match\n");*/
|
||||
SMqClientVg* pVg = rspMsg->extra;
|
||||
pVg->currentOffset = rspMsg->consumeRsp.rspOffset;
|
||||
SMqClientVg* pVg = rspMsg->vg;
|
||||
pVg->currentOffset = rspMsg->msg.rspOffset;
|
||||
atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE);
|
||||
return rspMsg;
|
||||
} else {
|
||||
|
@ -1153,8 +1157,8 @@ tmq_message_t* tmqHandleAllRsp(tmq_t* tmq, int64_t blockingTime, bool pollIfRese
|
|||
} else {
|
||||
/*printf("handle ep rsp %d\n", rspMsg->head.mqMsgType);*/
|
||||
bool reset = false;
|
||||
tmqHandleRes(tmq, rspMsg, &reset);
|
||||
taosFreeQitem(rspMsg);
|
||||
tmqHandleRes(tmq, rspHead, &reset);
|
||||
taosFreeQitem(rspHead);
|
||||
if (pollIfReset && reset) {
|
||||
printf("reset and repoll\n");
|
||||
tmqPollImpl(tmq, blockingTime);
|
||||
|
@ -1163,6 +1167,7 @@ tmq_message_t* tmqHandleAllRsp(tmq_t* tmq, int64_t blockingTime, bool pollIfRese
|
|||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
tmq_message_t* tmq_consumer_poll_v1(tmq_t* tmq, int64_t blocking_time) {
|
||||
tmq_message_t* rspMsg = NULL;
|
||||
int64_t startTime = taosGetTimestampMs();
|
||||
|
@ -1185,6 +1190,7 @@ tmq_message_t* tmq_consumer_poll_v1(tmq_t* tmq, int64_t blocking_time) {
|
|||
return NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
tmq_message_t* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) {
|
||||
tmq_message_t* rspMsg;
|
||||
|
@ -1350,7 +1356,7 @@ tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* tmq_topic_v
|
|||
|
||||
void tmq_message_destroy(tmq_message_t* tmq_message) {
|
||||
if (tmq_message == NULL) return;
|
||||
SMqPollRsp* pRsp = &tmq_message->consumeRsp;
|
||||
SMqPollRsp* pRsp = &tmq_message->msg;
|
||||
tDeleteSMqConsumeRsp(pRsp);
|
||||
/*free(tmq_message);*/
|
||||
taosFreeQitem(tmq_message);
|
||||
|
@ -1366,24 +1372,24 @@ const char* tmq_err2str(tmq_resp_err_t err) {
|
|||
}
|
||||
|
||||
TAOS_ROW tmq_get_row(tmq_message_t* message) {
|
||||
SMqPollRsp* rsp = &message->consumeRsp;
|
||||
SMqPollRsp* rsp = &message->msg;
|
||||
while (1) {
|
||||
if (message->curBlock < taosArrayGetSize(rsp->pBlockData)) {
|
||||
SSDataBlock* pBlock = taosArrayGet(rsp->pBlockData, message->curBlock);
|
||||
if (message->curRow < pBlock->info.rows) {
|
||||
if (message->iter.curBlock < taosArrayGetSize(rsp->pBlockData)) {
|
||||
SSDataBlock* pBlock = taosArrayGet(rsp->pBlockData, message->iter.curBlock);
|
||||
if (message->iter.curRow < pBlock->info.rows) {
|
||||
for (int i = 0; i < pBlock->info.numOfCols; i++) {
|
||||
SColumnInfoData* pData = taosArrayGet(pBlock->pDataBlock, i);
|
||||
if (colDataIsNull_s(pData, message->curRow))
|
||||
message->uData[i] = NULL;
|
||||
if (colDataIsNull_s(pData, message->iter.curRow))
|
||||
message->iter.uData[i] = NULL;
|
||||
else {
|
||||
message->uData[i] = colDataGetData(pData, message->curRow);
|
||||
message->iter.uData[i] = colDataGetData(pData, message->iter.curRow);
|
||||
}
|
||||
}
|
||||
message->curRow++;
|
||||
return message->uData;
|
||||
message->iter.curRow++;
|
||||
return message->iter.uData;
|
||||
} else {
|
||||
message->curBlock++;
|
||||
message->curRow = 0;
|
||||
message->iter.curBlock++;
|
||||
message->iter.curRow = 0;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,14 +18,14 @@
|
|||
#include "tcompare.h"
|
||||
#include "tglobal.h"
|
||||
|
||||
int32_t taosGetFqdnPortFromEp(const char *ep, SEp* pEp) {
|
||||
int32_t taosGetFqdnPortFromEp(const char* ep, SEp* pEp) {
|
||||
pEp->port = 0;
|
||||
strcpy(pEp->fqdn, ep);
|
||||
|
||||
char *temp = strchr(pEp->fqdn, ':');
|
||||
char* temp = strchr(pEp->fqdn, ':');
|
||||
if (temp) {
|
||||
*temp = 0;
|
||||
pEp->port = atoi(temp+1);
|
||||
pEp->port = atoi(temp + 1);
|
||||
}
|
||||
|
||||
if (pEp->port == 0) {
|
||||
|
@ -36,7 +36,7 @@ int32_t taosGetFqdnPortFromEp(const char *ep, SEp* pEp) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void addEpIntoEpSet(SEpSet *pEpSet, const char* fqdn, uint16_t port) {
|
||||
void addEpIntoEpSet(SEpSet* pEpSet, const char* fqdn, uint16_t port) {
|
||||
if (pEpSet == NULL || fqdn == NULL || strlen(fqdn) == 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -47,26 +47,25 @@ void addEpIntoEpSet(SEpSet *pEpSet, const char* fqdn, uint16_t port) {
|
|||
pEpSet->numOfEps += 1;
|
||||
}
|
||||
|
||||
bool isEpsetEqual(const SEpSet *s1, const SEpSet *s2) {
|
||||
bool isEpsetEqual(const SEpSet* s1, const SEpSet* s2) {
|
||||
if (s1->numOfEps != s2->numOfEps || s1->inUse != s2->inUse) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < s1->numOfEps; i++) {
|
||||
if (s1->eps[i].port != s2->eps[i].port
|
||||
|| strncmp(s1->eps[i].fqdn, s2->eps[i].fqdn, TSDB_FQDN_LEN) != 0)
|
||||
if (s1->eps[i].port != s2->eps[i].port || strncmp(s1->eps[i].fqdn, s2->eps[i].fqdn, TSDB_FQDN_LEN) != 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void updateEpSet_s(SCorEpSet *pEpSet, SEpSet *pNewEpSet) {
|
||||
void updateEpSet_s(SCorEpSet* pEpSet, SEpSet* pNewEpSet) {
|
||||
taosCorBeginWrite(&pEpSet->version);
|
||||
pEpSet->epSet = *pNewEpSet;
|
||||
taosCorEndWrite(&pEpSet->version);
|
||||
}
|
||||
|
||||
SEpSet getEpSet_s(SCorEpSet *pEpSet) {
|
||||
SEpSet getEpSet_s(SCorEpSet* pEpSet) {
|
||||
SEpSet ep = {0};
|
||||
taosCorBeginRead(&pEpSet->version);
|
||||
ep = pEpSet->epSet;
|
||||
|
@ -75,7 +74,6 @@ SEpSet getEpSet_s(SCorEpSet *pEpSet) {
|
|||
return ep;
|
||||
}
|
||||
|
||||
|
||||
int32_t colDataGetLength(const SColumnInfoData* pColumnInfoData, int32_t numOfRows) {
|
||||
ASSERT(pColumnInfoData != NULL);
|
||||
if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) {
|
||||
|
@ -95,7 +93,7 @@ int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, con
|
|||
if (isNull) {
|
||||
// There is a placehold for each NULL value of binary or nchar type.
|
||||
if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) {
|
||||
pColumnInfoData->varmeta.offset[currentRow] = -1; // it is a null value of VAR type.
|
||||
pColumnInfoData->varmeta.offset[currentRow] = -1; // it is a null value of VAR type.
|
||||
} else {
|
||||
colDataSetNull_f(pColumnInfoData->nullbitmap, currentRow);
|
||||
}
|
||||
|
@ -113,7 +111,7 @@ int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, con
|
|||
newSize = 8;
|
||||
}
|
||||
|
||||
while(newSize < pAttr->length + varDataTLen(pData)) {
|
||||
while (newSize < pAttr->length + varDataTLen(pData)) {
|
||||
newSize = newSize * 1.5;
|
||||
}
|
||||
|
||||
|
@ -133,19 +131,40 @@ int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, con
|
|||
pColumnInfoData->varmeta.length += varDataTLen(pData);
|
||||
} else {
|
||||
char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow;
|
||||
switch(type) {
|
||||
case TSDB_DATA_TYPE_BOOL: {*(bool*) p = *(bool*) pData;break;}
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_BOOL: {
|
||||
*(bool*)p = *(bool*)pData;
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDB_DATA_TYPE_UTINYINT: {*(int8_t*) p = *(int8_t*) pData;break;}
|
||||
case TSDB_DATA_TYPE_UTINYINT: {
|
||||
*(int8_t*)p = *(int8_t*)pData;
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDB_DATA_TYPE_USMALLINT: {*(int16_t*) p = *(int16_t*) pData;break;}
|
||||
case TSDB_DATA_TYPE_USMALLINT: {
|
||||
*(int16_t*)p = *(int16_t*)pData;
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
case TSDB_DATA_TYPE_UINT: {*(int32_t*) p = *(int32_t*) pData;break;}
|
||||
case TSDB_DATA_TYPE_UINT: {
|
||||
*(int32_t*)p = *(int32_t*)pData;
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_UBIGINT: {*(int64_t*) p = *(int64_t*) pData;break;}
|
||||
case TSDB_DATA_TYPE_FLOAT: {*(float*) p = *(float*) pData;break;}
|
||||
case TSDB_DATA_TYPE_DOUBLE: {*(double*) p = *(double*) pData;break;}
|
||||
case TSDB_DATA_TYPE_UBIGINT: {
|
||||
*(int64_t*)p = *(int64_t*)pData;
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
*(float*)p = *(float*)pData;
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
*(double*)p = *(double*)pData;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
|
@ -154,7 +173,8 @@ int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, con
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void doBitmapMerge(SColumnInfoData* pColumnInfoData, int32_t numOfRow1, const SColumnInfoData* pSource, int32_t numOfRow2) {
|
||||
static void doBitmapMerge(SColumnInfoData* pColumnInfoData, int32_t numOfRow1, const SColumnInfoData* pSource,
|
||||
int32_t numOfRow2) {
|
||||
uint32_t total = numOfRow1 + numOfRow2;
|
||||
|
||||
if (BitmapLen(numOfRow1) < BitmapLen(total)) {
|
||||
|
@ -188,7 +208,8 @@ static void doBitmapMerge(SColumnInfoData* pColumnInfoData, int32_t numOfRow1, c
|
|||
}
|
||||
}
|
||||
|
||||
int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, const SColumnInfoData* pSource, uint32_t numOfRow2) {
|
||||
int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, const SColumnInfoData* pSource,
|
||||
uint32_t numOfRow2) {
|
||||
ASSERT(pColumnInfoData != NULL && pSource != NULL && pColumnInfoData->info.type == pSource->info.type);
|
||||
|
||||
if (numOfRow2 == 0) {
|
||||
|
@ -202,8 +223,8 @@ int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, co
|
|||
// TODO
|
||||
}
|
||||
|
||||
pColumnInfoData->varmeta.offset = (int32_t*) p;
|
||||
for(int32_t i = 0; i < numOfRow2; ++i) {
|
||||
pColumnInfoData->varmeta.offset = (int32_t*)p;
|
||||
for (int32_t i = 0; i < numOfRow2; ++i) {
|
||||
pColumnInfoData->varmeta.offset[i + numOfRow1] = pSource->varmeta.offset[i] + pColumnInfoData->varmeta.length;
|
||||
}
|
||||
|
||||
|
@ -244,9 +265,7 @@ size_t blockDataGetNumOfCols(const SSDataBlock* pBlock) {
|
|||
return pBlock->info.numOfCols;
|
||||
}
|
||||
|
||||
size_t blockDataGetNumOfRows(const SSDataBlock* pBlock) {
|
||||
return pBlock->info.rows;
|
||||
}
|
||||
size_t blockDataGetNumOfRows(const SSDataBlock* pBlock) { return pBlock->info.rows; }
|
||||
|
||||
int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock) {
|
||||
if (pDataBlock == NULL || pDataBlock->info.rows <= 0) {
|
||||
|
@ -263,8 +282,8 @@ int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock) {
|
|||
}
|
||||
|
||||
ASSERT(pColInfoData->nullbitmap == NULL);
|
||||
pDataBlock->info.window.skey = *(TSKEY*) colDataGetData(pColInfoData, 0);
|
||||
pDataBlock->info.window.ekey = *(TSKEY*) colDataGetData(pColInfoData, (pDataBlock->info.rows - 1));
|
||||
pDataBlock->info.window.skey = *(TSKEY*)colDataGetData(pColInfoData, 0);
|
||||
pDataBlock->info.window.ekey = *(TSKEY*)colDataGetData(pColInfoData, (pDataBlock->info.rows - 1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -272,7 +291,7 @@ int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc) {
|
|||
assert(pSrc != NULL && pDest != NULL && pDest->info.numOfCols == pSrc->info.numOfCols);
|
||||
|
||||
int32_t numOfCols = pSrc->info.numOfCols;
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData* pCol2 = taosArrayGet(pDest->pDataBlock, i);
|
||||
SColumnInfoData* pCol1 = taosArrayGet(pSrc->pDataBlock, i);
|
||||
|
||||
|
@ -280,7 +299,7 @@ int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc) {
|
|||
uint32_t newLen = colDataGetLength(pCol1, pSrc->info.rows);
|
||||
|
||||
int32_t newSize = oldLen + newLen;
|
||||
char* tmp = realloc(pCol2->pData, newSize);
|
||||
char* tmp = realloc(pCol2->pData, newSize);
|
||||
if (tmp != NULL) {
|
||||
pCol2->pData = tmp;
|
||||
colDataMergeCol(pCol2, pDest->info.rows, pCol1, pSrc->info.rows);
|
||||
|
@ -296,10 +315,10 @@ int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc) {
|
|||
size_t blockDataGetSize(const SSDataBlock* pBlock) {
|
||||
assert(pBlock != NULL);
|
||||
|
||||
size_t total = 0;
|
||||
size_t total = 0;
|
||||
int32_t numOfCols = pBlock->info.numOfCols;
|
||||
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
|
||||
total += colDataGetLength(pColInfoData, pBlock->info.rows);
|
||||
|
||||
|
@ -315,7 +334,8 @@ size_t blockDataGetSize(const SSDataBlock* pBlock) {
|
|||
|
||||
// the number of tuples can be fit in one page.
|
||||
// Actual data rows pluses the corresponding meta data must fit in one memory buffer of the given page size.
|
||||
int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startIndex, int32_t* stopIndex, int32_t pageSize) {
|
||||
int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startIndex, int32_t* stopIndex,
|
||||
int32_t pageSize) {
|
||||
ASSERT(pBlock != NULL && stopIndex != NULL);
|
||||
|
||||
int32_t numOfCols = pBlock->info.numOfCols;
|
||||
|
@ -323,13 +343,13 @@ int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startInd
|
|||
|
||||
int32_t bitmapChar = 1;
|
||||
|
||||
size_t headerSize = sizeof(int32_t);
|
||||
size_t headerSize = sizeof(int32_t);
|
||||
size_t colHeaderSize = sizeof(int32_t) * numOfCols;
|
||||
size_t payloadSize = pageSize - (headerSize + colHeaderSize);
|
||||
size_t payloadSize = pageSize - (headerSize + colHeaderSize);
|
||||
|
||||
// TODO speedup by checking if the whole page can fit in firstly.
|
||||
if (!hasVarCol) {
|
||||
size_t rowSize = blockDataGetRowSize(pBlock);
|
||||
size_t rowSize = blockDataGetRowSize(pBlock);
|
||||
int32_t capacity = (payloadSize / (rowSize * 8 + bitmapChar * numOfCols)) * 8;
|
||||
|
||||
*stopIndex = startIndex + capacity;
|
||||
|
@ -342,7 +362,7 @@ int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startInd
|
|||
// iterate the rows that can be fit in this buffer page
|
||||
int32_t size = (headerSize + colHeaderSize);
|
||||
|
||||
for(int32_t j = startIndex; j < numOfRows; ++j) {
|
||||
for (int32_t j = startIndex; j < numOfRows; ++j) {
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData* pColInfoData = TARRAY_GET_ELEM(pBlock->pDataBlock, i);
|
||||
if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
|
||||
|
@ -359,7 +379,7 @@ int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startInd
|
|||
size += pColInfoData->info.bytes;
|
||||
|
||||
if (((j - startIndex) & 0x07) == 0) {
|
||||
size += 1; // the space for null bitmap
|
||||
size += 1; // the space for null bitmap
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -393,8 +413,8 @@ SSDataBlock* blockDataExtractBlock(SSDataBlock* pBlock, int32_t startIndex, int3
|
|||
pDst->info.rows = 0;
|
||||
pDst->pDataBlock = taosArrayInit(pBlock->info.numOfCols, sizeof(SColumnInfoData));
|
||||
|
||||
for(int32_t i = 0; i < pBlock->info.numOfCols; ++i) {
|
||||
SColumnInfoData colInfo = {0};
|
||||
for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) {
|
||||
SColumnInfoData colInfo = {0};
|
||||
SColumnInfoData* pSrcCol = taosArrayGet(pBlock->pDataBlock, i);
|
||||
colInfo.info = pSrcCol->info;
|
||||
|
||||
|
@ -414,7 +434,7 @@ SSDataBlock* blockDataExtractBlock(SSDataBlock* pBlock, int32_t startIndex, int3
|
|||
SColumnInfoData* pDstCol = taosArrayGet(pDst->pDataBlock, i);
|
||||
|
||||
for (int32_t j = startIndex; j < (startIndex + rowCount); ++j) {
|
||||
bool isNull = colDataIsNull(pColData, pBlock->info.rows, j, pBlock->pBlockAgg);
|
||||
bool isNull = colDataIsNull(pColData, pBlock->info.rows, j, pBlock->pBlockAgg);
|
||||
char* p = colDataGetData(pColData, j);
|
||||
|
||||
colDataAppend(pDstCol, j - startIndex, p, isNull);
|
||||
|
@ -440,14 +460,14 @@ int32_t blockDataToBuf(char* buf, const SSDataBlock* pBlock) {
|
|||
ASSERT(pBlock != NULL);
|
||||
|
||||
// write the number of rows
|
||||
*(uint32_t*) buf = pBlock->info.rows;
|
||||
*(uint32_t*)buf = pBlock->info.rows;
|
||||
|
||||
int32_t numOfCols = pBlock->info.numOfCols;
|
||||
int32_t numOfRows = pBlock->info.rows;
|
||||
|
||||
char* pStart = buf + sizeof(uint32_t);
|
||||
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, i);
|
||||
if (IS_VAR_DATA_TYPE(pCol->info.type)) {
|
||||
memcpy(pStart, pCol->varmeta.offset, numOfRows * sizeof(int32_t));
|
||||
|
@ -459,7 +479,7 @@ int32_t blockDataToBuf(char* buf, const SSDataBlock* pBlock) {
|
|||
|
||||
uint32_t dataSize = colDataGetLength(pCol, numOfRows);
|
||||
|
||||
*(int32_t*) pStart = dataSize;
|
||||
*(int32_t*)pStart = dataSize;
|
||||
pStart += sizeof(int32_t);
|
||||
|
||||
memcpy(pStart, pCol->pData, dataSize);
|
||||
|
@ -470,12 +490,12 @@ int32_t blockDataToBuf(char* buf, const SSDataBlock* pBlock) {
|
|||
}
|
||||
|
||||
int32_t blockDataFromBuf(SSDataBlock* pBlock, const char* buf) {
|
||||
pBlock->info.rows = *(int32_t*) buf;
|
||||
pBlock->info.rows = *(int32_t*)buf;
|
||||
|
||||
int32_t numOfCols = pBlock->info.numOfCols;
|
||||
int32_t numOfCols = pBlock->info.numOfCols;
|
||||
const char* pStart = buf + sizeof(uint32_t);
|
||||
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, i);
|
||||
|
||||
size_t metaSize = pBlock->info.rows * sizeof(int32_t);
|
||||
|
@ -487,7 +507,7 @@ int32_t blockDataFromBuf(SSDataBlock* pBlock, const char* buf) {
|
|||
pStart += BitmapLen(pBlock->info.rows);
|
||||
}
|
||||
|
||||
int32_t colLength = *(int32_t*) pStart;
|
||||
int32_t colLength = *(int32_t*)pStart;
|
||||
pStart += sizeof(int32_t);
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pCol->info.type)) {
|
||||
|
@ -517,7 +537,7 @@ size_t blockDataGetRowSize(const SSDataBlock* pBlock) {
|
|||
size_t rowSize = 0;
|
||||
|
||||
size_t numOfCols = pBlock->info.numOfCols;
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, i);
|
||||
rowSize += pColInfo->info.bytes;
|
||||
}
|
||||
|
@ -537,10 +557,10 @@ size_t blockDataGetSerialMetaSize(const SSDataBlock* pBlock) {
|
|||
|
||||
SSchema* blockDataExtractSchema(const SSDataBlock* pBlock, int32_t* numOfCols) {
|
||||
SSchema* pSchema = calloc(pBlock->info.numOfCols, sizeof(SSchema));
|
||||
for(int32_t i = 0; i < pBlock->info.numOfCols; ++i) {
|
||||
for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) {
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
|
||||
pSchema[i].bytes = pColInfoData->info.bytes;
|
||||
pSchema[i].type = pColInfoData->info.type;
|
||||
pSchema[i].type = pColInfoData->info.type;
|
||||
pSchema[i].colId = pColInfoData->info.colId;
|
||||
}
|
||||
|
||||
|
@ -556,14 +576,14 @@ double blockDataGetSerialRowSize(const SSDataBlock* pBlock) {
|
|||
double rowSize = 0;
|
||||
|
||||
size_t numOfCols = pBlock->info.numOfCols;
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, i);
|
||||
rowSize += pColInfo->info.bytes;
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pColInfo->info.type)) {
|
||||
rowSize += sizeof(int32_t);
|
||||
} else {
|
||||
rowSize += 1/8.0;
|
||||
rowSize += 1 / 8.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -571,56 +591,56 @@ double blockDataGetSerialRowSize(const SSDataBlock* pBlock) {
|
|||
}
|
||||
|
||||
typedef struct SSDataBlockSortHelper {
|
||||
SArray *orderInfo; // SArray<SBlockOrderInfo>
|
||||
SSDataBlock *pDataBlock;
|
||||
SArray* orderInfo; // SArray<SBlockOrderInfo>
|
||||
SSDataBlock* pDataBlock;
|
||||
bool nullFirst;
|
||||
} SSDataBlockSortHelper;
|
||||
|
||||
int32_t dataBlockCompar(const void* p1, const void* p2, const void* param) {
|
||||
const SSDataBlockSortHelper* pHelper = (const SSDataBlockSortHelper*) param;
|
||||
const SSDataBlockSortHelper* pHelper = (const SSDataBlockSortHelper*)param;
|
||||
|
||||
SSDataBlock* pDataBlock = pHelper->pDataBlock;
|
||||
|
||||
int32_t left = *(int32_t*) p1;
|
||||
int32_t right = *(int32_t*) p2;
|
||||
int32_t left = *(int32_t*)p1;
|
||||
int32_t right = *(int32_t*)p2;
|
||||
|
||||
SArray* pInfo = pHelper->orderInfo;
|
||||
|
||||
for(int32_t i = 0; i < pInfo->size; ++i) {
|
||||
for (int32_t i = 0; i < pInfo->size; ++i) {
|
||||
SBlockOrderInfo* pOrder = TARRAY_GET_ELEM(pInfo, i);
|
||||
SColumnInfoData* pColInfoData = pOrder->pColData;//TARRAY_GET_ELEM(pDataBlock->pDataBlock, pOrder->colIndex);
|
||||
SColumnInfoData* pColInfoData = pOrder->pColData; // TARRAY_GET_ELEM(pDataBlock->pDataBlock, pOrder->colIndex);
|
||||
|
||||
if (pColInfoData->hasNull) {
|
||||
bool leftNull = colDataIsNull(pColInfoData, pDataBlock->info.rows, left, pDataBlock->pBlockAgg);
|
||||
bool leftNull = colDataIsNull(pColInfoData, pDataBlock->info.rows, left, pDataBlock->pBlockAgg);
|
||||
bool rightNull = colDataIsNull(pColInfoData, pDataBlock->info.rows, right, pDataBlock->pBlockAgg);
|
||||
if (leftNull && rightNull) {
|
||||
continue; // continue to next slot
|
||||
continue; // continue to next slot
|
||||
}
|
||||
|
||||
if (rightNull) {
|
||||
return pHelper->nullFirst? 1:-1;
|
||||
return pHelper->nullFirst ? 1 : -1;
|
||||
}
|
||||
|
||||
if (leftNull) {
|
||||
return pHelper->nullFirst? -1:1;
|
||||
return pHelper->nullFirst ? -1 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
void* left1 = colDataGetData(pColInfoData, left);
|
||||
void* left1 = colDataGetData(pColInfoData, left);
|
||||
void* right1 = colDataGetData(pColInfoData, right);
|
||||
|
||||
switch(pColInfoData->info.type) {
|
||||
switch (pColInfoData->info.type) {
|
||||
case TSDB_DATA_TYPE_INT: {
|
||||
int32_t leftx = *(int32_t*) left1;
|
||||
int32_t rightx = *(int32_t*) right1;
|
||||
int32_t leftx = *(int32_t*)left1;
|
||||
int32_t rightx = *(int32_t*)right1;
|
||||
|
||||
if (leftx == rightx) {
|
||||
break;
|
||||
} else {
|
||||
if (pOrder->order == TSDB_ORDER_ASC) {
|
||||
return (leftx < rightx)? -1:1;
|
||||
return (leftx < rightx) ? -1 : 1;
|
||||
} else {
|
||||
return (leftx < rightx)? 1:-1;
|
||||
return (leftx < rightx) ? 1 : -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -632,7 +652,8 @@ int32_t dataBlockCompar(const void* p1, const void* p2, const void* param) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t doAssignOneTuple(SColumnInfoData* pDstCols, int32_t numOfRows, const SSDataBlock* pSrcBlock, int32_t tupleIndex) {
|
||||
static int32_t doAssignOneTuple(SColumnInfoData* pDstCols, int32_t numOfRows, const SSDataBlock* pSrcBlock,
|
||||
int32_t tupleIndex) {
|
||||
int32_t code = 0;
|
||||
int32_t numOfCols = pSrcBlock->info.numOfCols;
|
||||
|
||||
|
@ -666,17 +687,17 @@ static int32_t blockDataAssign(SColumnInfoData* pCols, const SSDataBlock* pDataB
|
|||
}
|
||||
}
|
||||
#else
|
||||
for(int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) {
|
||||
for (int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) {
|
||||
SColumnInfoData* pDst = &pCols[i];
|
||||
SColumnInfoData* pSrc = taosArrayGet(pDataBlock->pDataBlock, i);
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pSrc->info.type)) {
|
||||
memcpy(pDst->pData, pSrc->pData, pSrc->varmeta.length);
|
||||
pDst->varmeta.length = pSrc->varmeta.length;
|
||||
memcpy(pDst->pData, pSrc->pData, pSrc->varmeta.length);
|
||||
pDst->varmeta.length = pSrc->varmeta.length;
|
||||
|
||||
for(int32_t j = 0; j < pDataBlock->info.rows; ++j) {
|
||||
pDst->varmeta.offset[j] = pSrc->varmeta.offset[index[j]];
|
||||
}
|
||||
for (int32_t j = 0; j < pDataBlock->info.rows; ++j) {
|
||||
pDst->varmeta.offset[j] = pSrc->varmeta.offset[index[j]];
|
||||
}
|
||||
} else {
|
||||
switch (pSrc->info.type) {
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
|
@ -749,7 +770,7 @@ static SColumnInfoData* createHelpColInfoData(const SSDataBlock* pDataBlock) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, i);
|
||||
pCols[i].info = pColInfoData->info;
|
||||
|
||||
|
@ -771,7 +792,7 @@ static SColumnInfoData* createHelpColInfoData(const SSDataBlock* pDataBlock) {
|
|||
static void copyBackToBlock(SSDataBlock* pDataBlock, SColumnInfoData* pCols) {
|
||||
int32_t numOfCols = pDataBlock->info.numOfCols;
|
||||
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, i);
|
||||
pColInfoData->info = pCols[i].info;
|
||||
|
||||
|
@ -796,31 +817,39 @@ static int32_t* createTupleIndex(size_t rows) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
for(int32_t i = 0; i < rows; ++i) {
|
||||
for (int32_t i = 0; i < rows; ++i) {
|
||||
index[i] = i;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
static void destroyTupleIndex(int32_t* index) {
|
||||
tfree(index);
|
||||
}
|
||||
static void destroyTupleIndex(int32_t* index) { tfree(index); }
|
||||
|
||||
static __compar_fn_t getComparFn(int32_t type, int32_t order) {
|
||||
switch(type) {
|
||||
case TSDB_DATA_TYPE_TINYINT: return order == TSDB_ORDER_ASC? compareInt8Val:compareInt8ValDesc;
|
||||
case TSDB_DATA_TYPE_SMALLINT: return order == TSDB_ORDER_ASC? compareInt16Val:compareInt16ValDesc;
|
||||
case TSDB_DATA_TYPE_INT: return order == TSDB_ORDER_ASC? compareInt32Val:compareInt32ValDesc;
|
||||
case TSDB_DATA_TYPE_BIGINT: return order == TSDB_ORDER_ASC? compareInt64Val:compareInt64ValDesc;
|
||||
case TSDB_DATA_TYPE_FLOAT: return order == TSDB_ORDER_ASC? compareFloatVal:compareFloatValDesc;
|
||||
case TSDB_DATA_TYPE_DOUBLE: return order == TSDB_ORDER_ASC? compareDoubleVal:compareDoubleValDesc;
|
||||
case TSDB_DATA_TYPE_UTINYINT: return order == TSDB_ORDER_ASC? compareUint8Val:compareUint8ValDesc;
|
||||
case TSDB_DATA_TYPE_USMALLINT:return order == TSDB_ORDER_ASC? compareUint16Val:compareUint16ValDesc;
|
||||
case TSDB_DATA_TYPE_UINT: return order == TSDB_ORDER_ASC? compareUint32Val:compareUint32ValDesc;
|
||||
case TSDB_DATA_TYPE_UBIGINT: return order == TSDB_ORDER_ASC? compareUint64Val:compareUint64ValDesc;
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
return order == TSDB_ORDER_ASC ? compareInt8Val : compareInt8ValDesc;
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
return order == TSDB_ORDER_ASC ? compareInt16Val : compareInt16ValDesc;
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
return order == TSDB_ORDER_ASC ? compareInt32Val : compareInt32ValDesc;
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
return order == TSDB_ORDER_ASC ? compareInt64Val : compareInt64ValDesc;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
return order == TSDB_ORDER_ASC ? compareFloatVal : compareFloatValDesc;
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
return order == TSDB_ORDER_ASC ? compareDoubleVal : compareDoubleValDesc;
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
return order == TSDB_ORDER_ASC ? compareUint8Val : compareUint8ValDesc;
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
return order == TSDB_ORDER_ASC ? compareUint16Val : compareUint16ValDesc;
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
return order == TSDB_ORDER_ASC ? compareUint32Val : compareUint32ValDesc;
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
return order == TSDB_ORDER_ASC ? compareUint64Val : compareUint64ValDesc;
|
||||
default:
|
||||
return order == TSDB_ORDER_ASC? compareInt32Val:compareInt32ValDesc;
|
||||
return order == TSDB_ORDER_ASC ? compareInt32Val : compareInt32ValDesc;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -865,10 +894,8 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirs
|
|||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
} else { // var data type
|
||||
|
||||
}
|
||||
} else if (pDataBlock->info.numOfCols == 2) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -881,7 +908,7 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirs
|
|||
int64_t p0 = taosGetTimestampUs();
|
||||
|
||||
SSDataBlockSortHelper helper = {.nullFirst = nullFirst, .pDataBlock = pDataBlock, .orderInfo = pOrderInfo};
|
||||
for(int32_t i = 0; i < taosArrayGetSize(helper.orderInfo); ++i) {
|
||||
for (int32_t i = 0; i < taosArrayGetSize(helper.orderInfo); ++i) {
|
||||
struct SBlockOrderInfo* pInfo = taosArrayGet(helper.orderInfo, i);
|
||||
pInfo->pColData = taosArrayGet(pDataBlock->pDataBlock, pInfo->colIndex);
|
||||
}
|
||||
|
@ -909,7 +936,8 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirs
|
|||
copyBackToBlock(pDataBlock, pCols);
|
||||
int64_t p4 = taosGetTimestampUs();
|
||||
|
||||
printf("sort:%" PRId64 ", create:%" PRId64 ", assign:%" PRId64 ", copyback:%" PRId64 ", rows:%d\n", p1-p0, p2 - p1, p3 - p2, p4-p3, rows);
|
||||
printf("sort:%" PRId64 ", create:%" PRId64 ", assign:%" PRId64 ", copyback:%" PRId64 ", rows:%d\n", p1 - p0, p2 - p1,
|
||||
p3 - p2, p4 - p3, rows);
|
||||
destroyTupleIndex(index);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -917,14 +945,18 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirs
|
|||
|
||||
typedef struct SHelper {
|
||||
int32_t index;
|
||||
union {char *pData; int64_t i64; double d64;};
|
||||
union {
|
||||
char* pData;
|
||||
int64_t i64;
|
||||
double d64;
|
||||
};
|
||||
} SHelper;
|
||||
|
||||
SHelper* createTupleIndex_rv(int32_t numOfRows, SArray* pOrderInfo, SSDataBlock* pBlock) {
|
||||
int32_t sortValLengthPerRow = 0;
|
||||
int32_t numOfCols = taosArrayGetSize(pOrderInfo);
|
||||
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SBlockOrderInfo* pInfo = taosArrayGet(pOrderInfo, i);
|
||||
SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, pInfo->colIndex);
|
||||
pInfo->pColData = pColInfo;
|
||||
|
@ -933,19 +965,20 @@ SHelper* createTupleIndex_rv(int32_t numOfRows, SArray* pOrderInfo, SSDataBlock*
|
|||
|
||||
size_t len = sortValLengthPerRow * pBlock->info.rows;
|
||||
|
||||
char* buf = calloc(1, len);
|
||||
char* buf = calloc(1, len);
|
||||
SHelper* phelper = calloc(numOfRows, sizeof(SHelper));
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||
phelper[i].index = i;
|
||||
phelper[i].pData = buf + sortValLengthPerRow * i;
|
||||
}
|
||||
|
||||
int32_t offset = 0;
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SBlockOrderInfo* pInfo = taosArrayGet(pOrderInfo, i);
|
||||
for(int32_t j = 0; j < numOfRows; ++j) {
|
||||
phelper[j].i64 = *(int32_t*) pInfo->pColData->pData + pInfo->pColData->info.bytes * j;
|
||||
// memcpy(phelper[j].pData + offset, pInfo->pColData->pData + pInfo->pColData->info.bytes * j, pInfo->pColData->info.bytes);
|
||||
for (int32_t j = 0; j < numOfRows; ++j) {
|
||||
phelper[j].i64 = *(int32_t*)pInfo->pColData->pData + pInfo->pColData->info.bytes * j;
|
||||
// memcpy(phelper[j].pData + offset, pInfo->pColData->pData + pInfo->pColData->info.bytes * j,
|
||||
// pInfo->pColData->info.bytes);
|
||||
}
|
||||
|
||||
offset += pInfo->pColData->info.bytes;
|
||||
|
@ -955,70 +988,68 @@ SHelper* createTupleIndex_rv(int32_t numOfRows, SArray* pOrderInfo, SSDataBlock*
|
|||
}
|
||||
|
||||
int32_t dataBlockCompar_rv(const void* p1, const void* p2, const void* param) {
|
||||
const SSDataBlockSortHelper* pHelper = (const SSDataBlockSortHelper*) param;
|
||||
const SSDataBlockSortHelper* pHelper = (const SSDataBlockSortHelper*)param;
|
||||
|
||||
// SSDataBlock* pDataBlock = pHelper->pDataBlock;
|
||||
// SSDataBlock* pDataBlock = pHelper->pDataBlock;
|
||||
|
||||
SHelper* left = (SHelper*) p1;
|
||||
SHelper* right = (SHelper*) p2;
|
||||
SHelper* left = (SHelper*)p1;
|
||||
SHelper* right = (SHelper*)p2;
|
||||
|
||||
SArray* pInfo = pHelper->orderInfo;
|
||||
|
||||
int32_t offset = 0;
|
||||
// for(int32_t i = 0; i < pInfo->size; ++i) {
|
||||
// SBlockOrderInfo* pOrder = TARRAY_GET_ELEM(pInfo, 0);
|
||||
// SColumnInfoData* pColInfoData = pOrder->pColData;//TARRAY_GET_ELEM(pDataBlock->pDataBlock, pOrder->colIndex);
|
||||
// for(int32_t i = 0; i < pInfo->size; ++i) {
|
||||
// SBlockOrderInfo* pOrder = TARRAY_GET_ELEM(pInfo, 0);
|
||||
// SColumnInfoData* pColInfoData = pOrder->pColData;//TARRAY_GET_ELEM(pDataBlock->pDataBlock, pOrder->colIndex);
|
||||
|
||||
// if (pColInfoData->hasNull) {
|
||||
// bool leftNull = colDataIsNull(pColInfoData, pDataBlock->info.rows, left, pDataBlock->pBlockAgg);
|
||||
// bool rightNull = colDataIsNull(pColInfoData, pDataBlock->info.rows, right, pDataBlock->pBlockAgg);
|
||||
// if (leftNull && rightNull) {
|
||||
// continue; // continue to next slot
|
||||
// }
|
||||
//
|
||||
// if (rightNull) {
|
||||
// return pHelper->nullFirst? 1:-1;
|
||||
// }
|
||||
//
|
||||
// if (leftNull) {
|
||||
// return pHelper->nullFirst? -1:1;
|
||||
// }
|
||||
// }
|
||||
// if (pColInfoData->hasNull) {
|
||||
// bool leftNull = colDataIsNull(pColInfoData, pDataBlock->info.rows, left, pDataBlock->pBlockAgg);
|
||||
// bool rightNull = colDataIsNull(pColInfoData, pDataBlock->info.rows, right, pDataBlock->pBlockAgg);
|
||||
// if (leftNull && rightNull) {
|
||||
// continue; // continue to next slot
|
||||
// }
|
||||
//
|
||||
// if (rightNull) {
|
||||
// return pHelper->nullFirst? 1:-1;
|
||||
// }
|
||||
//
|
||||
// if (leftNull) {
|
||||
// return pHelper->nullFirst? -1:1;
|
||||
// }
|
||||
// }
|
||||
|
||||
// void* left1 = colDataGetData(pColInfoData, left);
|
||||
// void* right1 = colDataGetData(pColInfoData, right);
|
||||
// void* left1 = colDataGetData(pColInfoData, left);
|
||||
// void* right1 = colDataGetData(pColInfoData, right);
|
||||
|
||||
// switch(pColInfoData->info.type) {
|
||||
// case TSDB_DATA_TYPE_INT: {
|
||||
int32_t leftx = *(int32_t*)left->pData;//*(int32_t*)(left->pData + offset);
|
||||
int32_t rightx = *(int32_t*)right->pData;//*(int32_t*)(right->pData + offset);
|
||||
// switch(pColInfoData->info.type) {
|
||||
// case TSDB_DATA_TYPE_INT: {
|
||||
int32_t leftx = *(int32_t*)left->pData; //*(int32_t*)(left->pData + offset);
|
||||
int32_t rightx = *(int32_t*)right->pData; //*(int32_t*)(right->pData + offset);
|
||||
|
||||
// offset += pColInfoData->info.bytes;
|
||||
if (leftx == rightx) {
|
||||
// break;
|
||||
return 0;
|
||||
} else {
|
||||
// if (pOrder->order == TSDB_ORDER_ASC) {
|
||||
return (leftx < rightx)? -1:1;
|
||||
// } else {
|
||||
// return (leftx < rightx)? 1:-1;
|
||||
// }
|
||||
}
|
||||
// }
|
||||
// default:
|
||||
// assert(0);
|
||||
// }
|
||||
// }
|
||||
// offset += pColInfoData->info.bytes;
|
||||
if (leftx == rightx) {
|
||||
// break;
|
||||
return 0;
|
||||
} else {
|
||||
// if (pOrder->order == TSDB_ORDER_ASC) {
|
||||
return (leftx < rightx) ? -1 : 1;
|
||||
// } else {
|
||||
// return (leftx < rightx)? 1:-1;
|
||||
// }
|
||||
}
|
||||
// }
|
||||
// default:
|
||||
// assert(0);
|
||||
// }
|
||||
// }
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t varColSort(SColumnInfoData* pColumnInfoData, SBlockOrderInfo* pOrder) {
|
||||
return 0;
|
||||
}
|
||||
int32_t varColSort(SColumnInfoData* pColumnInfoData, SBlockOrderInfo* pOrder) { return 0; }
|
||||
|
||||
int32_t blockDataSort_rv(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirst) {
|
||||
// Allocate the additional buffer.
|
||||
// Allocate the additional buffer.
|
||||
int64_t p0 = taosGetTimestampUs();
|
||||
|
||||
SSDataBlockSortHelper helper = {.nullFirst = nullFirst, .pDataBlock = pDataBlock, .orderInfo = pOrderInfo};
|
||||
|
@ -1032,7 +1063,7 @@ int32_t blockDataSort_rv(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullF
|
|||
|
||||
taosqsort(index, rows, sizeof(SHelper), &helper, dataBlockCompar_rv);
|
||||
|
||||
int64_t p1 = taosGetTimestampUs();
|
||||
int64_t p1 = taosGetTimestampUs();
|
||||
SColumnInfoData* pCols = createHelpColInfoData(pDataBlock);
|
||||
if (pCols == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -1052,7 +1083,8 @@ int32_t blockDataSort_rv(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullF
|
|||
copyBackToBlock(pDataBlock, pCols);
|
||||
int64_t p4 = taosGetTimestampUs();
|
||||
|
||||
printf("sort:%" PRId64 ", create:%" PRId64", assign:%" PRId64 ", copyback:%" PRId64 ", rows:%d\n", p1 - p0, p2 - p1, p3 - p2, p4 - p3, rows);
|
||||
printf("sort:%" PRId64 ", create:%" PRId64 ", assign:%" PRId64 ", copyback:%" PRId64 ", rows:%d\n", p1 - p0, p2 - p1,
|
||||
p3 - p2, p4 - p3, rows);
|
||||
// destroyTupleIndex(index);
|
||||
return 0;
|
||||
}
|
||||
|
@ -1110,8 +1142,8 @@ int32_t blockDataEnsureColumnCapacity(SColumnInfoData* pColumn, uint32_t numOfRo
|
|||
|
||||
int32_t blockDataEnsureCapacity(SSDataBlock* pDataBlock, uint32_t numOfRows) {
|
||||
int32_t code = 0;
|
||||
|
||||
for(int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) {
|
||||
|
||||
for (int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) {
|
||||
SColumnInfoData* p = taosArrayGet(pDataBlock->pDataBlock, i);
|
||||
code = blockDataEnsureColumnCapacity(p, numOfRows);
|
||||
if (code) {
|
||||
|
@ -1127,21 +1159,8 @@ void* blockDataDestroy(SSDataBlock* pBlock) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int32_t numOfOutput = pBlock->info.numOfCols;
|
||||
for(int32_t i = 0; i < numOfOutput; ++i) {
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
|
||||
if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
|
||||
tfree(pColInfoData->varmeta.offset);
|
||||
} else {
|
||||
tfree(pColInfoData->nullbitmap);
|
||||
}
|
||||
|
||||
tfree(pColInfoData->pData);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pBlock->pDataBlock);
|
||||
tfree(pBlock->pBlockAgg);
|
||||
// tfree(pBlock);
|
||||
blockDestroyInner(pBlock);
|
||||
tfree(pBlock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -1154,7 +1173,7 @@ SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock) {
|
|||
pBlock->info.numOfCols = numOfCols;
|
||||
pBlock->info.hasVarCol = pDataBlock->info.hasVarCol;
|
||||
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData colInfo = {0};
|
||||
SColumnInfoData* p = taosArrayGet(pDataBlock->pDataBlock, i);
|
||||
colInfo.info = p->info;
|
||||
|
@ -1230,4 +1249,4 @@ void* tDecodeDataBlock(const void* buf, SSDataBlock* pBlock) {
|
|||
taosArrayPush(pBlock->pDataBlock, &data);
|
||||
}
|
||||
return (void*)buf;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2720,6 +2720,8 @@ int32_t tEncodeSStreamTask(SCoder *pEncoder, const SStreamTask *pTask) {
|
|||
if (tEncodeI32(pEncoder, pTask->taskId) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, pTask->level) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pTask->status) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pTask->pipeEnd) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pTask->parallel) < 0) return -1;
|
||||
if (tEncodeSEpSet(pEncoder, &pTask->NextOpEp) < 0) return -1;
|
||||
if (tEncodeCStr(pEncoder, pTask->qmsg) < 0) return -1;
|
||||
tEndEncode(pEncoder);
|
||||
|
@ -2732,6 +2734,8 @@ int32_t tDecodeSStreamTask(SCoder *pDecoder, SStreamTask *pTask) {
|
|||
if (tDecodeI32(pDecoder, &pTask->taskId) < 0) return -1;
|
||||
if (tDecodeI32(pDecoder, &pTask->level) < 0) return -1;
|
||||
if (tDecodeI8(pDecoder, &pTask->status) < 0) return -1;
|
||||
if (tDecodeI8(pDecoder, &pTask->pipeEnd) < 0) return -1;
|
||||
if (tDecodeI8(pDecoder, &pTask->parallel) < 0) return -1;
|
||||
if (tDecodeSEpSet(pDecoder, &pTask->NextOpEp) < 0) return -1;
|
||||
if (tDecodeCStrAlloc(pDecoder, &pTask->qmsg) < 0) return -1;
|
||||
tEndDecode(pDecoder);
|
||||
|
|
|
@ -77,8 +77,9 @@ static void vmProcessFetchQueue(SVnodeObj *pVnode, SNodeMsg *pMsg) {
|
|||
}
|
||||
|
||||
dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code));
|
||||
rpcFreeCont(pMsg->rpcMsg.pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
// TODO: handle invalid write
|
||||
/*rpcFreeCont(pMsg->rpcMsg.pCont);*/
|
||||
/*taosFreeQitem(pMsg);*/
|
||||
}
|
||||
|
||||
static void vmProcessWriteQueue(SVnodeObj *pVnode, STaosQall *qall, int32_t numOfMsgs) {
|
||||
|
|
|
@ -166,7 +166,7 @@ static int32_t mndStreamActionDelete(SSdb *pSdb, SStreamObj *pStream) {
|
|||
|
||||
static int32_t mndStreamActionUpdate(SSdb *pSdb, SStreamObj *pOldStream, SStreamObj *pNewStream) {
|
||||
mTrace("stream:%s, perform update action", pOldStream->name);
|
||||
atomic_exchange_32(&pOldStream->updateTime, pNewStream->updateTime);
|
||||
atomic_exchange_64(&pOldStream->updateTime, pNewStream->updateTime);
|
||||
atomic_exchange_32(&pOldStream->version, pNewStream->version);
|
||||
|
||||
taosWLockLatch(&pOldStream->lock);
|
||||
|
|
|
@ -272,7 +272,6 @@ static int32_t mndProcessGetSubEpReq(SNodeMsg *pMsg) {
|
|||
/*sdbWrite(pMnode->pSdb, pConsumerRaw);*/
|
||||
|
||||
strcpy(rsp.cgroup, pReq->cgroup);
|
||||
rsp.consumerId = consumerId;
|
||||
if (epoch != pConsumer->epoch) {
|
||||
mInfo("send new assignment to consumer, consumer epoch %d, server epoch %d", epoch, pConsumer->epoch);
|
||||
SArray *pTopics = pConsumer->currentTopics;
|
||||
|
@ -322,6 +321,7 @@ static int32_t mndProcessGetSubEpReq(SNodeMsg *pMsg) {
|
|||
}
|
||||
((SMqRspHead *)buf)->mqMsgType = TMQ_MSG_TYPE__EP_RSP;
|
||||
((SMqRspHead *)buf)->epoch = pConsumer->epoch;
|
||||
((SMqRspHead *)buf)->consumerId = pConsumer->consumerId;
|
||||
|
||||
void *abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
|
||||
tEncodeSMqCMGetSubEpRsp(&abuf, &rsp);
|
||||
|
@ -337,21 +337,21 @@ static int32_t mndSplitSubscribeKey(const char *key, char *topic, char *cgroup)
|
|||
while (key[i] != TMQ_SEPARATOR) {
|
||||
i++;
|
||||
}
|
||||
memcpy(topic, key, i - 1);
|
||||
topic[i] = 0;
|
||||
strcpy(cgroup, &key[i + 1]);
|
||||
memcpy(cgroup, key, i);
|
||||
cgroup[i] = 0;
|
||||
strcpy(topic, &key[i + 1]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SMqRebSubscribe *mndGetOrCreateRebSub(SHashObj *pHash, const char *key) {
|
||||
SMqRebSubscribe *pRebSub = taosHashGet(pHash, key, strlen(key));
|
||||
SMqRebSubscribe *pRebSub = taosHashGet(pHash, key, strlen(key) + 1);
|
||||
if (pRebSub == NULL) {
|
||||
pRebSub = tNewSMqRebSubscribe(key);
|
||||
if (pRebSub == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
taosHashPut(pHash, key, strlen(key), pRebSub, sizeof(SMqRebSubscribe));
|
||||
taosHashPut(pHash, key, strlen(key) + 1, pRebSub, sizeof(SMqRebSubscribe));
|
||||
}
|
||||
return pRebSub;
|
||||
}
|
||||
|
@ -441,6 +441,7 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) {
|
|||
if (pIter == NULL) break;
|
||||
SMqRebSubscribe *pRebSub = (SMqRebSubscribe *)pIter;
|
||||
SMqSubscribeObj *pSub = mndAcquireSubscribeByKey(pMnode, pRebSub->key);
|
||||
tfree(pRebSub->key);
|
||||
|
||||
mInfo("mq rebalance subscription: %s", pSub->key);
|
||||
|
||||
|
@ -503,7 +504,8 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) {
|
|||
atomic_store_32(&pRebConsumer->status, MQ_CONSUMER_STATUS__IDLE);
|
||||
}
|
||||
|
||||
mInfo("mq consumer:%" PRId64 ", status change from %d to %d", pRebConsumer->consumerId, status, pRebConsumer->status);
|
||||
mInfo("mq consumer:%" PRId64 ", status change from %d to %d", pRebConsumer->consumerId, status,
|
||||
pRebConsumer->status);
|
||||
|
||||
SSdbRaw *pConsumerRaw = mndConsumerActionEncode(pRebConsumer);
|
||||
sdbSetRawStatus(pConsumerRaw, SDB_STATUS_READY);
|
||||
|
@ -537,14 +539,14 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) {
|
|||
mndSplitSubscribeKey(pSub->key, topic, cgroup);
|
||||
SMqTopicObj *pTopic = mndAcquireTopic(pMnode, topic);
|
||||
|
||||
mInfo("mq set conn: assign vgroup %d of topic %s to consumer %" PRId64 "", pConsumerEp->vgId, topic,
|
||||
pConsumerEp->consumerId);
|
||||
mInfo("mq set conn: assign vgroup %d of topic %s to consumer %" PRId64 " cgroup: %s", pConsumerEp->vgId,
|
||||
topic, pConsumerEp->consumerId, cgroup);
|
||||
|
||||
mndPersistMqSetConnReq(pMnode, pTrans, pTopic, cgroup, pConsumerEp);
|
||||
mndReleaseTopic(pMnode, pTopic);
|
||||
} else {
|
||||
mInfo("mq rebalance: assign vgroup %d, from consumer %" PRId64 " to consumer %" PRId64 "", pConsumerEp->vgId,
|
||||
pConsumerEp->oldConsumerId, pConsumerEp->consumerId);
|
||||
mInfo("mq rebalance: assign vgroup %d, from consumer %" PRId64 " to consumer %" PRId64 "",
|
||||
pConsumerEp->vgId, pConsumerEp->oldConsumerId, pConsumerEp->consumerId);
|
||||
|
||||
mndPersistRebalanceMsg(pMnode, pTrans, pConsumerEp);
|
||||
}
|
||||
|
@ -1099,7 +1101,8 @@ static int32_t mndProcessSubscribeReq(SNodeMsg *pMsg) {
|
|||
SMqSubscribeObj *pSub = mndAcquireSubscribe(pMnode, cgroup, newTopicName);
|
||||
bool createSub = false;
|
||||
if (pSub == NULL) {
|
||||
mDebug("create new subscription by consumer %" PRId64 ", group: %s, topic %s", consumerId, cgroup, newTopicName);
|
||||
mDebug("create new subscription by consumer %" PRId64 ", group: %s, topic %s", consumerId, cgroup,
|
||||
newTopicName);
|
||||
pSub = mndCreateSubscription(pMnode, pTopic, cgroup);
|
||||
createSub = true;
|
||||
|
||||
|
|
|
@ -176,7 +176,7 @@ static int32_t mndTopicActionDelete(SSdb *pSdb, SMqTopicObj *pTopic) {
|
|||
|
||||
static int32_t mndTopicActionUpdate(SSdb *pSdb, SMqTopicObj *pOldTopic, SMqTopicObj *pNewTopic) {
|
||||
mTrace("topic:%s, perform update action", pOldTopic->name);
|
||||
atomic_exchange_32(&pOldTopic->updateTime, pNewTopic->updateTime);
|
||||
atomic_exchange_64(&pOldTopic->updateTime, pNewTopic->updateTime);
|
||||
atomic_exchange_32(&pOldTopic->version, pNewTopic->version);
|
||||
|
||||
taosWLockLatch(&pOldTopic->lock);
|
||||
|
@ -241,12 +241,12 @@ static int32_t mndGetPlanString(SCMCreateTopicReq *pCreate, char **pStr) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SNode* pAst = NULL;
|
||||
SNode *pAst = NULL;
|
||||
int32_t code = nodesStringToNode(pCreate->ast, &pAst);
|
||||
|
||||
SQueryPlan* pPlan = NULL;
|
||||
SQueryPlan *pPlan = NULL;
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
SPlanContext cxt = { .pAstRoot = pAst, .topicQuery = true };
|
||||
SPlanContext cxt = {.pAstRoot = pAst, .topicQuery = true};
|
||||
code = qCreateQueryPlan(&cxt, &pPlan, NULL);
|
||||
}
|
||||
|
||||
|
@ -274,7 +274,7 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq
|
|||
topicObj.logicalPlan = "";
|
||||
topicObj.sqlLen = strlen(pCreate->sql);
|
||||
|
||||
char* pPlanStr = NULL;
|
||||
char *pPlanStr = NULL;
|
||||
if (TSDB_CODE_SUCCESS != mndGetPlanString(pCreate, &pPlanStr)) {
|
||||
mError("topic:%s, failed to get plan since %s", pCreate->name, terrstr());
|
||||
return -1;
|
||||
|
|
|
@ -57,7 +57,9 @@ void sndMetaDelete(SStreamMeta *pMeta) {
|
|||
}
|
||||
|
||||
int32_t sndMetaDeployTask(SStreamMeta *pMeta, SStreamTask *pTask) {
|
||||
pTask->runner.executor = qCreateStreamExecTaskInfo(pTask->qmsg, NULL);
|
||||
for (int i = 0; i < pTask->parallel; i++) {
|
||||
pTask->runner.executor[i] = qCreateStreamExecTaskInfo(pTask->qmsg, NULL);
|
||||
}
|
||||
return taosHashPut(pMeta->pHash, &pTask->taskId, sizeof(int32_t), pTask, sizeof(void *));
|
||||
}
|
||||
|
||||
|
@ -95,6 +97,7 @@ void sndProcessUMsg(SSnode *pSnode, SRpcMsg *pMsg) {
|
|||
SStreamTask *pTask = malloc(sizeof(SStreamTask));
|
||||
if (pTask == NULL) {
|
||||
ASSERT(0);
|
||||
return;
|
||||
}
|
||||
SCoder decoder;
|
||||
tCoderInit(&decoder, TD_LITTLE_ENDIAN, msg, pMsg->contLen - sizeof(SMsgHead), TD_DECODER);
|
||||
|
|
|
@ -245,7 +245,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
|
|||
}
|
||||
|
||||
SMqPollRsp rsp = {
|
||||
.consumerId = consumerId,
|
||||
/*.consumerId = consumerId,*/
|
||||
.numOfTopics = 0,
|
||||
.pBlockData = NULL,
|
||||
};
|
||||
|
@ -298,7 +298,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
|
|||
}
|
||||
|
||||
taosArrayPush(pRes, pDataBlock);
|
||||
rsp.schemas = pTopic->buffer.output[pos].pReadHandle->pSchemaWrapper;
|
||||
rsp.schema = pTopic->buffer.output[pos].pReadHandle->pSchemaWrapper;
|
||||
rsp.rspOffset = fetchOffset;
|
||||
|
||||
rsp.numOfTopics = 1;
|
||||
|
@ -312,10 +312,11 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
|
|||
}
|
||||
((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__POLL_RSP;
|
||||
((SMqRspHead*)buf)->epoch = pReq->epoch;
|
||||
((SMqRspHead*)buf)->consumerId = consumerId;
|
||||
|
||||
void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
|
||||
tEncodeSMqPollRsp(&abuf, &rsp);
|
||||
taosArrayDestroyEx(rsp.pBlockData, (void (*)(void*))tDeleteSSDataBlock);
|
||||
/*taosArrayDestroyEx(rsp.pBlockData, (void (*)(void*))tDeleteSSDataBlock);*/
|
||||
pMsg->pCont = buf;
|
||||
pMsg->contLen = tlen;
|
||||
pMsg->code = 0;
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "vnd.h"
|
||||
#include "sync.h"
|
||||
#include "vnd.h"
|
||||
// #include "vnodeInt.h"
|
||||
|
||||
int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg) { return 0; }
|
||||
|
@ -41,6 +41,6 @@ int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
|
|||
}
|
||||
|
||||
int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||
vInfo("sync message is processed");
|
||||
/*vInfo("sync message is processed");*/
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -278,7 +278,7 @@ typedef struct SCtgAction {
|
|||
#define CTG_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)
|
||||
|
||||
#define CTG_API_LEAVE(c) do { int32_t __code = c; CTG_UNLOCK(CTG_READ, &gCtgMgmt.lock); CTG_API_DEBUG("CTG API leave %s", __FUNCTION__); CTG_RET(__code); } while (0)
|
||||
#define CTG_API_ENTER() do { CTG_API_DEBUG("CTG API enter %s", __FUNCTION__); CTG_LOCK(CTG_READ, &gCtgMgmt.lock); if (atomic_load_8(&gCtgMgmt.exit)) { CTG_API_LEAVE(TSDB_CODE_CTG_OUT_OF_SERVICE); } } while (0)
|
||||
#define CTG_API_ENTER() do { CTG_API_DEBUG("CTG API enter %s", __FUNCTION__); CTG_LOCK(CTG_READ, &gCtgMgmt.lock); if (atomic_load_8((int8_t*)&gCtgMgmt.exit)) { CTG_API_LEAVE(TSDB_CODE_CTG_OUT_OF_SERVICE); } } while (0)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -2044,7 +2044,7 @@ void* ctgUpdateThreadFunc(void* param) {
|
|||
while (true) {
|
||||
tsem_wait(&gCtgMgmt.sem);
|
||||
|
||||
if (atomic_load_8(&gCtgMgmt.exit)) {
|
||||
if (atomic_load_8((int8_t*)&gCtgMgmt.exit)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2090,7 +2090,7 @@ int32_t catalogInit(SCatalogCfg *cfg) {
|
|||
CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT);
|
||||
}
|
||||
|
||||
atomic_store_8(&gCtgMgmt.exit, false);
|
||||
atomic_store_8((int8_t*)&gCtgMgmt.exit, false);
|
||||
|
||||
if (cfg) {
|
||||
memcpy(&gCtgMgmt.cfg, cfg, sizeof(*cfg));
|
||||
|
@ -2705,11 +2705,11 @@ int32_t catalogGetExpiredDBs(SCatalog* pCtg, SDbVgVersion **dbs, uint32_t *num)
|
|||
void catalogDestroy(void) {
|
||||
qInfo("start to destroy catalog");
|
||||
|
||||
if (NULL == gCtgMgmt.pCluster || atomic_load_8(&gCtgMgmt.exit)) {
|
||||
if (NULL == gCtgMgmt.pCluster || atomic_load_8((int8_t*)&gCtgMgmt.exit)) {
|
||||
return;
|
||||
}
|
||||
|
||||
atomic_store_8(&gCtgMgmt.exit, true);
|
||||
atomic_store_8((int8_t*)&gCtgMgmt.exit, true);
|
||||
|
||||
tsem_post(&gCtgMgmt.sem);
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ typedef struct SHNode {
|
|||
typedef struct SSHashObj {
|
||||
SHNode **hashList;
|
||||
size_t capacity; // number of slots
|
||||
size_t size; // number of elements in hash table
|
||||
int64_t size; // number of elements in hash table
|
||||
_hash_fn_t hashFp; // hash function
|
||||
_equal_fn_t equalFp; // equal function
|
||||
int32_t keyLen;
|
||||
|
@ -91,7 +91,7 @@ int32_t tSimpleHashGetSize(const SSHashObj *pHashObj) {
|
|||
if (pHashObj == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return (int32_t)atomic_load_64(&pHashObj->size);
|
||||
return (int32_t)atomic_load_64((int64_t*)&pHashObj->size);
|
||||
}
|
||||
|
||||
static SHNode *doCreateHashNode(const void *key, size_t keyLen, const void *pData, size_t dsize, uint32_t hashVal) {
|
||||
|
|
|
@ -97,7 +97,7 @@ bool fmIsAggFunc(int32_t funcId) {
|
|||
|
||||
void fmFuncMgtDestroy() {
|
||||
void* m = gFunMgtService.pFuncNameHashTable;
|
||||
if (m != NULL && atomic_val_compare_exchange_ptr(&gFunMgtService.pFuncNameHashTable, m, 0) == m) {
|
||||
if (m != NULL && atomic_val_compare_exchange_ptr((void**)&gFunMgtService.pFuncNameHashTable, m, 0) == m) {
|
||||
taosHashCleanup(m);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include "tdatablock.h"
|
||||
#include "mockCatalogService.h"
|
||||
#include "tdatablock.h"
|
||||
|
||||
#include "tname.h"
|
||||
#include "ttypes.h"
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace {
|
|||
int32_t qwtTestMaxExecTaskUsec = 2;
|
||||
int32_t qwtTestReqMaxDelayUsec = 2;
|
||||
|
||||
uint64_t qwtTestQueryId = 0;
|
||||
int64_t qwtTestQueryId = 0;
|
||||
bool qwtTestEnableSleep = true;
|
||||
bool qwtTestStop = false;
|
||||
bool qwtTestDeadLoop = false;
|
||||
|
|
|
@ -35,7 +35,7 @@ extern "C" {
|
|||
typedef struct SSyncIO {
|
||||
STaosQueue *pMsgQ;
|
||||
STaosQset * pQset;
|
||||
TdThread consumerTid;
|
||||
TdThread consumerTid;
|
||||
|
||||
void * serverRpc;
|
||||
void * clientRpc;
|
||||
|
|
|
@ -217,10 +217,12 @@ int32_t syncNodeStartHeartbeatTimer(SSyncNode* pSyncNode);
|
|||
int32_t syncNodeStopHeartbeatTimer(SSyncNode* pSyncNode);
|
||||
|
||||
// utils --------------
|
||||
int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRpcMsg* pMsg);
|
||||
int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSyncNode, SRpcMsg* pMsg);
|
||||
cJSON* syncNode2Json(const SSyncNode* pSyncNode);
|
||||
char* syncNode2Str(const SSyncNode* pSyncNode);
|
||||
int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRpcMsg* pMsg);
|
||||
int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSyncNode, SRpcMsg* pMsg);
|
||||
cJSON* syncNode2Json(const SSyncNode* pSyncNode);
|
||||
char* syncNode2Str(const SSyncNode* pSyncNode);
|
||||
SSyncNode* syncNodeAcquire(int64_t rid);
|
||||
void syncNodeRelease(SSyncNode* pNode);
|
||||
|
||||
// raft state change --------------
|
||||
void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term);
|
||||
|
|
|
@ -575,6 +575,17 @@ char* syncNode2Str(const SSyncNode* pSyncNode) {
|
|||
return serialized;
|
||||
}
|
||||
|
||||
SSyncNode* syncNodeAcquire(int64_t rid) {
|
||||
SSyncNode* pNode = taosAcquireRef(tsNodeRefId, rid);
|
||||
if (pNode == NULL) {
|
||||
sTrace("failed to acquire node from refId:%" PRId64, rid);
|
||||
}
|
||||
|
||||
return pNode;
|
||||
}
|
||||
|
||||
void syncNodeRelease(SSyncNode* pNode) { taosReleaseRef(tsNodeRefId, pNode->rid); }
|
||||
|
||||
// raft state change --------------
|
||||
void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term) {
|
||||
if (term > pSyncNode->pRaftStore->currentTerm) {
|
||||
|
|
|
@ -28,6 +28,7 @@ add_executable(syncRpcMsgTest "")
|
|||
add_executable(syncPingTimerTest2 "")
|
||||
add_executable(syncPingSelfTest "")
|
||||
add_executable(syncElectTest "")
|
||||
add_executable(syncElectTest2 "")
|
||||
add_executable(syncEncodeTest "")
|
||||
add_executable(syncWriteTest "")
|
||||
add_executable(syncReplicateTest "")
|
||||
|
@ -154,6 +155,10 @@ target_sources(syncElectTest
|
|||
PRIVATE
|
||||
"syncElectTest.cpp"
|
||||
)
|
||||
target_sources(syncElectTest2
|
||||
PRIVATE
|
||||
"syncElectTest2.cpp"
|
||||
)
|
||||
target_sources(syncEncodeTest
|
||||
PRIVATE
|
||||
"syncEncodeTest.cpp"
|
||||
|
@ -322,7 +327,7 @@ target_include_directories(syncElectTest
|
|||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncElectTest
|
||||
target_include_directories(syncElectTest2
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
|
@ -469,6 +474,10 @@ target_link_libraries(syncElectTest
|
|||
sync
|
||||
gtest_main
|
||||
)
|
||||
target_link_libraries(syncElectTest2
|
||||
sync
|
||||
gtest_main
|
||||
)
|
||||
target_link_libraries(syncEncodeTest
|
||||
sync
|
||||
gtest_main
|
||||
|
|
|
@ -120,6 +120,7 @@ int main(int argc, char** argv) {
|
|||
"elect sleep, state: %d, %s, term:%lu electTimerLogicClock:%lu, electTimerLogicClockUser:%lu, electTimerMS:%d",
|
||||
gSyncNode->state, syncUtilState2String(gSyncNode->state), gSyncNode->pRaftStore->currentTerm,
|
||||
gSyncNode->electTimerLogicClock, gSyncNode->electTimerLogicClockUser, gSyncNode->electTimerMS);
|
||||
taosMsleep(1000);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -0,0 +1,135 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <stdio.h>
|
||||
#include "syncEnv.h"
|
||||
#include "syncIO.h"
|
||||
#include "syncInt.h"
|
||||
#include "syncRaftLog.h"
|
||||
#include "syncRaftStore.h"
|
||||
#include "syncUtil.h"
|
||||
#include "tref.h"
|
||||
|
||||
void logTest() {
|
||||
sTrace("--- sync log test: trace");
|
||||
sDebug("--- sync log test: debug");
|
||||
sInfo("--- sync log test: info");
|
||||
sWarn("--- sync log test: warn");
|
||||
sError("--- sync log test: error");
|
||||
sFatal("--- sync log test: fatal");
|
||||
}
|
||||
|
||||
uint16_t ports[] = {7010, 7110, 7210, 7310, 7410};
|
||||
int32_t replicaNum = 3;
|
||||
int32_t myIndex = 0;
|
||||
|
||||
SRaftId ids[TSDB_MAX_REPLICA];
|
||||
SSyncInfo syncInfo;
|
||||
SSyncFSM* pFsm;
|
||||
SWal* pWal;
|
||||
|
||||
int64_t syncNodeInit() {
|
||||
syncInfo.vgId = 1234;
|
||||
syncInfo.rpcClient = gSyncIO->clientRpc;
|
||||
syncInfo.FpSendMsg = syncIOSendMsg;
|
||||
syncInfo.queue = gSyncIO->pMsgQ;
|
||||
syncInfo.FpEqMsg = syncIOEqMsg;
|
||||
syncInfo.pFsm = pFsm;
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "./elect2_test_%d", myIndex);
|
||||
|
||||
int code = walInit();
|
||||
assert(code == 0);
|
||||
SWalCfg walCfg;
|
||||
memset(&walCfg, 0, sizeof(SWalCfg));
|
||||
walCfg.vgId = syncInfo.vgId;
|
||||
walCfg.fsyncPeriod = 1000;
|
||||
walCfg.retentionPeriod = 1000;
|
||||
walCfg.rollPeriod = 1000;
|
||||
walCfg.retentionSize = 1000;
|
||||
walCfg.segSize = 1000;
|
||||
walCfg.level = TAOS_WAL_FSYNC;
|
||||
|
||||
char tmpdir[128];
|
||||
snprintf(tmpdir, sizeof(tmpdir), "./elect2_test_wal_%d", myIndex);
|
||||
pWal = walOpen(tmpdir, &walCfg);
|
||||
assert(pWal != NULL);
|
||||
|
||||
syncInfo.pWal = pWal;
|
||||
|
||||
SSyncCfg* pCfg = &syncInfo.syncCfg;
|
||||
pCfg->myIndex = myIndex;
|
||||
pCfg->replicaNum = replicaNum;
|
||||
|
||||
for (int i = 0; i < replicaNum; ++i) {
|
||||
pCfg->nodeInfo[i].nodePort = ports[i];
|
||||
snprintf(pCfg->nodeInfo[i].nodeFqdn, sizeof(pCfg->nodeInfo[i].nodeFqdn), "%s", "127.0.0.1");
|
||||
// taosGetFqdn(pCfg->nodeInfo[0].nodeFqdn);
|
||||
}
|
||||
|
||||
int64_t rid = syncStart(&syncInfo);
|
||||
assert(rid > 0);
|
||||
|
||||
SSyncNode* pSyncNode = (SSyncNode*)syncNodeAcquire(rid);
|
||||
assert(pSyncNode != NULL);
|
||||
|
||||
gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
|
||||
gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
|
||||
gSyncIO->FpOnSyncRequestVote = pSyncNode->FpOnRequestVote;
|
||||
gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply;
|
||||
gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries;
|
||||
gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply;
|
||||
gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
|
||||
gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
|
||||
gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout;
|
||||
gSyncIO->pSyncNode = pSyncNode;
|
||||
|
||||
syncNodeRelease(pSyncNode);
|
||||
|
||||
return rid;
|
||||
}
|
||||
|
||||
void initRaftId(SSyncNode* pSyncNode) {
|
||||
for (int i = 0; i < replicaNum; ++i) {
|
||||
ids[i] = pSyncNode->replicasId[i];
|
||||
char* s = syncUtilRaftId2Str(&ids[i]);
|
||||
printf("raftId[%d] : %s\n", i, s);
|
||||
free(s);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
// taosInitLog((char *)"syncTest.log", 100000, 10);
|
||||
tsAsyncLog = 0;
|
||||
sDebugFlag = 143 + 64;
|
||||
|
||||
myIndex = 0;
|
||||
if (argc >= 2) {
|
||||
myIndex = atoi(argv[1]);
|
||||
}
|
||||
|
||||
int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]);
|
||||
assert(ret == 0);
|
||||
|
||||
ret = syncInit();
|
||||
assert(ret == 0);
|
||||
|
||||
int64_t rid = syncNodeInit();
|
||||
assert(rid > 0);
|
||||
|
||||
SSyncNode* pSyncNode = (SSyncNode*)syncNodeAcquire(rid);
|
||||
assert(pSyncNode != NULL);
|
||||
|
||||
syncNodePrint2((char*)"", pSyncNode);
|
||||
initRaftId(pSyncNode);
|
||||
|
||||
//---------------------------
|
||||
while (1) {
|
||||
sTrace(
|
||||
"elect sleep, state: %d, %s, term:%lu electTimerLogicClock:%lu, electTimerLogicClockUser:%lu, electTimerMS:%d",
|
||||
pSyncNode->state, syncUtilState2String(pSyncNode->state), pSyncNode->pRaftStore->currentTerm,
|
||||
pSyncNode->electTimerLogicClock, pSyncNode->electTimerLogicClockUser, pSyncNode->electTimerMS);
|
||||
taosMsleep(1000);
|
||||
}
|
||||
|
||||
syncNodeRelease(pSyncNode);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -13,25 +13,18 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define ALLOW_FORBID_FUNC
|
||||
#include "os.h"
|
||||
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
|
||||
// add
|
||||
char interlocked_add_fetch_8(char volatile* ptr, char val) {
|
||||
#ifdef _TD_GO_DLL_
|
||||
return __sync_fetch_and_add(ptr, val) + val;
|
||||
#else
|
||||
return _InterlockedExchangeAdd8(ptr, val) + val;
|
||||
#endif
|
||||
}
|
||||
|
||||
short interlocked_add_fetch_16(short volatile* ptr, short val) {
|
||||
#ifdef _TD_GO_DLL_
|
||||
return __sync_fetch_and_add(ptr, val) + val;
|
||||
#else
|
||||
return _InterlockedExchangeAdd16(ptr, val) + val;
|
||||
#endif
|
||||
}
|
||||
|
||||
long interlocked_add_fetch_32(long volatile* ptr, long val) {
|
||||
|
@ -39,11 +32,7 @@ long interlocked_add_fetch_32(long volatile* ptr, long val) {
|
|||
}
|
||||
|
||||
__int64 interlocked_add_fetch_64(__int64 volatile* ptr, __int64 val) {
|
||||
//#ifdef _WIN64
|
||||
return InterlockedExchangeAdd64(ptr, val) + val;
|
||||
//#else
|
||||
// return _InterlockedExchangeAdd(ptr, val) + val;
|
||||
//#endif
|
||||
}
|
||||
|
||||
char interlocked_and_fetch_8(char volatile* ptr, char val) {
|
||||
|
@ -197,3 +186,709 @@ int64_t atomic_exchange_64_impl(int64_t* ptr, int64_t val ) {
|
|||
return old;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
int8_t atomic_load_8(int8_t volatile *ptr) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return (*(int8_t volatile*)(ptr));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_add((ptr), 0);
|
||||
#else
|
||||
return __atomic_load_n((ptr), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int16_t atomic_load_16(int16_t volatile *ptr) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return (*(int16_t volatile*)(ptr));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_add((ptr), 0);
|
||||
#else
|
||||
return __atomic_load_n((ptr), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t atomic_load_32(int32_t volatile *ptr) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return (*(int32_t volatile*)(ptr));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_add((ptr), 0);
|
||||
#else
|
||||
return __atomic_load_n((ptr), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int64_t atomic_load_64(int64_t volatile *ptr) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return (*(int64_t volatile*)(ptr));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_add((ptr), 0);
|
||||
#else
|
||||
return __atomic_load_n((ptr), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
void* atomic_load_ptr(void *ptr) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return (*(void* volatile*)(ptr));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_add((ptr), 0);
|
||||
#else
|
||||
return __atomic_load_n((void**)(ptr), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
void atomic_store_8(int8_t volatile *ptr, int8_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
((*(int8_t volatile*)(ptr)) = (int8_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
(*(ptr)=(val));
|
||||
#else
|
||||
__atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
void atomic_store_16(int16_t volatile *ptr, int16_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
((*(int16_t volatile*)(ptr)) = (int16_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
(*(ptr)=(val));
|
||||
#else
|
||||
__atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
void atomic_store_32(int32_t volatile *ptr, int32_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
((*(int32_t volatile*)(ptr)) = (int32_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
(*(ptr)=(val));
|
||||
#else
|
||||
__atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
void atomic_store_64(int64_t volatile *ptr, int64_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
((*(int64_t volatile*)(ptr)) = (int64_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
(*(ptr)=(val));
|
||||
#else
|
||||
__atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
void atomic_store_ptr(void *ptr, void *val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
((*(void* volatile*)(ptr)) = (void*)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
(*(ptr)=(val));
|
||||
#else
|
||||
__atomic_store_n((void **)(ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int8_t atomic_exchange_8(int8_t volatile *ptr, int8_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedExchange8((int8_t volatile*)(ptr), (int8_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return atomic_exchange_8_impl((int8_t*)ptr, (int8_t)val);
|
||||
#else
|
||||
return __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int16_t atomic_exchange_16(int16_t volatile *ptr, int16_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedExchange16((int16_t volatile*)(ptr), (int16_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return atomic_exchange_16_impl((int16_t*)ptr, (int16_t)val);
|
||||
#else
|
||||
return __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t atomic_exchange_32(int32_t volatile *ptr, int32_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedExchange((int32_t volatile*)(ptr), (int32_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return atomic_exchange_32_impl((int32_t*)ptr, (int32_t)val);
|
||||
#else
|
||||
return __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int64_t atomic_exchange_64(int64_t volatile *ptr, int64_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedExchange64((int64_t volatile*)(ptr), (int64_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return atomic_exchange_64_impl((int64_t*)ptr, (int64_t)val);
|
||||
#else
|
||||
return __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
void* atomic_exchange_ptr(void *ptr, void *val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
#ifdef _WIN64
|
||||
return _InterlockedExchangePointer((void* volatile*)(ptr), (void*)(val));
|
||||
#else
|
||||
return _InlineInterlockedExchangePointer((void* volatile*)(ptr), (void*)(val));
|
||||
#endif
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return atomic_exchange_ptr_impl((void *)ptr, (void*)val);
|
||||
#else
|
||||
return __atomic_exchange_n((void **)(ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int8_t atomic_val_compare_exchange_8(int8_t volatile *ptr, int8_t oldval, int8_t newval) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedCompareExchange8((int8_t volatile*)(ptr), (int8_t)(newval), (int8_t)(oldval));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_val_compare_and_swap(ptr, oldval, newval);
|
||||
#else
|
||||
return __sync_val_compare_and_swap(ptr, oldval, newval);
|
||||
#endif
|
||||
}
|
||||
|
||||
int16_t atomic_val_compare_exchange_16(int16_t volatile *ptr, int16_t oldval, int16_t newval) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedCompareExchange16((int16_t volatile*)(ptr), (int16_t)(newval), (int16_t)(oldval));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_val_compare_and_swap(ptr, oldval, newval);
|
||||
#else
|
||||
return __sync_val_compare_and_swap(ptr, oldval, newval);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t atomic_val_compare_exchange_32(int32_t volatile *ptr, int32_t oldval, int32_t newval) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedCompareExchange((int32_t volatile*)(ptr), (int32_t)(newval), (int32_t)(oldval));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_val_compare_and_swap(ptr, oldval, newval);
|
||||
#else
|
||||
return __sync_val_compare_and_swap(ptr, oldval, newval);
|
||||
#endif
|
||||
}
|
||||
|
||||
int64_t atomic_val_compare_exchange_64(int64_t volatile *ptr, int64_t oldval, int64_t newval) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedCompareExchange64((int64_t volatile*)(ptr), (int64_t)(newval), (int64_t)(oldval));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_val_compare_and_swap(ptr, oldval, newval);
|
||||
#else
|
||||
return __sync_val_compare_and_swap(ptr, oldval, newval);
|
||||
#endif
|
||||
}
|
||||
|
||||
void* atomic_val_compare_exchange_ptr(void *ptr, void *oldval, void *newval) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedCompareExchangePointer((void* volatile*)(ptr), (void*)(newval), (void*)(oldval));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_val_compare_and_swap(ptr, oldval, newval);
|
||||
#else
|
||||
return __sync_val_compare_and_swap((void **)ptr, oldval, newval);
|
||||
#endif
|
||||
}
|
||||
|
||||
int8_t atomic_add_fetch_8(int8_t volatile *ptr, int8_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_add_fetch_8((int8_t volatile*)(ptr), (int8_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_add_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int16_t atomic_add_fetch_16(int16_t volatile *ptr, int16_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_add_fetch_16((int16_t volatile*)(ptr), (int16_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_add_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t atomic_add_fetch_32(int32_t volatile *ptr, int32_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_add_fetch_32((int32_t volatile*)(ptr), (int32_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_add_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int64_t atomic_add_fetch_64(int64_t volatile *ptr, int64_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_add_fetch_64((int64_t volatile*)(ptr), (int64_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_add_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
void* atomic_add_fetch_ptr(void *ptr, int32_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_add_fetch_ptr((void* volatile*)(ptr), (void*)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_add_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_add_fetch((void **)(ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int8_t atomic_fetch_add_8(int8_t volatile *ptr, int8_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedExchangeAdd8((int8_t volatile*)(ptr), (int8_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_add((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int16_t atomic_fetch_add_16(int16_t volatile *ptr, int16_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedExchangeAdd16((int16_t volatile*)(ptr), (int16_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_add((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t atomic_fetch_add_32(int32_t volatile *ptr, int32_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedExchangeAdd((int32_t volatile*)(ptr), (int32_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_add((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int64_t atomic_fetch_add_64(int64_t volatile *ptr, int64_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedExchangeAdd64((int64_t volatile*)(ptr), (int64_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_add((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
void* atomic_fetch_add_ptr(void *ptr, int32_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedExchangeAddptr((void* volatile*)(ptr), (void*)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_add((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_add((void **)(ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int8_t atomic_sub_fetch_8(int8_t volatile *ptr, int8_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_add_fetch_8((int8_t volatile*)(ptr), -(int8_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_sub_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int16_t atomic_sub_fetch_16(int16_t volatile *ptr, int16_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_add_fetch_16((int16_t volatile*)(ptr), -(int16_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_sub_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t atomic_sub_fetch_32(int32_t volatile *ptr, int32_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_add_fetch_32((int32_t volatile*)(ptr), -(int32_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_sub_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int64_t atomic_sub_fetch_64(int64_t volatile *ptr, int64_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_add_fetch_64((int64_t volatile*)(ptr), -(int64_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_sub_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
void* atomic_sub_fetch_ptr(void *ptr, int32_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_add_fetch_ptr((void* volatile*)(ptr), -(void*)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_sub_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_sub_fetch((void **)(ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int8_t atomic_fetch_sub_8(int8_t volatile *ptr, int8_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedExchangeAdd8((int8_t volatile*)(ptr), -(int8_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_sub((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int16_t atomic_fetch_sub_16(int16_t volatile *ptr, int16_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedExchangeAdd16((int16_t volatile*)(ptr), -(int16_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_sub((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t atomic_fetch_sub_32(int32_t volatile *ptr, int32_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedExchangeAdd((int32_t volatile*)(ptr), -(int32_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_sub((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int64_t atomic_fetch_sub_64(int64_t volatile *ptr, int64_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedExchangeAdd64((int64_t volatile*)(ptr), -(int64_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_sub((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
void* atomic_fetch_sub_ptr(void *ptr, int32_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedExchangeAddptr((void* volatile*)(ptr), -(void*)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_sub((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_sub((void **)(ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int8_t atomic_and_fetch_8(int8_t volatile *ptr, int8_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_and_fetch_8((int8_t volatile*)(ptr), (int8_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_and_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int16_t atomic_and_fetch_16(int16_t volatile *ptr, int16_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_and_fetch_16((int16_t volatile*)(ptr), (int16_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_and_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t atomic_and_fetch_32(int32_t volatile *ptr, int32_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_and_fetch_32((int32_t volatile*)(ptr), (int32_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_and_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int64_t atomic_and_fetch_64(int64_t volatile *ptr, int64_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_and_fetch_64((int64_t volatile*)(ptr), (int64_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_and_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
void* atomic_and_fetch_ptr(void *ptr, void *val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_and_fetch_ptr((void* volatile*)(ptr), (void*)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_and_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_and_fetch((void **)(ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int8_t atomic_fetch_and_8(int8_t volatile *ptr, int8_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedAnd8((int8_t volatile*)(ptr), (int8_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_and((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int16_t atomic_fetch_and_16(int16_t volatile *ptr, int16_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedAnd16((int16_t volatile*)(ptr), (int16_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_and((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t atomic_fetch_and_32(int32_t volatile *ptr, int32_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedAnd((int32_t volatile*)(ptr), (int32_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_and((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int64_t atomic_fetch_and_64(int64_t volatile *ptr, int64_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_fetch_and_64((int64_t volatile*)(ptr), (int64_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_and((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
void* atomic_fetch_and_ptr(void *ptr, void *val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_fetch_and_ptr((void* volatile*)(ptr), (void*)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_and((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_and((void **)(ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int8_t atomic_or_fetch_8(int8_t volatile *ptr, int8_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_or_fetch_8((int8_t volatile*)(ptr), (int8_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_or_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int16_t atomic_or_fetch_16(int16_t volatile *ptr, int16_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_or_fetch_16((int16_t volatile*)(ptr), (int16_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_or_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t atomic_or_fetch_32(int32_t volatile *ptr, int32_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_or_fetch_32((int32_t volatile*)(ptr), (int32_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_or_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int64_t atomic_or_fetch_64(int64_t volatile *ptr, int64_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_or_fetch_64((int64_t volatile*)(ptr), (int64_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_or_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
void* atomic_or_fetch_ptr(void *ptr, void *val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_or_fetch_ptr((void* volatile*)(ptr), (void*)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_or_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_or_fetch((void **)(ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int8_t atomic_fetch_or_8(int8_t volatile *ptr, int8_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedOr8((int8_t volatile*)(ptr), (int8_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_or((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int16_t atomic_fetch_or_16(int16_t volatile *ptr, int16_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedOr16((int16_t volatile*)(ptr), (int16_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_or((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t atomic_fetch_or_32(int32_t volatile *ptr, int32_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedOr((int32_t volatile*)(ptr), (int32_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_or((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int64_t atomic_fetch_or_64(int64_t volatile *ptr, int64_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_fetch_or_64((int64_t volatile*)(ptr), (int64_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_or((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
void* atomic_fetch_or_ptr(void *ptr, void *val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_fetch_or_ptr((void* volatile*)(ptr), (void*)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_or((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_or((void **)(ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int8_t atomic_xor_fetch_8(int8_t volatile *ptr, int8_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_xor_fetch_8((int8_t volatile*)(ptr), (int8_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_xor_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int16_t atomic_xor_fetch_16(int16_t volatile *ptr, int16_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_xor_fetch_16((int16_t volatile*)(ptr), (int16_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_xor_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t atomic_xor_fetch_32(int32_t volatile *ptr, int32_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_xor_fetch_32((int32_t volatile*)(ptr), (int32_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_xor_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int64_t atomic_xor_fetch_64(int64_t volatile *ptr, int64_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_xor_fetch_64((int64_t volatile*)(ptr), (int64_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_xor_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
void* atomic_xor_fetch_ptr(void *ptr, void *val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_xor_fetch_ptr((void* volatile*)(ptr), (void*)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_xor_and_fetch((ptr), (val));
|
||||
#else
|
||||
return __atomic_xor_fetch((void **)(ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int8_t atomic_fetch_xor_8(int8_t volatile *ptr, int8_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedXor8((int8_t volatile*)(ptr), (int8_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_xor((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int16_t atomic_fetch_xor_16(int16_t volatile *ptr, int16_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedXor16((int16_t volatile*)(ptr), (int16_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_xor((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t atomic_fetch_xor_32(int32_t volatile *ptr, int32_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return _InterlockedXor((int32_t volatile*)(ptr), (int32_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_xor((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
int64_t atomic_fetch_xor_64(int64_t volatile *ptr, int64_t val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_fetch_xor_64((int64_t volatile*)(ptr), (int64_t)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_xor((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
void* atomic_fetch_xor_ptr(void *ptr, void *val) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
return interlocked_fetch_xor_ptr((void* volatile*)(ptr), (void*)(val));
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
return __sync_fetch_and_xor((ptr), (val));
|
||||
#else
|
||||
return __atomic_fetch_xor((void **)(ptr), (val), __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -216,12 +216,6 @@ int32_t taosShutDownSocketServerRDWR(TdSocketServerPtr pSocketServer) {
|
|||
#endif
|
||||
}
|
||||
|
||||
#if (defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
|
||||
#if defined(_TD_GO_DLL_)
|
||||
uint64_t htonll(uint64_t val) { return (((uint64_t)htonl(val)) << 32) + htonl(val >> 32); }
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void taosWinSocketInit1() {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
static char flag = 0;
|
||||
|
|
|
@ -456,7 +456,7 @@ void *taosCacheAcquireByKey(SCacheObj *pCacheObj, const void *key, size_t keyLen
|
|||
}
|
||||
|
||||
if (pCacheObj->numOfElems == 0) {
|
||||
atomic_add_fetch_32(&pCacheObj->statistics.missCount, 1);
|
||||
atomic_add_fetch_64(&pCacheObj->statistics.missCount, 1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -475,15 +475,15 @@ void *taosCacheAcquireByKey(SCacheObj *pCacheObj, const void *key, size_t keyLen
|
|||
|
||||
void *pData = (pNode != NULL) ? pNode->data : NULL;
|
||||
if (pData != NULL) {
|
||||
atomic_add_fetch_32(&pCacheObj->statistics.hitCount, 1);
|
||||
atomic_add_fetch_64(&pCacheObj->statistics.hitCount, 1);
|
||||
uDebug("cache:%s, key:%p, %p is retrieved from cache, refcnt:%d", pCacheObj->name, key, pData,
|
||||
T_REF_VAL_GET(pNode));
|
||||
} else {
|
||||
atomic_add_fetch_32(&pCacheObj->statistics.missCount, 1);
|
||||
atomic_add_fetch_64(&pCacheObj->statistics.missCount, 1);
|
||||
uDebug("cache:%s, key:%p, not in cache, retrieved failed", pCacheObj->name, key);
|
||||
}
|
||||
|
||||
atomic_add_fetch_32(&pCacheObj->statistics.totalAccess, 1);
|
||||
atomic_add_fetch_64(&pCacheObj->statistics.totalAccess, 1);
|
||||
return pData;
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ typedef struct SHashEntry {
|
|||
struct SHashObj {
|
||||
SHashEntry ** hashList;
|
||||
size_t capacity; // number of slots
|
||||
size_t size; // number of elements in hash table
|
||||
int64_t size; // number of elements in hash table
|
||||
_hash_fn_t hashFp; // hash function
|
||||
_equal_fn_t equalFp; // equal function
|
||||
_hash_free_fn_t freeFp; // hash node free callback function
|
||||
|
@ -186,7 +186,7 @@ static SHashNode *doCreateHashNode(const void *key, size_t keyLen, const void *p
|
|||
static FORCE_INLINE void doUpdateHashNode(SHashObj *pHashObj, SHashEntry* pe, SHashNode* prev, SHashNode *pNode, SHashNode *pNewNode) {
|
||||
assert(pNode->keyLen == pNewNode->keyLen);
|
||||
|
||||
atomic_sub_fetch_32(&pNode->refCount, 1);
|
||||
atomic_sub_fetch_16(&pNode->refCount, 1);
|
||||
if (prev != NULL) {
|
||||
prev->next = pNewNode;
|
||||
} else {
|
||||
|
@ -302,7 +302,7 @@ int32_t taosHashGetSize(const SHashObj *pHashObj) {
|
|||
if (pHashObj == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return (int32_t)atomic_load_64(&pHashObj->size);
|
||||
return (int32_t)atomic_load_64((int64_t*)&pHashObj->size);
|
||||
}
|
||||
|
||||
int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *data, size_t size) {
|
||||
|
@ -508,7 +508,7 @@ int32_t taosHashRemove(SHashObj *pHashObj, const void *key, size_t keyLen) {
|
|||
pNode->removed == 0) {
|
||||
code = 0; // it is found
|
||||
|
||||
atomic_sub_fetch_32(&pNode->refCount, 1);
|
||||
atomic_sub_fetch_16(&pNode->refCount, 1);
|
||||
pNode->removed = 1;
|
||||
if (pNode->refCount <= 0) {
|
||||
if (prevNode == NULL) {
|
||||
|
@ -755,7 +755,7 @@ static void *taosHashReleaseNode(SHashObj *pHashObj, void *p, int *slot) {
|
|||
pNode = pNode->next;
|
||||
}
|
||||
|
||||
atomic_sub_fetch_32(&pOld->refCount, 1);
|
||||
atomic_sub_fetch_16(&pOld->refCount, 1);
|
||||
if (pOld->refCount <=0) {
|
||||
if (prevNode) {
|
||||
prevNode->next = pOld->next;
|
||||
|
|
|
@ -132,7 +132,7 @@ static timer_map_t timerMap;
|
|||
static uintptr_t getNextTimerId() {
|
||||
uintptr_t id;
|
||||
do {
|
||||
id = atomic_add_fetch_ptr(&nextTimerId, 1);
|
||||
id = (uintptr_t)atomic_add_fetch_ptr((void **)&nextTimerId, 1);
|
||||
} while (id == 0);
|
||||
return id;
|
||||
}
|
||||
|
|
|
@ -65,11 +65,11 @@ typedef struct {
|
|||
static SConfInfo g_stConfInfo = {
|
||||
"tmqdb",
|
||||
"stb",
|
||||
"./tmqResult.txt", // output_file
|
||||
"/data2/dnode/data/vnode/vnode2/wal",
|
||||
"./tmqResult.txt", // output_file
|
||||
"/data2/dnode/data/vnodes/vnode2/wal",
|
||||
1, // threads
|
||||
1, // tables
|
||||
1, // vgroups
|
||||
1, // vgroups
|
||||
0, // run mode
|
||||
1, // columns
|
||||
1, // ratio
|
||||
|
@ -306,7 +306,7 @@ int32_t init_env() {
|
|||
}
|
||||
|
||||
//const char* sql = "select * from tu1";
|
||||
sprintf(sqlStr, "create topic test_stb_topic_1 as select * from %s%d", g_stConfInfo.stbName, 0);
|
||||
sprintf(sqlStr, "create topic test_stb_topic_1 as select * from %s", g_stConfInfo.stbName);
|
||||
/*pRes = tmq_create_topic(pConn, "test_stb_topic_1", sqlStr, strlen(sqlStr));*/
|
||||
pRes = taos_query(pConn, sqlStr);
|
||||
if (taos_errno(pRes) != 0) {
|
||||
|
|
Loading…
Reference in New Issue