未验证 提交 e54eef75 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #10444 from taosdata/feature/config

util
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_TCOMPARE_H_
#define _TD_TCOMPARE_H_
#include "compare.h"
#include "ttypes.h"
#ifdef __cplusplus
extern "C" {
#endif
int32_t compareStrPatternMatch(const void* pLeft, const void* pRight);
int32_t compareStrPatternNotMatch(const void* pLeft, const void* pRight);
int32_t compareWStrPatternMatch(const void* pLeft, const void* pRight);
int32_t compareWStrPatternNotMatch(const void* pLeft, const void* pRight);
__compar_fn_t getComparFunc(int32_t type, int32_t optr);
__compar_fn_t getKeyComparFunc(int32_t keyType, int32_t order);
int32_t doCompare(const char* a, const char* b, int32_t type, size_t size);
#ifdef __cplusplus
}
#endif
#endif /*_TD_TCOMPARE_H_*/
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
extern "C" { extern "C" {
#endif #endif
#include "tcfg.h"
#include "tdef.h" #include "tdef.h"
#include "tarray.h" #include "tarray.h"
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
extern "C" { extern "C" {
#endif #endif
#include "encode.h" #include "tencode.h"
#include "taosdef.h" #include "taosdef.h"
#include "taoserror.h" #include "taoserror.h"
#include "tarray.h" #include "tarray.h"
......
...@@ -15,11 +15,6 @@ typedef uint8_t TDRowValT; ...@@ -15,11 +15,6 @@ typedef uint8_t TDRowValT;
typedef uint16_t col_id_t; typedef uint16_t col_id_t;
typedef int8_t col_type_t; typedef int8_t col_type_t;
typedef struct tstr {
VarDataLenT len;
char data[];
} tstr;
#pragma pack(push, 1) #pragma pack(push, 1)
typedef struct { typedef struct {
VarDataLenT len; VarDataLenT len;
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#define _TD_DNODE_H_ #define _TD_DNODE_H_
#include "tdef.h" #include "tdef.h"
#include "tcfg.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#ifndef _TD_TFS_H_ #ifndef _TD_TFS_H_
#define _TD_TFS_H_ #define _TD_TFS_H_
#include "tcfg.h" #include "tdef.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
......
/*
* Copyright (c) 2020 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_UTIL_EXCEPTION_H
#define _TD_UTIL_EXCEPTION_H
#include "os.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* cleanup actions
*/
typedef struct SCleanupAction {
bool failOnly;
uint8_t wrapper;
uint16_t reserved;
void* func;
union {
void* Ptr;
bool Bool;
char Char;
int8_t Int8;
uint8_t Uint8;
int16_t Int16;
uint16_t Uint16;
int Int;
unsigned int Uint;
int32_t Int32;
uint32_t Uint32;
int64_t Int64;
uint64_t Uint64;
float Float;
double Double;
} arg1, arg2;
} SCleanupAction;
/*
* exception hander registration
*/
typedef struct SExceptionNode {
struct SExceptionNode* prev;
jmp_buf jb;
int32_t code;
int32_t maxCleanupAction;
int32_t numCleanupAction;
SCleanupAction* cleanupActions;
} SExceptionNode;
////////////////////////////////////////////////////////////////////////////////
// functions & macros for auto-cleanup
void cleanupPush_void_ptr_ptr ( bool failOnly, void* func, void* arg1, void* arg2 );
void cleanupPush_void_ptr_bool ( bool failOnly, void* func, void* arg1, bool arg2 );
void cleanupPush_void_ptr ( bool failOnly, void* func, void* arg );
void cleanupPush_int_int ( bool failOnly, void* func, int arg );
void cleanupPush_void ( bool failOnly, void* func );
void cleanupPush_int_ptr ( bool failOnly, void* func, void* arg );
int32_t cleanupGetActionCount();
void cleanupExecuteTo( int32_t anchor, bool failed );
void cleanupExecute( SExceptionNode* node, bool failed );
bool cleanupExceedLimit();
#define CLEANUP_PUSH_VOID_PTR_PTR( failOnly, func, arg1, arg2 ) cleanupPush_void_ptr_ptr( (failOnly), (void*)(func), (void*)(arg1), (void*)(arg2) )
#define CLEANUP_PUSH_VOID_PTR_BOOL( failOnly, func, arg1, arg2 ) cleanupPush_void_ptr_bool( (failOnly), (void*)(func), (void*)(arg1), (bool)(arg2) )
#define CLEANUP_PUSH_VOID_PTR( failOnly, func, arg ) cleanupPush_void_ptr( (failOnly), (void*)(func), (void*)(arg) )
#define CLEANUP_PUSH_INT_INT( failOnly, func, arg ) cleanupPush_void_ptr( (failOnly), (void*)(func), (int)(arg) )
#define CLEANUP_PUSH_VOID( failOnly, func ) cleanupPush_void( (failOnly), (void*)(func) )
#define CLEANUP_PUSH_INT_PTR( failOnly, func, arg ) cleanupPush_int_ptr( (failOnly), (void*)(func), (void*)(arg) )
#define CLEANUP_PUSH_FREE( failOnly, arg ) cleanupPush_void_ptr( (failOnly), free, (void*)(arg) )
#define CLEANUP_PUSH_CLOSE( failOnly, arg ) cleanupPush_int_int( (failOnly), close, (int)(arg) )
#define CLEANUP_PUSH_FCLOSE( failOnly, arg ) cleanupPush_int_ptr( (failOnly), fclose, (void*)(arg) )
#define CLEANUP_GET_ANCHOR() cleanupGetActionCount()
#define CLEANUP_EXECUTE_TO( anchor, failed ) cleanupExecuteTo( (anchor), (failed) )
#define CLEANUP_EXCEED_LIMIT() cleanupExceedLimit()
////////////////////////////////////////////////////////////////////////////////
// functions & macros for exception handling
void exceptionPushNode( SExceptionNode* node );
int32_t exceptionPopNode();
void exceptionThrow( int32_t code );
#define TRY(maxCleanupActions) do { \
SExceptionNode exceptionNode = { 0 }; \
SCleanupAction cleanupActions[(maxCleanupActions) > 0 ? (maxCleanupActions) : 1]; \
exceptionNode.maxCleanupAction = (maxCleanupActions) > 0 ? (maxCleanupActions) : 1; \
exceptionNode.cleanupActions = cleanupActions; \
exceptionPushNode( &exceptionNode ); \
int caughtException = setjmp( exceptionNode.jb ); \
if( caughtException == 0 )
#define CATCH( code ) int32_t code = exceptionPopNode(); \
if( caughtException == 1 )
#define FINALLY( code ) int32_t code = exceptionPopNode();
#define END_TRY } while( 0 );
#define THROW( x ) exceptionThrow( (x) )
#define CAUGHT_EXCEPTION() ((bool)(caughtException == 1))
#define CLEANUP_EXECUTE() cleanupExecute( &exceptionNode, CAUGHT_EXCEPTION() )
#ifdef __cplusplus
}
#endif
#endif /*_TD_UTIL_EXCEPTION_H*/
...@@ -13,16 +13,18 @@ ...@@ -13,16 +13,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_TALGO_H #ifndef _TD_UTIL_TALGO_H_
#define _TD_UTIL_TALGO_H #define _TD_UTIL_TALGO_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#ifndef __COMPAR_FN_T #ifndef __COMPAR_FN_T
# define __COMPAR_FN_T #define __COMPAR_FN_T
typedef int (*__compar_fn_t) (const void *, const void *); typedef int32_t (*__compar_fn_t)(const void *, const void *);
#endif #endif
#define TD_EQ 0x1 #define TD_EQ 0x1
...@@ -45,7 +47,7 @@ typedef void (*__ext_swap_fn_t)(void *p1, void *p2, const void *param); ...@@ -45,7 +47,7 @@ typedef void (*__ext_swap_fn_t)(void *p1, void *p2, const void *param);
* @param param * @param param
* @param comparFn * @param comparFn
*/ */
void taosqsort(void *src, size_t numOfElem, size_t size, const void* param, __ext_compar_fn_t comparFn); void taosqsort(void *src, int64_t numOfElem, int64_t size, const void *param, __ext_compar_fn_t comparFn);
/** /**
* binary search, with range support * binary search, with range support
...@@ -58,7 +60,7 @@ void taosqsort(void *src, size_t numOfElem, size_t size, const void* param, __ex ...@@ -58,7 +60,7 @@ void taosqsort(void *src, size_t numOfElem, size_t size, const void* param, __ex
* @param flags * @param flags
* @return * @return
*/ */
void *taosbsearch(const void *key, const void *base, size_t nmemb, size_t size, __compar_fn_t fn, int flags); void *taosbsearch(const void *key, const void *base, int64_t nmemb, int64_t size, __compar_fn_t fn, int32_t flags);
/** /**
* adjust heap * adjust heap
...@@ -74,7 +76,8 @@ void *taosbsearch(const void *key, const void *base, size_t nmemb, size_t size, ...@@ -74,7 +76,8 @@ void *taosbsearch(const void *key, const void *base, size_t nmemb, size_t size,
* @param maxroot: if heap is max root heap * @param maxroot: if heap is max root heap
* @return * @return
*/ */
void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const void *parcompar, __ext_compar_fn_t compar, const void *parswap, __ext_swap_fn_t swap, bool maxroot); void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const void *parcompar,
__ext_compar_fn_t compar, const void *parswap, __ext_swap_fn_t swap, bool maxroot);
/** /**
* sort heap to make sure it is a max/min root heap * sort heap to make sure it is a max/min root heap
...@@ -89,10 +92,11 @@ void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const ...@@ -89,10 +92,11 @@ void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const
* @param maxroot: if heap is max root heap * @param maxroot: if heap is max root heap
* @return * @return
*/ */
void taosheapsort(void *base, int32_t size, int32_t len, const void *parcompar, __ext_compar_fn_t compar, const void *parswap, __ext_swap_fn_t swap, bool maxroot); void taosheapsort(void *base, int32_t size, int32_t len, const void *parcompar, __ext_compar_fn_t compar,
const void *parswap, __ext_swap_fn_t swap, bool maxroot);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /*_TD_UTIL_TALGO_H*/
#endif /*_TD_UTIL_TALGO_H_*/
...@@ -13,15 +13,13 @@ ...@@ -13,15 +13,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_TAOS_ERROR_H_ #ifndef _TD_UTIL_ERROR_H_
#define _TD_UTIL_TAOS_ERROR_H_ #define _TD_UTIL_ERROR_H_
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
// clang-format off
#define TAOS_DEF_ERROR_CODE(mod, code) ((int32_t)((0x80000000 | ((mod)<<16) | (code)))) #define TAOS_DEF_ERROR_CODE(mod, code) ((int32_t)((0x80000000 | ((mod)<<16) | (code))))
#define TAOS_SYSTEM_ERROR(code) (0x80ff0000 | (code)) #define TAOS_SYSTEM_ERROR(code) (0x80ff0000 | (code))
...@@ -469,4 +467,4 @@ int32_t* taosGetErrno(); ...@@ -469,4 +467,4 @@ int32_t* taosGetErrno();
} }
#endif #endif
#endif /*_TD_UTIL_TAOS_ERROR_H_*/ #endif /*_TD_UTIL_ERROR_H_*/
...@@ -13,16 +13,15 @@ ...@@ -13,16 +13,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_ARRAY_H #ifndef _TD_UTIL_ARRAY_H_
#define _TD_UTIL_ARRAY_H #define _TD_UTIL_ARRAY_H_
#include "talgo.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "os.h"
#include "talgo.h"
#if 0 #if 0
#define TARRAY(TYPE) \ #define TARRAY(TYPE) \
struct { \ struct { \
...@@ -31,15 +30,15 @@ extern "C" { ...@@ -31,15 +30,15 @@ extern "C" {
struct TYPE* td_array_data_; \ struct TYPE* td_array_data_; \
} }
#define TARRAY_SIZE(ARRAY) (ARRAY)->tarray_size_ #define TARRAY_SIZE(ARRAY) (ARRAY)->tarray_size_
#define TARRAY_NELES(ARRAY) (ARRAY)->tarray_neles_ #define TARRAY_NELES(ARRAY) (ARRAY)->tarray_neles_
#define TARRAY_ELE_AT(ARRAY, IDX) ((ARRAY)->td_array_data_ + idx) #define TARRAY_ELE_AT(ARRAY, IDX) ((ARRAY)->td_array_data_ + idx)
#endif #endif
#define TARRAY_MIN_SIZE 8 #define TARRAY_MIN_SIZE 8
#define TARRAY_GET_ELEM(array, index) ((void*)((char*)((array)->pData) + (index) * (array)->elemSize)) #define TARRAY_GET_ELEM(array, index) ((void*)((char*)((array)->pData) + (index) * (array)->elemSize))
#define TARRAY_ELEM_IDX(array, ele) (POINTER_DISTANCE(ele, (array)->pData) / (array)->elemSize) #define TARRAY_ELEM_IDX(array, ele) (POINTER_DISTANCE(ele, (array)->pData) / (array)->elemSize)
#define TARRAY_GET_START(array) ((array)->pData) #define TARRAY_GET_START(array) ((array)->pData)
typedef struct SArray { typedef struct SArray {
size_t size; size_t size;
...@@ -70,7 +69,7 @@ int32_t taosArrayEnsureCap(SArray* pArray, size_t tsize); ...@@ -70,7 +69,7 @@ int32_t taosArrayEnsureCap(SArray* pArray, size_t tsize);
* @param nEles * @param nEles
* @return * @return
*/ */
void* taosArrayAddBatch(SArray* pArray, const void* pData, int nEles); void* taosArrayAddBatch(SArray* pArray, const void* pData, int32_t nEles);
/** /**
* *
...@@ -238,7 +237,7 @@ void taosArraySortString(SArray* pArray, __compar_fn_t comparFn); ...@@ -238,7 +237,7 @@ void taosArraySortString(SArray* pArray, __compar_fn_t comparFn);
* @param compar * @param compar
* @param key * @param key
*/ */
void* taosArraySearch(const SArray* pArray, const void* key, __compar_fn_t comparFn, int flags); void* taosArraySearch(const SArray* pArray, const void* key, __compar_fn_t comparFn, int32_t flags);
/** /**
* search the array, return index of the element * search the array, return index of the element
...@@ -246,14 +245,14 @@ void* taosArraySearch(const SArray* pArray, const void* key, __compar_fn_t compa ...@@ -246,14 +245,14 @@ void* taosArraySearch(const SArray* pArray, const void* key, __compar_fn_t compa
* @param compar * @param compar
* @param key * @param key
*/ */
int32_t taosArraySearchIdx(const SArray* pArray, const void* key, __compar_fn_t comparFn, int flags); int32_t taosArraySearchIdx(const SArray* pArray, const void* key, __compar_fn_t comparFn, int32_t flags);
/** /**
* search the array * search the array
* @param pArray * @param pArray
* @param key * @param key
*/ */
char* taosArraySearchString(const SArray* pArray, const char* key, __compar_fn_t comparFn, int flags); char* taosArraySearchString(const SArray* pArray, const char* key, __compar_fn_t comparFn, int32_t flags);
/** /**
* sort the pointer data in the array * sort the pointer data in the array
...@@ -269,4 +268,4 @@ void taosArraySortPWithExt(SArray* pArray, __ext_compar_fn_t fn, const void* par ...@@ -269,4 +268,4 @@ void taosArraySortPWithExt(SArray* pArray, __ext_compar_fn_t fn, const void* par
} }
#endif #endif
#endif /*_TD_UTIL_ARRAY_H*/ #endif /*_TD_UTIL_ARRAY_H_*/
...@@ -13,15 +13,20 @@ ...@@ -13,15 +13,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_INT_H_ #ifndef _TD_UTIL_BASE64_H_
#define _TD_UTIL_INT_H_ #define _TD_UTIL_BASE64_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
uint8_t *base64_decode(const char *value, int32_t inlen, int32_t *outlen);
char *base64_encode(const uint8_t *value, int32_t vlen);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /*_TD_UTIL_INT_H_*/ #endif /*_TD_UTIL_BASE64_H_*/
\ No newline at end of file \ No newline at end of file
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_BUFFER_H #ifndef _TD_UTIL_BUFFER_H_
#define _TD_UTIL_BUFFER_H #define _TD_UTIL_BUFFER_H_
#include "os.h" #include "os.h"
...@@ -26,9 +26,9 @@ extern "C" { ...@@ -26,9 +26,9 @@ extern "C" {
// usage example // usage example
/* /*
#include <stdio.h> #include <stdio.h>
#include "exception.h" #include "texception.h"
int main( int argc, char** argv ) { int32_t main( int32_t argc, char** argv ) {
SBufferWriter bw = tbufInitWriter( NULL, false ); SBufferWriter bw = tbufInitWriter( NULL, false );
TRY( 1 ) { TRY( 1 ) {
...@@ -39,7 +39,7 @@ int main( int argc, char** argv ) { ...@@ -39,7 +39,7 @@ int main( int argc, char** argv ) {
// reserve space for the interger count // reserve space for the interger count
size_t pos = tbufReserve( &bw, sizeof(int32_t) ); size_t pos = tbufReserve( &bw, sizeof(int32_t) );
// write 5 integers to the buffer // write 5 integers to the buffer
for( int i = 0; i < 5; i++) { for( int32_t i = 0; i < 5; i++) {
tbufWriteInt32( &bw, i ); tbufWriteInt32( &bw, i );
} }
// write the integer count to buffer at reserved position // write the integer count to buffer at reserved position
...@@ -55,7 +55,7 @@ int main( int argc, char** argv ) { ...@@ -55,7 +55,7 @@ int main( int argc, char** argv ) {
SBufferReader br = tbufInitReader( data, size, false ); SBufferReader br = tbufInitReader( data, size, false );
// read & print out all integers // read & print out all integers
int32_t count = tbufReadInt32( &br ); int32_t count = tbufReadInt32( &br );
for( int i = 0; i < count; i++ ) { for( int32_t i = 0; i < count; i++ ) {
printf( "%d\n", tbufReadInt32(&br) ); printf( "%d\n", tbufReadInt32(&br) );
} }
// read & print out a string // read & print out a string
...@@ -87,12 +87,10 @@ typedef struct SBufferWriter { ...@@ -87,12 +87,10 @@ typedef struct SBufferWriter {
void* (*allocator)(void*, size_t); void* (*allocator)(void*, size_t);
} SBufferWriter; } SBufferWriter;
////////////////////////////////////////////////////////////////////////////////
// common functions & macros for both reader & writer // common functions & macros for both reader & writer
#define tbufTell(buf) ((buf)->pos) #define tbufTell(buf) ((buf)->pos)
////////////////////////////////////////////////////////////////////////////////
/* ------------------------ BUFFER WRITER FUNCTIONS AND MACROS ------------------------ */ /* ------------------------ BUFFER WRITER FUNCTIONS AND MACROS ------------------------ */
// *Allocator*, function to allocate memory, will use 'realloc' if NULL // *Allocator*, function to allocate memory, will use 'realloc' if NULL
// *Endian*, if true, writer functions of primitive types will do 'hton' automatically // *Endian*, if true, writer functions of primitive types will do 'hton' automatically
...@@ -167,4 +165,4 @@ double tbufReadDouble(SBufferReader* buf); ...@@ -167,4 +165,4 @@ double tbufReadDouble(SBufferReader* buf);
} }
#endif #endif
#endif /*_TD_UTIL_BUFFER_H*/ #endif /*_TD_UTIL_BUFFER_H_*/
...@@ -13,27 +13,25 @@ ...@@ -13,27 +13,25 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_CACHE_H #ifndef _TD_UTIL_CACHE_H_
#define _TD_UTIL_CACHE_H #define _TD_UTIL_CACHE_H_
#include "thash.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "os.h" #if defined(_TD_ARM_32)
#include "tlockfree.h" #define TSDB_CACHE_PTR_KEY TSDB_DATA_TYPE_INT
#include "thash.h" #define TSDB_CACHE_PTR_TYPE int32_t
#if defined(_TD_ARM_32)
#define TSDB_CACHE_PTR_KEY TSDB_DATA_TYPE_INT
#define TSDB_CACHE_PTR_TYPE int32_t
#else #else
#define TSDB_CACHE_PTR_KEY TSDB_DATA_TYPE_BIGINT #define TSDB_CACHE_PTR_KEY TSDB_DATA_TYPE_BIGINT
#define TSDB_CACHE_PTR_TYPE int64_t #define TSDB_CACHE_PTR_TYPE int64_t
#endif #endif
typedef void (*__cache_free_fn_t)(void*); typedef void (*__cache_free_fn_t)(void *);
typedef void (*__cache_trav_fn_t)(void*, void*); typedef void (*__cache_trav_fn_t)(void *, void *);
typedef struct SCacheStatis { typedef struct SCacheStatis {
int64_t missCount; int64_t missCount;
...@@ -45,17 +43,17 @@ typedef struct SCacheStatis { ...@@ -45,17 +43,17 @@ typedef struct SCacheStatis {
struct STrashElem; struct STrashElem;
typedef struct SCacheDataNode { typedef struct SCacheDataNode {
uint64_t addedTime; // the added time when this element is added or updated into cache uint64_t addedTime; // the added time when this element is added or updated into cache
uint64_t lifespan; // life duration when this element should be remove from cache uint64_t lifespan; // life duration when this element should be remove from cache
uint64_t expireTime; // expire time uint64_t expireTime; // expire time
uint64_t signature; uint64_t signature;
struct STrashElem *pTNodeHeader; // point to trash node head struct STrashElem *pTNodeHeader; // point to trash node head
uint16_t keySize: 15; // max key size: 32kb uint16_t keySize : 15; // max key size: 32kb
bool inTrashcan: 1;// denote if it is in trash or not bool inTrashcan : 1; // denote if it is in trash or not
uint32_t size; // allocated size for current SCacheDataNode uint32_t size; // allocated size for current SCacheDataNode
T_REF_DECLARE() T_REF_DECLARE()
char *key; char *key;
char data[]; char data[];
} SCacheDataNode; } SCacheDataNode;
typedef struct STrashElem { typedef struct STrashElem {
...@@ -73,22 +71,22 @@ typedef struct STrashElem { ...@@ -73,22 +71,22 @@ typedef struct STrashElem {
* when the node in pTrash does not be referenced, it will be release at the expired expiredTime * when the node in pTrash does not be referenced, it will be release at the expired expiredTime
*/ */
typedef struct { typedef struct {
int64_t totalSize; // total allocated buffer in this hash table, SCacheObj is not included. int64_t totalSize; // total allocated buffer in this hash table, SCacheObj is not included.
int64_t refreshTime; int64_t refreshTime;
STrashElem * pTrash; STrashElem *pTrash;
char* name; char *name;
SCacheStatis statistics; SCacheStatis statistics;
SHashObj * pHashTable; SHashObj *pHashTable;
__cache_free_fn_t freeFp; __cache_free_fn_t freeFp;
uint32_t numOfElemsInTrash; // number of element in trash uint32_t numOfElemsInTrash; // number of element in trash
uint8_t deleting; // set the deleting flag to stop refreshing ASAP. uint8_t deleting; // set the deleting flag to stop refreshing ASAP.
pthread_t refreshWorker; pthread_t refreshWorker;
bool extendLifespan; // auto extend life span when one item is accessed. bool extendLifespan; // auto extend life span when one item is accessed.
int64_t checkTick; // tick used to record the check times of the refresh threads int64_t checkTick; // tick used to record the check times of the refresh threads
#if defined(LINUX) #if defined(LINUX)
pthread_rwlock_t lock; pthread_rwlock_t lock;
#else #else
pthread_mutex_t lock; pthread_mutex_t lock;
#endif #endif
} SCacheObj; } SCacheObj;
...@@ -101,7 +99,8 @@ typedef struct { ...@@ -101,7 +99,8 @@ typedef struct {
* @param fn free resource callback function * @param fn free resource callback function
* @return * @return
*/ */
SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool extendLifespan, __cache_free_fn_t fn, const char *cacheName); SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool extendLifespan, __cache_free_fn_t fn,
const char *cacheName);
/** /**
* add data into cache * add data into cache
...@@ -113,7 +112,8 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext ...@@ -113,7 +112,8 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext
* @param keepTime survival time in second * @param keepTime survival time in second
* @return cached element * @return cached element
*/ */
void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const void *pData, size_t dataSize, int durationMS); void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const void *pData, size_t dataSize,
int32_t durationMS);
/** /**
* get data from cache * get data from cache
...@@ -177,7 +177,7 @@ void taosCacheCleanup(SCacheObj *pCacheObj); ...@@ -177,7 +177,7 @@ void taosCacheCleanup(SCacheObj *pCacheObj);
* @param fp * @param fp
* @return * @return
*/ */
void taosCacheRefresh(SCacheObj *pCacheObj, __cache_trav_fn_t fp, void* param1); void taosCacheRefresh(SCacheObj *pCacheObj, __cache_trav_fn_t fp, void *param1);
/** /**
* stop background refresh worker thread * stop background refresh worker thread
...@@ -188,4 +188,4 @@ void taosStopCacheRefreshWorker(); ...@@ -188,4 +188,4 @@ void taosStopCacheRefreshWorker();
} }
#endif #endif
#endif /*_TD_UTIL_CACHE_H*/ #endif /*_TD_UTIL_CACHE_H_*/
...@@ -13,24 +13,22 @@ ...@@ -13,24 +13,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_CHECKSUM_H #ifndef _TD_UTIL_CHECKSUM_H_
#define _TD_UTIL_CHECKSUM_H #define _TD_UTIL_CHECKSUM_H_
#include "tcrc32c.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "os.h"
#include "tcrc32c.h"
#include "tutil.h"
typedef uint32_t TSCKSUM; typedef uint32_t TSCKSUM;
static FORCE_INLINE TSCKSUM taosCalcChecksum(TSCKSUM csi, const uint8_t *stream, uint32_t ssize) { static FORCE_INLINE TSCKSUM taosCalcChecksum(TSCKSUM csi, const uint8_t *stream, uint32_t ssize) {
return (*crc32c)(csi, stream, (size_t)ssize); return (*crc32c)(csi, stream, (size_t)ssize);
} }
static FORCE_INLINE int taosCalcChecksumAppend(TSCKSUM csi, uint8_t *stream, uint32_t ssize) { static FORCE_INLINE int32_t taosCalcChecksumAppend(TSCKSUM csi, uint8_t *stream, uint32_t ssize) {
if (ssize < sizeof(TSCKSUM)) return -1; if (ssize < sizeof(TSCKSUM)) return -1;
*((TSCKSUM *)(stream + ssize - sizeof(TSCKSUM))) = (*crc32c)(csi, stream, (size_t)(ssize - sizeof(TSCKSUM))); *((TSCKSUM *)(stream + ssize - sizeof(TSCKSUM))) = (*crc32c)(csi, stream, (size_t)(ssize - sizeof(TSCKSUM)));
...@@ -38,11 +36,11 @@ static FORCE_INLINE int taosCalcChecksumAppend(TSCKSUM csi, uint8_t *stream, uin ...@@ -38,11 +36,11 @@ static FORCE_INLINE int taosCalcChecksumAppend(TSCKSUM csi, uint8_t *stream, uin
return 0; return 0;
} }
static FORCE_INLINE int taosCheckChecksum(const uint8_t *stream, uint32_t ssize, TSCKSUM checksum) { static FORCE_INLINE int32_t taosCheckChecksum(const uint8_t *stream, uint32_t ssize, TSCKSUM checksum) {
return (checksum != (*crc32c)(0, stream, (size_t)ssize)); return (checksum != (*crc32c)(0, stream, (size_t)ssize));
} }
static FORCE_INLINE int taosCheckChecksumWhole(const uint8_t *stream, uint32_t ssize) { static FORCE_INLINE int32_t taosCheckChecksumWhole(const uint8_t *stream, uint32_t ssize) {
if (ssize < sizeof(TSCKSUM)) return 0; if (ssize < sizeof(TSCKSUM)) return 0;
#if (_WIN64) #if (_WIN64)
...@@ -56,4 +54,4 @@ static FORCE_INLINE int taosCheckChecksumWhole(const uint8_t *stream, uint32_t s ...@@ -56,4 +54,4 @@ static FORCE_INLINE int taosCheckChecksumWhole(const uint8_t *stream, uint32_t s
} }
#endif #endif
#endif /*_TD_UTIL_CHECKSUM_H*/ #endif /*_TD_UTIL_CHECKSUM_H_*/
...@@ -12,29 +12,30 @@ ...@@ -12,29 +12,30 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_CODING_H
#define _TD_UTIL_CODING_H #ifndef _TD_UTIL_CODING_H_
#define _TD_UTIL_CODING_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "os.h" #define ENCODE_LIMIT (((uint8_t)1) << 7)
#define ENCODE_LIMIT (((uint8_t)1) << 7)
#define ZIGZAGE(T, v) ((u##T)((v) >> (sizeof(T) * 8 - 1))) ^ (((u##T)(v)) << 1) // zigzag encode #define ZIGZAGE(T, v) ((u##T)((v) >> (sizeof(T) * 8 - 1))) ^ (((u##T)(v)) << 1) // zigzag encode
#define ZIGZAGD(T, v) ((v) >> 1) ^ -((T)((v)&1)) // zigzag decode #define ZIGZAGD(T, v) ((v) >> 1) ^ -((T)((v)&1)) // zigzag decode
/* ------------------------ LEGACY CODES ------------------------ */ /* ------------------------ LEGACY CODES ------------------------ */
#if 1 #if 1
// ---- Fixed U8 // ---- Fixed U8
static FORCE_INLINE int taosEncodeFixedU8(void **buf, uint8_t value) { static FORCE_INLINE int32_t taosEncodeFixedU8(void **buf, uint8_t value) {
if (buf != NULL) { if (buf != NULL) {
((uint8_t *)(*buf))[0] = value; ((uint8_t *)(*buf))[0] = value;
*buf = POINTER_SHIFT(*buf, sizeof(value)); *buf = POINTER_SHIFT(*buf, sizeof(value));
} }
return (int)sizeof(value); return (int32_t)sizeof(value);
} }
static FORCE_INLINE void *taosDecodeFixedU8(const void *buf, uint8_t *value) { static FORCE_INLINE void *taosDecodeFixedU8(const void *buf, uint8_t *value) {
...@@ -43,12 +44,12 @@ static FORCE_INLINE void *taosDecodeFixedU8(const void *buf, uint8_t *value) { ...@@ -43,12 +44,12 @@ static FORCE_INLINE void *taosDecodeFixedU8(const void *buf, uint8_t *value) {
} }
// ---- Fixed I8 // ---- Fixed I8
static FORCE_INLINE int taosEncodeFixedI8(void **buf, int8_t value) { static FORCE_INLINE int32_t taosEncodeFixedI8(void **buf, int8_t value) {
if (buf != NULL) { if (buf != NULL) {
((int8_t *)(*buf))[0] = value; ((int8_t *)(*buf))[0] = value;
*buf = POINTER_SHIFT(*buf, sizeof(value)); *buf = POINTER_SHIFT(*buf, sizeof(value));
} }
return (int)sizeof(value); return (int32_t)sizeof(value);
} }
static FORCE_INLINE void *taosDecodeFixedI8(const void *buf, int8_t *value) { static FORCE_INLINE void *taosDecodeFixedI8(const void *buf, int8_t *value) {
...@@ -57,7 +58,7 @@ static FORCE_INLINE void *taosDecodeFixedI8(const void *buf, int8_t *value) { ...@@ -57,7 +58,7 @@ static FORCE_INLINE void *taosDecodeFixedI8(const void *buf, int8_t *value) {
} }
// ---- Fixed U16 // ---- Fixed U16
static FORCE_INLINE int taosEncodeFixedU16(void **buf, uint16_t value) { static FORCE_INLINE int32_t taosEncodeFixedU16(void **buf, uint16_t value) {
if (buf != NULL) { if (buf != NULL) {
if (IS_LITTLE_ENDIAN()) { if (IS_LITTLE_ENDIAN()) {
memcpy(*buf, &value, sizeof(value)); memcpy(*buf, &value, sizeof(value));
...@@ -68,7 +69,7 @@ static FORCE_INLINE int taosEncodeFixedU16(void **buf, uint16_t value) { ...@@ -68,7 +69,7 @@ static FORCE_INLINE int taosEncodeFixedU16(void **buf, uint16_t value) {
*buf = POINTER_SHIFT(*buf, sizeof(value)); *buf = POINTER_SHIFT(*buf, sizeof(value));
} }
return (int)sizeof(value); return (int32_t)sizeof(value);
} }
static FORCE_INLINE void *taosDecodeFixedU16(const void *buf, uint16_t *value) { static FORCE_INLINE void *taosDecodeFixedU16(const void *buf, uint16_t *value) {
...@@ -83,7 +84,7 @@ static FORCE_INLINE void *taosDecodeFixedU16(const void *buf, uint16_t *value) { ...@@ -83,7 +84,7 @@ static FORCE_INLINE void *taosDecodeFixedU16(const void *buf, uint16_t *value) {
} }
// ---- Fixed I16 // ---- Fixed I16
static FORCE_INLINE int taosEncodeFixedI16(void **buf, int16_t value) { static FORCE_INLINE int32_t taosEncodeFixedI16(void **buf, int16_t value) {
return taosEncodeFixedU16(buf, ZIGZAGE(int16_t, value)); return taosEncodeFixedU16(buf, ZIGZAGE(int16_t, value));
} }
...@@ -95,7 +96,7 @@ static FORCE_INLINE void *taosDecodeFixedI16(const void *buf, int16_t *value) { ...@@ -95,7 +96,7 @@ static FORCE_INLINE void *taosDecodeFixedI16(const void *buf, int16_t *value) {
} }
// ---- Fixed U32 // ---- Fixed U32
static FORCE_INLINE int taosEncodeFixedU32(void **buf, uint32_t value) { static FORCE_INLINE int32_t taosEncodeFixedU32(void **buf, uint32_t value) {
if (buf != NULL) { if (buf != NULL) {
if (IS_LITTLE_ENDIAN()) { if (IS_LITTLE_ENDIAN()) {
memcpy(*buf, &value, sizeof(value)); memcpy(*buf, &value, sizeof(value));
...@@ -108,7 +109,7 @@ static FORCE_INLINE int taosEncodeFixedU32(void **buf, uint32_t value) { ...@@ -108,7 +109,7 @@ static FORCE_INLINE int taosEncodeFixedU32(void **buf, uint32_t value) {
*buf = POINTER_SHIFT(*buf, sizeof(value)); *buf = POINTER_SHIFT(*buf, sizeof(value));
} }
return (int)sizeof(value); return (int32_t)sizeof(value);
} }
static FORCE_INLINE void *taosDecodeFixedU32(const void *buf, uint32_t *value) { static FORCE_INLINE void *taosDecodeFixedU32(const void *buf, uint32_t *value) {
...@@ -125,7 +126,7 @@ static FORCE_INLINE void *taosDecodeFixedU32(const void *buf, uint32_t *value) { ...@@ -125,7 +126,7 @@ static FORCE_INLINE void *taosDecodeFixedU32(const void *buf, uint32_t *value) {
} }
// ---- Fixed I32 // ---- Fixed I32
static FORCE_INLINE int taosEncodeFixedI32(void **buf, int32_t value) { static FORCE_INLINE int32_t taosEncodeFixedI32(void **buf, int32_t value) {
return taosEncodeFixedU32(buf, ZIGZAGE(int32_t, value)); return taosEncodeFixedU32(buf, ZIGZAGE(int32_t, value));
} }
...@@ -137,7 +138,7 @@ static FORCE_INLINE void *taosDecodeFixedI32(const void *buf, int32_t *value) { ...@@ -137,7 +138,7 @@ static FORCE_INLINE void *taosDecodeFixedI32(const void *buf, int32_t *value) {
} }
// ---- Fixed U64 // ---- Fixed U64
static FORCE_INLINE int taosEncodeFixedU64(void **buf, uint64_t value) { static FORCE_INLINE int32_t taosEncodeFixedU64(void **buf, uint64_t value) {
if (buf != NULL) { if (buf != NULL) {
if (IS_LITTLE_ENDIAN()) { if (IS_LITTLE_ENDIAN()) {
memcpy(*buf, &value, sizeof(value)); memcpy(*buf, &value, sizeof(value));
...@@ -155,7 +156,7 @@ static FORCE_INLINE int taosEncodeFixedU64(void **buf, uint64_t value) { ...@@ -155,7 +156,7 @@ static FORCE_INLINE int taosEncodeFixedU64(void **buf, uint64_t value) {
*buf = POINTER_SHIFT(*buf, sizeof(value)); *buf = POINTER_SHIFT(*buf, sizeof(value));
} }
return (int)sizeof(value); return (int32_t)sizeof(value);
} }
static FORCE_INLINE void *taosDecodeFixedU64(const void *buf, uint64_t *value) { static FORCE_INLINE void *taosDecodeFixedU64(const void *buf, uint64_t *value) {
...@@ -176,7 +177,7 @@ static FORCE_INLINE void *taosDecodeFixedU64(const void *buf, uint64_t *value) { ...@@ -176,7 +177,7 @@ static FORCE_INLINE void *taosDecodeFixedU64(const void *buf, uint64_t *value) {
} }
// ---- Fixed I64 // ---- Fixed I64
static FORCE_INLINE int taosEncodeFixedI64(void **buf, int64_t value) { static FORCE_INLINE int32_t taosEncodeFixedI64(void **buf, int64_t value) {
return taosEncodeFixedU64(buf, ZIGZAGE(int64_t, value)); return taosEncodeFixedU64(buf, ZIGZAGE(int64_t, value));
} }
...@@ -188,8 +189,8 @@ static FORCE_INLINE void *taosDecodeFixedI64(const void *buf, int64_t *value) { ...@@ -188,8 +189,8 @@ static FORCE_INLINE void *taosDecodeFixedI64(const void *buf, int64_t *value) {
} }
// ---- Variant U16 // ---- Variant U16
static FORCE_INLINE int taosEncodeVariantU16(void **buf, uint16_t value) { static FORCE_INLINE int32_t taosEncodeVariantU16(void **buf, uint16_t value) {
int i = 0; int32_t i = 0;
while (value >= ENCODE_LIMIT) { while (value >= ENCODE_LIMIT) {
if (buf != NULL) ((uint8_t *)(*buf))[i] = (uint8_t)(value | ENCODE_LIMIT); if (buf != NULL) ((uint8_t *)(*buf))[i] = (uint8_t)(value | ENCODE_LIMIT);
value >>= 7; value >>= 7;
...@@ -206,7 +207,7 @@ static FORCE_INLINE int taosEncodeVariantU16(void **buf, uint16_t value) { ...@@ -206,7 +207,7 @@ static FORCE_INLINE int taosEncodeVariantU16(void **buf, uint16_t value) {
} }
static FORCE_INLINE void *taosDecodeVariantU16(const void *buf, uint16_t *value) { static FORCE_INLINE void *taosDecodeVariantU16(const void *buf, uint16_t *value) {
int i = 0; int32_t i = 0;
uint16_t tval = 0; uint16_t tval = 0;
*value = 0; *value = 0;
while (i < 3) { while (i < 3) {
...@@ -224,7 +225,7 @@ static FORCE_INLINE void *taosDecodeVariantU16(const void *buf, uint16_t *value) ...@@ -224,7 +225,7 @@ static FORCE_INLINE void *taosDecodeVariantU16(const void *buf, uint16_t *value)
} }
// ---- Variant I16 // ---- Variant I16
static FORCE_INLINE int taosEncodeVariantI16(void **buf, int16_t value) { static FORCE_INLINE int32_t taosEncodeVariantI16(void **buf, int16_t value) {
return taosEncodeVariantU16(buf, ZIGZAGE(int16_t, value)); return taosEncodeVariantU16(buf, ZIGZAGE(int16_t, value));
} }
...@@ -236,8 +237,8 @@ static FORCE_INLINE void *taosDecodeVariantI16(const void *buf, int16_t *value) ...@@ -236,8 +237,8 @@ static FORCE_INLINE void *taosDecodeVariantI16(const void *buf, int16_t *value)
} }
// ---- Variant U32 // ---- Variant U32
static FORCE_INLINE int taosEncodeVariantU32(void **buf, uint32_t value) { static FORCE_INLINE int32_t taosEncodeVariantU32(void **buf, uint32_t value) {
int i = 0; int32_t i = 0;
while (value >= ENCODE_LIMIT) { while (value >= ENCODE_LIMIT) {
if (buf != NULL) ((uint8_t *)(*buf))[i] = (value | ENCODE_LIMIT); if (buf != NULL) ((uint8_t *)(*buf))[i] = (value | ENCODE_LIMIT);
value >>= 7; value >>= 7;
...@@ -254,7 +255,7 @@ static FORCE_INLINE int taosEncodeVariantU32(void **buf, uint32_t value) { ...@@ -254,7 +255,7 @@ static FORCE_INLINE int taosEncodeVariantU32(void **buf, uint32_t value) {
} }
static FORCE_INLINE void *taosDecodeVariantU32(const void *buf, uint32_t *value) { static FORCE_INLINE void *taosDecodeVariantU32(const void *buf, uint32_t *value) {
int i = 0; int32_t i = 0;
uint32_t tval = 0; uint32_t tval = 0;
*value = 0; *value = 0;
while (i < 5) { while (i < 5) {
...@@ -272,7 +273,7 @@ static FORCE_INLINE void *taosDecodeVariantU32(const void *buf, uint32_t *value) ...@@ -272,7 +273,7 @@ static FORCE_INLINE void *taosDecodeVariantU32(const void *buf, uint32_t *value)
} }
// ---- Variant I32 // ---- Variant I32
static FORCE_INLINE int taosEncodeVariantI32(void **buf, int32_t value) { static FORCE_INLINE int32_t taosEncodeVariantI32(void **buf, int32_t value) {
return taosEncodeVariantU32(buf, ZIGZAGE(int32_t, value)); return taosEncodeVariantU32(buf, ZIGZAGE(int32_t, value));
} }
...@@ -284,8 +285,8 @@ static FORCE_INLINE void *taosDecodeVariantI32(const void *buf, int32_t *value) ...@@ -284,8 +285,8 @@ static FORCE_INLINE void *taosDecodeVariantI32(const void *buf, int32_t *value)
} }
// ---- Variant U64 // ---- Variant U64
static FORCE_INLINE int taosEncodeVariantU64(void **buf, uint64_t value) { static FORCE_INLINE int32_t taosEncodeVariantU64(void **buf, uint64_t value) {
int i = 0; int32_t i = 0;
while (value >= ENCODE_LIMIT) { while (value >= ENCODE_LIMIT) {
if (buf != NULL) ((uint8_t *)(*buf))[i] = (uint8_t)(value | ENCODE_LIMIT); if (buf != NULL) ((uint8_t *)(*buf))[i] = (uint8_t)(value | ENCODE_LIMIT);
value >>= 7; value >>= 7;
...@@ -302,7 +303,7 @@ static FORCE_INLINE int taosEncodeVariantU64(void **buf, uint64_t value) { ...@@ -302,7 +303,7 @@ static FORCE_INLINE int taosEncodeVariantU64(void **buf, uint64_t value) {
} }
static FORCE_INLINE void *taosDecodeVariantU64(const void *buf, uint64_t *value) { static FORCE_INLINE void *taosDecodeVariantU64(const void *buf, uint64_t *value) {
int i = 0; int32_t i = 0;
uint64_t tval = 0; uint64_t tval = 0;
*value = 0; *value = 0;
while (i < 10) { while (i < 10) {
...@@ -320,7 +321,7 @@ static FORCE_INLINE void *taosDecodeVariantU64(const void *buf, uint64_t *value) ...@@ -320,7 +321,7 @@ static FORCE_INLINE void *taosDecodeVariantU64(const void *buf, uint64_t *value)
} }
// ---- Variant I64 // ---- Variant I64
static FORCE_INLINE int taosEncodeVariantI64(void **buf, int64_t value) { static FORCE_INLINE int32_t taosEncodeVariantI64(void **buf, int64_t value) {
return taosEncodeVariantU64(buf, ZIGZAGE(int64_t, value)); return taosEncodeVariantU64(buf, ZIGZAGE(int64_t, value));
} }
...@@ -332,16 +333,16 @@ static FORCE_INLINE void *taosDecodeVariantI64(const void *buf, int64_t *value) ...@@ -332,16 +333,16 @@ static FORCE_INLINE void *taosDecodeVariantI64(const void *buf, int64_t *value)
} }
// ---- string // ---- string
static FORCE_INLINE int taosEncodeString(void **buf, const char *value) { static FORCE_INLINE int32_t taosEncodeString(void **buf, const char *value) {
int tlen = 0; int32_t tlen = 0;
size_t size = strlen(value); size_t size = strlen(value);
tlen += taosEncodeVariantU64(buf, size); tlen += taosEncodeVariantU64(buf, size);
if (buf != NULL) { if (buf != NULL) {
memcpy(*buf, value, size); memcpy(*buf, value, size);
*buf = POINTER_SHIFT(*buf, size); *buf = POINTER_SHIFT(*buf, size);
} }
tlen += (int)size; tlen += (int32_t)size;
return tlen; return tlen;
} }
...@@ -372,14 +373,14 @@ static FORCE_INLINE void *taosDecodeStringTo(const void *buf, char *value) { ...@@ -372,14 +373,14 @@ static FORCE_INLINE void *taosDecodeStringTo(const void *buf, char *value) {
} }
// ---- binary // ---- binary
static FORCE_INLINE int taosEncodeBinary(void **buf, const void *value, int32_t valueLen) { static FORCE_INLINE int32_t taosEncodeBinary(void **buf, const void *value, int32_t valueLen) {
int tlen = 0; int32_t tlen = 0;
if (buf != NULL) { if (buf != NULL) {
memcpy(*buf, value, valueLen); memcpy(*buf, value, valueLen);
*buf = POINTER_SHIFT(*buf, valueLen); *buf = POINTER_SHIFT(*buf, valueLen);
} }
tlen += (int)valueLen; tlen += (int32_t)valueLen;
return tlen; return tlen;
} }
...@@ -403,4 +404,4 @@ static FORCE_INLINE void *taosDecodeBinaryTo(const void *buf, void *value, int32 ...@@ -403,4 +404,4 @@ static FORCE_INLINE void *taosDecodeBinaryTo(const void *buf, void *value, int32
} }
#endif #endif
#endif /*_TD_UTIL_CODING_H*/ #endif /*_TD_UTIL_CODING_H_*/
...@@ -17,12 +17,12 @@ ...@@ -17,12 +17,12 @@
#define _TD_UTIL_COMPARE_H_ #define _TD_UTIL_COMPARE_H_
#include "os.h" #include "os.h"
#include "taos.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#define TSDB_PATTERN_MATCH 0 #define TSDB_PATTERN_MATCH 0
#define TSDB_PATTERN_NOMATCH 1 #define TSDB_PATTERN_NOMATCH 1
#define TSDB_PATTERN_NOWILDCARDMATCH 2 #define TSDB_PATTERN_NOWILDCARDMATCH 2
...@@ -99,7 +99,15 @@ int32_t compareUint64ValDesc(const void *pLeft, const void *pRight); ...@@ -99,7 +99,15 @@ int32_t compareUint64ValDesc(const void *pLeft, const void *pRight);
int32_t compareLenPrefixedStrDesc(const void *pLeft, const void *pRight); int32_t compareLenPrefixedStrDesc(const void *pLeft, const void *pRight);
int32_t compareLenPrefixedWStrDesc(const void *pLeft, const void *pRight); int32_t compareLenPrefixedWStrDesc(const void *pLeft, const void *pRight);
int32_t compareStrPatternMatch(const void *pLeft, const void *pRight);
int32_t compareStrPatternNotMatch(const void *pLeft, const void *pRight);
int32_t compareWStrPatternMatch(const void *pLeft, const void *pRight);
int32_t compareWStrPatternNotMatch(const void *pLeft, const void *pRight);
__compar_fn_t getComparFunc(int32_t type, int32_t optr); __compar_fn_t getComparFunc(int32_t type, int32_t optr);
__compar_fn_t getKeyComparFunc(int32_t keyType, int32_t order);
int32_t doCompare(const char *a, const char *b, int32_t type, size_t size);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
此差异已折叠。
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#ifndef _TD_CONFIG_H_ #ifndef _TD_CONFIG_H_
#define _TD_CONFIG_H_ #define _TD_CONFIG_H_
#include "os.h"
#include "tarray.h" #include "tarray.h"
#ifdef __cplusplus #ifdef __cplusplus
...@@ -54,11 +53,11 @@ typedef struct SConfigItem { ...@@ -54,11 +53,11 @@ typedef struct SConfigItem {
bool tsc; bool tsc;
char *name; char *name;
union { union {
bool bval; bool bval;
float fval; float fval;
int32_t i32; int32_t i32;
int64_t i64; int64_t i64;
char *str; char *str;
}; };
union { union {
int64_t imin; int64_t imin;
...@@ -76,16 +75,17 @@ typedef struct { ...@@ -76,16 +75,17 @@ typedef struct {
const char *value; const char *value;
} SConfigPair; } SConfigPair;
typedef struct SConfig SConfig; typedef struct SConfig {
ECfgSrcType stype;
SArray *array;
} SConfig;
SConfig *cfgInit(); SConfig *cfgInit();
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr); int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr);
int32_t cfgLoadArray(SConfig *pCfg, SArray *pArgs); // SConfigPair int32_t cfgLoadArray(SConfig *pCfg, SArray *pArgs); // SConfigPair
void cfgCleanup(SConfig *pCfg); void cfgCleanup(SConfig *pCfg);
int32_t cfgGetSize(SConfig *pCfg); int32_t cfgGetSize(SConfig *pCfg);
SConfigItem *cfgIterate(SConfig *pCfg, SConfigItem *pIter);
void cfgCancelIterate(SConfig *pCfg, SConfigItem *pIter);
SConfigItem *cfgGetItem(SConfig *pCfg, const char *name); SConfigItem *cfgGetItem(SConfig *pCfg, const char *name);
int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcType stype); int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcType stype);
......
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef _TD_UTIL_CRC32_H #ifndef _TD_UTIL_CRC32_H_
#define _TD_UTIL_CRC32_H #define _TD_UTIL_CRC32_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -39,4 +41,4 @@ void taosResolveCRC(); ...@@ -39,4 +41,4 @@ void taosResolveCRC();
} }
#endif #endif
#endif /*_TD_UTIL_CRC32_H*/ #endif /*_TD_UTIL_CRC32_H_*/
此差异已折叠。
...@@ -13,23 +13,20 @@ ...@@ -13,23 +13,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_COMMON_CFG_H_ #ifndef _TD_UTIL_DES_H
#define _TD_COMMON_CFG_H_ #define _TD_UTIL_DES_H
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "tdef.h" char *taosDesEncode(int64_t key, char *src, int32_t len);
char *taosDesDecode(int64_t key, char *src, int32_t len);
typedef struct {
char dir[TSDB_FILENAME_LEN];
int level;
int primary;
} SDiskCfg;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /*_TD_COMMON_CFG_H_*/ #endif /*_TD_UTIL_DES_H*/
\ No newline at end of file
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
#ifndef _TD_UTIL_ENCODE_H_ #ifndef _TD_UTIL_ENCODE_H_
#define _TD_UTIL_ENCODE_H_ #define _TD_UTIL_ENCODE_H_
#include "freelist.h"
#include "tcoding.h" #include "tcoding.h"
#include "tfreelist.h"
#include "tmacro.h" #include "tmacro.h"
#ifdef __cplusplus #ifdef __cplusplus
...@@ -71,62 +71,62 @@ typedef struct { ...@@ -71,62 +71,62 @@ typedef struct {
TD_SLIST(SCoderNode) stack; TD_SLIST(SCoderNode) stack;
} SCoder; } SCoder;
#define TD_CODER_POS(CODER) ((CODER)->pos) #define TD_CODER_POS(CODER) ((CODER)->pos)
#define TD_CODER_CURRENT(CODER) ((CODER)->data + (CODER)->pos) #define TD_CODER_CURRENT(CODER) ((CODER)->data + (CODER)->pos)
#define TD_CODER_MOVE_POS(CODER, MOVE) ((CODER)->pos += (MOVE)) #define TD_CODER_MOVE_POS(CODER, MOVE) ((CODER)->pos += (MOVE))
#define TD_CODER_CHECK_CAPACITY_FAILED(CODER, EXPSIZE) (((CODER)->size - (CODER)->pos) < (EXPSIZE)) #define TD_CODER_CHECK_CAPACITY_FAILED(CODER, EXPSIZE) (((CODER)->size - (CODER)->pos) < (EXPSIZE))
#define TCODER_MALLOC(SIZE, CODER) TFL_MALLOC(SIZE, &((CODER)->fl)) #define TCODER_MALLOC(SIZE, CODER) TFL_MALLOC(SIZE, &((CODER)->fl))
void tCoderInit(SCoder* pCoder, td_endian_t endian, uint8_t* data, int32_t size, td_coder_t type); void tCoderInit(SCoder* pCoder, td_endian_t endian, uint8_t* data, int32_t size, td_coder_t type);
void tCoderClear(SCoder* pCoder); void tCoderClear(SCoder* pCoder);
/* ------------------------ ENCODE ------------------------ */ /* ------------------------ ENCODE ------------------------ */
int tStartEncode(SCoder* pEncoder); int32_t tStartEncode(SCoder* pEncoder);
void tEndEncode(SCoder* pEncoder); void tEndEncode(SCoder* pEncoder);
static int tEncodeU8(SCoder* pEncoder, uint8_t val); static int32_t tEncodeU8(SCoder* pEncoder, uint8_t val);
static int tEncodeI8(SCoder* pEncoder, int8_t val); static int32_t tEncodeI8(SCoder* pEncoder, int8_t val);
static int tEncodeU16(SCoder* pEncoder, uint16_t val); static int32_t tEncodeU16(SCoder* pEncoder, uint16_t val);
static int tEncodeI16(SCoder* pEncoder, int16_t val); static int32_t tEncodeI16(SCoder* pEncoder, int16_t val);
static int tEncodeU32(SCoder* pEncoder, uint32_t val); static int32_t tEncodeU32(SCoder* pEncoder, uint32_t val);
static int tEncodeI32(SCoder* pEncoder, int32_t val); static int32_t tEncodeI32(SCoder* pEncoder, int32_t val);
static int tEncodeU64(SCoder* pEncoder, uint64_t val); static int32_t tEncodeU64(SCoder* pEncoder, uint64_t val);
static int tEncodeI64(SCoder* pEncoder, int64_t val); static int32_t tEncodeI64(SCoder* pEncoder, int64_t val);
static int tEncodeU16v(SCoder* pEncoder, uint16_t val); static int32_t tEncodeU16v(SCoder* pEncoder, uint16_t val);
static int tEncodeI16v(SCoder* pEncoder, int16_t val); static int32_t tEncodeI16v(SCoder* pEncoder, int16_t val);
static int tEncodeU32v(SCoder* pEncoder, uint32_t val); static int32_t tEncodeU32v(SCoder* pEncoder, uint32_t val);
static int tEncodeI32v(SCoder* pEncoder, int32_t val); static int32_t tEncodeI32v(SCoder* pEncoder, int32_t val);
static int tEncodeU64v(SCoder* pEncoder, uint64_t val); static int32_t tEncodeU64v(SCoder* pEncoder, uint64_t val);
static int tEncodeI64v(SCoder* pEncoder, int64_t val); static int32_t tEncodeI64v(SCoder* pEncoder, int64_t val);
static int tEncodeFloat(SCoder* pEncoder, float val); static int32_t tEncodeFloat(SCoder* pEncoder, float val);
static int tEncodeDouble(SCoder* pEncoder, double val); static int32_t tEncodeDouble(SCoder* pEncoder, double val);
static int tEncodeBinary(SCoder* pEncoder, const void* val, uint64_t len); static int32_t tEncodeBinary(SCoder* pEncoder, const void* val, uint64_t len);
static int tEncodeCStrWithLen(SCoder* pEncoder, const char* val, uint64_t len); static int32_t tEncodeCStrWithLen(SCoder* pEncoder, const char* val, uint64_t len);
static int tEncodeCStr(SCoder* pEncoder, const char* val); static int32_t tEncodeCStr(SCoder* pEncoder, const char* val);
/* ------------------------ DECODE ------------------------ */ /* ------------------------ DECODE ------------------------ */
int tStartDecode(SCoder* pDecoder); int32_t tStartDecode(SCoder* pDecoder);
void tEndDecode(SCoder* pDecoder); void tEndDecode(SCoder* pDecoder);
static bool tDecodeIsEnd(SCoder* pCoder); static bool tDecodeIsEnd(SCoder* pCoder);
static int tDecodeU8(SCoder* pDecoder, uint8_t* val); static int32_t tDecodeU8(SCoder* pDecoder, uint8_t* val);
static int tDecodeI8(SCoder* pDecoder, int8_t* val); static int32_t tDecodeI8(SCoder* pDecoder, int8_t* val);
static int tDecodeU16(SCoder* pDecoder, uint16_t* val); static int32_t tDecodeU16(SCoder* pDecoder, uint16_t* val);
static int tDecodeI16(SCoder* pDecoder, int16_t* val); static int32_t tDecodeI16(SCoder* pDecoder, int16_t* val);
static int tDecodeU32(SCoder* pDecoder, uint32_t* val); static int32_t tDecodeU32(SCoder* pDecoder, uint32_t* val);
static int tDecodeI32(SCoder* pDecoder, int32_t* val); static int32_t tDecodeI32(SCoder* pDecoder, int32_t* val);
static int tDecodeU64(SCoder* pDecoder, uint64_t* val); static int32_t tDecodeU64(SCoder* pDecoder, uint64_t* val);
static int tDecodeI64(SCoder* pDecoder, int64_t* val); static int32_t tDecodeI64(SCoder* pDecoder, int64_t* val);
static int tDecodeU16v(SCoder* pDecoder, uint16_t* val); static int32_t tDecodeU16v(SCoder* pDecoder, uint16_t* val);
static int tDecodeI16v(SCoder* pDecoder, int16_t* val); static int32_t tDecodeI16v(SCoder* pDecoder, int16_t* val);
static int tDecodeU32v(SCoder* pDecoder, uint32_t* val); static int32_t tDecodeU32v(SCoder* pDecoder, uint32_t* val);
static int tDecodeI32v(SCoder* pDecoder, int32_t* val); static int32_t tDecodeI32v(SCoder* pDecoder, int32_t* val);
static int tDecodeU64v(SCoder* pDecoder, uint64_t* val); static int32_t tDecodeU64v(SCoder* pDecoder, uint64_t* val);
static int tDecodeI64v(SCoder* pDecoder, int64_t* val); static int32_t tDecodeI64v(SCoder* pDecoder, int64_t* val);
static int tDecodeFloat(SCoder* pDecoder, float* val); static int32_t tDecodeFloat(SCoder* pDecoder, float* val);
static int tDecodeDouble(SCoder* pDecoder, double* val); static int32_t tDecodeDouble(SCoder* pDecoder, double* val);
static int tDecodeBinary(SCoder* pDecoder, const void** val, uint64_t* len); static int32_t tDecodeBinary(SCoder* pDecoder, const void** val, uint64_t* len);
static int tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint64_t* len); static int32_t tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint64_t* len);
static int tDecodeCStr(SCoder* pDecoder, const char** val); static int32_t tDecodeCStr(SCoder* pDecoder, const char** val);
static int tDecodeCStrTo(SCoder* pDecoder, char* val); static int32_t tDecodeCStrTo(SCoder* pDecoder, char* val);
/* ------------------------ IMPL ------------------------ */ /* ------------------------ IMPL ------------------------ */
#define TD_ENCODE_MACRO(CODER, VAL, TYPE, BITS) \ #define TD_ENCODE_MACRO(CODER, VAL, TYPE, BITS) \
...@@ -190,7 +190,7 @@ static int tDecodeCStrTo(SCoder* pDecoder, char* val); ...@@ -190,7 +190,7 @@ static int tDecodeCStrTo(SCoder* pDecoder, char* val);
return 0; return 0;
// 8 // 8
static FORCE_INLINE int tEncodeU8(SCoder* pEncoder, uint8_t val) { static FORCE_INLINE int32_t tEncodeU8(SCoder* pEncoder, uint8_t val) {
if (pEncoder->data) { if (pEncoder->data) {
if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1; if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1;
tPut(uint8_t, TD_CODER_CURRENT(pEncoder), val); tPut(uint8_t, TD_CODER_CURRENT(pEncoder), val);
...@@ -199,7 +199,7 @@ static FORCE_INLINE int tEncodeU8(SCoder* pEncoder, uint8_t val) { ...@@ -199,7 +199,7 @@ static FORCE_INLINE int tEncodeU8(SCoder* pEncoder, uint8_t val) {
return 0; return 0;
} }
static FORCE_INLINE int tEncodeI8(SCoder* pEncoder, int8_t val) { static FORCE_INLINE int32_t tEncodeI8(SCoder* pEncoder, int8_t val) {
if (pEncoder->data) { if (pEncoder->data) {
if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1; if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1;
tPut(int8_t, TD_CODER_CURRENT(pEncoder), val); tPut(int8_t, TD_CODER_CURRENT(pEncoder), val);
...@@ -209,31 +209,31 @@ static FORCE_INLINE int tEncodeI8(SCoder* pEncoder, int8_t val) { ...@@ -209,31 +209,31 @@ static FORCE_INLINE int tEncodeI8(SCoder* pEncoder, int8_t val) {
} }
// 16 // 16
static FORCE_INLINE int tEncodeU16(SCoder* pEncoder, uint16_t val) { TD_ENCODE_MACRO(pEncoder, val, uint16_t, 16); } static FORCE_INLINE int32_t tEncodeU16(SCoder* pEncoder, uint16_t val) { TD_ENCODE_MACRO(pEncoder, val, uint16_t, 16); }
static FORCE_INLINE int tEncodeI16(SCoder* pEncoder, int16_t val) { TD_ENCODE_MACRO(pEncoder, val, int16_t, 16); } static FORCE_INLINE int32_t tEncodeI16(SCoder* pEncoder, int16_t val) { TD_ENCODE_MACRO(pEncoder, val, int16_t, 16); }
// 32 // 32
static FORCE_INLINE int tEncodeU32(SCoder* pEncoder, uint32_t val) { TD_ENCODE_MACRO(pEncoder, val, uint32_t, 32); } static FORCE_INLINE int32_t tEncodeU32(SCoder* pEncoder, uint32_t val) { TD_ENCODE_MACRO(pEncoder, val, uint32_t, 32); }
static FORCE_INLINE int tEncodeI32(SCoder* pEncoder, int32_t val) { TD_ENCODE_MACRO(pEncoder, val, int32_t, 32); } static FORCE_INLINE int32_t tEncodeI32(SCoder* pEncoder, int32_t val) { TD_ENCODE_MACRO(pEncoder, val, int32_t, 32); }
// 64 // 64
static FORCE_INLINE int tEncodeU64(SCoder* pEncoder, uint64_t val) { TD_ENCODE_MACRO(pEncoder, val, uint64_t, 64); } static FORCE_INLINE int32_t tEncodeU64(SCoder* pEncoder, uint64_t val) { TD_ENCODE_MACRO(pEncoder, val, uint64_t, 64); }
static FORCE_INLINE int tEncodeI64(SCoder* pEncoder, int64_t val) { TD_ENCODE_MACRO(pEncoder, val, int64_t, 64); } static FORCE_INLINE int32_t tEncodeI64(SCoder* pEncoder, int64_t val) { TD_ENCODE_MACRO(pEncoder, val, int64_t, 64); }
// 16v // 16v
static FORCE_INLINE int tEncodeU16v(SCoder* pEncoder, uint16_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); } static FORCE_INLINE int32_t tEncodeU16v(SCoder* pEncoder, uint16_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); }
static FORCE_INLINE int tEncodeI16v(SCoder* pEncoder, int16_t val) { static FORCE_INLINE int32_t tEncodeI16v(SCoder* pEncoder, int16_t val) {
return tEncodeU16v(pEncoder, ZIGZAGE(int16_t, val)); return tEncodeU16v(pEncoder, ZIGZAGE(int16_t, val));
} }
// 32v // 32v
static FORCE_INLINE int tEncodeU32v(SCoder* pEncoder, uint32_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); } static FORCE_INLINE int32_t tEncodeU32v(SCoder* pEncoder, uint32_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); }
static FORCE_INLINE int tEncodeI32v(SCoder* pEncoder, int32_t val) { static FORCE_INLINE int32_t tEncodeI32v(SCoder* pEncoder, int32_t val) {
return tEncodeU32v(pEncoder, ZIGZAGE(int32_t, val)); return tEncodeU32v(pEncoder, ZIGZAGE(int32_t, val));
} }
// 64v // 64v
static FORCE_INLINE int tEncodeU64v(SCoder* pEncoder, uint64_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); } static FORCE_INLINE int32_t tEncodeU64v(SCoder* pEncoder, uint64_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); }
static FORCE_INLINE int tEncodeI64v(SCoder* pEncoder, int64_t val) { static FORCE_INLINE int32_t tEncodeI64v(SCoder* pEncoder, int64_t val) {
return tEncodeU64v(pEncoder, ZIGZAGE(int64_t, val)); return tEncodeU64v(pEncoder, ZIGZAGE(int64_t, val));
} }
static FORCE_INLINE int tEncodeFloat(SCoder* pEncoder, float val) { static FORCE_INLINE int32_t tEncodeFloat(SCoder* pEncoder, float val) {
union { union {
uint32_t ui; uint32_t ui;
float f; float f;
...@@ -242,7 +242,7 @@ static FORCE_INLINE int tEncodeFloat(SCoder* pEncoder, float val) { ...@@ -242,7 +242,7 @@ static FORCE_INLINE int tEncodeFloat(SCoder* pEncoder, float val) {
return tEncodeU32(pEncoder, v.ui); return tEncodeU32(pEncoder, v.ui);
} }
static FORCE_INLINE int tEncodeDouble(SCoder* pEncoder, double val) { static FORCE_INLINE int32_t tEncodeDouble(SCoder* pEncoder, double val) {
union { union {
uint64_t ui; uint64_t ui;
double d; double d;
...@@ -251,7 +251,7 @@ static FORCE_INLINE int tEncodeDouble(SCoder* pEncoder, double val) { ...@@ -251,7 +251,7 @@ static FORCE_INLINE int tEncodeDouble(SCoder* pEncoder, double val) {
return tEncodeU64(pEncoder, v.ui); return tEncodeU64(pEncoder, v.ui);
} }
static FORCE_INLINE int tEncodeBinary(SCoder* pEncoder, const void* val, uint64_t len) { static FORCE_INLINE int32_t tEncodeBinary(SCoder* pEncoder, const void* val, uint64_t len) {
if (tEncodeU64v(pEncoder, len) < 0) return -1; if (tEncodeU64v(pEncoder, len) < 0) return -1;
if (pEncoder->data) { if (pEncoder->data) {
if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, len)) return -1; if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, len)) return -1;
...@@ -262,24 +262,24 @@ static FORCE_INLINE int tEncodeBinary(SCoder* pEncoder, const void* val, uint64_ ...@@ -262,24 +262,24 @@ static FORCE_INLINE int tEncodeBinary(SCoder* pEncoder, const void* val, uint64_
return 0; return 0;
} }
static FORCE_INLINE int tEncodeCStrWithLen(SCoder* pEncoder, const char* val, uint64_t len) { static FORCE_INLINE int32_t tEncodeCStrWithLen(SCoder* pEncoder, const char* val, uint64_t len) {
return tEncodeBinary(pEncoder, (void*)val, len + 1); return tEncodeBinary(pEncoder, (void*)val, len + 1);
} }
static FORCE_INLINE int tEncodeCStr(SCoder* pEncoder, const char* val) { static FORCE_INLINE int32_t tEncodeCStr(SCoder* pEncoder, const char* val) {
return tEncodeCStrWithLen(pEncoder, val, (uint64_t)strlen(val)); return tEncodeCStrWithLen(pEncoder, val, (uint64_t)strlen(val));
} }
/* ------------------------ FOR DECODER ------------------------ */ /* ------------------------ FOR DECODER ------------------------ */
// 8 // 8
static FORCE_INLINE int tDecodeU8(SCoder* pDecoder, uint8_t* val) { static FORCE_INLINE int32_t tDecodeU8(SCoder* pDecoder, uint8_t* val) {
if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1; if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1;
tGet(uint8_t, TD_CODER_CURRENT(pDecoder), *val); tGet(uint8_t, TD_CODER_CURRENT(pDecoder), *val);
TD_CODER_MOVE_POS(pDecoder, sizeof(*val)); TD_CODER_MOVE_POS(pDecoder, sizeof(*val));
return 0; return 0;
} }
static FORCE_INLINE int tDecodeI8(SCoder* pDecoder, int8_t* val) { static FORCE_INLINE int32_t tDecodeI8(SCoder* pDecoder, int8_t* val) {
if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1; if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1;
tGet(int8_t, TD_CODER_CURRENT(pDecoder), *val); tGet(int8_t, TD_CODER_CURRENT(pDecoder), *val);
TD_CODER_MOVE_POS(pDecoder, sizeof(*val)); TD_CODER_MOVE_POS(pDecoder, sizeof(*val));
...@@ -287,21 +287,27 @@ static FORCE_INLINE int tDecodeI8(SCoder* pDecoder, int8_t* val) { ...@@ -287,21 +287,27 @@ static FORCE_INLINE int tDecodeI8(SCoder* pDecoder, int8_t* val) {
} }
// 16 // 16
static FORCE_INLINE int tDecodeU16(SCoder* pDecoder, uint16_t* val) { TD_DECODE_MACRO(pDecoder, val, uint16_t, 16); } static FORCE_INLINE int32_t tDecodeU16(SCoder* pDecoder, uint16_t* val) {
static FORCE_INLINE int tDecodeI16(SCoder* pDecoder, int16_t* val) { TD_DECODE_MACRO(pDecoder, val, int16_t, 16); } TD_DECODE_MACRO(pDecoder, val, uint16_t, 16);
}
static FORCE_INLINE int32_t tDecodeI16(SCoder* pDecoder, int16_t* val) { TD_DECODE_MACRO(pDecoder, val, int16_t, 16); }
// 32 // 32
static FORCE_INLINE int tDecodeU32(SCoder* pDecoder, uint32_t* val) { TD_DECODE_MACRO(pDecoder, val, uint32_t, 32); } static FORCE_INLINE int32_t tDecodeU32(SCoder* pDecoder, uint32_t* val) {
static FORCE_INLINE int tDecodeI32(SCoder* pDecoder, int32_t* val) { TD_DECODE_MACRO(pDecoder, val, int32_t, 32); } TD_DECODE_MACRO(pDecoder, val, uint32_t, 32);
}
static FORCE_INLINE int32_t tDecodeI32(SCoder* pDecoder, int32_t* val) { TD_DECODE_MACRO(pDecoder, val, int32_t, 32); }
// 64 // 64
static FORCE_INLINE int tDecodeU64(SCoder* pDecoder, uint64_t* val) { TD_DECODE_MACRO(pDecoder, val, uint64_t, 64); } static FORCE_INLINE int32_t tDecodeU64(SCoder* pDecoder, uint64_t* val) {
static FORCE_INLINE int tDecodeI64(SCoder* pDecoder, int64_t* val) { TD_DECODE_MACRO(pDecoder, val, int64_t, 64); } TD_DECODE_MACRO(pDecoder, val, uint64_t, 64);
}
static FORCE_INLINE int32_t tDecodeI64(SCoder* pDecoder, int64_t* val) { TD_DECODE_MACRO(pDecoder, val, int64_t, 64); }
// 16v // 16v
static FORCE_INLINE int tDecodeU16v(SCoder* pDecoder, uint16_t* val) { static FORCE_INLINE int32_t tDecodeU16v(SCoder* pDecoder, uint16_t* val) {
TD_DECODE_VARIANT_MACRO(pDecoder, val, uint16_t); TD_DECODE_VARIANT_MACRO(pDecoder, val, uint16_t);
} }
static FORCE_INLINE int tDecodeI16v(SCoder* pDecoder, int16_t* val) { static FORCE_INLINE int32_t tDecodeI16v(SCoder* pDecoder, int16_t* val) {
uint16_t tval; uint16_t tval;
if (tDecodeU16v(pDecoder, &tval) < 0) { if (tDecodeU16v(pDecoder, &tval) < 0) {
return -1; return -1;
...@@ -311,11 +317,11 @@ static FORCE_INLINE int tDecodeI16v(SCoder* pDecoder, int16_t* val) { ...@@ -311,11 +317,11 @@ static FORCE_INLINE int tDecodeI16v(SCoder* pDecoder, int16_t* val) {
} }
// 32v // 32v
static FORCE_INLINE int tDecodeU32v(SCoder* pDecoder, uint32_t* val) { static FORCE_INLINE int32_t tDecodeU32v(SCoder* pDecoder, uint32_t* val) {
TD_DECODE_VARIANT_MACRO(pDecoder, val, uint32_t); TD_DECODE_VARIANT_MACRO(pDecoder, val, uint32_t);
} }
static FORCE_INLINE int tDecodeI32v(SCoder* pDecoder, int32_t* val) { static FORCE_INLINE int32_t tDecodeI32v(SCoder* pDecoder, int32_t* val) {
uint32_t tval; uint32_t tval;
if (tDecodeU32v(pDecoder, &tval) < 0) { if (tDecodeU32v(pDecoder, &tval) < 0) {
return -1; return -1;
...@@ -325,11 +331,11 @@ static FORCE_INLINE int tDecodeI32v(SCoder* pDecoder, int32_t* val) { ...@@ -325,11 +331,11 @@ static FORCE_INLINE int tDecodeI32v(SCoder* pDecoder, int32_t* val) {
} }
// 64v // 64v
static FORCE_INLINE int tDecodeU64v(SCoder* pDecoder, uint64_t* val) { static FORCE_INLINE int32_t tDecodeU64v(SCoder* pDecoder, uint64_t* val) {
TD_DECODE_VARIANT_MACRO(pDecoder, val, uint64_t); TD_DECODE_VARIANT_MACRO(pDecoder, val, uint64_t);
} }
static FORCE_INLINE int tDecodeI64v(SCoder* pDecoder, int64_t* val) { static FORCE_INLINE int32_t tDecodeI64v(SCoder* pDecoder, int64_t* val) {
uint64_t tval; uint64_t tval;
if (tDecodeU64v(pDecoder, &tval) < 0) { if (tDecodeU64v(pDecoder, &tval) < 0) {
return -1; return -1;
...@@ -338,7 +344,7 @@ static FORCE_INLINE int tDecodeI64v(SCoder* pDecoder, int64_t* val) { ...@@ -338,7 +344,7 @@ static FORCE_INLINE int tDecodeI64v(SCoder* pDecoder, int64_t* val) {
return 0; return 0;
} }
static FORCE_INLINE int tDecodeFloat(SCoder* pDecoder, float* val) { static FORCE_INLINE int32_t tDecodeFloat(SCoder* pDecoder, float* val) {
union { union {
uint32_t ui; uint32_t ui;
float f; float f;
...@@ -352,7 +358,7 @@ static FORCE_INLINE int tDecodeFloat(SCoder* pDecoder, float* val) { ...@@ -352,7 +358,7 @@ static FORCE_INLINE int tDecodeFloat(SCoder* pDecoder, float* val) {
return 0; return 0;
} }
static FORCE_INLINE int tDecodeDouble(SCoder* pDecoder, double* val) { static FORCE_INLINE int32_t tDecodeDouble(SCoder* pDecoder, double* val) {
union { union {
uint64_t ui; uint64_t ui;
double d; double d;
...@@ -366,7 +372,7 @@ static FORCE_INLINE int tDecodeDouble(SCoder* pDecoder, double* val) { ...@@ -366,7 +372,7 @@ static FORCE_INLINE int tDecodeDouble(SCoder* pDecoder, double* val) {
return 0; return 0;
} }
static FORCE_INLINE int tDecodeBinary(SCoder* pDecoder, const void** val, uint64_t* len) { static FORCE_INLINE int32_t tDecodeBinary(SCoder* pDecoder, const void** val, uint64_t* len) {
if (tDecodeU64v(pDecoder, len) < 0) return -1; if (tDecodeU64v(pDecoder, len) < 0) return -1;
if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, *len)) return -1; if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, *len)) return -1;
...@@ -376,18 +382,18 @@ static FORCE_INLINE int tDecodeBinary(SCoder* pDecoder, const void** val, uint64 ...@@ -376,18 +382,18 @@ static FORCE_INLINE int tDecodeBinary(SCoder* pDecoder, const void** val, uint64
return 0; return 0;
} }
static FORCE_INLINE int tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint64_t* len) { static FORCE_INLINE int32_t tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint64_t* len) {
if (tDecodeBinary(pDecoder, (const void**)val, len) < 0) return -1; if (tDecodeBinary(pDecoder, (const void**)val, len) < 0) return -1;
(*len) -= 1; (*len) -= 1;
return 0; return 0;
} }
static FORCE_INLINE int tDecodeCStr(SCoder* pDecoder, const char** val) { static FORCE_INLINE int32_t tDecodeCStr(SCoder* pDecoder, const char** val) {
uint64_t len; uint64_t len;
return tDecodeCStrAndLen(pDecoder, val, &len); return tDecodeCStrAndLen(pDecoder, val, &len);
} }
static int tDecodeCStrTo(SCoder* pDecoder, char* val) { static int32_t tDecodeCStrTo(SCoder* pDecoder, char* val) {
const char* pStr; const char* pStr;
uint64_t len; uint64_t len;
if (tDecodeCStrAndLen(pDecoder, &pStr, &len) < 0) return -1; if (tDecodeCStrAndLen(pDecoder, &pStr, &len) < 0) return -1;
......
/*
* Copyright (c) 2020 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_UTIL_EXCEPTION_H_
#define _TD_UTIL_EXCEPTION_H_
#include "os.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* cleanup actions
*/
typedef struct SCleanupAction {
bool failOnly;
uint8_t wrapper;
uint16_t reserved;
void* func;
union {
void* Ptr;
bool Bool;
char Char;
int8_t Int8;
uint8_t Uint8;
int16_t Int16;
uint16_t Uint16;
int32_t Int;
uint32_t Uint;
int32_t Int32;
uint32_t Uint32;
int64_t Int64;
uint64_t Uint64;
float Float;
double Double;
} arg1, arg2;
} SCleanupAction;
/*
* exception hander registration
*/
typedef struct SExceptionNode {
struct SExceptionNode* prev;
jmp_buf jb;
int32_t code;
int32_t maxCleanupAction;
int32_t numCleanupAction;
SCleanupAction* cleanupActions;
} SExceptionNode;
// functions & macros for auto-cleanup
void cleanupPush_void_ptr_ptr(bool failOnly, void* func, void* arg1, void* arg2);
void cleanupPush_void_ptr_bool(bool failOnly, void* func, void* arg1, bool arg2);
void cleanupPush_void_ptr(bool failOnly, void* func, void* arg);
void cleanupPush_int_int(bool failOnly, void* func, int32_t arg);
void cleanupPush_void(bool failOnly, void* func);
void cleanupPush_int_ptr(bool failOnly, void* func, void* arg);
int32_t cleanupGetActionCount();
void cleanupExecuteTo(int32_t anchor, bool failed);
void cleanupExecute(SExceptionNode* node, bool failed);
bool cleanupExceedLimit();
#define CLEANUP_PUSH_VOID_PTR_PTR(failOnly, func, arg1, arg2) \
cleanupPush_void_ptr_ptr((failOnly), (void*)(func), (void*)(arg1), (void*)(arg2))
#define CLEANUP_PUSH_VOID_PTR_BOOL(failOnly, func, arg1, arg2) \
cleanupPush_void_ptr_bool((failOnly), (void*)(func), (void*)(arg1), (bool)(arg2))
#define CLEANUP_PUSH_VOID_PTR(failOnly, func, arg) cleanupPush_void_ptr((failOnly), (void*)(func), (void*)(arg))
#define CLEANUP_PUSH_INT_INT(failOnly, func, arg) cleanupPush_void_ptr((failOnly), (void*)(func), (int32_t)(arg))
#define CLEANUP_PUSH_VOID(failOnly, func) cleanupPush_void((failOnly), (void*)(func))
#define CLEANUP_PUSH_INT_PTR(failOnly, func, arg) cleanupPush_int_ptr((failOnly), (void*)(func), (void*)(arg))
#define CLEANUP_PUSH_FREE(failOnly, arg) cleanupPush_void_ptr((failOnly), free, (void*)(arg))
#define CLEANUP_PUSH_CLOSE(failOnly, arg) cleanupPush_int_int((failOnly), close, (int32_t)(arg))
#define CLEANUP_PUSH_FCLOSE(failOnly, arg) cleanupPush_int_ptr((failOnly), fclose, (void*)(arg))
#define CLEANUP_GET_ANCHOR() cleanupGetActionCount()
#define CLEANUP_EXECUTE_TO(anchor, failed) cleanupExecuteTo((anchor), (failed))
#define CLEANUP_EXCEED_LIMIT() cleanupExceedLimit()
// functions & macros for exception handling
void exceptionPushNode(SExceptionNode* node);
int32_t exceptionPopNode();
void exceptionThrow(int32_t code);
#define TRY(maxCleanupActions) \
do { \
SExceptionNode exceptionNode = {0}; \
SCleanupAction cleanupActions[(maxCleanupActions) > 0 ? (maxCleanupActions) : 1]; \
exceptionNode.maxCleanupAction = (maxCleanupActions) > 0 ? (maxCleanupActions) : 1; \
exceptionNode.cleanupActions = cleanupActions; \
exceptionPushNode(&exceptionNode); \
int32_t caughtException = setjmp(exceptionNode.jb); \
if (caughtException == 0)
#define CATCH(code) \
int32_t code = exceptionPopNode(); \
if (caughtException == 1)
#define FINALLY(code) int32_t code = exceptionPopNode();
#define END_TRY \
} \
while (0) \
;
#define THROW(x) exceptionThrow((x))
#define CAUGHT_EXCEPTION() ((bool)(caughtException == 1))
#define CLEANUP_EXECUTE() cleanupExecute(&exceptionNode, CAUGHT_EXCEPTION())
#ifdef __cplusplus
}
#endif
#endif /*_TD_UTIL_EXCEPTION_H_*/
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_UTIL_FILE_H
#define _TD_UTIL_FILE_H
#include "os.h"
#ifdef __cplusplus
extern "C" {
#endif
// init taos file module
int32_t tfInit();
// clean up taos file module
void tfCleanup();
// the same syntax as UNIX standard open/close/read/write
// but FD is int64_t and will never be reused
// int64_t tfOpenRead(const char *pathname);
// int64_t tfOpenReadWrite(const char *pathname);
// int64_t tfOpenCreateWrite(const char *pathname);
// int64_t tfOpenCreateWriteAppend(const char *pathname);
// int64_t tfClose(int64_t tfd);
// int64_t tfWrite(int64_t tfd, void *buf, int64_t count);
// int64_t tfRead(int64_t tfd, void *buf, int64_t count);
// int64_t tfPread(int64_t tfd, void *buf, int64_t count, int64_t offset);
// int32_t tfFsync(int64_t tfd);
// bool tfValid(int64_t tfd);
// int64_t tfLseek(int64_t tfd, int64_t offset, int32_t whence);
// int32_t tfFtruncate(int64_t tfd, int64_t length);
// void * tfMmapReadOnly(int64_t tfd, int64_t length);
#ifdef __cplusplus
}
#endif
#endif /*_TD_UTIL_FILE_H*/
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#ifndef _TD_UTIL_FREELIST_H_ #ifndef _TD_UTIL_FREELIST_H_
#define _TD_UTIL_FREELIST_H_ #define _TD_UTIL_FREELIST_H_
#include "os.h"
#include "tlist.h" #include "tlist.h"
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -12,45 +12,45 @@ ...@@ -12,45 +12,45 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_FUNCTIONAL_H #ifndef _TD_UTIL_FUNCTIONAL_H_
#define _TD_UTIL_FUNCTIONAL_H #define _TD_UTIL_FUNCTIONAL_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "os.h" // TODO: hard to use, trying to rewrite it using va_list
//TODO: hard to use, trying to rewrite it using va_list
typedef void* (*GenericVaFunc)(void* args[]); typedef void* (*GenericVaFunc)(void* args[]);
typedef int32_t (*I32VaFunc) (void* args[]); typedef int32_t (*I32VaFunc)(void* args[]);
typedef void (*VoidVaFunc) (void* args[]); typedef void (*VoidVaFunc)(void* args[]);
typedef struct GenericSavedFunc { typedef struct GenericSavedFunc {
GenericVaFunc func; GenericVaFunc func;
void * args[]; void* args[];
} tGenericSavedFunc; } tGenericSavedFunc;
typedef struct I32SavedFunc { typedef struct I32SavedFunc {
I32VaFunc func; I32VaFunc func;
void * args[]; void* args[];
} tI32SavedFunc; } tI32SavedFunc;
typedef struct VoidSavedFunc { typedef struct VoidSavedFunc {
VoidVaFunc func; VoidVaFunc func;
void * args[]; void* args[];
} tVoidSavedFunc; } tVoidSavedFunc;
tGenericSavedFunc* genericSavedFuncInit(GenericVaFunc func, int numOfArgs); tGenericSavedFunc* genericSavedFuncInit(GenericVaFunc func, int32_t numOfArgs);
tI32SavedFunc* i32SavedFuncInit(I32VaFunc func, int numOfArgs); tI32SavedFunc* i32SavedFuncInit(I32VaFunc func, int32_t numOfArgs);
tVoidSavedFunc* voidSavedFuncInit(VoidVaFunc func, int numOfArgs); tVoidSavedFunc* voidSavedFuncInit(VoidVaFunc func, int32_t numOfArgs);
void* genericInvoke(tGenericSavedFunc* const pSavedFunc); void* genericInvoke(tGenericSavedFunc* const pSavedFunc);
int32_t i32Invoke(tI32SavedFunc* const pSavedFunc); int32_t i32Invoke(tI32SavedFunc* const pSavedFunc);
void voidInvoke(tVoidSavedFunc* const pSavedFunc); void voidInvoke(tVoidSavedFunc* const pSavedFunc);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /*_TD_UTIL_FUNCTIONAL_H*/ #endif /*_TD_UTIL_FUNCTIONAL_H_*/
...@@ -13,22 +13,22 @@ ...@@ -13,22 +13,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_HASH_H #ifndef _TD_UTIL_HASH_H_
#define TDENGINE_HASH_H #define _TD_UTIL_HASH_H_
#include "tarray.h"
#include "tlockfree.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "tarray.h"
#include "tlockfree.h"
typedef uint32_t (*_hash_fn_t)(const char *, uint32_t); typedef uint32_t (*_hash_fn_t)(const char *, uint32_t);
typedef int32_t (*_equal_fn_t)(const void*, const void*, size_t len); typedef int32_t (*_equal_fn_t)(const void *, const void *, size_t len);
typedef void (*_hash_before_fn_t)(void *); typedef void (*_hash_before_fn_t)(void *);
typedef void (*_hash_free_fn_t)(void *); typedef void (*_hash_free_fn_t)(void *);
#define HASH_MAX_CAPACITY (1024 * 1024 * 16) #define HASH_MAX_CAPACITY (1024 * 1024 * 16)
#define HASH_DEFAULT_LOAD_FACTOR (0.75) #define HASH_DEFAULT_LOAD_FACTOR (0.75)
#define HASH_INDEX(v, c) ((v) & ((c)-1)) #define HASH_INDEX(v, c) ((v) & ((c)-1))
...@@ -59,43 +59,43 @@ _equal_fn_t taosGetDefaultEqualFunction(int32_t type); ...@@ -59,43 +59,43 @@ _equal_fn_t taosGetDefaultEqualFunction(int32_t type);
typedef struct SHashNode { typedef struct SHashNode {
struct SHashNode *next; struct SHashNode *next;
uint32_t hashVal; // the hash value of key uint32_t hashVal; // the hash value of key
uint32_t dataLen; // length of data uint32_t dataLen; // length of data
uint32_t keyLen; // length of the key uint32_t keyLen; // length of the key
uint16_t count; // reference count uint16_t count; // reference count
int8_t removed; // flag to indicate removed int8_t removed; // flag to indicate removed
char data[]; char data[];
} SHashNode; } SHashNode;
#define GET_HASH_NODE_KEY(_n) ((char*)(_n) + sizeof(SHashNode) + (_n)->dataLen) #define GET_HASH_NODE_KEY(_n) ((char *)(_n) + sizeof(SHashNode) + (_n)->dataLen)
#define GET_HASH_NODE_DATA(_n) ((char*)(_n) + sizeof(SHashNode)) #define GET_HASH_NODE_DATA(_n) ((char *)(_n) + sizeof(SHashNode))
#define GET_HASH_PNODE(_n) ((SHashNode *)((char*)(_n) - sizeof(SHashNode))) #define GET_HASH_PNODE(_n) ((SHashNode *)((char *)(_n) - sizeof(SHashNode)))
typedef enum SHashLockTypeE { typedef enum SHashLockTypeE {
HASH_NO_LOCK = 0, HASH_NO_LOCK = 0,
HASH_ENTRY_LOCK = 1, HASH_ENTRY_LOCK = 1,
} SHashLockTypeE; } SHashLockTypeE;
typedef struct SHashEntry { typedef struct SHashEntry {
int32_t num; // number of elements in current entry int32_t num; // number of elements in current entry
SRWLatch latch; // entry latch SRWLatch latch; // entry latch
SHashNode *next; SHashNode *next;
} SHashEntry; } SHashEntry;
typedef struct SHashObj { typedef struct SHashObj {
SHashEntry **hashList; SHashEntry **hashList;
uint32_t capacity; // number of slots uint32_t capacity; // number of slots
uint32_t size; // number of elements in hash table uint32_t size; // number of elements in hash table
_hash_fn_t hashFp; // hash function _hash_fn_t hashFp; // hash function
_hash_free_fn_t freeFp; // hash node free callback function _hash_free_fn_t freeFp; // hash node free callback function
_equal_fn_t equalFp; // equal function _equal_fn_t equalFp; // equal function
_hash_before_fn_t callbackFp; // function invoked before return the value to caller _hash_before_fn_t callbackFp; // function invoked before return the value to caller
SRWLatch lock; // read-write spin lock SRWLatch lock; // read-write spin lock
SHashLockTypeE type; // lock type SHashLockTypeE type; // lock type
bool enableUpdate; // enable update bool enableUpdate; // enable update
SArray *pMemBlock; // memory block allocated for SHashEntry SArray *pMemBlock; // memory block allocated for SHashEntry
} SHashObj; } SHashObj;
/** /**
...@@ -128,7 +128,6 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *da ...@@ -128,7 +128,6 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *da
int32_t taosHashPutExt(SHashObj *pHashObj, const void *key, size_t keyLen, void *data, size_t size, bool *newAdded); int32_t taosHashPutExt(SHashObj *pHashObj, const void *key, size_t keyLen, void *data, size_t size, bool *newAdded);
/** /**
* return the payload data with the specified key * return the payload data with the specified key
* *
...@@ -147,7 +146,7 @@ void *taosHashGet(SHashObj *pHashObj, const void *key, size_t keyLen); ...@@ -147,7 +146,7 @@ void *taosHashGet(SHashObj *pHashObj, const void *key, size_t keyLen);
* @param destBuf * @param destBuf
* @return * @return
*/ */
void *taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void* destBuf); void *taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void *destBuf);
/** /**
* Clone the result to interval allocated buffer * Clone the result to interval allocated buffer
...@@ -157,7 +156,7 @@ void *taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void* ...@@ -157,7 +156,7 @@ void *taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void*
* @param destBuf * @param destBuf
* @return * @return
*/ */
void* taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, void (*fp)(void *), void** d, size_t *sz); void *taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, void (*fp)(void *), void **d, size_t *sz);
/** /**
* remove item with the specified key * remove item with the specified key
...@@ -206,15 +205,14 @@ void *taosHashIterate(SHashObj *pHashObj, void *p); ...@@ -206,15 +205,14 @@ void *taosHashIterate(SHashObj *pHashObj, void *p);
* @param pHashObj * @param pHashObj
* @param p * @param p
*/ */
void taosHashCancelIterate(SHashObj *pHashObj, void *p); void taosHashCancelIterate(SHashObj *pHashObj, void *p);
/** /**
* Get the corresponding key information for a given data in hash table * Get the corresponding key information for a given data in hash table
* @param data * @param data
* @return * @return
*/ */
int32_t taosHashGetKey(void *data, void** key, size_t* keyLen); int32_t taosHashGetKey(void *data, void **key, size_t *keyLen);
/** /**
* Get the corresponding key information for a given data in hash table, using memcpy * Get the corresponding key information for a given data in hash table, using memcpy
...@@ -222,13 +220,13 @@ int32_t taosHashGetKey(void *data, void** key, size_t* keyLen); ...@@ -222,13 +220,13 @@ int32_t taosHashGetKey(void *data, void** key, size_t* keyLen);
* @param dst * @param dst
* @return * @return
*/ */
static FORCE_INLINE int32_t taosHashCopyKey(void *data, void* dst) { static FORCE_INLINE int32_t taosHashCopyKey(void *data, void *dst) {
if (NULL == data || NULL == dst) { if (NULL == data || NULL == dst) {
return -1; return -1;
} }
SHashNode * node = GET_HASH_PNODE(data); SHashNode *node = GET_HASH_PNODE(data);
void* key = GET_HASH_NODE_KEY(node); void *key = GET_HASH_NODE_KEY(node);
memcpy(dst, key, node->keyLen); memcpy(dst, key, node->keyLen);
return 0; return 0;
...@@ -249,7 +247,7 @@ int32_t taosHashGetDataLen(void *data); ...@@ -249,7 +247,7 @@ int32_t taosHashGetDataLen(void *data);
* @param keyLen * @param keyLen
* @return * @return
*/ */
void* taosHashAcquire(SHashObj *pHashObj, const void *key, size_t keyLen); void *taosHashAcquire(SHashObj *pHashObj, const void *key, size_t keyLen);
/** /**
* release the prevous acquired obj * release the prevous acquired obj
...@@ -262,9 +260,8 @@ void taosHashRelease(SHashObj *pHashObj, void *p); ...@@ -262,9 +260,8 @@ void taosHashRelease(SHashObj *pHashObj, void *p);
void taosHashSetEqualFp(SHashObj *pHashObj, _equal_fn_t fp); void taosHashSetEqualFp(SHashObj *pHashObj, _equal_fn_t fp);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif // TDENGINE_HASH_H #endif // _TD_UTIL_HASH_H_
...@@ -12,19 +12,20 @@ ...@@ -12,19 +12,20 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_HEAP_H
#define TDENGINE_HEAP_H #ifndef _TD_UTIL_HEAP_H_
#define _TD_UTIL_HEAP_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "os.h"
struct HeapNode; struct HeapNode;
/* Return non-zero if a < b. */ /* Return non-zero if a < b. */
typedef int (*HeapCompareFn)(const struct HeapNode* a, const struct HeapNode* b); typedef int32_t (*HeapCompareFn)(const struct HeapNode* a, const struct HeapNode* b);
typedef struct HeapNode { typedef struct HeapNode {
struct HeapNode* left; struct HeapNode* left;
...@@ -38,15 +39,14 @@ typedef struct HeapNode { ...@@ -38,15 +39,14 @@ typedef struct HeapNode {
* *
*/ */
typedef struct { typedef struct {
HeapNode* min; HeapNode* min;
size_t nelts; size_t nelts;
HeapCompareFn compFn; HeapCompareFn compFn;
} Heap; } Heap;
Heap* heapCreate(HeapCompareFn fn); Heap* heapCreate(HeapCompareFn fn);
void heapDestroy(Heap *heap); void heapDestroy(Heap* heap);
HeapNode* heapMin(const Heap* heap); HeapNode* heapMin(const Heap* heap);
...@@ -56,10 +56,10 @@ void heapRemove(Heap* heap, struct HeapNode* node); ...@@ -56,10 +56,10 @@ void heapRemove(Heap* heap, struct HeapNode* node);
void heapDequeue(Heap* heap); void heapDequeue(Heap* heap);
size_t heapSize(Heap *heap); size_t heapSize(Heap* heap);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif // TDENGINE_HASH_H #endif /*_TD_UTIL_HEAP_H_*/
...@@ -13,31 +13,34 @@ ...@@ -13,31 +13,34 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_IDPOOL_H #ifndef _TD_UTIL_IDPOOL_H_
#define _TD_UTIL_IDPOOL_H #define _TD_UTIL_IDPOOL_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
void *taosInitIdPool(int maxId); typedef struct {
int32_t maxId;
int taosUpdateIdPool(void *handle, int maxId); int32_t numOfFree;
int32_t freeSlot;
int taosIdPoolMaxSize(void *handle); bool *freeList;
pthread_mutex_t mutex;
int taosAllocateId(void *handle); } id_pool_t;
void taosFreeId(void *handle, int id); void *taosInitIdPool(int32_t maxId);
int32_t taosUpdateIdPool(id_pool_t *handle, int32_t maxId);
void taosIdPoolCleanUp(void *handle); int32_t taosIdPoolMaxSize(id_pool_t *handle);
int32_t taosAllocateId(id_pool_t *handle);
int taosIdPoolNumOfUsed(void *handle); void taosFreeId(id_pool_t *handle, int32_t id);
void taosIdPoolCleanUp(id_pool_t *handle);
bool taosIdPoolMarkStatus(void *handle, int id); int32_t taosIdPoolNumOfUsed(id_pool_t *handle);
bool taosIdPoolMarkStatus(id_pool_t *handle, int32_t id);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /*_TD_UTIL_IDPOOL_H*/ #endif /*_TD_UTIL_IDPOOL_H_*/
...@@ -16,18 +16,18 @@ ...@@ -16,18 +16,18 @@
#ifndef _TD_UTIL_JSON_H_ #ifndef _TD_UTIL_JSON_H_
#define _TD_UTIL_JSON_H_ #define _TD_UTIL_JSON_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "os.h"
typedef void SJson; typedef void SJson;
SJson* tjsonCreateObject(); SJson* tjsonCreateObject();
void tjsonDelete(SJson* pJson); void tjsonDelete(SJson* pJson);
SJson* tjsonAddArrayToObject(SJson* pJson, const char* pName); SJson* tjsonAddArrayToObject(SJson* pJson, const char* pName);
int32_t tjsonAddIntegerToObject(SJson* pJson, const char* pName, const uint64_t number); int32_t tjsonAddIntegerToObject(SJson* pJson, const char* pName, const uint64_t number);
int32_t tjsonAddDoubleToObject(SJson* pJson, const char* pName, const double number); int32_t tjsonAddDoubleToObject(SJson* pJson, const char* pName, const double number);
int32_t tjsonAddBoolToObject(SJson* pJson, const char* pName, const bool boolean); int32_t tjsonAddBoolToObject(SJson* pJson, const char* pName, const bool boolean);
...@@ -35,7 +35,7 @@ int32_t tjsonAddStringToObject(SJson* pJson, const char* pName, const char* pVal ...@@ -35,7 +35,7 @@ int32_t tjsonAddStringToObject(SJson* pJson, const char* pName, const char* pVal
int32_t tjsonAddItemToObject(SJson* pJson, const char* pName, SJson* pItem); int32_t tjsonAddItemToObject(SJson* pJson, const char* pName, SJson* pItem);
int32_t tjsonAddItemToArray(SJson* pJson, SJson* pItem); int32_t tjsonAddItemToArray(SJson* pJson, SJson* pItem);
SJson* tjsonGetObjectItem(const SJson* pJson, const char* pName); SJson* tjsonGetObjectItem(const SJson* pJson, const char* pName);
int32_t tjsonGetStringValue(const SJson* pJson, const char* pName, char* pVal); int32_t tjsonGetStringValue(const SJson* pJson, const char* pName, char* pVal);
int32_t tjsonDupStringValue(const SJson* pJson, const char* pName, char** pVal); int32_t tjsonDupStringValue(const SJson* pJson, const char* pName, char** pVal);
int32_t tjsonGetBigIntValue(const SJson* pJson, const char* pName, int64_t* pVal); int32_t tjsonGetBigIntValue(const SJson* pJson, const char* pName, int64_t* pVal);
...@@ -48,7 +48,7 @@ int32_t tjsonGetBoolValue(const SJson* pJson, const char* pName, bool* pVal); ...@@ -48,7 +48,7 @@ int32_t tjsonGetBoolValue(const SJson* pJson, const char* pName, bool* pVal);
int32_t tjsonGetDoubleValue(const SJson* pJson, const char* pName, double* pVal); int32_t tjsonGetDoubleValue(const SJson* pJson, const char* pName, double* pVal);
int32_t tjsonGetArraySize(const SJson* pJson); int32_t tjsonGetArraySize(const SJson* pJson);
SJson* tjsonGetArrayItem(const SJson* pJson, int32_t index); SJson* tjsonGetArrayItem(const SJson* pJson, int32_t index);
typedef int32_t (*FToJson)(const void* pObj, SJson* pJson); typedef int32_t (*FToJson)(const void* pObj, SJson* pJson);
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_UTIL_KEY_H
#define _TD_UTIL_KEY_H
#ifdef __cplusplus
extern "C" {
#endif
unsigned char *base64_decode(const char *value, int inlen, int *outlen);
char * base64_encode(const unsigned char *value, int vlen);
char * taosDesEncode(int64_t key, char *src, int len);
char * taosDesDecode(int64_t key, char *src, int len);
#ifdef __cplusplus
}
#endif
#endif /*_TD_UTIL_KEY_H*/
\ No newline at end of file
...@@ -12,8 +12,11 @@ ...@@ -12,8 +12,11 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_LIST_H
#define _TD_UTIL_LIST_H #ifndef _TD_UTIL_LIST_H_
#define _TD_UTIL_LIST_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -28,12 +31,12 @@ extern "C" { ...@@ -28,12 +31,12 @@ extern "C" {
#define TD_SLIST(TYPE) \ #define TD_SLIST(TYPE) \
struct { \ struct { \
struct TYPE *sl_head_; \ struct TYPE *sl_head_; \
int sl_neles_; \ int32_t sl_neles_; \
} }
#define TD_SLIST_HEAD(sl) ((sl)->sl_head_) #define TD_SLIST_HEAD(sl) ((sl)->sl_head_)
#define TD_SLIST_NELES(sl) ((sl)->sl_neles_) #define TD_SLIST_NELES(sl) ((sl)->sl_neles_)
#define TD_SLIST_NODE_NEXT(sln) ((sln)->sl_next_) #define TD_SLIST_NODE_NEXT(sln) ((sln)->sl_next_)
#define TD_SLIST_NODE_NEXT_WITH_FIELD(sln, field) ((sln)->field.sl_next_) #define TD_SLIST_NODE_NEXT_WITH_FIELD(sln, field) ((sln)->field.sl_next_)
#define TD_SLIST_INIT(sl) \ #define TD_SLIST_INIT(sl) \
...@@ -79,16 +82,16 @@ extern "C" { ...@@ -79,16 +82,16 @@ extern "C" {
struct { \ struct { \
struct TYPE *dl_head_; \ struct TYPE *dl_head_; \
struct TYPE *dl_tail_; \ struct TYPE *dl_tail_; \
int dl_neles_; \ int32_t dl_neles_; \
} }
#define TD_DLIST_NODE_PREV(dln) ((dln)->dl_prev_) #define TD_DLIST_NODE_PREV(dln) ((dln)->dl_prev_)
#define TD_DLIST_NODE_NEXT(dln) ((dln)->dl_next_) #define TD_DLIST_NODE_NEXT(dln) ((dln)->dl_next_)
#define TD_DLIST_NODE_PREV_WITH_FIELD(dln, field) ((dln)->field.dl_prev_) #define TD_DLIST_NODE_PREV_WITH_FIELD(dln, field) ((dln)->field.dl_prev_)
#define TD_DLIST_NODE_NEXT_WITH_FIELD(dln, field) ((dln)->field.dl_next_) #define TD_DLIST_NODE_NEXT_WITH_FIELD(dln, field) ((dln)->field.dl_next_)
#define TD_DLIST_HEAD(dl) ((dl)->dl_head_) #define TD_DLIST_HEAD(dl) ((dl)->dl_head_)
#define TD_DLIST_TAIL(dl) ((dl)->dl_tail_) #define TD_DLIST_TAIL(dl) ((dl)->dl_tail_)
#define TD_DLIST_NELES(dl) ((dl)->dl_neles_) #define TD_DLIST_NELES(dl) ((dl)->dl_neles_)
#define TD_DLIST_INIT(dl) \ #define TD_DLIST_INIT(dl) \
do { \ do { \
...@@ -200,29 +203,29 @@ typedef struct SListNode { ...@@ -200,29 +203,29 @@ typedef struct SListNode {
typedef struct { typedef struct {
TD_DLIST(SListNode); TD_DLIST(SListNode);
int eleSize; int32_t eleSize;
} SList; } SList;
typedef struct { typedef struct {
SListNode * next; SListNode *next;
TD_LIST_DIRECTION_T direction; TD_LIST_DIRECTION_T direction;
} SListIter; } SListIter;
#define listHead(l) TD_DLIST_HEAD(l) #define listHead(l) TD_DLIST_HEAD(l)
#define listTail(l) TD_DLIST_TAIL(l) #define listTail(l) TD_DLIST_TAIL(l)
#define listNEles(l) TD_DLIST_NELES(l) #define listNEles(l) TD_DLIST_NELES(l)
#define listEleSize(l) ((l)->eleSize) #define listEleSize(l) ((l)->eleSize)
#define isListEmpty(l) (TD_DLIST_NELES(l) == 0) #define isListEmpty(l) (TD_DLIST_NELES(l) == 0)
#define listNodeFree(n) free(n) #define listNodeFree(n) free(n)
void tdListInit(SList *list, int eleSize); void tdListInit(SList *list, int32_t eleSize);
void tdListEmpty(SList *list); void tdListEmpty(SList *list);
SList * tdListNew(int eleSize); SList *tdListNew(int32_t eleSize);
void * tdListFree(SList *list); void *tdListFree(SList *list);
void tdListPrependNode(SList *list, SListNode *node); void tdListPrependNode(SList *list, SListNode *node);
void tdListAppendNode(SList *list, SListNode *node); void tdListAppendNode(SList *list, SListNode *node);
int tdListPrepend(SList *list, void *data); int32_t tdListPrepend(SList *list, void *data);
int tdListAppend(SList *list, void *data); int32_t tdListAppend(SList *list, void *data);
SListNode *tdListPopHead(SList *list); SListNode *tdListPopHead(SList *list);
SListNode *tdListPopTail(SList *list); SListNode *tdListPopTail(SList *list);
SListNode *tdListGetHead(SList *list); SListNode *tdListGetHead(SList *list);
...@@ -239,4 +242,4 @@ SListNode *tdListNext(SListIter *pIter); ...@@ -239,4 +242,4 @@ SListNode *tdListNext(SListIter *pIter);
} }
#endif #endif
#endif /*_TD_UTIL_LIST_H*/ #endif /*_TD_UTIL_LIST_H_*/
\ No newline at end of file \ No newline at end of file
...@@ -12,8 +12,9 @@ ...@@ -12,8 +12,9 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_LOCK_FREE_H
#define _TD_UTIL_LOCK_FREE_H #ifndef _TD_UTIL_LOCK_FREE_H_
#define _TD_UTIL_LOCK_FREE_H_
#include "os.h" #include "os.h"
...@@ -22,7 +23,7 @@ extern "C" { ...@@ -22,7 +23,7 @@ extern "C" {
#endif #endif
// reference counting // reference counting
typedef void (*_ref_fn_t)(const void* pObj); typedef void (*_ref_fn_t)(const void *pObj);
#define T_REF_DECLARE() \ #define T_REF_DECLARE() \
struct { \ struct { \
...@@ -67,8 +68,6 @@ typedef void (*_ref_fn_t)(const void* pObj); ...@@ -67,8 +68,6 @@ typedef void (*_ref_fn_t)(const void* pObj);
#define T_REF_VAL_GET(x) (x)->_ref.val #define T_REF_VAL_GET(x) (x)->_ref.val
// single writer multiple reader lock // single writer multiple reader lock
typedef volatile int32_t SRWLatch; typedef volatile int32_t SRWLatch;
...@@ -78,35 +77,33 @@ void taosWUnLockLatch(SRWLatch *pLatch); ...@@ -78,35 +77,33 @@ void taosWUnLockLatch(SRWLatch *pLatch);
void taosRLockLatch(SRWLatch *pLatch); void taosRLockLatch(SRWLatch *pLatch);
void taosRUnLockLatch(SRWLatch *pLatch); void taosRUnLockLatch(SRWLatch *pLatch);
// copy on read // copy on read
#define taosCorBeginRead(x) for (uint32_t i_ = 1; 1; ++i_) { \ #define taosCorBeginRead(x) \
for (uint32_t i_ = 1; 1; ++i_) { \
int32_t old_ = atomic_add_fetch_32((x), 0); \ int32_t old_ = atomic_add_fetch_32((x), 0); \
if (old_ & 0x00000001) { \ if (old_ & 0x00000001) { \
if (i_ % 1000 == 0) { \ if (i_ % 1000 == 0) { \
sched_yield(); \ sched_yield(); \
} \ } \
continue; \ continue; \
} }
#define taosCorEndRead(x) \ #define taosCorEndRead(x) \
if (atomic_add_fetch_32((x), 0) == old_) { \ if (atomic_add_fetch_32((x), 0) == old_) { \
break; \ break; \
} \ } \
} }
#define taosCorBeginWrite(x) taosCorBeginRead(x) \ #define taosCorBeginWrite(x) \
if (atomic_val_compare_exchange_32((x), old_, old_ + 1) != old_) { \ taosCorBeginRead(x) if (atomic_val_compare_exchange_32((x), old_, old_ + 1) != old_) { continue; }
continue; \
}
#define taosCorEndWrite(x) atomic_add_fetch_32((x), 1); \ #define taosCorEndWrite(x) \
break; \ atomic_add_fetch_32((x), 1); \
break; \
} }
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /*_TD_UTIL_LOCK_FREE_H*/ #endif /*_TD_UTIL_LOCK_FREE_H_*/
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_LOG_H #ifndef _TD_UTIL_LOG_H_
#define _TD_UTIL_LOG_H #define _TD_UTIL_LOG_H_
#include "os.h" #include "os.h"
...@@ -84,4 +84,4 @@ extern int8_t tscEmbeddedInUtil; ...@@ -84,4 +84,4 @@ extern int8_t tscEmbeddedInUtil;
} }
#endif #endif
#endif /*_TD_UTIL_LOG_H*/ #endif /*_TD_UTIL_LOG_H_*/
...@@ -13,14 +13,16 @@ ...@@ -13,14 +13,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_LOSERTREE_H #ifndef _TD_UTIL_LOSERTREE_H_
#define _TD_UTIL_LOSERTREE_H #define _TD_UTIL_LOSERTREE_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
typedef int (*__merge_compare_fn_t)(const void *, const void *, void *param); typedef int32_t (*__merge_compare_fn_t)(const void *, const void *, void *param);
typedef struct STreeNode { typedef struct STreeNode {
int32_t index; int32_t index;
...@@ -31,16 +33,17 @@ typedef struct SMultiwayMergeTreeInfo { ...@@ -31,16 +33,17 @@ typedef struct SMultiwayMergeTreeInfo {
int32_t numOfSources; int32_t numOfSources;
int32_t totalSources; int32_t totalSources;
__merge_compare_fn_t comparFn; __merge_compare_fn_t comparFn;
void * param; void *param;
struct STreeNode *pNode; struct STreeNode *pNode;
} SMultiwayMergeTreeInfo; } SMultiwayMergeTreeInfo;
#define tMergeTreeGetChosenIndex(t_) ((t_)->pNode[0].index) #define tMergeTreeGetChosenIndex(t_) ((t_)->pNode[0].index)
#define tMergeTreeGetAdjustIndex(t_) (tMergeTreeGetChosenIndex(t_) + (t_)->numOfSources) #define tMergeTreeGetAdjustIndex(t_) (tMergeTreeGetChosenIndex(t_) + (t_)->numOfSources)
int32_t tMergeTreeCreate(SMultiwayMergeTreeInfo **pTree, uint32_t numOfEntries, void *param, __merge_compare_fn_t compareFn); int32_t tMergeTreeCreate(SMultiwayMergeTreeInfo **pTree, uint32_t numOfEntries, void *param,
__merge_compare_fn_t compareFn);
void tMergeTreeDestroy(SMultiwayMergeTreeInfo* pTree); void tMergeTreeDestroy(SMultiwayMergeTreeInfo *pTree);
void tMergeTreeAdjust(SMultiwayMergeTreeInfo *pTree, int32_t idx); void tMergeTreeAdjust(SMultiwayMergeTreeInfo *pTree, int32_t idx);
...@@ -52,4 +55,4 @@ void tMergeTreePrint(const SMultiwayMergeTreeInfo *pTree); ...@@ -52,4 +55,4 @@ void tMergeTreePrint(const SMultiwayMergeTreeInfo *pTree);
} }
#endif #endif
#endif /*_TD_UTIL_LOSERTREE_H*/ #endif /*_TD_UTIL_LOSERTREE_H_*/
...@@ -24,7 +24,7 @@ extern "C" { ...@@ -24,7 +24,7 @@ extern "C" {
// Module init/clear MACRO definitions // Module init/clear MACRO definitions
#define TD_MOD_UNINITIALIZED 0 #define TD_MOD_UNINITIALIZED 0
#define TD_MOD_INITIALIZED 1 #define TD_MOD_INITIALIZED 1
typedef int8_t td_mode_flag_t; typedef int8_t td_mode_flag_t;
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_MALLOCATOR_H_ #ifndef _TD_UTIL_MALLOCATOR_H_
#define _TD_MALLOCATOR_H_ #define _TD_UTIL_MALLOCATOR_H_
#include "os.h" #include "os.h"
...@@ -29,10 +29,10 @@ extern "C" { ...@@ -29,10 +29,10 @@ extern "C" {
void (*free_)(struct TYPE *, void *ptr); \ void (*free_)(struct TYPE *, void *ptr); \
} }
#define TD_MA_MALLOC_FUNC(TMA) (TMA)->malloc_ #define TD_MA_MALLOC_FUNC(TMA) (TMA)->malloc_
#define TD_MA_FREE_FUNC(TMA) (TMA)->free_ #define TD_MA_FREE_FUNC(TMA) (TMA)->free_
#define TD_MA_MALLOC(TMA, SIZE) (*((TMA)->malloc_))(TMA, (SIZE)) #define TD_MA_MALLOC(TMA, SIZE) (*((TMA)->malloc_))(TMA, (SIZE))
#define TD_MA_FREE(TMA, PTR) (*((TMA)->free_))(TMA, (PTR)) #define TD_MA_FREE(TMA, PTR) (*((TMA)->free_))(TMA, (PTR))
typedef struct SMemAllocator { typedef struct SMemAllocator {
void *impl; void *impl;
...@@ -40,7 +40,7 @@ typedef struct SMemAllocator { ...@@ -40,7 +40,7 @@ typedef struct SMemAllocator {
} SMemAllocator; } SMemAllocator;
#define tMalloc(pMA, SIZE) TD_MA_MALLOC(PMA, SIZE) #define tMalloc(pMA, SIZE) TD_MA_MALLOC(PMA, SIZE)
#define tFree(pMA, PTR) TD_MA_FREE(PMA, PTR) #define tFree(pMA, PTR) TD_MA_FREE(PMA, PTR)
typedef struct SMemAllocatorFactory { typedef struct SMemAllocatorFactory {
void *impl; void *impl;
...@@ -52,4 +52,4 @@ typedef struct SMemAllocatorFactory { ...@@ -52,4 +52,4 @@ typedef struct SMemAllocatorFactory {
} }
#endif #endif
#endif /*_TD_MALLOCATOR_H_*/ #endif /*_TD_UTIL_MALLOCATOR_H_*/
\ No newline at end of file \ No newline at end of file
...@@ -25,6 +25,12 @@ ...@@ -25,6 +25,12 @@
#ifndef _TD_UTIL_MD5_H #ifndef _TD_UTIL_MD5_H
#define _TD_UTIL_MD5_H #define _TD_UTIL_MD5_H
#include "os.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct { typedef struct {
uint32_t i[2]; /* number of _bits_ handled mod 2^64 */ uint32_t i[2]; /* number of _bits_ handled mod 2^64 */
uint32_t buf[4]; /* scratch buffer */ uint32_t buf[4]; /* scratch buffer */
...@@ -33,7 +39,11 @@ typedef struct { ...@@ -33,7 +39,11 @@ typedef struct {
} T_MD5_CTX; } T_MD5_CTX;
void tMD5Init(T_MD5_CTX *mdContext); void tMD5Init(T_MD5_CTX *mdContext);
void tMD5Update(T_MD5_CTX *mdContext, uint8_t *inBuf, unsigned int inLen); void tMD5Update(T_MD5_CTX *mdContext, uint8_t *inBuf, uint32_t inLen);
void tMD5Final(T_MD5_CTX *mdContext); void tMD5Final(T_MD5_CTX *mdContext);
#ifdef __cplusplus
}
#endif
#endif /*_TD_UTIL_MD5_H*/ #endif /*_TD_UTIL_MD5_H*/
...@@ -12,25 +12,24 @@ ...@@ -12,25 +12,24 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_MEMPOOL_H #ifndef _TD_UTIL_MEMPOOL_H_
#define _TD_UTIL_MEMPOOL_H #define _TD_UTIL_MEMPOOL_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#define mpool_h void * typedef void *mpool_h;
mpool_h taosMemPoolInit(int maxNum, int blockSize);
char *taosMemPoolMalloc(mpool_h handle);
void taosMemPoolFree(mpool_h handle, char *p);
void taosMemPoolCleanUp(mpool_h handle); mpool_h taosMemPoolInit(int32_t maxNum, int32_t blockSize);
char *taosMemPoolMalloc(mpool_h handle);
void taosMemPoolFree(mpool_h handle, char *p);
void taosMemPoolCleanUp(mpool_h handle);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /*_TD_UTIL_MEMPOOL_H*/ #endif /*_TD_UTIL_MEMPOOL_H_*/
...@@ -13,23 +13,22 @@ ...@@ -13,23 +13,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_TPAGEDBUF_H #ifndef _TD_UTIL_PAGEDBUF_H_
#define TDENGINE_TPAGEDBUF_H #define _TD_UTIL_PAGEDBUF_H_
#include "thash.h"
#include "tlist.h"
#include "tlockfree.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "tlist.h" typedef struct SArray* SIDList;
#include "thash.h" typedef struct SPageInfo SPageInfo;
#include "os.h"
#include "tlockfree.h"
typedef struct SArray* SIDList;
typedef struct SPageInfo SPageInfo;
typedef struct SDiskbasedBuf SDiskbasedBuf; typedef struct SDiskbasedBuf SDiskbasedBuf;
#define DEFAULT_INTERN_BUF_PAGE_SIZE (1024L) // in bytes #define DEFAULT_INTERN_BUF_PAGE_SIZE (1024L) // in bytes
typedef struct SFilePage { typedef struct SFilePage {
int32_t num; int32_t num;
...@@ -193,4 +192,4 @@ void dBufPrintStatis(const SDiskbasedBuf* pBuf); ...@@ -193,4 +192,4 @@ void dBufPrintStatis(const SDiskbasedBuf* pBuf);
} }
#endif #endif
#endif // TDENGINE_TPAGEDBUF_H #endif // _TD_UTIL_PAGEDBUF_H_
...@@ -13,8 +13,9 @@ ...@@ -13,8 +13,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_QUEUE_H #ifndef _TD_UTIL_QUEUE_H_
#define _TD_UTIL_QUEUE_H #define _TD_UTIL_QUEUE_H_
#include "os.h" #include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
...@@ -47,7 +48,7 @@ typedef void (*FItems)(void *ahandle, STaosQall *qall, int32_t numOfItems); ...@@ -47,7 +48,7 @@ typedef void (*FItems)(void *ahandle, STaosQall *qall, int32_t numOfItems);
STaosQueue *taosOpenQueue(); STaosQueue *taosOpenQueue();
void taosCloseQueue(STaosQueue *queue); void taosCloseQueue(STaosQueue *queue);
void taosSetQueueFp(STaosQueue *queue, FItem itemFp, FItems itemsFp); void taosSetQueueFp(STaosQueue *queue, FItem itemFp, FItems itemsFp);
void * taosAllocateQitem(int32_t size); void *taosAllocateQitem(int32_t size);
void taosFreeQitem(void *pItem); void taosFreeQitem(void *pItem);
int32_t taosWriteQitem(STaosQueue *queue, void *pItem); int32_t taosWriteQitem(STaosQueue *queue, void *pItem);
int32_t taosReadQitem(STaosQueue *queue, void **ppItem); int32_t taosReadQitem(STaosQueue *queue, void **ppItem);
...@@ -80,4 +81,4 @@ int32_t taosGetQsetItemsNumber(STaosQset *qset); ...@@ -80,4 +81,4 @@ int32_t taosGetQsetItemsNumber(STaosQset *qset);
} }
#endif #endif
#endif /*_TD_UTIL_QUEUE_H*/ #endif /*_TD_UTIL_QUEUE_H_*/
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_REF_H #ifndef _TD_UTIL_REF_H_
#define _TD_UTIL_REF_H #define _TD_UTIL_REF_H_
#include "os.h" #include "os.h"
...@@ -25,45 +25,45 @@ extern "C" { ...@@ -25,45 +25,45 @@ extern "C" {
// open a reference set, max is the mod used by hash, fp is the pointer to free resource function // open a reference set, max is the mod used by hash, fp is the pointer to free resource function
// return rsetId which will be used by other APIs. On error, -1 is returned, and terrno is set appropriately // return rsetId which will be used by other APIs. On error, -1 is returned, and terrno is set appropriately
int taosOpenRef(int max, void (*fp)(void *)); int32_t taosOpenRef(int32_t max, void (*fp)(void *));
// close the reference set, refId is the return value by taosOpenRef // close the reference set, refId is the return value by taosOpenRef
// return 0 if success. On error, -1 is returned, and terrno is set appropriately // return 0 if success. On error, -1 is returned, and terrno is set appropriately
int taosCloseRef(int refId); int32_t taosCloseRef(int32_t refId);
// add ref, p is the pointer to resource or pointer ID // add ref, p is the pointer to resource or pointer ID
// return Reference ID(rid) allocated. On error, -1 is returned, and terrno is set appropriately // return Reference ID(rid) allocated. On error, -1 is returned, and terrno is set appropriately
int64_t taosAddRef(int refId, void *p); int64_t taosAddRef(int32_t refId, void *p);
// remove ref, rid is the reference ID returned by taosAddRef // remove ref, rid is the reference ID returned by taosAddRef
// return 0 if success. On error, -1 is returned, and terrno is set appropriately // return 0 if success. On error, -1 is returned, and terrno is set appropriately
int taosRemoveRef(int rsetId, int64_t rid); int32_t taosRemoveRef(int32_t rsetId, int64_t rid);
// acquire ref, rid is the reference ID returned by taosAddRef // acquire ref, rid is the reference ID returned by taosAddRef
// return the resource p. On error, NULL is returned, and terrno is set appropriately // return the resource p. On error, NULL is returned, and terrno is set appropriately
void *taosAcquireRef(int rsetId, int64_t rid); void *taosAcquireRef(int32_t rsetId, int64_t rid);
// release ref, rid is the reference ID returned by taosAddRef // release ref, rid is the reference ID returned by taosAddRef
// return 0 if success. On error, -1 is returned, and terrno is set appropriately // return 0 if success. On error, -1 is returned, and terrno is set appropriately
int taosReleaseRef(int rsetId, int64_t rid); int32_t taosReleaseRef(int32_t rsetId, int64_t rid);
// return the first reference if rid is 0, otherwise return the next after current reference. // return the first reference if rid is 0, otherwise return the next after current reference.
// if return value is NULL, it means list is over(if terrno is set, it means error happens) // if return value is NULL, it means list is over(if terrno is set, it means error happens)
void *taosIterateRef(int rsetId, int64_t rid); void *taosIterateRef(int32_t rsetId, int64_t rid);
// return the number of references in system // return the number of references in system
int taosListRef(); int32_t taosListRef();
#define RID_VALID(x) ((x) > 0) #define RID_VALID(x) ((x) > 0)
/* sample code to iterate the refs /* sample code to iterate the refs
void demoIterateRefs(int rsetId) { void demoIterateRefs(int32_t rsetId) {
void *p = taosIterateRef(refId, 0); void *p = taosIterateRef(refId, 0);
while (p) { while (p) {
// process P // process P
// get the rid from p // get the rid from p
p = taosIterateRef(rsetId, rid); p = taosIterateRef(rsetId, rid);
...@@ -76,4 +76,4 @@ void demoIterateRefs(int rsetId) { ...@@ -76,4 +76,4 @@ void demoIterateRefs(int rsetId) {
} }
#endif #endif
#endif /*_TD_UTIL_REF_H*/ #endif /*_TD_UTIL_REF_H_*/
...@@ -13,8 +13,10 @@ ...@@ -13,8 +13,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_SCHED_H #ifndef _TD_UTIL_SCHED_H_
#define _TD_UTIL_SCHED_H #define _TD_UTIL_SCHED_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -36,7 +38,7 @@ typedef struct SSchedMsg { ...@@ -36,7 +38,7 @@ typedef struct SSchedMsg {
* @param label the label of the queue * @param label the label of the queue
* @return the created queue scheduler * @return the created queue scheduler
*/ */
void *taosInitScheduler(int capacity, int numOfThreads, const char *label); void *taosInitScheduler(int32_t capacity, int32_t numOfThreads, const char *label);
/** /**
* Create a thread-safe ring-buffer based task queue and return the instance. * Create a thread-safe ring-buffer based task queue and return the instance.
...@@ -47,7 +49,7 @@ void *taosInitScheduler(int capacity, int numOfThreads, const char *label); ...@@ -47,7 +49,7 @@ void *taosInitScheduler(int capacity, int numOfThreads, const char *label);
* @param tmrCtrl the timer controller, tmr_ctrl_t* * @param tmrCtrl the timer controller, tmr_ctrl_t*
* @return the created queue scheduler * @return the created queue scheduler
*/ */
void *taosInitSchedulerWithInfo(int capacity, int numOfThreads, const char *label, void *tmrCtrl); void *taosInitSchedulerWithInfo(int32_t capacity, int32_t numOfThreads, const char *label, void *tmrCtrl);
/** /**
* Clean up the queue scheduler instance and free the memory. * Clean up the queue scheduler instance and free the memory.
...@@ -68,4 +70,4 @@ void taosScheduleTask(void *queueScheduler, SSchedMsg *pMsg); ...@@ -68,4 +70,4 @@ void taosScheduleTask(void *queueScheduler, SSchedMsg *pMsg);
} }
#endif #endif
#endif /*_TD_UTIL_SCHED_H*/ #endif /*_TD_UTIL_SCHED_H_*/
...@@ -16,22 +16,22 @@ ...@@ -16,22 +16,22 @@
#ifndef _TD_UTIL_SKILIST_H #ifndef _TD_UTIL_SKILIST_H
#define _TD_UTIL_SKILIST_H #define _TD_UTIL_SKILIST_H
#ifdef __cplusplus
extern "C" {
#endif
#include "os.h" #include "os.h"
#include "taos.h" #include "taos.h"
#include "tarray.h" #include "tarray.h"
#include "tfunctional.h" #include "tfunctional.h"
#define MAX_SKIP_LIST_LEVEL 15 #ifdef __cplusplus
extern "C" {
#endif
#define MAX_SKIP_LIST_LEVEL 15
#define SKIP_LIST_RECORD_PERFORMANCE 0 #define SKIP_LIST_RECORD_PERFORMANCE 0
// For key property setting // For key property setting
#define SL_ALLOW_DUP_KEY (uint8_t)0x0 // Allow duplicate key exists (for tag index usage) #define SL_ALLOW_DUP_KEY (uint8_t)0x0 // Allow duplicate key exists (for tag index usage)
#define SL_DISCARD_DUP_KEY (uint8_t)0x1 // Discard duplicate key (for data update=0 case) #define SL_DISCARD_DUP_KEY (uint8_t)0x1 // Discard duplicate key (for data update=0 case)
#define SL_UPDATE_DUP_KEY (uint8_t)0x2 // Update duplicate key by remove/insert (for data update!=0 case) #define SL_UPDATE_DUP_KEY (uint8_t)0x2 // Update duplicate key by remove/insert (for data update!=0 case)
// For thread safety setting // For thread safety setting
#define SL_THREAD_SAFE (uint8_t)0x4 #define SL_THREAD_SAFE (uint8_t)0x4
...@@ -39,17 +39,17 @@ extern "C" { ...@@ -39,17 +39,17 @@ extern "C" {
typedef char *SSkipListKey; typedef char *SSkipListKey;
typedef char *(*__sl_key_fn_t)(const void *); typedef char *(*__sl_key_fn_t)(const void *);
typedef void (*sl_patch_row_fn_t)(void * pDst, const void * pSrc); typedef void (*sl_patch_row_fn_t)(void *pDst, const void *pSrc);
typedef void* (*iter_next_fn_t)(void *iter); typedef void *(*iter_next_fn_t)(void *iter);
typedef struct SSkipListNode { typedef struct SSkipListNode {
uint8_t level; uint8_t level;
void * pData; void *pData;
struct SSkipListNode *forwards[]; struct SSkipListNode *forwards[];
} SSkipListNode; } SSkipListNode;
#define SL_GET_NODE_DATA(n) (n)->pData #define SL_GET_NODE_DATA(n) (n)->pData
#define SL_NODE_GET_FORWARD_POINTER(n, l) (n)->forwards[(l)] #define SL_NODE_GET_FORWARD_POINTER(n, l) (n)->forwards[(l)]
#define SL_NODE_GET_BACKWARD_POINTER(n, l) (n)->forwards[(n)->level + (l)] #define SL_NODE_GET_BACKWARD_POINTER(n, l) (n)->forwards[(n)->level + (l)]
/* /*
...@@ -100,14 +100,10 @@ typedef struct tSkipListState { ...@@ -100,14 +100,10 @@ typedef struct tSkipListState {
uint64_t nTotalElapsedTimeForInsert; uint64_t nTotalElapsedTimeForInsert;
} tSkipListState; } tSkipListState;
typedef enum { typedef enum { SSkipListPutSuccess = 0, SSkipListPutEarlyStop = 1, SSkipListPutSkipOne = 2 } SSkipListPutStatus;
SSkipListPutSuccess = 0,
SSkipListPutEarlyStop = 1,
SSkipListPutSkipOne = 2
} SSkipListPutStatus;
typedef struct SSkipList { typedef struct SSkipList {
unsigned int seed; uint32_t seed;
__compar_fn_t comparFn; __compar_fn_t comparFn;
__sl_key_fn_t keyFn; __sl_key_fn_t keyFn;
pthread_rwlock_t *lock; pthread_rwlock_t *lock;
...@@ -117,41 +113,41 @@ typedef struct SSkipList { ...@@ -117,41 +113,41 @@ typedef struct SSkipList {
uint8_t type; // static info above uint8_t type; // static info above
uint8_t level; uint8_t level;
uint32_t size; uint32_t size;
SSkipListNode * pHead; // point to the first element SSkipListNode *pHead; // point to the first element
SSkipListNode * pTail; // point to the last element SSkipListNode *pTail; // point to the last element
#if SKIP_LIST_RECORD_PERFORMANCE #if SKIP_LIST_RECORD_PERFORMANCE
tSkipListState state; // skiplist state tSkipListState state; // skiplist state
#endif #endif
tGenericSavedFunc* insertHandleFn; tGenericSavedFunc *insertHandleFn;
} SSkipList; } SSkipList;
typedef struct SSkipListIterator { typedef struct SSkipListIterator {
SSkipList * pSkipList; SSkipList *pSkipList;
SSkipListNode *cur; SSkipListNode *cur;
int32_t step; // the number of nodes that have been checked already int32_t step; // the number of nodes that have been checked already
int32_t order; // order of the iterator int32_t order; // order of the iterator
SSkipListNode *next; // next points to the true qualified node in skiplist SSkipListNode *next; // next points to the true qualified node in skiplist
} SSkipListIterator; } SSkipListIterator;
#define SL_IS_THREAD_SAFE(s) (((s)->flags) & SL_THREAD_SAFE) #define SL_IS_THREAD_SAFE(s) (((s)->flags) & SL_THREAD_SAFE)
#define SL_DUP_MODE(s) (((s)->flags) & ((((uint8_t)1) << 2) - 1)) #define SL_DUP_MODE(s) (((s)->flags) & ((((uint8_t)1) << 2) - 1))
#define SL_GET_NODE_KEY(s, n) ((s)->keyFn((n)->pData)) #define SL_GET_NODE_KEY(s, n) ((s)->keyFn((n)->pData))
#define SL_GET_MIN_KEY(s) SL_GET_NODE_KEY(s, SL_NODE_GET_FORWARD_POINTER((s)->pHead, 0)) #define SL_GET_MIN_KEY(s) SL_GET_NODE_KEY(s, SL_NODE_GET_FORWARD_POINTER((s)->pHead, 0))
#define SL_GET_MAX_KEY(s) SL_GET_NODE_KEY((s), SL_NODE_GET_BACKWARD_POINTER((s)->pTail, 0)) #define SL_GET_MAX_KEY(s) SL_GET_NODE_KEY((s), SL_NODE_GET_BACKWARD_POINTER((s)->pTail, 0))
#define SL_SIZE(s) (s)->size #define SL_SIZE(s) (s)->size
SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, __compar_fn_t comparFn, uint8_t flags, SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, __compar_fn_t comparFn, uint8_t flags,
__sl_key_fn_t fn); __sl_key_fn_t fn);
void tSkipListDestroy(SSkipList *pSkipList); void tSkipListDestroy(SSkipList *pSkipList);
SSkipListNode * tSkipListPut(SSkipList *pSkipList, void *pData); SSkipListNode *tSkipListPut(SSkipList *pSkipList, void *pData);
void tSkipListPutBatchByIter(SSkipList *pSkipList, void *iter, iter_next_fn_t iterate); void tSkipListPutBatchByIter(SSkipList *pSkipList, void *iter, iter_next_fn_t iterate);
SArray * tSkipListGet(SSkipList *pSkipList, SSkipListKey pKey); SArray *tSkipListGet(SSkipList *pSkipList, SSkipListKey pKey);
void tSkipListPrint(SSkipList *pSkipList, int16_t nlevel); void tSkipListPrint(SSkipList *pSkipList, int16_t nlevel);
SSkipListIterator *tSkipListCreateIter(SSkipList *pSkipList); SSkipListIterator *tSkipListCreateIter(SSkipList *pSkipList);
SSkipListIterator *tSkipListCreateIterFromVal(SSkipList *pSkipList, const char *val, int32_t type, int32_t order); SSkipListIterator *tSkipListCreateIterFromVal(SSkipList *pSkipList, const char *val, int32_t type, int32_t order);
bool tSkipListIterNext(SSkipListIterator *iter); bool tSkipListIterNext(SSkipListIterator *iter);
SSkipListNode * tSkipListIterGet(SSkipListIterator *iter); SSkipListNode *tSkipListIterGet(SSkipListIterator *iter);
void * tSkipListDestroyIter(SSkipListIterator *iter); void *tSkipListDestroyIter(SSkipListIterator *iter);
uint32_t tSkipListRemove(SSkipList *pSkipList, SSkipListKey key); uint32_t tSkipListRemove(SSkipList *pSkipList, SSkipListKey key);
void tSkipListRemoveNode(SSkipList *pSkipList, SSkipListNode *pNode); void tSkipListRemoveNode(SSkipList *pSkipList, SSkipListNode *pNode);
...@@ -159,4 +155,4 @@ void tSkipListRemoveNode(SSkipList *pSkipList, SSkipListNode *pNod ...@@ -159,4 +155,4 @@ void tSkipListRemoveNode(SSkipList *pSkipList, SSkipListNode *pNod
} }
#endif #endif
#endif /*_TD_UTIL_SKILIST_H*/ #endif /*_TD_UTIL_SKILIST_H*/
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_UTIL_STEP_H_
#define _TD_UTIL_STEP_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef struct SSteps SSteps;
typedef int32_t (*InitFp)();
typedef void (*CleanupFp)();
typedef void (*ReportFp)(char *name, char *desc);
SSteps *taosStepInit(int32_t maxsize, ReportFp fp);
int32_t taosStepExec(SSteps *steps);
void taosStepCleanup(SSteps *steps);
int32_t taosStepAdd(SSteps *steps, char *name, InitFp initFp, CleanupFp cleanupFp);
#ifdef __cplusplus
}
#endif
#endif /*_TD_UTIL_STEP_H_*/
...@@ -13,12 +13,10 @@ ...@@ -13,12 +13,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_STRING_BUILDER_H #ifndef _TD_UTIL_STRING_BUILDER_H_
#define _TD_UTIL_STRING_BUILDER_H #define _TD_UTIL_STRING_BUILDER_H_
#include <stddef.h> #include "os.h"
#include <stdint.h>
#include <setjmp.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -26,16 +24,16 @@ extern "C" { ...@@ -26,16 +24,16 @@ extern "C" {
typedef struct SStringBuilder { typedef struct SStringBuilder {
jmp_buf jb; jmp_buf jb;
size_t size; size_t size;
size_t pos; size_t pos;
char* buf; char* buf;
} SStringBuilder; } SStringBuilder;
#define taosStringBuilderSetJmp(sb) setjmp((sb)->jb) #define taosStringBuilderSetJmp(sb) setjmp((sb)->jb)
void taosStringBuilderEnsureCapacity(SStringBuilder* sb, size_t size); void taosStringBuilderEnsureCapacity(SStringBuilder* sb, size_t size);
char* taosStringBuilderGetResult(SStringBuilder* sb, size_t* len); char* taosStringBuilderGetResult(SStringBuilder* sb, size_t* len);
void taosStringBuilderDestroy(SStringBuilder* sb); void taosStringBuilderDestroy(SStringBuilder* sb);
void taosStringBuilderAppend(SStringBuilder* sb, const void* data, size_t len); void taosStringBuilderAppend(SStringBuilder* sb, const void* data, size_t len);
void taosStringBuilderAppendChar(SStringBuilder* sb, char c); void taosStringBuilderAppendChar(SStringBuilder* sb, char c);
...@@ -49,4 +47,4 @@ void taosStringBuilderAppendDouble(SStringBuilder* sb, double v); ...@@ -49,4 +47,4 @@ void taosStringBuilderAppendDouble(SStringBuilder* sb, double v);
} }
#endif #endif
#endif /*_TD_UTIL_STRING_BUILDER_H*/ #endif /*_TD_UTIL_STRING_BUILDER_H_*/
\ No newline at end of file \ No newline at end of file
...@@ -13,25 +13,21 @@ ...@@ -13,25 +13,21 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_THREAD_H #ifndef _TD_UTIL_THREAD_H_
#define _TD_UTIL_THREAD_H #define _TD_UTIL_THREAD_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "os.h"
#include "tdef.h"
// create new thread
pthread_t* taosCreateThread(void* (*__start_routine)(void*), void* param); pthread_t* taosCreateThread(void* (*__start_routine)(void*), void* param);
// destory thread bool taosDestoryThread(pthread_t* pthread);
bool taosDestoryThread(pthread_t* pthread); bool taosThreadRunning(pthread_t* pthread);
// thread running return true
bool taosThreadRunning(pthread_t* pthread);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /*_TD_UTIL_THREAD_H*/ #endif /*_TD_UTIL_THREAD_H_*/
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_TIMER_H #ifndef _TD_UTIL_TIMER_H_
#define _TD_UTIL_TIMER_H #define _TD_UTIL_TIMER_H_
#include "os.h" #include "os.h"
...@@ -25,23 +25,23 @@ extern "C" { ...@@ -25,23 +25,23 @@ extern "C" {
typedef void *tmr_h; typedef void *tmr_h;
typedef void (*TAOS_TMR_CALLBACK)(void *, void *); typedef void (*TAOS_TMR_CALLBACK)(void *, void *);
extern int taosTmrThreads; extern int32_t taosTmrThreads;
#define MSECONDS_PER_TICK 5 #define MSECONDS_PER_TICK 5
void *taosTmrInit(int maxTmr, int resoultion, int longest, const char *label); void *taosTmrInit(int32_t maxTmr, int32_t resoultion, int32_t longest, const char *label);
tmr_h taosTmrStart(TAOS_TMR_CALLBACK fp, int mseconds, void *param, void *handle); tmr_h taosTmrStart(TAOS_TMR_CALLBACK fp, int32_t mseconds, void *param, void *handle);
bool taosTmrStop(tmr_h tmrId); bool taosTmrStop(tmr_h tmrId);
bool taosTmrStopA(tmr_h *timerId); bool taosTmrStopA(tmr_h *timerId);
bool taosTmrReset(TAOS_TMR_CALLBACK fp, int mseconds, void *param, void *handle, tmr_h *pTmrId); bool taosTmrReset(TAOS_TMR_CALLBACK fp, int32_t mseconds, void *param, void *handle, tmr_h *pTmrId);
void taosTmrCleanUp(void *handle); void taosTmrCleanUp(void *handle);
int32_t taosInitTimer(void (*callback)(int), int32_t ms); int32_t taosInitTimer(void (*callback)(int32_t), int32_t ms);
void taosUninitTimer(); void taosUninitTimer();
...@@ -49,4 +49,4 @@ void taosUninitTimer(); ...@@ -49,4 +49,4 @@ void taosUninitTimer();
} }
#endif #endif
#endif /*_TD_UTIL_TIMER_H*/ #endif /*_TD_UTIL_TIMER_H_*/
...@@ -13,18 +13,18 @@ ...@@ -13,18 +13,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_UTIL_H #ifndef _TD_UTIL_UTIL_H_
#define _TD_UTIL_UTIL_H #define _TD_UTIL_UTIL_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "os.h" #include "os.h"
#include "tcrc32c.h" #include "tcrc32c.h"
#include "tdef.h" #include "tdef.h"
#include "tmd5.h" #include "tmd5.h"
#ifdef __cplusplus
extern "C" {
#endif
int32_t strdequote(char *src); int32_t strdequote(char *src);
int32_t strndequote(char *dst, const char *z, int32_t len); int32_t strndequote(char *dst, const char *z, int32_t len);
int32_t strRmquote(char *z, int32_t len); int32_t strRmquote(char *z, int32_t len);
...@@ -49,7 +49,7 @@ void taosIpPort2String(uint32_t ip, uint16_t port, char *str); ...@@ -49,7 +49,7 @@ void taosIpPort2String(uint32_t ip, uint16_t port, char *str);
static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, size_t inLen, char *target) { static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, size_t inLen, char *target) {
T_MD5_CTX context; T_MD5_CTX context;
tMD5Init(&context); tMD5Init(&context);
tMD5Update(&context, inBuf, (unsigned int)inLen); tMD5Update(&context, inBuf, (uint32_t)inLen);
tMD5Final(&context); tMD5Final(&context);
memcpy(target, context.digest, tListLen(context.digest)); memcpy(target, context.digest, tListLen(context.digest));
} }
...@@ -57,17 +57,17 @@ static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, size_t inLen, char *tar ...@@ -57,17 +57,17 @@ static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, size_t inLen, char *tar
static FORCE_INLINE void taosEncryptPass_c(uint8_t *inBuf, size_t len, char *target) { static FORCE_INLINE void taosEncryptPass_c(uint8_t *inBuf, size_t len, char *target) {
T_MD5_CTX context; T_MD5_CTX context;
tMD5Init(&context); tMD5Init(&context);
tMD5Update(&context, inBuf, (unsigned int)len); tMD5Update(&context, inBuf, (uint32_t)len);
tMD5Final(&context); tMD5Final(&context);
sprintf(target, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", context.digest[0], context.digest[1], context.digest[2], sprintf(target, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", context.digest[0],
context.digest[3], context.digest[4], context.digest[5], context.digest[6], context.digest[7], context.digest[1], context.digest[2], context.digest[3], context.digest[4], context.digest[5],
context.digest[8], context.digest[9], context.digest[10], context.digest[11], context.digest[12], context.digest[6], context.digest[7], context.digest[8], context.digest[9], context.digest[10],
context.digest[13], context.digest[14], context.digest[15]); context.digest[11], context.digest[12], context.digest[13], context.digest[14], context.digest[15]);
} }
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /*_TD_UTIL_UTIL_H*/ #endif /*_TD_UTIL_UTIL_H_*/
...@@ -13,8 +13,10 @@ ...@@ -13,8 +13,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_VERSION_H #ifndef _TD_UTIL_VERSION_H_
#define _TD_UTIL_VERSION_H #define _TD_UTIL_VERSION_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -28,4 +30,4 @@ int32_t taosCheckVersionCompatible(int32_t clientVer, int32_t serverVer, int32_t ...@@ -28,4 +30,4 @@ int32_t taosCheckVersionCompatible(int32_t clientVer, int32_t serverVer, int32_t
} }
#endif #endif
#endif /*_TD_UTIL_VERSION_H*/ #endif /*_TD_UTIL_VERSION_H_*/
...@@ -13,8 +13,9 @@ ...@@ -13,8 +13,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_WORKER_H #ifndef _TD_UTIL_WORKER_H_
#define _TD_UTIL_WORKER_H #define _TD_UTIL_WORKER_H_
#include "tqueue.h" #include "tqueue.h"
#ifdef __cplusplus #ifdef __cplusplus
...@@ -34,25 +35,25 @@ typedef struct SQWorkerPool { ...@@ -34,25 +35,25 @@ typedef struct SQWorkerPool {
int32_t max; // max number of workers int32_t max; // max number of workers
int32_t min; // min number of workers int32_t min; // min number of workers
int32_t num; // current number of workers int32_t num; // current number of workers
STaosQset * qset; STaosQset *qset;
const char * name; const char *name;
SQWorker * workers; SQWorker *workers;
pthread_mutex_t mutex; pthread_mutex_t mutex;
} SQWorkerPool, SFWorkerPool; } SQWorkerPool, SFWorkerPool;
typedef struct SWWorker { typedef struct SWWorker {
int32_t id; // worker id int32_t id; // worker id
pthread_t thread; // thread pthread_t thread; // thread
STaosQall * qall; STaosQall *qall;
STaosQset * qset; // queue set STaosQset *qset; // queue set
SWWorkerPool *pool; SWWorkerPool *pool;
} SWWorker; } SWWorker;
typedef struct SWWorkerPool { typedef struct SWWorkerPool {
int32_t max; // max number of workers int32_t max; // max number of workers
int32_t nextId; // from 0 to max-1, cyclic int32_t nextId; // from 0 to max-1, cyclic
const char * name; const char *name;
SWWorker * workers; SWWorker *workers;
pthread_mutex_t mutex; pthread_mutex_t mutex;
} SWWorkerPool; } SWWorkerPool;
...@@ -75,4 +76,4 @@ void tWWorkerFreeQueue(SWWorkerPool *pool, STaosQueue *queue); ...@@ -75,4 +76,4 @@ void tWWorkerFreeQueue(SWWorkerPool *pool, STaosQueue *queue);
} }
#endif #endif
#endif /*_TD_UTIL_WORKER_H*/ #endif /*_TD_UTIL_WORKER_H_*/
...@@ -22,14 +22,14 @@ ...@@ -22,14 +22,14 @@
extern "C" { extern "C" {
#endif #endif
#define GET_INT8_VAL(x) (*(int8_t *)(x)) #define GET_INT8_VAL(x) (*(int8_t *)(x))
#define GET_INT16_VAL(x) (*(int16_t *)(x)) #define GET_INT16_VAL(x) (*(int16_t *)(x))
#define GET_INT32_VAL(x) (*(int32_t *)(x)) #define GET_INT32_VAL(x) (*(int32_t *)(x))
#define GET_INT64_VAL(x) (*(int64_t *)(x)) #define GET_INT64_VAL(x) (*(int64_t *)(x))
#define GET_UINT8_VAL(x) (*(uint8_t*) (x)) #define GET_UINT8_VAL(x) (*(uint8_t *)(x))
#define GET_UINT16_VAL(x) (*(uint16_t *)(x)) #define GET_UINT16_VAL(x) (*(uint16_t *)(x))
#define GET_UINT32_VAL(x) (*(uint32_t *)(x)) #define GET_UINT32_VAL(x) (*(uint32_t *)(x))
#define GET_UINT64_VAL(x) (*(uint64_t *)(x)) #define GET_UINT64_VAL(x) (*(uint64_t *)(x))
static FORCE_INLINE float taos_align_get_float(const char *pBuf) { static FORCE_INLINE float taos_align_get_float(const char *pBuf) {
#if __STDC_VERSION__ >= 201112L #if __STDC_VERSION__ >= 201112L
...@@ -64,23 +64,33 @@ static FORCE_INLINE double taos_align_get_double(const char *pBuf) { ...@@ -64,23 +64,33 @@ static FORCE_INLINE double taos_align_get_double(const char *pBuf) {
// #define SET_FLOAT_PTR(x, y) { (*(int32_t*) x = *(int32_t*)y); } // #define SET_FLOAT_PTR(x, y) { (*(int32_t*) x = *(int32_t*)y); }
// #define SET_DOUBLE_PTR(x, y) { (*(int64_t*) x = *(int64_t*)y); } // #define SET_DOUBLE_PTR(x, y) { (*(int64_t*) x = *(int64_t*)y); }
// #else // #else
#define GET_FLOAT_VAL(x) (*(float *)(x)) #define GET_FLOAT_VAL(x) (*(float *)(x))
#define GET_DOUBLE_VAL(x) (*(double *)(x)) #define GET_DOUBLE_VAL(x) (*(double *)(x))
#define SET_BIGINT_VAL(x, y) { (*(int64_t *)(x)) = (int64_t)(y); } #define SET_BIGINT_VAL(x, y) \
#define SET_FLOAT_VAL(x, y) { (*(float *)(x)) = (float)(y); } { (*(int64_t *)(x)) = (int64_t)(y); }
#define SET_DOUBLE_VAL(x, y) { (*(double *)(x)) = (double)(y); } #define SET_FLOAT_VAL(x, y) \
#define SET_FLOAT_PTR(x, y) { (*(float *)(x)) = (*(float *)(y)); } { (*(float *)(x)) = (float)(y); }
#define SET_DOUBLE_PTR(x, y) { (*(double *)(x)) = (*(double *)(y)); } #define SET_DOUBLE_VAL(x, y) \
{ (*(double *)(x)) = (double)(y); }
#define SET_FLOAT_PTR(x, y) \
{ (*(float *)(x)) = (*(float *)(y)); }
#define SET_DOUBLE_PTR(x, y) \
{ (*(double *)(x)) = (*(double *)(y)); }
// #endif // #endif
typedef uint16_t VarDataLenT; // maxVarDataLen: 32767 typedef uint16_t VarDataLenT; // maxVarDataLen: 32767
#define VARSTR_HEADER_SIZE sizeof(VarDataLenT) #define VARSTR_HEADER_SIZE sizeof(VarDataLenT)
#define varDataLen(v) ((VarDataLenT *)(v))[0] #define varDataLen(v) ((VarDataLenT *)(v))[0]
#define varDataVal(v) ((void *)((char *)v + VARSTR_HEADER_SIZE)) #define varDataVal(v) ((void *)((char *)v + VARSTR_HEADER_SIZE))
typedef int32_t VarDataOffsetT; typedef int32_t VarDataOffsetT;
typedef struct tstr {
VarDataLenT len;
char data[];
} tstr;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_VERSION_H #ifndef _TD_UTIL_VERSION_H_
#define _TD_UTIL_VERSION_H #define _TD_UTIL_VERSION_H_
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -30,4 +30,4 @@ extern char buildinfo[]; ...@@ -30,4 +30,4 @@ extern char buildinfo[];
} }
#endif #endif
#endif /*_TD_UTIL_VERSION_H*/ #endif /*_TD_UTIL_VERSION_H_*/
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tcompare.h"
__compar_fn_t getKeyComparFunc(int32_t keyType, int32_t order) {
__compar_fn_t comparFn = NULL;
switch (keyType) {
case TSDB_DATA_TYPE_TINYINT:
case TSDB_DATA_TYPE_BOOL:
comparFn = (order == TSDB_ORDER_ASC)? compareInt8Val:compareInt8ValDesc;
break;
case TSDB_DATA_TYPE_SMALLINT:
comparFn = (order == TSDB_ORDER_ASC)? compareInt16Val:compareInt16ValDesc;
break;
case TSDB_DATA_TYPE_INT:
comparFn = (order == TSDB_ORDER_ASC)? compareInt32Val:compareInt32ValDesc;
break;
case TSDB_DATA_TYPE_BIGINT:
case TSDB_DATA_TYPE_TIMESTAMP:
comparFn = (order == TSDB_ORDER_ASC)? compareInt64Val:compareInt64ValDesc;
break;
case TSDB_DATA_TYPE_FLOAT:
comparFn = (order == TSDB_ORDER_ASC)? compareFloatVal:compareFloatValDesc;
break;
case TSDB_DATA_TYPE_DOUBLE:
comparFn = (order == TSDB_ORDER_ASC)? compareDoubleVal:compareDoubleValDesc;
break;
case TSDB_DATA_TYPE_UTINYINT:
comparFn = (order == TSDB_ORDER_ASC)? compareUint8Val:compareUint8ValDesc;
break;
case TSDB_DATA_TYPE_USMALLINT:
comparFn = (order == TSDB_ORDER_ASC)? compareUint16Val:compareUint16ValDesc;
break;
case TSDB_DATA_TYPE_UINT:
comparFn = (order == TSDB_ORDER_ASC)? compareUint32Val:compareUint32ValDesc;
break;
case TSDB_DATA_TYPE_UBIGINT:
comparFn = (order == TSDB_ORDER_ASC)? compareUint64Val:compareUint64ValDesc;
break;
case TSDB_DATA_TYPE_BINARY:
comparFn = (order == TSDB_ORDER_ASC)? compareLenPrefixedStr:compareLenPrefixedStrDesc;
break;
case TSDB_DATA_TYPE_NCHAR:
comparFn = (order == TSDB_ORDER_ASC)? compareLenPrefixedWStr:compareLenPrefixedWStrDesc;
break;
default:
comparFn = (order == TSDB_ORDER_ASC)? compareInt32Val:compareInt32ValDesc;
break;
}
return comparFn;
}
int32_t doCompare(const char* f1, const char* f2, int32_t type, size_t size) {
switch (type) {
case TSDB_DATA_TYPE_INT: DEFAULT_COMP(GET_INT32_VAL(f1), GET_INT32_VAL(f2));
case TSDB_DATA_TYPE_DOUBLE: DEFAULT_DOUBLE_COMP(GET_DOUBLE_VAL(f1), GET_DOUBLE_VAL(f2));
case TSDB_DATA_TYPE_FLOAT: DEFAULT_FLOAT_COMP(GET_FLOAT_VAL(f1), GET_FLOAT_VAL(f2));
case TSDB_DATA_TYPE_BIGINT: DEFAULT_COMP(GET_INT64_VAL(f1), GET_INT64_VAL(f2));
case TSDB_DATA_TYPE_SMALLINT: DEFAULT_COMP(GET_INT16_VAL(f1), GET_INT16_VAL(f2));
case TSDB_DATA_TYPE_TINYINT:
case TSDB_DATA_TYPE_BOOL: DEFAULT_COMP(GET_INT8_VAL(f1), GET_INT8_VAL(f2));
case TSDB_DATA_TYPE_UTINYINT: DEFAULT_COMP(GET_UINT8_VAL(f1), GET_UINT8_VAL(f2));
case TSDB_DATA_TYPE_USMALLINT: DEFAULT_COMP(GET_UINT16_VAL(f1), GET_UINT16_VAL(f2));
case TSDB_DATA_TYPE_UINT: DEFAULT_COMP(GET_UINT32_VAL(f1), GET_UINT32_VAL(f2));
case TSDB_DATA_TYPE_UBIGINT: DEFAULT_COMP(GET_UINT64_VAL(f1), GET_UINT64_VAL(f2));
case TSDB_DATA_TYPE_NCHAR: {
tstr* t1 = (tstr*) f1;
tstr* t2 = (tstr*) f2;
if (t1->len != t2->len) {
return t1->len > t2->len? 1:-1;
}
int32_t ret = memcmp((wchar_t*) t1, (wchar_t*) t2, t2->len);
if (ret == 0) {
return ret;
}
return (ret < 0) ? -1 : 1;
}
default: { // todo refactor
tstr* t1 = (tstr*) f1;
tstr* t2 = (tstr*) f2;
if (t1->len != t2->len) {
return t1->len > t2->len? 1:-1;
} else {
int32_t ret = strncmp(t1->data, t2->data, t1->len);
if (ret == 0) {
return 0;
} else {
return ret < 0? -1:1;
}
}
}
}
}
#include "tep.h" #include "tep.h"
#include <compare.h> #include "tcompare.h"
#include "common.h" #include "common.h"
#include "tglobal.h" #include "tglobal.h"
#include "tlockfree.h" #include "tlockfree.h"
......
...@@ -207,6 +207,8 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e ...@@ -207,6 +207,8 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e
} }
static int32_t taosAddClientLogCfg(SConfig *pCfg) { static int32_t taosAddClientLogCfg(SConfig *pCfg) {
if (cfgAddDir(pCfg, "configDir", configDir, 1) != 0) return -1;
if (cfgAddDir(pCfg, "scriptDir", configDir, 1) != 0) return -1;
if (cfgAddDir(pCfg, "logDir", tsLogDir, 1) != 0) return -1; if (cfgAddDir(pCfg, "logDir", tsLogDir, 1) != 0) return -1;
if (cfgAddFloat(pCfg, "minimalLogDirGB", 1.0f, 0.001f, 10000000, 1) != 0) return -1; if (cfgAddFloat(pCfg, "minimalLogDirGB", 1.0f, 0.001f, 10000000, 1) != 0) return -1;
if (cfgAddInt32(pCfg, "numOfLogLines", tsNumOfLogLines, 1000, 2000000000, 1) != 0) return -1; if (cfgAddInt32(pCfg, "numOfLogLines", tsNumOfLogLines, 1000, 2000000000, 1) != 0) return -1;
...@@ -218,8 +220,6 @@ static int32_t taosAddClientLogCfg(SConfig *pCfg) { ...@@ -218,8 +220,6 @@ static int32_t taosAddClientLogCfg(SConfig *pCfg) {
if (cfgAddInt32(pCfg, "tmrDebugFlag", tmrDebugFlag, 0, 255, 1) != 0) return -1; if (cfgAddInt32(pCfg, "tmrDebugFlag", tmrDebugFlag, 0, 255, 1) != 0) return -1;
if (cfgAddInt32(pCfg, "jniDebugFlag", jniDebugFlag, 0, 255, 1) != 0) return -1; if (cfgAddInt32(pCfg, "jniDebugFlag", jniDebugFlag, 0, 255, 1) != 0) return -1;
if (cfgAddInt32(pCfg, "simDebugFlag", 143, 0, 255, 1) != 0) return -1; if (cfgAddInt32(pCfg, "simDebugFlag", 143, 0, 255, 1) != 0) return -1;
if (cfgAddDir(pCfg, "configDir", configDir, 1) != 0) return -1;
if (cfgAddDir(pCfg, "scriptDir", configDir, 1) != 0) return -1;
if (cfgAddInt32(pCfg, "debugFlag", 0, 0, 255, 1) != 0) return -1; if (cfgAddInt32(pCfg, "debugFlag", 0, 0, 255, 1) != 0) return -1;
return 0; return 0;
} }
...@@ -325,6 +325,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { ...@@ -325,6 +325,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
static void taosSetClientLogCfg(SConfig *pCfg) { static void taosSetClientLogCfg(SConfig *pCfg) {
SConfigItem *pItem = cfgGetItem(pCfg, "logDir"); SConfigItem *pItem = cfgGetItem(pCfg, "logDir");
tstrncpy(tsLogDir, cfgGetItem(pCfg, "logDir")->str, PATH_MAX); tstrncpy(tsLogDir, cfgGetItem(pCfg, "logDir")->str, PATH_MAX);
taosExpandDir(tsLogDir, tsLogDir, PATH_MAX);
tsLogSpace.reserved = cfgGetItem(pCfg, "minimalLogDirGB")->fval; tsLogSpace.reserved = cfgGetItem(pCfg, "minimalLogDirGB")->fval;
tsNumOfLogLines = cfgGetItem(pCfg, "numOfLogLines")->i32; tsNumOfLogLines = cfgGetItem(pCfg, "numOfLogLines")->i32;
tsAsyncLog = cfgGetItem(pCfg, "asyncLog")->bval; tsAsyncLog = cfgGetItem(pCfg, "asyncLog")->bval;
...@@ -349,12 +350,24 @@ static void taosSetServerLogCfg(SConfig *pCfg) { ...@@ -349,12 +350,24 @@ static void taosSetServerLogCfg(SConfig *pCfg) {
} }
static void taosSetClientCfg(SConfig *pCfg) { static void taosSetClientCfg(SConfig *pCfg) {
tstrncpy(tsFirst, cfgGetItem(pCfg, "firstEp")->str, TSDB_EP_LEN);
tstrncpy(tsSecond, cfgGetItem(pCfg, "secondEp")->str, TSDB_EP_LEN);
tstrncpy(tsLocalFqdn, cfgGetItem(pCfg, "fqdn")->str, TSDB_EP_LEN); tstrncpy(tsLocalFqdn, cfgGetItem(pCfg, "fqdn")->str, TSDB_EP_LEN);
tsServerPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32; tsServerPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32;
snprintf(tsLocalEp, sizeof(tsLocalEp), "%s:%u", tsLocalFqdn, tsServerPort); snprintf(tsLocalEp, sizeof(tsLocalEp), "%s:%u", tsLocalFqdn, tsServerPort);
SConfigItem *pFirstEpItem = cfgGetItem(pCfg, "firstEp");
SEp firstEp = {0};
taosGetFqdnPortFromEp(pFirstEpItem->str, &firstEp);
snprintf(tsFirst, sizeof(tsFirst), "%s:%u", firstEp.fqdn, firstEp.port);
cfgSetItem(pCfg, "firstEp", tsFirst, pFirstEpItem->stype);
SConfigItem *pSecondpItem = cfgGetItem(pCfg, "secondEp");
SEp secondEp = {0};
taosGetFqdnPortFromEp(pSecondpItem->str, &secondEp);
snprintf(tsSecond, sizeof(tsSecond), "%s:%u", secondEp.fqdn, secondEp.port);
cfgSetItem(pCfg, "secondEp", tsSecond, pSecondpItem->stype);
tstrncpy(tsLogDir, cfgGetItem(pCfg, "tempDir")->str, PATH_MAX); tstrncpy(tsLogDir, cfgGetItem(pCfg, "tempDir")->str, PATH_MAX);
taosExpandDir(tsLogDir, tsLogDir, PATH_MAX);
tsTempSpace.reserved = cfgGetItem(pCfg, "minimalTempDirGB")->fval; tsTempSpace.reserved = cfgGetItem(pCfg, "minimalTempDirGB")->fval;
tsNumOfThreadsPerCore = cfgGetItem(pCfg, "maxTmrCtrl")->fval; tsNumOfThreadsPerCore = cfgGetItem(pCfg, "maxTmrCtrl")->fval;
...@@ -395,6 +408,8 @@ static void taosSetSystemCfg(SConfig *pCfg) { ...@@ -395,6 +408,8 @@ static void taosSetSystemCfg(SConfig *pCfg) {
static void taosSetServerCfg(SConfig *pCfg) { static void taosSetServerCfg(SConfig *pCfg) {
tstrncpy(tsDataDir, cfgGetItem(pCfg, "dataDir")->str, PATH_MAX); tstrncpy(tsDataDir, cfgGetItem(pCfg, "dataDir")->str, PATH_MAX);
taosExpandDir(tsDataDir, tsDataDir, PATH_MAX);
tsTempSpace.reserved = cfgGetItem(pCfg, "minimalDataDirGB")->fval; tsTempSpace.reserved = cfgGetItem(pCfg, "minimalDataDirGB")->fval;
tsNumOfCommitThreads = cfgGetItem(pCfg, "numOfCommitThreads")->i32; tsNumOfCommitThreads = cfgGetItem(pCfg, "numOfCommitThreads")->i32;
tsRatioOfQueryCores = cfgGetItem(pCfg, "ratioOfQueryCores")->fval; tsRatioOfQueryCores = cfgGetItem(pCfg, "ratioOfQueryCores")->fval;
...@@ -473,10 +488,10 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU ...@@ -473,10 +488,10 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU
if (taosAddClientLogCfg(tsCfg) != 0) return -1; if (taosAddClientLogCfg(tsCfg) != 0) return -1;
if (taosAddClientCfg(tsCfg) != 0) return -1; if (taosAddClientCfg(tsCfg) != 0) return -1;
} else { } else {
if (taosAddClientLogCfg(tsCfg) != 0) return -1;
if (taosAddServerLogCfg(tsCfg) != 0) return -1;
if (taosAddClientCfg(tsCfg) != 0) return -1; if (taosAddClientCfg(tsCfg) != 0) return -1;
if (taosAddServerCfg(tsCfg) != 0) return -1; if (taosAddServerCfg(tsCfg) != 0) return -1;
if (taosAddClientLogCfg(tsCfg) != 0) return -1;
if (taosAddServerLogCfg(tsCfg) != 0) return -1;
} }
taosAddSystemCfg(tsCfg); taosAddSystemCfg(tsCfg);
......
...@@ -22,11 +22,11 @@ SDnodeObjCfg dmnGetObjCfg() { ...@@ -22,11 +22,11 @@ SDnodeObjCfg dmnGetObjCfg() {
SDnodeObjCfg objCfg = {0}; SDnodeObjCfg objCfg = {0};
objCfg.numOfSupportVnodes = cfgGetItem(pCfg, "supportVnodes")->i32; objCfg.numOfSupportVnodes = cfgGetItem(pCfg, "supportVnodes")->i32;
tstrncpy(objCfg.dataDir, cfgGetItem(pCfg, "dataDir")->str, sizeof(objCfg.dataDir)); tstrncpy(objCfg.dataDir, tsDataDir, sizeof(objCfg.dataDir));
tstrncpy(objCfg.firstEp, cfgGetItem(pCfg, "firstEp")->str, sizeof(objCfg.firstEp)); tstrncpy(objCfg.firstEp, tsFirst, sizeof(objCfg.firstEp));
tstrncpy(objCfg.secondEp, cfgGetItem(pCfg, "secondEp")->str, sizeof(objCfg.firstEp)); tstrncpy(objCfg.secondEp, tsSecond, sizeof(objCfg.firstEp));
objCfg.serverPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32; objCfg.serverPort = tsServerPort;
tstrncpy(objCfg.localFqdn, cfgGetItem(pCfg, "fqdn")->str, sizeof(objCfg.localFqdn)); tstrncpy(objCfg.localFqdn, tsLocalFqdn, sizeof(objCfg.localFqdn));
snprintf(objCfg.localEp, sizeof(objCfg.localEp), "%s:%u", objCfg.localFqdn, objCfg.serverPort); snprintf(objCfg.localEp, sizeof(objCfg.localEp), "%s:%u", objCfg.localFqdn, objCfg.serverPort);
objCfg.pDisks = tsDiskCfg; objCfg.pDisks = tsDiskCfg;
objCfg.numOfDisks = tsDiskCfgNum; objCfg.numOfDisks = tsDiskCfgNum;
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include "mndDb.h" #include "mndDb.h"
#include "mndShow.h" #include "mndShow.h"
#include "mndTrans.h" #include "mndTrans.h"
#include "tkey.h" #include "tbase64.h"
#define TSDB_USER_VER_NUMBER 1 #define TSDB_USER_VER_NUMBER 1
#define TSDB_USER_RESERVE_SIZE 64 #define TSDB_USER_RESERVE_SIZE 64
......
...@@ -119,8 +119,8 @@ TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) { ...@@ -119,8 +119,8 @@ TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) {
EXPECT_EQ(test.GetShowRows(), 2); EXPECT_EQ(test.GetShowRows(), 2);
CheckInt32(2); CheckInt32(2);
CheckInt32(3); CheckInt32(3);
CheckInt32(0); IgnoreInt32();
CheckInt32(0); IgnoreInt32();
CheckInt16(1); CheckInt16(1);
CheckInt16(1); CheckInt16(1);
CheckBinary("master", 9); CheckBinary("master", 9);
......
...@@ -16,8 +16,7 @@ ...@@ -16,8 +16,7 @@
#ifndef _TD_META_H_ #ifndef _TD_META_H_
#define _TD_META_H_ #define _TD_META_H_
#include "mallocator.h" #include "tmallocator.h"
#include "os.h"
#include "tmsg.h" #include "tmsg.h"
#include "trow.h" #include "trow.h"
......
...@@ -18,9 +18,8 @@ ...@@ -18,9 +18,8 @@
#include "common.h" #include "common.h"
#include "executor.h" #include "executor.h"
#include "mallocator.h" #include "tmallocator.h"
#include "meta.h" #include "meta.h"
#include "os.h"
#include "scheduler.h" #include "scheduler.h"
#include "taoserror.h" #include "taoserror.h"
#include "tlist.h" #include "tlist.h"
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#ifndef _TD_TSDB_H_ #ifndef _TD_TSDB_H_
#define _TD_TSDB_H_ #define _TD_TSDB_H_
#include "mallocator.h" #include "tmallocator.h"
#include "meta.h" #include "meta.h"
#include "common.h" #include "common.h"
#include "tfs.h" #include "tfs.h"
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#ifndef _TD_META_DEF_H_ #ifndef _TD_META_DEF_H_
#define _TD_META_DEF_H_ #define _TD_META_DEF_H_
#include "mallocator.h" #include "tmallocator.h"
#include "meta.h" #include "meta.h"
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#ifndef _TD_TSDB_DEF_H_ #ifndef _TD_TSDB_DEF_H_
#define _TD_TSDB_DEF_H_ #define _TD_TSDB_DEF_H_
#include "mallocator.h" #include "tmallocator.h"
#include "meta.h" #include "meta.h"
#include "tcompression.h" #include "tcompression.h"
#include "tglobal.h" #include "tglobal.h"
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#ifndef _TD_VNODE_DEF_H_ #ifndef _TD_VNODE_DEF_H_
#define _TD_VNODE_DEF_H_ #define _TD_VNODE_DEF_H_
#include "mallocator.h" #include "tmallocator.h"
// #include "sync.h" // #include "sync.h"
#include "tcoding.h" #include "tcoding.h"
#include "tfs.h" #include "tfs.h"
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include "tsdbLog.h" #include "tsdbLog.h"
#include "tsdbReadImpl.h" #include "tsdbReadImpl.h"
#include "ttime.h" #include "ttime.h"
#include "exception.h" #include "texception.h"
#include "os.h" #include "os.h"
#include "talgo.h" #include "talgo.h"
#include "tcompare.h" #include "tcompare.h"
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include <tsdb.h> #include <tsdb.h>
#include "dataSinkMgt.h" #include "dataSinkMgt.h"
#include "exception.h" #include "texception.h"
#include "os.h" #include "os.h"
#include "tarray.h" #include "tarray.h"
#include "tcache.h" #include "tcache.h"
......
...@@ -12,11 +12,12 @@ ...@@ -12,11 +12,12 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "os.h" #include "os.h"
#include "tep.h" #include "tep.h"
#include "tsort.h" #include "tsort.h"
#include "exception.h" #include "texception.h"
#include "parser.h" #include "parser.h"
#include "tglobal.h" #include "tglobal.h"
#include "tmsg.h" #include "tmsg.h"
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
*/ */
#include "tlinearhash.h" #include "tlinearhash.h"
#include "tcfg.h" #include "tdef.h"
#include "taoserror.h" #include "taoserror.h"
#include "tpagedbuf.h" #include "tpagedbuf.h"
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "tsort.h" #include "tsort.h"
#include "tep.h" #include "tep.h"
#include "tcfg.h" #include "tdef.h"
#include "tlosertree.h" #include "tlosertree.h"
#include "tpagedbuf.h" #include "tpagedbuf.h"
#include "tutil.h" #include "tutil.h"
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "function.h" #include "function.h"
#include "os.h" #include "os.h"
#include "exception.h" #include "texception.h"
#include "taosdef.h" #include "taosdef.h"
#include "tmsg.h" #include "tmsg.h"
#include "tarray.h" #include "tarray.h"
......
...@@ -12,8 +12,9 @@ ...@@ -12,8 +12,9 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <tglobal.h>
#include "os.h" #include "tglobal.h"
#include "tcompare.h"
#include "taosdef.h" #include "taosdef.h"
#include "tcompare.h" #include "tcompare.h"
......
...@@ -16,12 +16,15 @@ ...@@ -16,12 +16,15 @@
#ifndef _TD_INDEX_INT_H_ #ifndef _TD_INDEX_INT_H_
#define _TD_INDEX_INT_H_ #define _TD_INDEX_INT_H_
#include "os.h"
#include "index.h" #include "index.h"
#include "index_fst.h"
#include "taos.h" #include "taos.h"
#include "tarray.h"
#include "tchecksum.h" #include "tchecksum.h"
#include "thash.h" #include "thash.h"
#include "tlog.h" #include "tlog.h"
#include "tutil.h"
#ifdef USE_LUCENE #ifdef USE_LUCENE
#include <lucene++/Lucene_c.h> #include <lucene++/Lucene_c.h>
......
...@@ -15,10 +15,9 @@ ...@@ -15,10 +15,9 @@
#ifndef __INDEX_CACHE_H__ #ifndef __INDEX_CACHE_H__
#define __INDEX_CACHE_H__ #define __INDEX_CACHE_H__
#include "index.h"
#include "indexInt.h" #include "indexInt.h"
#include "tlockfree.h"
#include "tskiplist.h" #include "tskiplist.h"
// ----------------- key structure in skiplist --------------------- // ----------------- key structure in skiplist ---------------------
/* A data row, the format is like below /* A data row, the format is like below
......
...@@ -20,11 +20,12 @@ ...@@ -20,11 +20,12 @@
extern "C" { extern "C" {
#endif #endif
#include "indexInt.h"
#include "index_fst_node.h"
#include "index_fst_automation.h" #include "index_fst_automation.h"
#include "index_fst_counting_writer.h" #include "index_fst_counting_writer.h"
#include "index_fst_registry.h" #include "index_fst_registry.h"
#include "index_fst_util.h" #include "index_fst_util.h"
#include "tarray.h"
#define OUTPUT_PREFIX(a, b) ((a) > (b) ? (b) : (a) #define OUTPUT_PREFIX(a, b) ((a) > (b) ? (b) : (a)
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
extern "C" { extern "C" {
#endif #endif
#include "indexInt.h"
#include "index_fst_util.h" #include "index_fst_util.h"
typedef struct AutomationCtx AutomationCtx; typedef struct AutomationCtx AutomationCtx;
......
...@@ -16,12 +16,12 @@ ...@@ -16,12 +16,12 @@
#ifndef __INDEX_FST_COUNTING_WRITER_H__ #ifndef __INDEX_FST_COUNTING_WRITER_H__
#define __INDEX_FST_COUNTING_WRITER_H__ #define __INDEX_FST_COUNTING_WRITER_H__
#include "indexInt.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "tfile.h"
//#define USE_MMAP 1 //#define USE_MMAP 1
#define DefaultMem 1024 * 1024 #define DefaultMem 1024 * 1024
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
extern "C" { extern "C" {
#endif #endif
#include "indexInt.h"
#include "index_fst_counting_writer.h" #include "index_fst_counting_writer.h"
#include "index_fst_util.h" #include "index_fst_util.h"
......
...@@ -19,9 +19,9 @@ ...@@ -19,9 +19,9 @@
extern "C" { extern "C" {
#endif #endif
#include "indexInt.h"
#include "index_fst_node.h" #include "index_fst_node.h"
#include "index_fst_util.h" #include "index_fst_util.h"
#include "tarray.h"
typedef struct FstRegistryCell { typedef struct FstRegistryCell {
CompiledAddr addr; CompiledAddr addr;
......
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
extern "C" { extern "C" {
#endif #endif
#include "indexInt.h"
#include "index_fst_common.h" #include "index_fst_common.h"
#include "tarray.h"
typedef uint64_t FstType; typedef uint64_t FstType;
typedef uint64_t CompiledAddr; typedef uint64_t CompiledAddr;
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#ifndef __INDEX_TFILE_H__ #ifndef __INDEX_TFILE_H__
#define __INDEX_TFILE_H__ #define __INDEX_TFILE_H__
#include "index.h"
#include "indexInt.h" #include "indexInt.h"
#include "index_fst.h" #include "index_fst.h"
#include "index_fst_counting_writer.h" #include "index_fst_counting_writer.h"
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#ifndef __INDEX_UTIL_H__ #ifndef __INDEX_UTIL_H__
#define __INDEX_UTIL_H__ #define __INDEX_UTIL_H__
#include "tarray.h" #include "indexInt.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "os.h"
#include "index_fst_counting_writer.h" #include "index_fst_counting_writer.h"
#include "indexInt.h" #include "indexInt.h"
#include "index_fst_util.h" #include "index_fst_util.h"
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "os.h"
#include "index_fst_registry.h" #include "index_fst_registry.h"
uint64_t fstRegistryHash(FstRegistry* registry, FstBuilderNode* bNode) { uint64_t fstRegistryHash(FstRegistry* registry, FstBuilderNode* bNode) {
......
...@@ -49,7 +49,6 @@ class FstWriter { ...@@ -49,7 +49,6 @@ class FstWriter {
class FstReadMemory { class FstReadMemory {
public: public:
FstReadMemory(size_t size, const std::string& fileName = "/tmp/tindex.tindex") { FstReadMemory(size_t size, const std::string& fileName = "/tmp/tindex.tindex") {
tfInit();
_wc = writerCtxCreate(TFile, fileName.c_str(), true, 64 * 1024); _wc = writerCtxCreate(TFile, fileName.c_str(), true, 64 * 1024);
_w = fstCountingWriterCreate(_wc); _w = fstCountingWriterCreate(_wc);
_size = size; _size = size;
...@@ -116,7 +115,6 @@ class FstReadMemory { ...@@ -116,7 +115,6 @@ class FstReadMemory {
fstDestroy(_fst); fstDestroy(_fst);
fstSliceDestroy(&_s); fstSliceDestroy(&_s);
writerCtxDestroy(_wc, false); writerCtxDestroy(_wc, false);
tfCleanup();
} }
private: private:
...@@ -170,7 +168,6 @@ void Performance_fstReadRecords(FstReadMemory* m) { ...@@ -170,7 +168,6 @@ void Performance_fstReadRecords(FstReadMemory* m) {
} }
void checkMillonWriteAndReadOfFst() { void checkMillonWriteAndReadOfFst() {
tfInit();
FstWriter* fw = new FstWriter; FstWriter* fw = new FstWriter;
Performance_fstWriteRecords(fw); Performance_fstWriteRecords(fw);
delete fw; delete fw;
...@@ -181,11 +178,9 @@ void checkMillonWriteAndReadOfFst() { ...@@ -181,11 +178,9 @@ void checkMillonWriteAndReadOfFst() {
} }
Performance_fstReadRecords(fr); Performance_fstReadRecords(fr);
tfCleanup();
delete fr; delete fr;
} }
void checkFstLongTerm() { void checkFstLongTerm() {
tfInit();
FstWriter* fw = new FstWriter; FstWriter* fw = new FstWriter;
// Performance_fstWriteRecords(fw); // Performance_fstWriteRecords(fw);
...@@ -235,12 +230,10 @@ void checkFstLongTerm() { ...@@ -235,12 +230,10 @@ void checkFstLongTerm() {
// for (int i = 0; i < result.size(); i++) { // for (int i = 0; i < result.size(); i++) {
// assert(result[i] == i); // check result // assert(result[i] == i); // check result
//} //}
tfCleanup();
// free(ctx); // free(ctx);
// delete m; // delete m;
} }
void checkFstCheckIterator() { void checkFstCheckIterator() {
tfInit();
FstWriter* fw = new FstWriter; FstWriter* fw = new FstWriter;
int64_t s = taosGetTimestampUs(); int64_t s = taosGetTimestampUs();
int count = 2; int count = 2;
...@@ -275,7 +268,6 @@ void checkFstCheckIterator() { ...@@ -275,7 +268,6 @@ void checkFstCheckIterator() {
free(ctx); free(ctx);
delete m; delete m;
tfCleanup();
} }
void fst_get(Fst* fst) { void fst_get(Fst* fst) {
...@@ -294,8 +286,6 @@ void fst_get(Fst* fst) { ...@@ -294,8 +286,6 @@ void fst_get(Fst* fst) {
#define NUM_OF_THREAD 10 #define NUM_OF_THREAD 10
void validateTFile(char* arg) { void validateTFile(char* arg) {
tfInit();
std::thread threads[NUM_OF_THREAD]; std::thread threads[NUM_OF_THREAD];
// std::vector<std::thread> threads; // std::vector<std::thread> threads;
TFileReader* reader = tfileReaderOpen(arg, 0, 20000000, "tag1"); TFileReader* reader = tfileReaderOpen(arg, 0, 20000000, "tag1");
...@@ -309,12 +299,9 @@ void validateTFile(char* arg) { ...@@ -309,12 +299,9 @@ void validateTFile(char* arg) {
// wait join // wait join
threads[i].join(); threads[i].join();
} }
tfCleanup();
} }
void iterTFileReader(char* path, char* ver) { void iterTFileReader(char* path, char* ver) {
tfInit();
int version = atoi(ver); int version = atoi(ver);
TFileReader* reader = tfileReaderOpen(path, 0, version, "tag1"); TFileReader* reader = tfileReaderOpen(path, 0, version, "tag1");
Iterate* iter = tfileIteratorCreate(reader); Iterate* iter = tfileIteratorCreate(reader);
...@@ -331,7 +318,6 @@ void iterTFileReader(char* path, char* ver) { ...@@ -331,7 +318,6 @@ void iterTFileReader(char* path, char* ver) {
printf("total size: %d\n term count: %d\n", count, termCount); printf("total size: %d\n term count: %d\n", count, termCount);
tfileIteratorDestroy(iter); tfileIteratorDestroy(iter);
tfCleanup();
} }
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
......
...@@ -24,8 +24,6 @@ static char tindex[PATH_MAX] = {0}; ...@@ -24,8 +24,6 @@ static char tindex[PATH_MAX] = {0};
static char tindexDir[PATH_MAX] = {0}; static char tindexDir[PATH_MAX] = {0};
static void EnvInit() { static void EnvInit() {
tfInit();
std::string path = dir; std::string path = dir;
taosRemoveDir(path.c_str()); taosRemoveDir(path.c_str());
taosMkDir(path.c_str()); taosMkDir(path.c_str());
...@@ -136,7 +134,6 @@ class FstReadMemory { ...@@ -136,7 +134,6 @@ class FstReadMemory {
fstDestroy(_fst); fstDestroy(_fst);
fstSliceDestroy(&_s); fstSliceDestroy(&_s);
writerCtxDestroy(_wc, false); writerCtxDestroy(_wc, false);
// tfCleanup();
} }
private: private:
......
...@@ -420,7 +420,6 @@ class IndexTFileEnv : public ::testing::Test { ...@@ -420,7 +420,6 @@ class IndexTFileEnv : public ::testing::Test {
virtual void SetUp() { virtual void SetUp() {
taosRemoveDir(dir.c_str()); taosRemoveDir(dir.c_str());
taosMkDir(dir.c_str()); taosMkDir(dir.c_str());
tfInit();
fObj = new TFileObj(dir, colName); fObj = new TFileObj(dir, colName);
} }
...@@ -428,7 +427,6 @@ class IndexTFileEnv : public ::testing::Test { ...@@ -428,7 +427,6 @@ class IndexTFileEnv : public ::testing::Test {
// indexClose(index); // indexClose(index);
// indexeptsDestroy(opts); // indexeptsDestroy(opts);
delete fObj; delete fObj;
tfCleanup();
// tfileWriterDestroy(twrite); // tfileWriterDestroy(twrite);
} }
TFileObj* fObj; TFileObj* fObj;
...@@ -800,13 +798,10 @@ class IndexObj { ...@@ -800,13 +798,10 @@ class IndexObj {
class IndexEnv2 : public ::testing::Test { class IndexEnv2 : public ::testing::Test {
protected: protected:
virtual void SetUp() { virtual void SetUp() {
tfInit();
index = new IndexObj(); index = new IndexObj();
//
} }
virtual void TearDown() { virtual void TearDown() {
delete index; delete index;
tfCleanup();
} }
IndexObj* index; IndexObj* index;
}; };
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
*/ */
#include "plannerInt.h" #include "plannerInt.h"
#include "exception.h" #include "texception.h"
#include "parser.h" #include "parser.h"
#define STORE_CURRENT_SUBPLAN(cxt) SSubplan* _ = cxt->pCurrentSubplan #define STORE_CURRENT_SUBPLAN(cxt) SSubplan* _ = cxt->pCurrentSubplan
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#ifndef _TD_WAL_INT_H_ #ifndef _TD_WAL_INT_H_
#define _TD_WAL_INT_H_ #define _TD_WAL_INT_H_
#include "compare.h" #include "tcompare.h"
#include "taoserror.h" #include "taoserror.h"
#include "tchecksum.h" #include "tchecksum.h"
#include "tcoding.h" #include "tcoding.h"
......
...@@ -14,10 +14,9 @@ ...@@ -14,10 +14,9 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "compare.h" #include "tcompare.h"
#include "os.h" #include "os.h"
#include "taoserror.h" #include "taoserror.h"
#include "tfile.h"
#include "tref.h" #include "tref.h"
#include "walInt.h" #include "walInt.h"
...@@ -40,15 +39,9 @@ int32_t walInit() { ...@@ -40,15 +39,9 @@ int32_t walInit() {
int8_t old = atomic_val_compare_exchange_8(&tsWal.inited, 0, 1); int8_t old = atomic_val_compare_exchange_8(&tsWal.inited, 0, 1);
if (old == 1) return 0; if (old == 1) return 0;
int code = tfInit();
if (code != 0) {
wError("failed to init tfile since %s", tstrerror(code));
atomic_store_8(&tsWal.inited, 0);
return code;
}
tsWal.refSetId = taosOpenRef(TSDB_MIN_VNODES, walFreeObj); tsWal.refSetId = taosOpenRef(TSDB_MIN_VNODES, walFreeObj);
code = walCreateThread(); int32_t code = walCreateThread();
if (code != 0) { if (code != 0) {
wError("failed to init wal module since %s", tstrerror(code)); wError("failed to init wal module since %s", tstrerror(code));
atomic_store_8(&tsWal.inited, 0); atomic_store_8(&tsWal.inited, 0);
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "tfile.h"
#include "walInt.h" #include "walInt.h"
#include "taoserror.h" #include "taoserror.h"
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "taoserror.h" #include "taoserror.h"
#include "tfile.h"
#include "tref.h" #include "tref.h"
#include "walInt.h" #include "walInt.h"
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "os.h" #include "os.h"
#include "taoserror.h" #include "taoserror.h"
#include "tchecksum.h" #include "tchecksum.h"
#include "tfile.h"
#include "walInt.h" #include "walInt.h"
int32_t walCommit(SWal *pWal, int64_t ver) { int32_t walCommit(SWal *pWal, int64_t ver) {
......
...@@ -46,6 +46,8 @@ ...@@ -46,6 +46,8 @@
#endif #endif
void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight) { void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight) {
if (inTimezone == NULL || inTimezone[0] == 0) return;
#ifdef WINDOWS #ifdef WINDOWS
char winStr[TD_LOCALE_LEN * 2]; char winStr[TD_LOCALE_LEN * 2];
sprintf(winStr, "TZ=%s", inTimezone); sprintf(winStr, "TZ=%s", inTimezone);
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "os.h"
#include "exception.h"
static threadlocal SExceptionNode* expList;
void exceptionPushNode( SExceptionNode* node ) {
node->prev = expList;
expList = node;
}
int32_t exceptionPopNode() {
SExceptionNode* node = expList;
expList = node->prev;
return node->code;
}
void exceptionThrow( int32_t code ) {
expList->code = code;
longjmp( expList->jb, 1 );
}
static void cleanupWrapper_void_ptr_ptr( SCleanupAction* ca ) {
void (*func)( void*, void* ) = ca->func;
func( ca->arg1.Ptr, ca->arg2.Ptr );
}
static void cleanupWrapper_void_ptr_bool( SCleanupAction* ca ) {
void (*func)( void*, bool ) = ca->func;
func( ca->arg1.Ptr, ca->arg2.Bool );
}
static void cleanupWrapper_void_ptr( SCleanupAction* ca ) {
void (*func)( void* ) = ca->func;
func( ca->arg1.Ptr );
}
static void cleanupWrapper_int_int( SCleanupAction* ca ) {
int (*func)( int ) = ca->func;
func( ca->arg1.Int );
}
static void cleanupWrapper_void( SCleanupAction* ca ) {
void (*func)() = ca->func;
func();
}
static void cleanupWrapper_int_ptr( SCleanupAction* ca ) {
int (*func)( void* ) = ca->func;
func( ca->arg1.Ptr );
}
typedef void (*wrapper)(SCleanupAction*);
static wrapper wrappers[] = {
cleanupWrapper_void_ptr_ptr,
cleanupWrapper_void_ptr_bool,
cleanupWrapper_void_ptr,
cleanupWrapper_int_int,
cleanupWrapper_void,
cleanupWrapper_int_ptr,
};
void cleanupPush_void_ptr_ptr( bool failOnly, void* func, void* arg1, void* arg2 ) {
assert( expList->numCleanupAction < expList->maxCleanupAction );
SCleanupAction *ca = expList->cleanupActions + expList->numCleanupAction++;
ca->wrapper = 0;
ca->failOnly = failOnly;
ca->func = func;
ca->arg1.Ptr = arg1;
ca->arg2.Ptr = arg2;
}
void cleanupPush_void_ptr_bool( bool failOnly, void* func, void* arg1, bool arg2 ) {
assert( expList->numCleanupAction < expList->maxCleanupAction );
SCleanupAction *ca = expList->cleanupActions + expList->numCleanupAction++;
ca->wrapper = 1;
ca->failOnly = failOnly;
ca->func = func;
ca->arg1.Ptr = arg1;
ca->arg2.Bool = arg2;
}
void cleanupPush_void_ptr( bool failOnly, void* func, void* arg ) {
assert( expList->numCleanupAction < expList->maxCleanupAction );
SCleanupAction *ca = expList->cleanupActions + expList->numCleanupAction++;
ca->wrapper = 2;
ca->failOnly = failOnly;
ca->func = func;
ca->arg1.Ptr = arg;
}
void cleanupPush_int_int( bool failOnly, void* func, int arg ) {
assert( expList->numCleanupAction < expList->maxCleanupAction );
SCleanupAction *ca = expList->cleanupActions + expList->numCleanupAction++;
ca->wrapper = 3;
ca->failOnly = failOnly;
ca->func = func;
ca->arg1.Int = arg;
}
void cleanupPush_void( bool failOnly, void* func ) {
assert( expList->numCleanupAction < expList->maxCleanupAction );
SCleanupAction *ca = expList->cleanupActions + expList->numCleanupAction++;
ca->wrapper = 4;
ca->failOnly = failOnly;
ca->func = func;
}
void cleanupPush_int_ptr( bool failOnly, void* func, void* arg ) {
assert( expList->numCleanupAction < expList->maxCleanupAction );
SCleanupAction *ca = expList->cleanupActions + expList->numCleanupAction++;
ca->wrapper = 5;
ca->failOnly = failOnly;
ca->func = func;
ca->arg1.Ptr = arg;
}
int32_t cleanupGetActionCount() {
return expList->numCleanupAction;
}
static void doExecuteCleanup( SExceptionNode* node, int32_t anchor, bool failed ) {
while( node->numCleanupAction > anchor ) {
--node->numCleanupAction;
SCleanupAction *ca = node->cleanupActions + node->numCleanupAction;
if( failed || !(ca->failOnly) ) {
wrappers[ca->wrapper]( ca );
}
}
}
void cleanupExecuteTo( int32_t anchor, bool failed ) {
doExecuteCleanup( expList, anchor, failed );
}
void cleanupExecute( SExceptionNode* node, bool failed ) {
doExecuteCleanup( node, 0, failed );
}
bool cleanupExceedLimit() {
return expList->numCleanupAction >= expList->maxCleanupAction;
}
此差异已折叠。
此差异已折叠。
...@@ -13,15 +13,15 @@ ...@@ -13,15 +13,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "os.h" #define _DEFAULT_SOURCE
#include "tbase64.h"
// deprecated this file for bug prone
// base64 encode
static char basis_64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static char basis_64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
char *base64_encode(const unsigned char *value, int vlen) {
unsigned char oval = 0; char *base64_encode(const uint8_t *value, int32_t vlen) {
char * result = (char *)malloc((size_t)(vlen * 4) / 3 + 10); uint8_t oval = 0;
char * out = result; char *result = (char *)malloc((size_t)(vlen * 4) / 3 + 10);
char *out = result;
while (vlen >= 3) { while (vlen >= 3) {
*out++ = basis_64[value[0] >> 2]; *out++ = basis_64[value[0] >> 2];
*out++ = basis_64[((value[0] << 4) & 0x30) | (value[1] >> 4)]; *out++ = basis_64[((value[0] << 4) & 0x30) | (value[1] >> 4)];
...@@ -42,8 +42,8 @@ char *base64_encode(const unsigned char *value, int vlen) { ...@@ -42,8 +42,8 @@ char *base64_encode(const unsigned char *value, int vlen) {
return result; return result;
} }
// base64 decode
#define CHAR64(c) (((c) < 0 || (c) > 127) ? -1 : index_64[(c)]) #define CHAR64(c) (((c) < 0 || (c) > 127) ? -1 : index_64[(c)])
static signed char index_64[128] = { static signed char index_64[128] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55,
...@@ -51,10 +51,10 @@ static signed char index_64[128] = { ...@@ -51,10 +51,10 @@ static signed char index_64[128] = {
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32,
33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1}; 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1};
unsigned char *base64_decode(const char *value, int inlen, int *outlen) { uint8_t *base64_decode(const char *value, int32_t inlen, int32_t *outlen) {
int c1, c2, c3, c4; int32_t c1, c2, c3, c4;
unsigned char *result = (unsigned char *)malloc((size_t)(inlen * 3) / 4 + 1); uint8_t *result = (uint8_t *)malloc((size_t)(inlen * 3) / 4 + 1);
unsigned char *out = result; uint8_t *out = result;
*outlen = 0; *outlen = 0;
...@@ -80,13 +80,13 @@ unsigned char *base64_decode(const char *value, int inlen, int *outlen) { ...@@ -80,13 +80,13 @@ unsigned char *base64_decode(const char *value, int inlen, int *outlen) {
if ((c4 != '=') && (CHAR64(c4) == -1)) goto base64_decode_error; if ((c4 != '=') && (CHAR64(c4) == -1)) goto base64_decode_error;
value += 4; value += 4;
*out++ = (unsigned char)((CHAR64(c1) << 2) | (CHAR64(c2) >> 4)); *out++ = (uint8_t)((CHAR64(c1) << 2) | (CHAR64(c2) >> 4));
*outlen += 1; *outlen += 1;
if (c3 != '=') { if (c3 != '=') {
*out++ = (unsigned char)(((CHAR64(c2) << 4) & 0xf0) | (CHAR64(c3) >> 2)); *out++ = (uint8_t)(((CHAR64(c2) << 4) & 0xf0) | (CHAR64(c3) >> 2));
*outlen += 1; *outlen += 1;
if (c4 != '=') { if (c4 != '=') {
*out++ = (unsigned char)(((CHAR64(c3) << 6) & 0xc0) | CHAR64(c4)); *out++ = (uint8_t)(((CHAR64(c3) << 6) & 0xc0) | CHAR64(c4));
*outlen += 1; *outlen += 1;
} }
} }
......
...@@ -14,11 +14,8 @@ ...@@ -14,11 +14,8 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "tbuffer.h" #include "tbuffer.h"
#include "exception.h" #include "texception.h"
#include "os.h"
//#include "taoserror.h"
typedef union Un4B { typedef union Un4B {
uint32_t ui; uint32_t ui;
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册