commit
2927084a49
|
@ -190,7 +190,7 @@ matrix:
|
|||
|
||||
script:
|
||||
- cmake .. > /dev/null
|
||||
- make > /dev/null
|
||||
- make > /dev/null
|
||||
|
||||
- os: linux
|
||||
arch: arm64
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
PROJECT(TDengine)
|
||||
IF (CMAKE_VERSION VERSION_LESS 3.0)
|
||||
PROJECT(TDengine CXX)
|
||||
SET(PROJECT_VERSION_MAJOR "${LIB_MAJOR_VERSION}")
|
||||
SET(PROJECT_VERSION_MINOR "${LIB_MINOR_VERSION}")
|
||||
SET(PROJECT_VERSION_PATCH"${LIB_PATCH_VERSION}")
|
||||
SET(PROJECT_VERSION "${LIB_VERSION_STRING}")
|
||||
ELSE ()
|
||||
CMAKE_POLICY(SET CMP0048 NEW)
|
||||
PROJECT(TDengine VERSION "${LIB_VERSION_STRING}" LANGUAGES CXX)
|
||||
ENDIF ()
|
||||
|
||||
SET(TD_ACCOUNT FALSE)
|
||||
SET(TD_ADMIN FALSE)
|
||||
|
|
|
@ -53,14 +53,18 @@ IF (TD_LINUX_64)
|
|||
ADD_DEFINITIONS(-D_M_X64)
|
||||
ADD_DEFINITIONS(-D_TD_LINUX_64)
|
||||
IF (NOT TD_ARM)
|
||||
IF (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
|
||||
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -Wno-missing-braces -fPIC -g3 -gdwarf-2 -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||
ELSE ()
|
||||
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -malign-double -g3 -gdwarf-2 -malign-stringops -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||
ENDIF ()
|
||||
#IF ((${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") OR (${CMAKE_CXX_COMPILER_ID} MATCHES "clang"))
|
||||
# SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -Wno-missing-braces -fPIC -g3 -gdwarf-2 -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||
#ELSE ()
|
||||
# SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -malign-double -g3 -gdwarf-2 -malign-stringops -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||
#ENDIF ()
|
||||
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -g3 -gdwarf-2 -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||
ELSE ()
|
||||
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -g -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||
ENDIF ()
|
||||
MESSAGE(STATUS "CMAKE_CXX_COMPILER_ID: " ${CMAKE_CXX_COMPILER_ID})
|
||||
MESSAGE(STATUS "COMMON_FLAGS: " ${COMMON_FLAGS})
|
||||
|
||||
FIND_PATH(ICONV_INCLUDE_EXIST iconv.h /usr/include/ /usr/local/include/)
|
||||
IF (ICONV_INCLUDE_EXIST)
|
||||
ADD_DEFINITIONS(-DUSE_LIBICONV)
|
||||
|
|
|
@ -52,14 +52,16 @@ ELSE ()
|
|||
MESSAGE(STATUS "input cpuType unknown " ${CPUTYPE})
|
||||
ENDIF ()
|
||||
|
||||
#
|
||||
# Get OS information and store in variable TD_OS_INFO.
|
||||
#
|
||||
execute_process(COMMAND chmod 777 ${TD_COMMUNITY_DIR}/packaging/tools/get_os.sh)
|
||||
execute_process(COMMAND ${TD_COMMUNITY_DIR}/packaging/tools/get_os.sh "" OUTPUT_VARIABLE TD_OS_INFO)
|
||||
MESSAGE(STATUS "The current os is " ${TD_OS_INFO})
|
||||
|
||||
|
||||
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
#
|
||||
# Get OS information and store in variable TD_OS_INFO.
|
||||
#
|
||||
execute_process(COMMAND chmod 777 ${TD_COMMUNITY_DIR}/packaging/tools/get_os.sh)
|
||||
execute_process(COMMAND ${TD_COMMUNITY_DIR}/packaging/tools/get_os.sh "" OUTPUT_VARIABLE TD_OS_INFO)
|
||||
MESSAGE(STATUS "The current os is " ${TD_OS_INFO})
|
||||
|
||||
SET(TD_LINUX TRUE)
|
||||
IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
|
||||
SET(TD_LINUX_64 TRUE)
|
||||
|
|
|
@ -14,10 +14,10 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tutil.h"
|
||||
#include "tbalance.h"
|
||||
#include "tsync.h"
|
||||
#include "ttime.h"
|
||||
#include "ttimer.h"
|
||||
#include "tglobal.h"
|
||||
#include "tdataformat.h"
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include "tlog.h"
|
||||
#include "tscUtil.h"
|
||||
#include "tsclient.h"
|
||||
#include "ttime.h"
|
||||
|
||||
#include "com_taosdata_jdbc_TSDBJNIConnector.h"
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include "tscSubquery.h"
|
||||
#include "tscompression.h"
|
||||
#include "tsqlfunction.h"
|
||||
#include "ttime.h"
|
||||
#include "tutil.h"
|
||||
|
||||
#define GET_INPUT_CHAR(x) (((char *)((x)->aInputElemBuf)) + ((x)->startOffset) * ((x)->inputBytes))
|
||||
|
@ -2108,7 +2107,7 @@ static void copyTopBotRes(SQLFunctionCtx *pCtx, int32_t type) {
|
|||
}
|
||||
}
|
||||
|
||||
tfree(pData);
|
||||
taosTFree(pData);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -326,7 +326,7 @@ static void tscProcessServerVer(SSqlObj *pSql) {
|
|||
STR_WITH_SIZE_TO_VARSTR(vx, v, t);
|
||||
tscSetLocalQueryResult(pSql, vx, pExpr->aliasName, pExpr->resType, pExpr->resBytes);
|
||||
|
||||
tfree(vx);
|
||||
taosTFree(vx);
|
||||
}
|
||||
|
||||
static void tscProcessClientVer(SSqlObj *pSql) {
|
||||
|
@ -342,7 +342,7 @@ static void tscProcessClientVer(SSqlObj *pSql) {
|
|||
STR_WITH_SIZE_TO_VARSTR(v, version, t);
|
||||
tscSetLocalQueryResult(pSql, v, pExpr->aliasName, pExpr->resType, pExpr->resBytes);
|
||||
|
||||
tfree(v);
|
||||
taosTFree(v);
|
||||
}
|
||||
|
||||
static void tscProcessServStatus(SSqlObj *pSql) {
|
||||
|
|
|
@ -230,7 +230,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
|||
if (ds == NULL) {
|
||||
tscError("%p failed to create merge structure", pSql);
|
||||
pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
tfree(pReducer);
|
||||
taosTFree(pReducer);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -257,7 +257,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
|||
|
||||
if (ds->filePage.num == 0) { // no data in this flush, the index does not increase
|
||||
tscDebug("%p flush data is empty, ignore %d flush record", pSql, idx);
|
||||
tfree(ds);
|
||||
taosTFree(ds);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -267,7 +267,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
|||
|
||||
// no data actually, no need to merge result.
|
||||
if (idx == 0) {
|
||||
tfree(pReducer);
|
||||
taosTFree(pReducer);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -275,7 +275,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
|||
|
||||
SCompareParam *param = malloc(sizeof(SCompareParam));
|
||||
if (param == NULL) {
|
||||
tfree(pReducer);
|
||||
taosTFree(pReducer);
|
||||
return;
|
||||
}
|
||||
param->pLocalData = pReducer->pLocalDataSrc;
|
||||
|
@ -288,8 +288,8 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
|||
|
||||
pRes->code = tLoserTreeCreate(&pReducer->pLoserTree, pReducer->numOfBuffer, param, treeComparator);
|
||||
if (pReducer->pLoserTree == NULL || pRes->code != 0) {
|
||||
tfree(param);
|
||||
tfree(pReducer);
|
||||
taosTFree(param);
|
||||
taosTFree(pReducer);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -332,14 +332,14 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
|||
|
||||
if (pReducer->pTempBuffer == NULL || pReducer->discardData == NULL || pReducer->pResultBuf == NULL ||
|
||||
/*pReducer->pBufForInterpo == NULL || */pReducer->pFinalRes == NULL || pReducer->prevRowOfInput == NULL) {
|
||||
tfree(pReducer->pTempBuffer);
|
||||
tfree(pReducer->discardData);
|
||||
tfree(pReducer->pResultBuf);
|
||||
tfree(pReducer->pFinalRes);
|
||||
tfree(pReducer->prevRowOfInput);
|
||||
tfree(pReducer->pLoserTree);
|
||||
tfree(param);
|
||||
tfree(pReducer);
|
||||
taosTFree(pReducer->pTempBuffer);
|
||||
taosTFree(pReducer->discardData);
|
||||
taosTFree(pReducer->pResultBuf);
|
||||
taosTFree(pReducer->pFinalRes);
|
||||
taosTFree(pReducer->prevRowOfInput);
|
||||
taosTFree(pReducer->pLoserTree);
|
||||
taosTFree(param);
|
||||
taosTFree(pReducer);
|
||||
pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
return;
|
||||
}
|
||||
|
@ -516,38 +516,38 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
|
|||
|
||||
tVariantDestroy(&pCtx->tag);
|
||||
if (pCtx->tagInfo.pTagCtxList != NULL) {
|
||||
tfree(pCtx->tagInfo.pTagCtxList);
|
||||
taosTFree(pCtx->tagInfo.pTagCtxList);
|
||||
}
|
||||
}
|
||||
|
||||
tfree(pLocalReducer->pCtx);
|
||||
taosTFree(pLocalReducer->pCtx);
|
||||
}
|
||||
|
||||
tfree(pLocalReducer->prevRowOfInput);
|
||||
taosTFree(pLocalReducer->prevRowOfInput);
|
||||
|
||||
tfree(pLocalReducer->pTempBuffer);
|
||||
tfree(pLocalReducer->pResultBuf);
|
||||
taosTFree(pLocalReducer->pTempBuffer);
|
||||
taosTFree(pLocalReducer->pResultBuf);
|
||||
|
||||
if (pLocalReducer->pResInfo != NULL) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
tfree(pLocalReducer->pResInfo[i].interResultBuf);
|
||||
taosTFree(pLocalReducer->pResInfo[i].interResultBuf);
|
||||
}
|
||||
|
||||
tfree(pLocalReducer->pResInfo);
|
||||
taosTFree(pLocalReducer->pResInfo);
|
||||
}
|
||||
|
||||
if (pLocalReducer->pLoserTree) {
|
||||
tfree(pLocalReducer->pLoserTree->param);
|
||||
tfree(pLocalReducer->pLoserTree);
|
||||
taosTFree(pLocalReducer->pLoserTree->param);
|
||||
taosTFree(pLocalReducer->pLoserTree);
|
||||
}
|
||||
|
||||
tfree(pLocalReducer->pFinalRes);
|
||||
tfree(pLocalReducer->discardData);
|
||||
taosTFree(pLocalReducer->pFinalRes);
|
||||
taosTFree(pLocalReducer->discardData);
|
||||
|
||||
tscLocalReducerEnvDestroy(pLocalReducer->pExtMemBuffer, pLocalReducer->pDesc, pLocalReducer->resColModel,
|
||||
pLocalReducer->numOfVnode);
|
||||
for (int32_t i = 0; i < pLocalReducer->numOfBuffer; ++i) {
|
||||
tfree(pLocalReducer->pLocalDataSrc[i]);
|
||||
taosTFree(pLocalReducer->pLocalDataSrc[i]);
|
||||
}
|
||||
|
||||
pLocalReducer->numOfBuffer = 0;
|
||||
|
@ -593,7 +593,7 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm
|
|||
}
|
||||
|
||||
*pOrderDesc = tOrderDesCreate(orderIdx, numOfGroupByCols, pModel, pQueryInfo->order.order);
|
||||
tfree(orderIdx);
|
||||
taosTFree(orderIdx);
|
||||
|
||||
if (*pOrderDesc == NULL) {
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
|
@ -705,7 +705,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
|
|||
|
||||
if (createOrderDescriptor(pOrderDesc, pCmd, pModel) != TSDB_CODE_SUCCESS) {
|
||||
pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
tfree(pSchema);
|
||||
taosTFree(pSchema);
|
||||
return pRes->code;
|
||||
}
|
||||
|
||||
|
@ -746,7 +746,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
|
|||
}
|
||||
|
||||
*pFinalModel = createColumnModel(pSchema, size, capacity);
|
||||
tfree(pSchema);
|
||||
taosTFree(pSchema);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -765,7 +765,7 @@ void tscLocalReducerEnvDestroy(tExtMemBuffer **pMemBuffer, tOrderDescriptor *pDe
|
|||
pMemBuffer[i] = destoryExtMemBuffer(pMemBuffer[i]);
|
||||
}
|
||||
|
||||
tfree(pMemBuffer);
|
||||
taosTFree(pMemBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1036,10 +1036,10 @@ static void doFillResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool doneO
|
|||
|
||||
pFinalDataPage->num = 0;
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
tfree(pResPages[i]);
|
||||
taosTFree(pResPages[i]);
|
||||
}
|
||||
|
||||
tfree(pResPages);
|
||||
taosTFree(pResPages);
|
||||
}
|
||||
|
||||
static void savePreviousRow(SLocalReducer *pLocalReducer, tFilePage *tmpBuffer) {
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
#include "tscLog.h"
|
||||
#include "tscSubquery.h"
|
||||
#include "tstoken.h"
|
||||
#include "ttime.h"
|
||||
|
||||
#include "tdataformat.h"
|
||||
|
||||
|
@ -1388,7 +1387,7 @@ static void parseFileSendDataBlock(void *param, TAOS_RES *tres, int code) {
|
|||
assert(taos_errno(pSql) == code);
|
||||
|
||||
taos_free_result(pSql);
|
||||
tfree(pSupporter);
|
||||
taosTFree(pSupporter);
|
||||
fclose(fp);
|
||||
|
||||
pParentSql->res.code = code;
|
||||
|
@ -1453,7 +1452,7 @@ static void parseFileSendDataBlock(void *param, TAOS_RES *tres, int code) {
|
|||
}
|
||||
}
|
||||
|
||||
tfree(tokenBuf);
|
||||
taosTFree(tokenBuf);
|
||||
free(line);
|
||||
|
||||
if (count > 0) {
|
||||
|
@ -1466,7 +1465,7 @@ static void parseFileSendDataBlock(void *param, TAOS_RES *tres, int code) {
|
|||
|
||||
} else {
|
||||
taos_free_result(pSql);
|
||||
tfree(pSupporter);
|
||||
taosTFree(pSupporter);
|
||||
fclose(fp);
|
||||
|
||||
pParentSql->fp = pParentSql->fetchFp;
|
||||
|
@ -1496,7 +1495,7 @@ void tscProcessMultiVnodesImportFromFile(SSqlObj *pSql) {
|
|||
pSql->res.code = TAOS_SYSTEM_ERROR(errno);
|
||||
tscError("%p failed to open file %s to load data from file, code:%s", pSql, pCmd->payload, tstrerror(pSql->res.code));
|
||||
|
||||
tfree(pSupporter)
|
||||
taosTFree(pSupporter)
|
||||
tscQueueAsyncRes(pSql);
|
||||
|
||||
return;
|
||||
|
|
|
@ -613,7 +613,7 @@ int taos_stmt_execute(TAOS_STMT* stmt) {
|
|||
if (sql == NULL) {
|
||||
ret = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
} else {
|
||||
tfree(pStmt->pSql->sqlstr);
|
||||
taosTFree(pStmt->pSql->sqlstr);
|
||||
pStmt->pSql->sqlstr = sql;
|
||||
SSqlObj* pSql = taos_query((TAOS*)pStmt->taos, pStmt->pSql->sqlstr);
|
||||
ret = taos_errno(pSql);
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#include "os.h"
|
||||
#include "tscLog.h"
|
||||
#include "tsclient.h"
|
||||
#include "ttime.h"
|
||||
#include "ttimer.h"
|
||||
#include "tutil.h"
|
||||
#include "taosmsg.h"
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include "tsclient.h"
|
||||
#include "tstoken.h"
|
||||
#include "tstrbuild.h"
|
||||
#include "ttime.h"
|
||||
#include "ttokendef.h"
|
||||
|
||||
#define DEFAULT_PRIMARY_TIMESTAMP_COL_NAME "_c0"
|
||||
|
@ -737,7 +736,7 @@ int32_t tscSetTableFullName(STableMetaInfo* pTableMetaInfo, SSQLToken* pzTableNa
|
|||
assert(pTableMetaInfo->pTableMeta == NULL);
|
||||
}
|
||||
|
||||
tfree(oldName);
|
||||
taosTFree(oldName);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -3648,7 +3647,7 @@ static int32_t setTableCondForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
|
|||
int32_t ret = setObjFullName(idBuf, account, &dbToken, &t, &xlen);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
taosStringBuilderDestroy(&sb1);
|
||||
tfree(segments);
|
||||
taosTFree(segments);
|
||||
|
||||
invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg);
|
||||
return ret;
|
||||
|
@ -3661,7 +3660,7 @@ static int32_t setTableCondForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
|
|||
pQueryInfo->tagCond.tbnameCond.cond = strdup(str);
|
||||
|
||||
taosStringBuilderDestroy(&sb1);
|
||||
tfree(segments);
|
||||
taosTFree(segments);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "tscUtil.h"
|
||||
#include "tschemautil.h"
|
||||
#include "tsclient.h"
|
||||
#include "ttime.h"
|
||||
#include "ttimer.h"
|
||||
#include "tutil.h"
|
||||
#include "tlockfree.h"
|
||||
|
@ -196,7 +195,7 @@ void tscProcessActivityTimer(void *handle, void *tmrId) {
|
|||
|
||||
pSql->cmd.command = TSDB_SQL_HB;
|
||||
if (TSDB_CODE_SUCCESS != tscAllocPayload(&(pSql->cmd), TSDB_DEFAULT_PAYLOAD_SIZE)) {
|
||||
tfree(pSql);
|
||||
taosTFree(pSql);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1538,7 +1537,7 @@ int tscBuildTableMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
pCmd->payloadLen = pMsg - (char*)pInfoMsg;
|
||||
pCmd->msgType = TSDB_MSG_TYPE_CM_TABLE_META;
|
||||
|
||||
tfree(tmpData);
|
||||
taosTFree(tmpData);
|
||||
|
||||
assert(msgLen + minMsgSize() <= pCmd->allocSize);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -1572,7 +1571,7 @@ int tscBuildMultiMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
memcpy(pInfoMsg->tableIds, tmpData, pCmd->payloadLen);
|
||||
}
|
||||
|
||||
tfree(tmpData);
|
||||
taosTFree(tmpData);
|
||||
|
||||
pCmd->payloadLen += sizeof(SMgmtHead) + sizeof(SCMMultiTableInfoMsg);
|
||||
pCmd->msgType = TSDB_MSG_TYPE_CM_TABLES_META;
|
||||
|
@ -1962,7 +1961,7 @@ int tscProcessShowRsp(SSqlObj *pSql) {
|
|||
pCmd->numOfCols = pQueryInfo->fieldsInfo.numOfOutput;
|
||||
tscFieldInfoUpdateOffset(pQueryInfo);
|
||||
|
||||
tfree(pTableMeta);
|
||||
taosTFree(pTableMeta);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -474,7 +474,7 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) {
|
|||
pRes->rspType = 0;
|
||||
|
||||
pSql->numOfSubs = 0;
|
||||
tfree(pSql->pSubs);
|
||||
taosTFree(pSql->pSubs);
|
||||
|
||||
assert(pSql->fp == NULL);
|
||||
|
||||
|
@ -753,7 +753,7 @@ int taos_validate_sql(TAOS *taos, const char *sql) {
|
|||
if (sqlLen > tsMaxSQLStringLen) {
|
||||
tscError("%p sql too long", pSql);
|
||||
pRes->code = TSDB_CODE_TSC_INVALID_SQL;
|
||||
tfree(pSql);
|
||||
taosTFree(pSql);
|
||||
return pRes->code;
|
||||
}
|
||||
|
||||
|
@ -762,7 +762,7 @@ int taos_validate_sql(TAOS *taos, const char *sql) {
|
|||
pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
tscError("%p failed to malloc sql string buffer", pSql);
|
||||
tscDebug("%p Valid SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj);
|
||||
tfree(pSql);
|
||||
taosTFree(pSql);
|
||||
return pRes->code;
|
||||
}
|
||||
|
||||
|
@ -896,7 +896,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) {
|
|||
if (tblListLen > MAX_TABLE_NAME_LENGTH) {
|
||||
tscError("%p tableNameList too long, length:%d, maximum allowed:%d", pSql, tblListLen, MAX_TABLE_NAME_LENGTH);
|
||||
pRes->code = TSDB_CODE_TSC_INVALID_SQL;
|
||||
tfree(pSql);
|
||||
taosTFree(pSql);
|
||||
return pRes->code;
|
||||
}
|
||||
|
||||
|
@ -904,7 +904,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) {
|
|||
if (str == NULL) {
|
||||
pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
tscError("%p failed to malloc sql string buffer", pSql);
|
||||
tfree(pSql);
|
||||
taosTFree(pSql);
|
||||
return pRes->code;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "tsched.h"
|
||||
#include "tcache.h"
|
||||
#include "tsclient.h"
|
||||
#include "ttime.h"
|
||||
#include "ttimer.h"
|
||||
#include "tutil.h"
|
||||
|
||||
|
@ -156,7 +155,7 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf
|
|||
|
||||
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pStream->pSql->cmd, 0, 0);
|
||||
taosCacheRelease(tscCacheHandle, (void**)&(pTableMetaInfo->pTableMeta), true);
|
||||
tfree(pTableMetaInfo->vgroupList);
|
||||
taosTFree(pTableMetaInfo->vgroupList);
|
||||
|
||||
tscSetRetryTimer(pStream, pStream->pSql, retryDelay);
|
||||
return;
|
||||
|
@ -260,9 +259,9 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
|
|||
|
||||
taosCacheRelease(tscCacheHandle, (void**)&(pTableMetaInfo->pTableMeta), false);
|
||||
tscFreeSqlResult(pSql);
|
||||
tfree(pSql->pSubs);
|
||||
taosTFree(pSql->pSubs);
|
||||
pSql->numOfSubs = 0;
|
||||
tfree(pTableMetaInfo->vgroupList);
|
||||
taosTFree(pTableMetaInfo->vgroupList);
|
||||
tscSetNextLaunchTimer(pStream, pSql);
|
||||
}
|
||||
}
|
||||
|
@ -592,6 +591,6 @@ void taos_close_stream(TAOS_STREAM *handle) {
|
|||
tscFreeSqlObj(pSql);
|
||||
pStream->pSql = NULL;
|
||||
|
||||
tfree(pStream);
|
||||
taosTFree(pStream);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include "trpc.h"
|
||||
#include "tsclient.h"
|
||||
#include "tsocket.h"
|
||||
#include "ttime.h"
|
||||
#include "ttimer.h"
|
||||
#include "tutil.h"
|
||||
#include "tscLog.h"
|
||||
|
|
|
@ -183,7 +183,7 @@ SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, in
|
|||
pSupporter->uid = pTableMetaInfo->pTableMeta->id.uid;
|
||||
assert (pSupporter->uid != 0);
|
||||
|
||||
getTmpfilePath("join-", pSupporter->path);
|
||||
taosGetTmpfilePath("join-", pSupporter->path);
|
||||
pSupporter->f = fopen(pSupporter->path, "w");
|
||||
|
||||
// todo handle error
|
||||
|
@ -215,7 +215,7 @@ static void tscDestroyJoinSupporter(SJoinSupporter* pSupporter) {
|
|||
pSupporter->f = NULL;
|
||||
}
|
||||
|
||||
tfree(pSupporter->pIdTagList);
|
||||
taosTFree(pSupporter->pIdTagList);
|
||||
tscTagCondRelease(&pSupporter->tagCond);
|
||||
free(pSupporter);
|
||||
}
|
||||
|
@ -407,7 +407,7 @@ void freeJoinSubqueryObj(SSqlObj* pSql) {
|
|||
}
|
||||
}
|
||||
|
||||
tfree(pState);
|
||||
taosTFree(pState);
|
||||
pSql->numOfSubs = 0;
|
||||
}
|
||||
|
||||
|
@ -773,7 +773,7 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
|
|||
|
||||
// continue to retrieve ts-comp data from vnode
|
||||
if (!pRes->completed) {
|
||||
getTmpfilePath("ts-join", pSupporter->path);
|
||||
taosGetTmpfilePath("ts-join", pSupporter->path);
|
||||
pSupporter->f = fopen(pSupporter->path, "w");
|
||||
pRes->row = pRes->numOfRows;
|
||||
|
||||
|
@ -797,7 +797,7 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
|
|||
tscResetForNextRetrieve(&pSql->res);
|
||||
|
||||
assert(pSupporter->f == NULL);
|
||||
getTmpfilePath("ts-join", pSupporter->path);
|
||||
taosGetTmpfilePath("ts-join", pSupporter->path);
|
||||
|
||||
// TODO check for failure
|
||||
pSupporter->f = fopen(pSupporter->path, "w");
|
||||
|
@ -1317,12 +1317,12 @@ static void doCleanupSubqueries(SSqlObj *pSql, int32_t numOfSubs, SSubqueryState
|
|||
|
||||
SRetrieveSupport* pSupport = pSub->param;
|
||||
|
||||
tfree(pSupport->localBuffer);
|
||||
taosTFree(pSupport->localBuffer);
|
||||
|
||||
pthread_mutex_unlock(&pSupport->queryMutex);
|
||||
pthread_mutex_destroy(&pSupport->queryMutex);
|
||||
|
||||
tfree(pSupport);
|
||||
taosTFree(pSupport);
|
||||
|
||||
tscFreeSqlObj(pSub);
|
||||
}
|
||||
|
@ -1358,7 +1358,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
|
|||
if (ret != 0) {
|
||||
pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
tscQueueAsyncRes(pSql);
|
||||
tfree(pMemoryBuf);
|
||||
taosTFree(pMemoryBuf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1386,7 +1386,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
|
|||
trs->localBuffer = (tFilePage *)calloc(1, nBufferSize + sizeof(tFilePage));
|
||||
if (trs->localBuffer == NULL) {
|
||||
tscError("%p failed to malloc buffer for local buffer, orderOfSub:%d, reason:%s", pSql, i, strerror(errno));
|
||||
tfree(trs);
|
||||
taosTFree(trs);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1404,8 +1404,8 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
|
|||
SSqlObj *pNew = tscCreateSqlObjForSubquery(pSql, trs, NULL);
|
||||
if (pNew == NULL) {
|
||||
tscError("%p failed to malloc buffer for subObj, orderOfSub:%d, reason:%s", pSql, i, strerror(errno));
|
||||
tfree(trs->localBuffer);
|
||||
tfree(trs);
|
||||
taosTFree(trs->localBuffer);
|
||||
taosTFree(trs);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1450,12 +1450,12 @@ static void tscFreeSubSqlObj(SRetrieveSupport *trsupport, SSqlObj *pSql) {
|
|||
|
||||
taos_free_result(pSql);
|
||||
|
||||
tfree(trsupport->localBuffer);
|
||||
taosTFree(trsupport->localBuffer);
|
||||
|
||||
pthread_mutex_unlock(&trsupport->queryMutex);
|
||||
pthread_mutex_destroy(&trsupport->queryMutex);
|
||||
|
||||
tfree(trsupport);
|
||||
taosTFree(trsupport);
|
||||
}
|
||||
|
||||
static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfRows);
|
||||
|
@ -1572,7 +1572,7 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO
|
|||
tscLocalReducerEnvDestroy(trsupport->pExtMemBuffer, trsupport->pOrderDescriptor, trsupport->pFinalColModel,
|
||||
pState->numOfTotal);
|
||||
|
||||
tfree(trsupport->pState);
|
||||
taosTFree(trsupport->pState);
|
||||
tscFreeSubSqlObj(trsupport, pSql);
|
||||
|
||||
// in case of second stage join subquery, invoke its callback function instead of regular QueueAsyncRes
|
||||
|
@ -1651,7 +1651,7 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p
|
|||
pParentSql->res.row = 0;
|
||||
|
||||
// only free once
|
||||
tfree(trsupport->pState);
|
||||
taosTFree(trsupport->pState);
|
||||
tscFreeSubSqlObj(trsupport, pSql);
|
||||
|
||||
// set the command flag must be after the semaphore been correctly set.
|
||||
|
@ -1855,7 +1855,7 @@ static void multiVnodeInsertFinalize(void* param, TAOS_RES* tres, int numOfRows)
|
|||
}
|
||||
|
||||
taos_free_result(tres);
|
||||
tfree(pSupporter);
|
||||
taosTFree(pSupporter);
|
||||
|
||||
if (atomic_sub_fetch_32(&pState->numOfRemain, 1) > 0) {
|
||||
return;
|
||||
|
@ -1864,7 +1864,7 @@ static void multiVnodeInsertFinalize(void* param, TAOS_RES* tres, int numOfRows)
|
|||
tscDebug("%p Async insertion completed, total inserted:%" PRId64, pParentObj, pParentObj->res.numOfRows);
|
||||
|
||||
// release data block data
|
||||
tfree(pState);
|
||||
taosTFree(pState);
|
||||
|
||||
// restore user defined fp
|
||||
pParentObj->fp = pParentObj->fetchFp;
|
||||
|
@ -1968,11 +1968,11 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) {
|
|||
|
||||
_error:
|
||||
for(int32_t j = 0; j < numOfSub; ++j) {
|
||||
tfree(pSql->pSubs[j]->param);
|
||||
taosTFree(pSql->pSubs[j]->param);
|
||||
taos_free_result(pSql->pSubs[j]);
|
||||
}
|
||||
|
||||
tfree(pState);
|
||||
taosTFree(pState);
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
@ -2143,7 +2143,7 @@ void **doSetResultRowData(SSqlObj *pSql, bool finalResult) {
|
|||
assert(pRes->row >= 0 && pRes->row <= pRes->numOfRows);
|
||||
|
||||
if (pRes->row >= pRes->numOfRows) { // all the results has returned to invoker
|
||||
tfree(pRes->tsrow);
|
||||
taosTFree(pRes->tsrow);
|
||||
return pRes->tsrow;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include "tcache.h"
|
||||
#include "trpc.h"
|
||||
#include "tsystem.h"
|
||||
#include "ttime.h"
|
||||
#include "ttimer.h"
|
||||
#include "tutil.h"
|
||||
#include "tsched.h"
|
||||
|
|
|
@ -245,7 +245,7 @@ void tscClearInterpInfo(SQueryInfo* pQueryInfo) {
|
|||
}
|
||||
|
||||
pQueryInfo->fillType = TSDB_FILL_NONE;
|
||||
tfree(pQueryInfo->fillVal);
|
||||
taosTFree(pQueryInfo->fillVal);
|
||||
}
|
||||
|
||||
int32_t tscCreateResPointerInfo(SSqlRes* pRes, SQueryInfo* pQueryInfo) {
|
||||
|
@ -259,9 +259,9 @@ int32_t tscCreateResPointerInfo(SSqlRes* pRes, SQueryInfo* pQueryInfo) {
|
|||
|
||||
// not enough memory
|
||||
if (pRes->tsrow == NULL || (pRes->buffer == NULL && pRes->numOfCols > 0)) {
|
||||
tfree(pRes->tsrow);
|
||||
tfree(pRes->buffer);
|
||||
tfree(pRes->length);
|
||||
taosTFree(pRes->tsrow);
|
||||
taosTFree(pRes->buffer);
|
||||
taosTFree(pRes->length);
|
||||
|
||||
pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
return pRes->code;
|
||||
|
@ -274,23 +274,23 @@ int32_t tscCreateResPointerInfo(SSqlRes* pRes, SQueryInfo* pQueryInfo) {
|
|||
void tscDestroyResPointerInfo(SSqlRes* pRes) {
|
||||
if (pRes->buffer != NULL) { // free all buffers containing the multibyte string
|
||||
for (int i = 0; i < pRes->numOfCols; i++) {
|
||||
tfree(pRes->buffer[i]);
|
||||
taosTFree(pRes->buffer[i]);
|
||||
}
|
||||
|
||||
pRes->numOfCols = 0;
|
||||
}
|
||||
|
||||
tfree(pRes->pRsp);
|
||||
tfree(pRes->tsrow);
|
||||
tfree(pRes->length);
|
||||
taosTFree(pRes->pRsp);
|
||||
taosTFree(pRes->tsrow);
|
||||
taosTFree(pRes->length);
|
||||
|
||||
tfree(pRes->pGroupRec);
|
||||
tfree(pRes->pColumnIndex);
|
||||
tfree(pRes->buffer);
|
||||
taosTFree(pRes->pGroupRec);
|
||||
taosTFree(pRes->pColumnIndex);
|
||||
taosTFree(pRes->buffer);
|
||||
|
||||
if (pRes->pArithSup != NULL) {
|
||||
tfree(pRes->pArithSup->data);
|
||||
tfree(pRes->pArithSup);
|
||||
taosTFree(pRes->pArithSup->data);
|
||||
taosTFree(pRes->pArithSup);
|
||||
}
|
||||
|
||||
pRes->data = NULL; // pRes->data points to the buffer of pRsp, no need to free
|
||||
|
@ -307,11 +307,11 @@ static void tscFreeQueryInfo(SSqlCmd* pCmd) {
|
|||
|
||||
freeQueryInfoImpl(pQueryInfo);
|
||||
clearAllTableMetaInfo(pQueryInfo, (const char*)addr, false);
|
||||
tfree(pQueryInfo);
|
||||
taosTFree(pQueryInfo);
|
||||
}
|
||||
|
||||
pCmd->numOfClause = 0;
|
||||
tfree(pCmd->pQueryInfo);
|
||||
taosTFree(pCmd->pQueryInfo);
|
||||
}
|
||||
|
||||
void tscResetSqlCmdObj(SSqlCmd* pCmd) {
|
||||
|
@ -357,13 +357,13 @@ void tscPartiallyFreeSqlObj(SSqlObj* pSql) {
|
|||
// pSql->sqlstr will be used by tscBuildQueryStreamDesc
|
||||
if (pObj->signature == pObj) {
|
||||
//pthread_mutex_lock(&pObj->mutex);
|
||||
tfree(pSql->sqlstr);
|
||||
taosTFree(pSql->sqlstr);
|
||||
//pthread_mutex_unlock(&pObj->mutex);
|
||||
}
|
||||
|
||||
tscFreeSqlResult(pSql);
|
||||
|
||||
tfree(pSql->pSubs);
|
||||
taosTFree(pSql->pSubs);
|
||||
pSql->numOfSubs = 0;
|
||||
|
||||
tscResetSqlCmdObj(pCmd);
|
||||
|
@ -383,10 +383,10 @@ void tscFreeSqlObj(SSqlObj* pSql) {
|
|||
SSqlCmd* pCmd = &pSql->cmd;
|
||||
|
||||
memset(pCmd->payload, 0, (size_t)pCmd->allocSize);
|
||||
tfree(pCmd->payload);
|
||||
taosTFree(pCmd->payload);
|
||||
pCmd->allocSize = 0;
|
||||
|
||||
tfree(pSql->sqlstr);
|
||||
taosTFree(pSql->sqlstr);
|
||||
sem_destroy(&pSql->rspSem);
|
||||
free(pSql);
|
||||
}
|
||||
|
@ -396,12 +396,12 @@ void tscDestroyDataBlock(STableDataBlocks* pDataBlock) {
|
|||
return;
|
||||
}
|
||||
|
||||
tfree(pDataBlock->pData);
|
||||
tfree(pDataBlock->params);
|
||||
taosTFree(pDataBlock->pData);
|
||||
taosTFree(pDataBlock->params);
|
||||
|
||||
// free the refcount for metermeta
|
||||
taosCacheRelease(tscCacheHandle, (void**)&(pDataBlock->pTableMeta), false);
|
||||
tfree(pDataBlock);
|
||||
taosTFree(pDataBlock);
|
||||
}
|
||||
|
||||
SParamInfo* tscAddParamToDataBlock(STableDataBlocks* pDataBlock, char type, uint8_t timePrec, short bytes,
|
||||
|
@ -679,7 +679,7 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SArray* pTableDataBlockList) {
|
|||
|
||||
taosHashCleanup(pVnodeDataBlockHashList);
|
||||
tscDestroyBlockArrayList(pVnodeDataBlockList);
|
||||
tfree(dataBuf->pData);
|
||||
taosTFree(dataBuf->pData);
|
||||
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -735,7 +735,7 @@ void tscCloseTscObj(STscObj* pObj) {
|
|||
}
|
||||
|
||||
tscDebug("%p DB connection is closed, dnodeConn:%p", pObj, pObj->pDnodeConn);
|
||||
tfree(pObj);
|
||||
taosTFree(pObj);
|
||||
}
|
||||
|
||||
bool tscIsInsertData(char* sqlstr) {
|
||||
|
@ -916,7 +916,7 @@ void tscFieldInfoClear(SFieldInfo* pFieldInfo) {
|
|||
|
||||
if (pInfo->pArithExprInfo != NULL) {
|
||||
tExprTreeDestroy(&pInfo->pArithExprInfo->pExpr, NULL);
|
||||
tfree(pInfo->pArithExprInfo);
|
||||
taosTFree(pInfo->pArithExprInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1029,7 +1029,7 @@ void* sqlExprDestroy(SSqlExpr* pExpr) {
|
|||
tVariantDestroy(&pExpr->param[i]);
|
||||
}
|
||||
|
||||
tfree(pExpr);
|
||||
taosTFree(pExpr);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1116,11 +1116,11 @@ SColumn* tscColumnListInsert(SArray* pColumnList, SColumnIndex* pColIndex) {
|
|||
static void destroyFilterInfo(SColumnFilterInfo* pFilterInfo, int32_t numOfFilters) {
|
||||
for(int32_t i = 0; i < numOfFilters; ++i) {
|
||||
if (pFilterInfo[i].filterstr) {
|
||||
tfree(pFilterInfo[i].pz);
|
||||
taosTFree(pFilterInfo[i].pz);
|
||||
}
|
||||
}
|
||||
|
||||
tfree(pFilterInfo);
|
||||
taosTFree(pFilterInfo);
|
||||
}
|
||||
|
||||
SColumn* tscColumnClone(const SColumn* src) {
|
||||
|
@ -1351,7 +1351,7 @@ void tscTagCondRelease(STagCond* pTagCond) {
|
|||
size_t s = taosArrayGetSize(pTagCond->pCond);
|
||||
for (int32_t i = 0; i < s; ++i) {
|
||||
SCond* p = taosArrayGet(pTagCond->pCond, i);
|
||||
tfree(p->cond);
|
||||
taosTFree(p->cond);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pTagCond->pCond);
|
||||
|
@ -1546,7 +1546,7 @@ static void freeQueryInfoImpl(SQueryInfo* pQueryInfo) {
|
|||
|
||||
pQueryInfo->tsBuf = tsBufDestroy(pQueryInfo->tsBuf);
|
||||
|
||||
tfree(pQueryInfo->fillVal);
|
||||
taosTFree(pQueryInfo->fillVal);
|
||||
}
|
||||
|
||||
void tscClearSubqueryInfo(SSqlCmd* pCmd) {
|
||||
|
@ -1566,7 +1566,7 @@ void clearAllTableMetaInfo(SQueryInfo* pQueryInfo, const char* address, bool rem
|
|||
free(pTableMetaInfo);
|
||||
}
|
||||
|
||||
tfree(pQueryInfo->pTableMetaInfo);
|
||||
taosTFree(pQueryInfo->pTableMetaInfo);
|
||||
}
|
||||
|
||||
STableMetaInfo* tscAddTableMetaInfo(SQueryInfo* pQueryInfo, const char* name, STableMeta* pTableMeta,
|
||||
|
@ -1613,7 +1613,7 @@ void tscClearTableMetaInfo(STableMetaInfo* pTableMetaInfo, bool removeFromCache)
|
|||
}
|
||||
|
||||
taosCacheRelease(tscCacheHandle, (void**)&(pTableMetaInfo->pTableMeta), removeFromCache);
|
||||
tfree(pTableMetaInfo->vgroupList);
|
||||
taosTFree(pTableMetaInfo->vgroupList);
|
||||
|
||||
tscColumnListDestroy(pTableMetaInfo->tagColList);
|
||||
pTableMetaInfo->tagColList = NULL;
|
||||
|
@ -2084,7 +2084,7 @@ void tscTryQueryNextClause(SSqlObj* pSql, __async_cb_func_t fp) {
|
|||
|
||||
pRes->numOfTotal = num;
|
||||
|
||||
tfree(pSql->pSubs);
|
||||
taosTFree(pSql->pSubs);
|
||||
pSql->numOfSubs = 0;
|
||||
pSql->fp = fp;
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#include "os.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
#include "taos.h"
|
||||
#include "tstoken.h"
|
||||
#include "ttime.h"
|
||||
#include "tutil.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
|
|
@ -80,7 +80,7 @@ typedef struct {
|
|||
#define schemaFLen(s) ((s)->flen)
|
||||
#define schemaVLen(s) ((s)->vlen)
|
||||
#define schemaColAt(s, i) ((s)->columns + i)
|
||||
#define tdFreeSchema(s) tfree((s))
|
||||
#define tdFreeSchema(s) taosTFree((s))
|
||||
|
||||
STSchema *tdDupSchema(STSchema *pSchema);
|
||||
int tdEncodeSchema(void **buf, STSchema *pSchema);
|
||||
|
@ -284,7 +284,7 @@ typedef struct {
|
|||
#define kvRowCpy(dst, r) memcpy((dst), (r), kvRowLen(r))
|
||||
#define kvRowColVal(r, colIdx) POINTER_SHIFT(kvRowValues(r), (colIdx)->offset)
|
||||
#define kvRowColIdxAt(r, i) (kvRowColIdx(r) + (i))
|
||||
#define kvRowFree(r) tfree(r)
|
||||
#define kvRowFree(r) taosTFree(r)
|
||||
#define kvRowEnd(r) POINTER_SHIFT(r, kvRowLen(r))
|
||||
|
||||
SKVRow tdKVRowDup(SKVRow row);
|
||||
|
|
|
@ -93,7 +93,7 @@ int tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version) {
|
|||
|
||||
void tdDestroyTSchemaBuilder(STSchemaBuilder *pBuilder) {
|
||||
if (pBuilder) {
|
||||
tfree(pBuilder->columns);
|
||||
taosTFree(pBuilder->columns);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -361,8 +361,8 @@ int tdInitDataCols(SDataCols *pCols, STSchema *pSchema) {
|
|||
|
||||
void tdFreeDataCols(SDataCols *pCols) {
|
||||
if (pCols) {
|
||||
tfree(pCols->buf);
|
||||
tfree(pCols->cols);
|
||||
taosTFree(pCols->buf);
|
||||
taosTFree(pCols->cols);
|
||||
free(pCols);
|
||||
}
|
||||
}
|
||||
|
@ -685,8 +685,8 @@ int tdInitKVRowBuilder(SKVRowBuilder *pBuilder) {
|
|||
}
|
||||
|
||||
void tdDestroyKVRowBuilder(SKVRowBuilder *pBuilder) {
|
||||
tfree(pBuilder->pColIdx);
|
||||
tfree(pBuilder->buf);
|
||||
taosTFree(pBuilder->pColIdx);
|
||||
taosTFree(pBuilder->buf);
|
||||
}
|
||||
|
||||
void tdResetKVRowBuilder(SKVRowBuilder *pBuilder) {
|
||||
|
|
|
@ -111,7 +111,7 @@ int32_t tsFsyncPeriod = TSDB_DEFAULT_FSYNC_PERIOD;
|
|||
int32_t tsReplications = TSDB_DEFAULT_DB_REPLICA_OPTION;
|
||||
int32_t tsQuorum = TSDB_DEFAULT_DB_QUORUM_OPTION;
|
||||
int32_t tsMaxVgroupsPerDb = 0;
|
||||
int32_t tsMinTablePerVnode = 100;
|
||||
int32_t tsMinTablePerVnode = TSDB_TABLES_STEP;
|
||||
int32_t tsMaxTablePerVnode = TSDB_DEFAULT_TABLES;
|
||||
int32_t tsTableIncStepPerVnode = TSDB_TABLES_STEP;
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ void tVariantDestroy(tVariant *pVar) {
|
|||
if (pVar == NULL) return;
|
||||
|
||||
if (pVar->nType == TSDB_DATA_TYPE_BINARY || pVar->nType == TSDB_DATA_TYPE_NCHAR) {
|
||||
tfree(pVar->pz);
|
||||
taosTFree(pVar->pz);
|
||||
pVar->nLen = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -114,7 +114,7 @@ void cqClose(void *handle) {
|
|||
SCqObj *pTemp = pObj;
|
||||
pObj = pObj->next;
|
||||
tdFreeSchema(pTemp->pSchema);
|
||||
tfree(pTemp->sqlStr);
|
||||
taosTFree(pTemp->sqlStr);
|
||||
free(pTemp);
|
||||
}
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ void dnodeCleanupMnodePeer() {
|
|||
}
|
||||
|
||||
taosCloseQset(tsMPeerQset);
|
||||
tfree(tsMPeerPool.peerWorker);
|
||||
taosTFree(tsMPeerPool.peerWorker);
|
||||
dInfo("dnode mpeer is closed");
|
||||
}
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ void dnodeCleanupMnodeWrite() {
|
|||
}
|
||||
|
||||
taosCloseQset(tsMWriteQset);
|
||||
tfree(tsMWritePool.writeWorker);
|
||||
taosTFree(tsMWritePool.writeWorker);
|
||||
dInfo("dnode mwrite is closed");
|
||||
}
|
||||
|
||||
|
|
|
@ -18,13 +18,11 @@
|
|||
#include "cJSON.h"
|
||||
#include "taoserror.h"
|
||||
#include "taosmsg.h"
|
||||
#include "ttime.h"
|
||||
#include "ttimer.h"
|
||||
#include "tsdb.h"
|
||||
#include "twal.h"
|
||||
#include "tqueue.h"
|
||||
#include "tsync.h"
|
||||
#include "ttime.h"
|
||||
#include "ttimer.h"
|
||||
#include "tbalance.h"
|
||||
#include "tglobal.h"
|
||||
|
|
|
@ -22,6 +22,7 @@ extern "C" {
|
|||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "osDef.h"
|
||||
#include "taos.h"
|
||||
|
||||
#define TSDB__packed
|
||||
|
@ -161,7 +162,7 @@ extern tDataTypeDescriptor tDataTypeDesc[11];
|
|||
|
||||
bool isValidDataType(int32_t type);
|
||||
//bool isNull(const char *val, int32_t type);
|
||||
static inline __attribute__((always_inline)) bool isNull(const char *val, int32_t type) {
|
||||
static FORCE_INLINE bool isNull(const char *val, int32_t type) {
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
return *(uint8_t *)val == TSDB_DATA_BOOL_NULL;
|
||||
|
|
|
@ -229,8 +229,8 @@ void shellReadCommand(TAOS *con, char *command) {
|
|||
printf("\n");
|
||||
if (isReadyGo(&cmd)) {
|
||||
sprintf(command, "%s%s", cmd.buffer, cmd.command);
|
||||
tfree(cmd.buffer);
|
||||
tfree(cmd.command);
|
||||
taosTFree(cmd.buffer);
|
||||
taosTFree(cmd.command);
|
||||
return;
|
||||
} else {
|
||||
updateBuffer(&cmd);
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "os.h"
|
||||
#include "shell.h"
|
||||
#include "shellCommand.h"
|
||||
#include "ttime.h"
|
||||
#include "tutil.h"
|
||||
#include "taosdef.h"
|
||||
#include "taoserror.h"
|
||||
|
@ -176,7 +175,7 @@ int32_t shellRunCommand(TAOS* con, char* command) {
|
|||
history.hist[(history.hend + MAX_HISTORY_SIZE - 1) % MAX_HISTORY_SIZE] == NULL ||
|
||||
strcmp(command, history.hist[(history.hend + MAX_HISTORY_SIZE - 1) % MAX_HISTORY_SIZE]) != 0) {
|
||||
if (history.hist[history.hend] != NULL) {
|
||||
tfree(history.hist[history.hend]);
|
||||
taosTFree(history.hist[history.hend]);
|
||||
}
|
||||
history.hist[history.hend] = strdup(command);
|
||||
|
||||
|
@ -770,7 +769,7 @@ void write_history() {
|
|||
for (int i = history.hstart; i != history.hend;) {
|
||||
if (history.hist[i] != NULL) {
|
||||
fprintf(f, "%s\n", history.hist[i]);
|
||||
tfree(history.hist[i]);
|
||||
taosTFree(history.hist[i]);
|
||||
}
|
||||
i = (i + 1) % MAX_HISTORY_SIZE;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "shell.h"
|
||||
#include "shellCommand.h"
|
||||
#include "tglobal.h"
|
||||
#include "ttime.h"
|
||||
#include "tutil.h"
|
||||
|
||||
static char **shellSQLFiles = NULL;
|
||||
|
|
|
@ -201,8 +201,8 @@ void shellReadCommand(TAOS *con, char *command) {
|
|||
printf("\n");
|
||||
if (isReadyGo(&cmd)) {
|
||||
sprintf(command, "%s%s", cmd.buffer, cmd.command);
|
||||
tfree(cmd.buffer);
|
||||
tfree(cmd.command);
|
||||
taosTFree(cmd.buffer);
|
||||
taosTFree(cmd.command);
|
||||
return;
|
||||
} else {
|
||||
updateBuffer(&cmd);
|
||||
|
@ -320,7 +320,7 @@ void *shellLoopQuery(void *arg) {
|
|||
reset_terminal_mode();
|
||||
} while (shellRunCommand(con, command) == 0);
|
||||
|
||||
tfree(command);
|
||||
taosTFree(command);
|
||||
exitShell();
|
||||
|
||||
pthread_cleanup_pop(1);
|
||||
|
|
|
@ -448,8 +448,8 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
void taosFreeDbInfos() {
|
||||
if (dbInfos == NULL) return;
|
||||
for (int i = 0; i < 128; i++) tfree(dbInfos[i]);
|
||||
tfree(dbInfos);
|
||||
for (int i = 0; i < 128; i++) taosTFree(dbInfos[i]);
|
||||
taosTFree(dbInfos);
|
||||
}
|
||||
|
||||
// check table is normal table or super table
|
||||
|
@ -606,11 +606,11 @@ int32_t taosSaveTableOfMetricToTempFile(TAOS *taosCon, char* metric, struct argu
|
|||
|
||||
if (numOfTable >= arguments->table_batch) {
|
||||
numOfTable = 0;
|
||||
tclose(fd);
|
||||
taosClose(fd);
|
||||
fd = -1;
|
||||
}
|
||||
}
|
||||
tclose(fd);
|
||||
taosClose(fd);
|
||||
fd = -1;
|
||||
taos_free_result(result);
|
||||
|
||||
|
@ -780,14 +780,14 @@ int taosDumpOut(struct arguments *arguments) {
|
|||
|
||||
if (retCode < 0) {
|
||||
if (-1 != normalTblFd){
|
||||
tclose(normalTblFd);
|
||||
taosClose(normalTblFd);
|
||||
}
|
||||
goto _clean_tmp_file;
|
||||
}
|
||||
}
|
||||
|
||||
if (-1 != normalTblFd){
|
||||
tclose(normalTblFd);
|
||||
taosClose(normalTblFd);
|
||||
}
|
||||
|
||||
// start multi threads to dumpout
|
||||
|
@ -806,7 +806,7 @@ int taosDumpOut(struct arguments *arguments) {
|
|||
fclose(fp);
|
||||
taos_close(taos);
|
||||
taos_free_result(result);
|
||||
tfree(command);
|
||||
taosTFree(command);
|
||||
taosFreeDbInfos();
|
||||
fprintf(stderr, "dump out rows: %" PRId64 "\n", totalDumpOutRows);
|
||||
return 0;
|
||||
|
@ -815,7 +815,7 @@ _exit_failure:
|
|||
fclose(fp);
|
||||
taos_close(taos);
|
||||
taos_free_result(result);
|
||||
tfree(command);
|
||||
taosTFree(command);
|
||||
taosFreeDbInfos();
|
||||
fprintf(stderr, "dump out rows: %" PRId64 "\n", totalDumpOutRows);
|
||||
return -1;
|
||||
|
@ -1076,7 +1076,7 @@ void* taosDumpOutWorkThreadFp(void *arg)
|
|||
}
|
||||
|
||||
taos_free_result(tmpResult);
|
||||
tclose(fd);
|
||||
taosClose(fd);
|
||||
fclose(fp);
|
||||
|
||||
return NULL;
|
||||
|
@ -1206,7 +1206,7 @@ int32_t taosDumpCreateSuperTableClause(TAOS* taosCon, char* dbName, FILE *fp)
|
|||
(void)taosDumpStable(tableRecord.name, fp, taosCon);
|
||||
}
|
||||
|
||||
tclose(fd);
|
||||
taosClose(fd);
|
||||
remove(".stables.tmp");
|
||||
|
||||
free(tmpCommand);
|
||||
|
@ -1288,11 +1288,11 @@ int taosDumpDb(SDbInfo *dbInfo, struct arguments *arguments, FILE *fp, TAOS *tao
|
|||
|
||||
if (numOfTable >= arguments->table_batch) {
|
||||
numOfTable = 0;
|
||||
tclose(fd);
|
||||
taosClose(fd);
|
||||
fd = -1;
|
||||
}
|
||||
}
|
||||
tclose(fd);
|
||||
taosClose(fd);
|
||||
fd = -1;
|
||||
taos_free_result(tmpResult);
|
||||
|
||||
|
@ -1760,13 +1760,13 @@ void taosLoadFileCharset(FILE *fp, char *fcharset) {
|
|||
}
|
||||
strcpy(fcharset, line + 2);
|
||||
|
||||
tfree(line);
|
||||
taosTFree(line);
|
||||
return;
|
||||
|
||||
_exit_no_charset:
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
*fcharset = '\0';
|
||||
tfree(line);
|
||||
taosTFree(line);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1860,9 +1860,9 @@ static void taosMallocSQLFiles()
|
|||
static void taosFreeSQLFiles()
|
||||
{
|
||||
for (int i = 0; i < tsSqlFileNum; i++) {
|
||||
tfree(tsDumpInSqlFiles[i]);
|
||||
taosTFree(tsDumpInSqlFiles[i]);
|
||||
}
|
||||
tfree(tsDumpInSqlFiles);
|
||||
taosTFree(tsDumpInSqlFiles);
|
||||
}
|
||||
|
||||
static void taosGetDirectoryFileList(char *inputDir)
|
||||
|
@ -2063,17 +2063,17 @@ int taosDumpInOneFile_old(TAOS * taos, FILE* fp, char* fcharset, char* encod
|
|||
}
|
||||
|
||||
if (cd != ((iconv_t)(-1))) iconv_close(cd);
|
||||
tfree(line);
|
||||
tfree(command);
|
||||
tfree(lcommand);
|
||||
taosTFree(line);
|
||||
taosTFree(command);
|
||||
taosTFree(lcommand);
|
||||
taos_close(taos);
|
||||
fclose(fp);
|
||||
return 0;
|
||||
|
||||
_dumpin_exit_failure:
|
||||
if (cd != ((iconv_t)(-1))) iconv_close(cd);
|
||||
tfree(command);
|
||||
tfree(lcommand);
|
||||
taosTFree(command);
|
||||
taosTFree(lcommand);
|
||||
taos_close(taos);
|
||||
fclose(fp);
|
||||
return -1;
|
||||
|
@ -2120,8 +2120,8 @@ int taosDumpInOneFile(TAOS * taos, FILE* fp, char* fcharset, char* encode, c
|
|||
cmd_len = 0;
|
||||
}
|
||||
|
||||
tfree(cmd);
|
||||
tfree(line);
|
||||
taosTFree(cmd);
|
||||
taosTFree(line);
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -289,7 +289,7 @@ static int32_t readVnodeCfg(SVnodeObj *pVnode, char* cfgFile)
|
|||
//}
|
||||
|
||||
PARSE_OVER:
|
||||
tfree(content);
|
||||
taosTFree(content);
|
||||
cJSON_Delete(root);
|
||||
if (fp) fclose(fp);
|
||||
return ret;
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "taoserror.h"
|
||||
#include "ttime.h"
|
||||
#include "dnode.h"
|
||||
#include "mnodeDef.h"
|
||||
#include "mnodeInt.h"
|
||||
|
@ -34,7 +33,7 @@ static int32_t mnodeCreateRootAcct();
|
|||
static int32_t mnodeAcctActionDestroy(SSdbOper *pOper) {
|
||||
SAcctObj *pAcct = pOper->pObj;
|
||||
pthread_mutex_destroy(&pAcct->mutex);
|
||||
tfree(pOper->pObj);
|
||||
taosTFree(pOper->pObj);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "taoserror.h"
|
||||
#include "ttime.h"
|
||||
#include "dnode.h"
|
||||
#include "mnodeDef.h"
|
||||
#include "mnodeInt.h"
|
||||
|
@ -34,7 +33,7 @@ static int32_t mnodeGetClusterMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *
|
|||
static int32_t mnodeRetrieveClusters(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||
|
||||
static int32_t mnodeClusterActionDestroy(SSdbOper *pOper) {
|
||||
tfree(pOper->pObj);
|
||||
taosTFree(pOper->pObj);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "tutil.h"
|
||||
#include "tgrant.h"
|
||||
#include "tglobal.h"
|
||||
#include "ttime.h"
|
||||
#include "tname.h"
|
||||
#include "tbalance.h"
|
||||
#include "tdataformat.h"
|
||||
|
@ -53,8 +52,8 @@ static int32_t mnodeProcessDropDbMsg(SMnodeMsg *pMsg);
|
|||
|
||||
static void mnodeDestroyDb(SDbObj *pDb) {
|
||||
pthread_mutex_destroy(&pDb->mutex);
|
||||
tfree(pDb->vgList);
|
||||
tfree(pDb);
|
||||
taosTFree(pDb->vgList);
|
||||
taosTFree(pDb);
|
||||
}
|
||||
|
||||
static int32_t mnodeDbActionDestroy(SSdbOper *pOper) {
|
||||
|
@ -386,7 +385,7 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate, void *pMs
|
|||
|
||||
code = mnodeCheckDbCfg(&pDb->cfg);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tfree(pDb);
|
||||
taosTFree(pDb);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "tbalance.h"
|
||||
#include "tglobal.h"
|
||||
#include "tconfig.h"
|
||||
#include "ttime.h"
|
||||
#include "tutil.h"
|
||||
#include "tsocket.h"
|
||||
#include "tbalance.h"
|
||||
|
@ -62,7 +61,7 @@ static int32_t mnodeRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, vo
|
|||
static char* mnodeGetDnodeAlternativeRoleStr(int32_t alternativeRole);
|
||||
|
||||
static int32_t mnodeDnodeActionDestroy(SSdbOper *pOper) {
|
||||
tfree(pOper->pObj);
|
||||
taosTFree(pOper->pObj);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -504,7 +503,7 @@ static int32_t mnodeCreateDnode(char *ep, SMnodeMsg *pMsg) {
|
|||
int32_t code = sdbInsertRow(&oper);
|
||||
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
|
||||
int dnodeId = pDnode->dnodeId;
|
||||
tfree(pDnode);
|
||||
taosTFree(pDnode);
|
||||
mError("failed to create dnode:%d, reason:%s", dnodeId, tstrerror(code));
|
||||
} else {
|
||||
mLInfo("dnode:%d is created", pDnode->dnodeId);
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "tsync.h"
|
||||
#include "tbalance.h"
|
||||
#include "tutil.h"
|
||||
#include "ttime.h"
|
||||
#include "tsocket.h"
|
||||
#include "tdataformat.h"
|
||||
#include "mnodeDef.h"
|
||||
|
@ -57,7 +56,7 @@ static int32_t mnodeRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, vo
|
|||
#endif
|
||||
|
||||
static int32_t mnodeMnodeActionDestroy(SSdbOper *pOper) {
|
||||
tfree(pOper->pObj);
|
||||
taosTFree(pOper->pObj);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -279,7 +278,7 @@ int32_t mnodeAddMnode(int32_t dnodeId) {
|
|||
|
||||
int32_t code = sdbInsertRow(&oper);
|
||||
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
|
||||
tfree(pMnode);
|
||||
taosTFree(pMnode);
|
||||
}
|
||||
|
||||
mnodeUpdateMnodeEpSet();
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include "taosmsg.h"
|
||||
#include "taoserror.h"
|
||||
#include "tutil.h"
|
||||
#include "ttime.h"
|
||||
#include "tcache.h"
|
||||
#include "tglobal.h"
|
||||
#include "tdataformat.h"
|
||||
|
@ -133,8 +132,8 @@ SConnObj *mnodeAccquireConn(int32_t connId, char *user, uint32_t ip, uint16_t po
|
|||
|
||||
static void mnodeFreeConn(void *data) {
|
||||
SConnObj *pConn = data;
|
||||
tfree(pConn->pQueries);
|
||||
tfree(pConn->pStreams);
|
||||
taosTFree(pConn->pQueries);
|
||||
taosTFree(pConn->pStreams);
|
||||
|
||||
mDebug("connId:%d, is destroyed", pConn->connId);
|
||||
}
|
||||
|
|
|
@ -934,7 +934,7 @@ void sdbCleanupWriteWorker() {
|
|||
}
|
||||
|
||||
sdbFreeWritequeue();
|
||||
tfree(tsSdbPool.writeWorker);
|
||||
taosTFree(tsSdbPool.writeWorker);
|
||||
|
||||
mInfo("sdb write is closed");
|
||||
}
|
||||
|
|
|
@ -403,7 +403,7 @@ static void mnodeFreeShowObj(void *data) {
|
|||
sdbFreeIter(pShow->pIter);
|
||||
|
||||
mDebug("%p, show is destroyed, data:%p index:%d", pShow, data, pShow->index);
|
||||
tfree(pShow);
|
||||
taosTFree(pShow);
|
||||
}
|
||||
|
||||
static void mnodeReleaseShowObj(SShowObj *pShow, bool forceRemove) {
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "taosmsg.h"
|
||||
#include "ttime.h"
|
||||
#include "tutil.h"
|
||||
#include "taoserror.h"
|
||||
#include "taosmsg.h"
|
||||
|
@ -90,10 +89,10 @@ static void mnodeProcessAlterTableRsp(SRpcMsg *rpcMsg);
|
|||
static int32_t mnodeFindSuperTableColumnIndex(SSuperTableObj *pStable, char *colName);
|
||||
|
||||
static void mnodeDestroyChildTable(SChildTableObj *pTable) {
|
||||
tfree(pTable->info.tableId);
|
||||
tfree(pTable->schema);
|
||||
tfree(pTable->sql);
|
||||
tfree(pTable);
|
||||
taosTFree(pTable->info.tableId);
|
||||
taosTFree(pTable->schema);
|
||||
taosTFree(pTable->sql);
|
||||
taosTFree(pTable);
|
||||
}
|
||||
|
||||
static int32_t mnodeChildTableActionDestroy(SSdbOper *pOper) {
|
||||
|
@ -411,9 +410,9 @@ static void mnodeDestroySuperTable(SSuperTableObj *pStable) {
|
|||
taosHashCleanup(pStable->vgHash);
|
||||
pStable->vgHash = NULL;
|
||||
}
|
||||
tfree(pStable->info.tableId);
|
||||
tfree(pStable->schema);
|
||||
tfree(pStable);
|
||||
taosTFree(pStable->info.tableId);
|
||||
taosTFree(pStable->schema);
|
||||
taosTFree(pStable);
|
||||
}
|
||||
|
||||
static int32_t mnodeSuperTableActionDestroy(SSdbOper *pOper) {
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "trpc.h"
|
||||
#include "ttime.h"
|
||||
#include "tutil.h"
|
||||
#include "tglobal.h"
|
||||
#include "tgrant.h"
|
||||
|
@ -43,7 +42,7 @@ static int32_t mnodeProcessDropUserMsg(SMnodeMsg *pMsg);
|
|||
static int32_t mnodeProcessAuthMsg(SMnodeMsg *pMsg);
|
||||
|
||||
static int32_t mnodeUserActionDestroy(SSdbOper *pOper) {
|
||||
tfree(pOper->pObj);
|
||||
taosTFree(pOper->pObj);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -239,7 +238,7 @@ int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass, void *pMsg) {
|
|||
code = sdbInsertRow(&oper);
|
||||
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
|
||||
mError("user:%s, failed to create by %s, reason:%s", pUser->user, mnodeGetUserFromMsg(pMsg), tstrerror(code));
|
||||
tfree(pUser);
|
||||
taosTFree(pUser);
|
||||
} else {
|
||||
mLInfo("user:%s, is created by %s", pUser->user, mnodeGetUserFromMsg(pMsg));
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#include "tsocket.h"
|
||||
#include "tidpool.h"
|
||||
#include "tsync.h"
|
||||
#include "ttime.h"
|
||||
#include "tbalance.h"
|
||||
#include "tglobal.h"
|
||||
#include "tdataformat.h"
|
||||
|
@ -70,7 +69,7 @@ static void mnodeDestroyVgroup(SVgObj *pVgroup) {
|
|||
pVgroup->idPool = NULL;
|
||||
}
|
||||
|
||||
tfree(pVgroup);
|
||||
taosTFree(pVgroup);
|
||||
}
|
||||
|
||||
static int32_t mnodeVgroupActionDestroy(SSdbOper *pOper) {
|
||||
|
|
|
@ -6,11 +6,11 @@ IF (TD_LINUX_64)
|
|||
ELSEIF (TD_LINUX_32)
|
||||
ADD_SUBDIRECTORY(src/linux32)
|
||||
ELSEIF (TD_DARWIN_64)
|
||||
ADD_SUBDIRECTORY(src/darwin64)
|
||||
ADD_SUBDIRECTORY(src/darwin)
|
||||
ELSEIF (TD_WINDOWS_64)
|
||||
ADD_SUBDIRECTORY(src/windows64)
|
||||
ADD_SUBDIRECTORY(src/windows)
|
||||
ELSEIF (TD_WINDOWS_32)
|
||||
ADD_SUBDIRECTORY(src/windows32)
|
||||
ADD_SUBDIRECTORY(src/windows)
|
||||
ENDIF ()
|
||||
|
||||
ADD_SUBDIRECTORY(src/detail)
|
||||
|
|
|
@ -21,7 +21,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#ifdef _TD_DARWIN_64
|
||||
#include "osDarwin64.h"
|
||||
#include "osDarwin.h"
|
||||
#endif
|
||||
|
||||
#ifdef _TD_LINUX_64
|
||||
|
@ -36,15 +36,26 @@ extern "C" {
|
|||
#include "osAlpine.h"
|
||||
#endif
|
||||
|
||||
#ifdef _TD_WINDOWS_64
|
||||
#include "osWindows64.h"
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
#include "osWindows.h"
|
||||
#endif
|
||||
|
||||
#ifdef _TD_WINDOWS_32
|
||||
#include "osWindows32.h"
|
||||
#endif
|
||||
#include "osAtomic.h"
|
||||
#include "osDef.h"
|
||||
#include "osDir.h"
|
||||
#include "osFile.h"
|
||||
#include "osLz4.h"
|
||||
#include "osMath.h"
|
||||
#include "osMemory.h"
|
||||
#include "osRand.h"
|
||||
#include "osSemphone.h"
|
||||
#include "osSocket.h"
|
||||
#include "osString.h"
|
||||
#include "osSysinfo.h"
|
||||
#include "osTime.h"
|
||||
#include "osTimer.h"
|
||||
|
||||
#include "osSpec.h"
|
||||
void osInit();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* 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 TDENGINE_OS_ATOMIC_H
|
||||
#define TDENGINE_OS_ATOMIC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_ATOMIC
|
||||
#define atomic_load_8(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_16(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_32(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_64(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_ptr(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_store_8(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_store_16(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_store_32(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_store_64(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_store_ptr(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_exchange_8(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_exchange_16(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_exchange_32(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_exchange_64(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_exchange_ptr(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_val_compare_exchange_8 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_16 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_32 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_64 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_ptr __sync_val_compare_and_swap
|
||||
|
||||
#define atomic_add_fetch_8(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_add_fetch_16(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_add_fetch_32(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_add_fetch_64(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_add_fetch_ptr(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_add_8(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_16(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_32(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_64(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_ptr(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_sub_fetch_8(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_sub_fetch_16(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_sub_fetch_32(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_sub_fetch_64(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_sub_fetch_ptr(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_sub_8(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_16(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_32(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_64(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_ptr(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_and_fetch_8(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_and_fetch_16(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_and_fetch_32(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_and_fetch_64(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_and_fetch_ptr(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_and_8(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_16(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_32(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_64(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_ptr(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_or_fetch_8(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_or_fetch_16(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_or_fetch_32(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_or_fetch_64(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_or_fetch_ptr(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_or_8(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_16(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_32(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_64(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_ptr(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_xor_fetch_8(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_xor_fetch_16(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_xor_fetch_32(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_xor_fetch_64(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_xor_fetch_ptr(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_xor_8(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_16(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_32(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_64(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_ptr(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* 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 TDENGINE_PLATFORM_LINUX_H
|
||||
#define TDENGINE_PLATFORM_LINUX_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <float.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <libgen.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <math.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <pthread.h>
|
||||
#include <pwd.h>
|
||||
#include <regex.h>
|
||||
#include <semaphore.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#include <syslog.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <wordexp.h>
|
||||
#include <wctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <dispatch/dispatch.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#define TAOS_OS_FUNC_FILE_SENDIFLE
|
||||
#define taosFSendFile(outfile, infile, offset, count) taosFSendFileImp(outfile, infile, offset, size)
|
||||
#define taosTSendFile(dfd, sfd, offset, size) taosTSendFileImp(dfd, sfd, offset, size)
|
||||
|
||||
#define TAOS_OS_FUNC_SEMPHONE
|
||||
#define tsem_t dispatch_semaphore_t
|
||||
int tsem_init(dispatch_semaphore_t *sem, int pshared, unsigned int value);
|
||||
int tsem_wait(dispatch_semaphore_t *sem);
|
||||
int tsem_post(dispatch_semaphore_t *sem);
|
||||
int tsem_destroy(dispatch_semaphore_t *sem);
|
||||
|
||||
#define TAOS_OS_FUNC_SOCKET_SETSOCKETOPT
|
||||
#define TAOS_OS_FUNC_STRING_STR2INT64
|
||||
#define TAOS_OS_FUNC_SYSINFO
|
||||
#define TAOS_OS_FUNC_TIMER
|
||||
|
||||
// specific
|
||||
#define htobe64 htonll
|
||||
typedef int(*__compar_fn_t)(const void *, const void *);
|
||||
|
||||
// for send function in tsocket.c
|
||||
#define MSG_NOSIGNAL 0
|
||||
#define SO_NO_CHECK 0x1234
|
||||
#define SOL_TCP 0x1234
|
||||
#define TCP_KEEPIDLE 0x1234
|
||||
|
||||
#ifndef PTHREAD_MUTEX_RECURSIVE_NP
|
||||
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,274 +0,0 @@
|
|||
/*
|
||||
* 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 TDENGINE_PLATFORM_LINUX_H
|
||||
#define TDENGINE_PLATFORM_LINUX_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <float.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <libgen.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <math.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <pthread.h>
|
||||
#include <pwd.h>
|
||||
#include <regex.h>
|
||||
#include <semaphore.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#include <syslog.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <wordexp.h>
|
||||
#include <wctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <dispatch/dispatch.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#define htobe64 htonll
|
||||
|
||||
#define taosCloseSocket(x) \
|
||||
{ \
|
||||
if (FD_VALID(x)) { \
|
||||
close(x); \
|
||||
x = FD_INITIALIZER; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define taosWriteSocket(fd, buf, len) write(fd, buf, len)
|
||||
#define taosReadSocket(fd, buf, len) read(fd, buf, len)
|
||||
|
||||
#define atomic_load_8(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_16(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_32(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_64(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_ptr(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_store_8(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_store_16(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_store_32(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_store_64(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_store_ptr(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_exchange_8(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_exchange_16(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_exchange_32(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_exchange_64(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_exchange_ptr(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_val_compare_exchange_8 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_16 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_32 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_64 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_ptr __sync_val_compare_and_swap
|
||||
|
||||
#define atomic_add_fetch_8(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_add_fetch_16(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_add_fetch_32(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_add_fetch_64(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_add_fetch_ptr(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_add_8(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_16(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_32(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_64(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_ptr(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_sub_fetch_8(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_sub_fetch_16(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_sub_fetch_32(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_sub_fetch_64(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_sub_fetch_ptr(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_sub_8(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_16(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_32(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_64(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_ptr(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_and_fetch_8(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_and_fetch_16(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_and_fetch_32(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_and_fetch_64(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_and_fetch_ptr(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_and_8(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_16(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_32(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_64(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_ptr(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_or_fetch_8(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_or_fetch_16(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_or_fetch_32(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_or_fetch_64(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_or_fetch_ptr(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_or_8(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_16(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_32(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_64(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_ptr(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_xor_fetch_8(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_xor_fetch_16(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_xor_fetch_32(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_xor_fetch_64(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_xor_fetch_ptr(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_xor_8(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_16(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_32(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_64(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_ptr(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define SWAP(a, b, c) \
|
||||
do { \
|
||||
typeof(a) __tmp = (a); \
|
||||
(a) = (b); \
|
||||
(b) = __tmp; \
|
||||
} while (0)
|
||||
|
||||
#define MAX(a, b) \
|
||||
({ \
|
||||
typeof(a) __a = (a); \
|
||||
typeof(b) __b = (b); \
|
||||
(__a > __b) ? __a : __b; \
|
||||
})
|
||||
|
||||
#define MIN(a, b) \
|
||||
({ \
|
||||
typeof(a) __a = (a); \
|
||||
typeof(b) __b = (b); \
|
||||
(__a < __b) ? __a : __b; \
|
||||
})
|
||||
|
||||
#define MILLISECOND_PER_SECOND ((int64_t)1000L)
|
||||
|
||||
#define tsem_t dispatch_semaphore_t
|
||||
|
||||
int tsem_init(dispatch_semaphore_t *sem, int pshared, unsigned int value);
|
||||
int tsem_wait(dispatch_semaphore_t *sem);
|
||||
int tsem_post(dispatch_semaphore_t *sem);
|
||||
int tsem_destroy(dispatch_semaphore_t *sem);
|
||||
|
||||
void osInit();
|
||||
|
||||
ssize_t tread(int fd, void *buf, size_t count);
|
||||
|
||||
ssize_t twrite(int fd, void *buf, size_t n);
|
||||
|
||||
|
||||
bool taosCheckPthreadValid(pthread_t thread);
|
||||
|
||||
void taosResetPthread(pthread_t *thread);
|
||||
|
||||
int64_t taosGetPthreadId();
|
||||
|
||||
int taosSetNonblocking(int sock, int on);
|
||||
|
||||
int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen);
|
||||
|
||||
void taosPrintOsInfo();
|
||||
|
||||
void taosPrintOsInfo();
|
||||
|
||||
void taosGetSystemInfo();
|
||||
|
||||
void taosKillSystem();
|
||||
|
||||
bool taosSkipSocketCheck();
|
||||
|
||||
bool taosGetDisk();
|
||||
|
||||
int fsendfile(FILE* out_file, FILE* in_file, int64_t* offset, int32_t count);
|
||||
|
||||
void taosSetCoreDump();
|
||||
|
||||
int tSystem(const char * cmd);
|
||||
|
||||
typedef int(*__compar_fn_t)(const void *, const void *);
|
||||
|
||||
// for send function in tsocket.c
|
||||
#define MSG_NOSIGNAL 0
|
||||
#define SO_NO_CHECK 0x1234
|
||||
#define SOL_TCP 0x1234
|
||||
#define TCP_KEEPIDLE 0x1234
|
||||
|
||||
#ifndef PTHREAD_MUTEX_RECURSIVE_NP
|
||||
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
|
||||
#endif
|
||||
|
||||
#ifndef _TD_ARM_32_
|
||||
#define BUILDIN_CLZL(val) __builtin_clzl(val)
|
||||
#define BUILDIN_CTZL(val) __builtin_ctzl(val)
|
||||
#else
|
||||
#define BUILDIN_CLZL(val) __builtin_clzll(val)
|
||||
#define BUILDIN_CTZL(val) __builtin_ctzll(val)
|
||||
#endif
|
||||
#define BUILDIN_CLZ(val) __builtin_clz(val)
|
||||
#define BUILDIN_CTZ(val) __builtin_ctz(val)
|
||||
|
||||
#undef threadlocal
|
||||
#ifdef _ISOC11_SOURCE
|
||||
#define threadlocal _Thread_local
|
||||
#elif defined(__APPLE__)
|
||||
#define threadlocal
|
||||
#elif defined(__GNUC__) && !defined(threadlocal)
|
||||
#define threadlocal __thread
|
||||
#else
|
||||
#define threadlocal
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* 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 TDENGINE_OS_DEF_H
|
||||
#define TDENGINE_OS_DEF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef STDERR_FILENO
|
||||
#define STDERR_FILENO (2)
|
||||
#endif
|
||||
|
||||
#define FD_VALID(x) ((x) > STDERR_FILENO)
|
||||
#define FD_INITIALIZER ((int32_t)-1)
|
||||
|
||||
#define WCHAR wchar_t
|
||||
|
||||
#define POINTER_SHIFT(p, b) ((void *)((char *)(p) + (b)))
|
||||
#define POINTER_DISTANCE(p1, p2) ((char *)(p1) - (char *)(p2))
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define ASSERT(x) assert(x)
|
||||
#else
|
||||
#define ASSERT(x)
|
||||
#endif
|
||||
|
||||
#ifdef UNUSED
|
||||
#undefine UNUSED
|
||||
#endif
|
||||
#define UNUSED(x) ((void)(x))
|
||||
|
||||
#ifdef UNUSED_FUNC
|
||||
#undefine UNUSED_FUNC
|
||||
#endif
|
||||
|
||||
#ifdef UNUSED_PARAM
|
||||
#undef UNUSED_PARAM
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define UNUSED_PARAM(x) _UNUSED##x __attribute__((unused))
|
||||
#define UNUSED_FUNC __attribute__((unused))
|
||||
#else
|
||||
#define UNUSED_PARAM(x) x
|
||||
#define UNUSED_FUNC
|
||||
#endif
|
||||
|
||||
#ifdef tListLen
|
||||
#undefine tListLen
|
||||
#endif
|
||||
#define tListLen(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define FORCE_INLINE inline __attribute__((always_inline))
|
||||
#else
|
||||
#define FORCE_INLINE
|
||||
#endif
|
||||
|
||||
#define DEFAULT_UNICODE_ENCODEC "UCS-4LE"
|
||||
|
||||
#define DEFAULT_COMP(x, y) \
|
||||
do { \
|
||||
if ((x) == (y)) { \
|
||||
return 0; \
|
||||
} else { \
|
||||
return (x) < (y) ? -1 : 1; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ALIGN_NUM(n, align) (((n) + ((align)-1)) & (~((align)-1)))
|
||||
|
||||
// align to 8bytes
|
||||
#define ALIGN8(n) ALIGN_NUM(n, 8)
|
||||
|
||||
#undef threadlocal
|
||||
#ifdef _ISOC11_SOURCE
|
||||
#define threadlocal _Thread_local
|
||||
#elif defined(__APPLE__)
|
||||
#define threadlocal
|
||||
#elif defined(__GNUC__) && !defined(threadlocal)
|
||||
#define threadlocal __thread
|
||||
#else
|
||||
#define threadlocal
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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 TDENGINE_OS_DIR_H
|
||||
#define TDENGINE_OS_DIR_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// TAOS_OS_FUNC_DIR
|
||||
void taosRemoveDir(char *rootDir);
|
||||
int taosMkDir(const char *pathname, mode_t mode);
|
||||
void taosMvDir(char* destDir, char *srcDir);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* 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 TDENGINE_OS_FILE_H
|
||||
#define TDENGINE_OS_FILE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
ssize_t taosTReadImp(int fd, void *buf, size_t count);
|
||||
ssize_t taosTWriteImp(int fd, void *buf, size_t count);
|
||||
|
||||
ssize_t taosTSendFileImp(int dfd, int sfd, off_t *offset, size_t size);
|
||||
int taosFSendFileImp(FILE* out_file, FILE* in_file, int64_t* offset, int32_t count);
|
||||
|
||||
#ifndef TAOS_OS_FUNC_FILE_SENDIFLE
|
||||
#define taosTSendFile(dfd, sfd, offset, size) taosTSendFileImp(dfd, sfd, offset, size)
|
||||
#define taosFSendFile(outfile, infile, offset, count) taosTSendFileImp(fileno(outfile), fileno(infile), offset, size)
|
||||
#endif
|
||||
|
||||
#define taosTRead(fd, buf, count) taosTReadImp(fd, buf, count)
|
||||
#define taosTWrite(fd, buf, count) taosTWriteImp(fd, buf, count)
|
||||
#define taosLSeek(fd, offset, whence) lseek(fd, offset, whence)
|
||||
|
||||
#ifdef TAOS_RANDOM_FILE_FAIL
|
||||
void taosSetRandomFileFailFactor(int factor);
|
||||
void taosSetRandomFileFailOutput(const char *path);
|
||||
#ifdef TAOS_RANDOM_FILE_FAIL_TEST
|
||||
ssize_t taosReadFileRandomFail(int fd, void *buf, size_t count, const char *file, uint32_t line);
|
||||
ssize_t taosWriteFileRandomFail(int fd, void *buf, size_t count, const char *file, uint32_t line);
|
||||
off_t taosLSeekRandomFail(int fd, off_t offset, int whence, const char *file, uint32_t line);
|
||||
#undef taosTRead
|
||||
#undef taosTWrite
|
||||
#undef taosLSeek
|
||||
#define taosTRead(fd, buf, count) taosReadFileRandomFail(fd, buf, count, __FILE__, __LINE__)
|
||||
#define taosTWrite(fd, buf, count) taosWriteFileRandomFail(fd, buf, count, __FILE__, __LINE__)
|
||||
#define taosLSeek(fd, offset, whence) taosLSeekRandomFail(fd, offset, whence, __FILE__, __LINE__)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int32_t taosFileRename(char *fullPath, char *suffix, char delimiter, char **dstPath);
|
||||
|
||||
// TAOS_OS_FUNC_FILE_GETTMPFILEPATH
|
||||
void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -22,7 +22,6 @@ extern "C" {
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <argp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
|
@ -78,6 +77,12 @@ extern "C" {
|
|||
#include <sys/resource.h>
|
||||
#include <error.h>
|
||||
|
||||
#define TAOS_OS_FUNC_LZ4
|
||||
#define BUILDIN_CLZL(val) __builtin_clzll(val)
|
||||
#define BUILDIN_CTZL(val) __builtin_ctzll(val)
|
||||
#define BUILDIN_CLZ(val) __builtin_clz(val)
|
||||
#define BUILDIN_CTZ(val) __builtin_ctz(val)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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 TDENGINE_OS_LZ4_H
|
||||
#define TDENGINE_OS_LZ4_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_LZ4
|
||||
#define BUILDIN_CLZL(val) __builtin_clzl(val)
|
||||
#define BUILDIN_CTZL(val) __builtin_ctzl(val)
|
||||
#define BUILDIN_CLZ(val) __builtin_clz(val)
|
||||
#define BUILDIN_CTZ(val) __builtin_ctz(val)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* 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 TDENGINE_OS_MATH_H
|
||||
#define TDENGINE_OS_MATH_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define POW2(x) ((x) * (x))
|
||||
|
||||
#ifndef TAOS_OS_FUNC_MATH
|
||||
#define SWAP(a, b, c) \
|
||||
do { \
|
||||
typeof(a) __tmp = (a); \
|
||||
(a) = (b); \
|
||||
(b) = __tmp; \
|
||||
} while (0)
|
||||
|
||||
#define MAX(a, b) \
|
||||
({ \
|
||||
typeof(a) __a = (a); \
|
||||
typeof(b) __b = (b); \
|
||||
(__a > __b) ? __a : __b; \
|
||||
})
|
||||
|
||||
#define MIN(a, b) \
|
||||
({ \
|
||||
typeof(a) __a = (a); \
|
||||
typeof(b) __b = (b); \
|
||||
(__a < __b) ? __a : __b; \
|
||||
})
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* 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 TDENGINE_OS_MEMORY_H
|
||||
#define TDENGINE_OS_MEMORY_H
|
||||
|
||||
#include "osString.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
TAOS_ALLOC_MODE_DEFAULT = 0,
|
||||
TAOS_ALLOC_MODE_RANDOM_FAIL = 1,
|
||||
TAOS_ALLOC_MODE_DETECT_LEAK = 2
|
||||
} ETaosMemoryAllocMode;
|
||||
|
||||
void taosSetAllocMode(int mode, const char *path, bool autoDump);
|
||||
void taosDumpMemoryLeak();
|
||||
|
||||
void * taosTMalloc(size_t size);
|
||||
void * taosTCalloc(size_t nmemb, size_t size);
|
||||
void * taosTRealloc(void *ptr, size_t size);
|
||||
void taosTZfree(void *ptr);
|
||||
size_t taosTSizeof(void *ptr);
|
||||
void taosTMemset(void *ptr, int c);
|
||||
|
||||
#define taosTFree(x) \
|
||||
do { \
|
||||
if (x) { \
|
||||
free((void *)(x)); \
|
||||
x = 0; \
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
#define taosMalloc(size) malloc(size)
|
||||
#define taosCalloc(num, size) calloc(num, size)
|
||||
#define taosRealloc(ptr, size) realloc(ptr, size)
|
||||
#define taosFree(ptr) free(ptr)
|
||||
#define taosStrdup(str) taosStrdupImp(str)
|
||||
#define taosStrndup(str, size) taosStrndupImp(str, size)
|
||||
#define taosGetline(lineptr, n, stream) taosGetlineImp(lineptr, n, stream)
|
||||
|
||||
#ifdef TAOS_MEM_CHECK
|
||||
#ifdef TAOS_MEM_CHECK_TEST
|
||||
void * taos_malloc(size_t size, const char *file, uint32_t line);
|
||||
void * taos_calloc(size_t num, size_t size, const char *file, uint32_t line);
|
||||
void * taos_realloc(void *ptr, size_t size, const char *file, uint32_t line);
|
||||
void taos_free(void *ptr, const char *file, uint32_t line);
|
||||
char * taos_strdup(const char *str, const char *file, uint32_t line);
|
||||
char * taos_strndup(const char *str, size_t size, const char *file, uint32_t line);
|
||||
ssize_t taos_getline(char **lineptr, size_t *n, FILE *stream, const char *file, uint32_t line);
|
||||
#undef taosMalloc
|
||||
#undef taosCalloc
|
||||
#undef taosRealloc
|
||||
#undef taosFree
|
||||
#undef taosStrdup
|
||||
#undef taosStrndup
|
||||
#undef taosGetline
|
||||
#define taosMalloc(size) taos_malloc(size, __FILE__, __LINE__)
|
||||
#define taosCalloc(num, size) taos_calloc(num, size, __FILE__, __LINE__)
|
||||
#define taosRealloc(ptr, size) taos_realloc(ptr, size, __FILE__, __LINE__)
|
||||
#define taosFree(ptr) taos_free(ptr, __FILE__, __LINE__)
|
||||
#define taosStrdup(str) taos_strdup(str, __FILE__, __LINE__)
|
||||
#define taosStrndup(str, size) taos_strndup(str, size, __FILE__, __LINE__)
|
||||
#define taosGetline(lineptr, n, stream) taos_getline(lineptr, n, stream, __FILE__, __LINE__)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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 TDENGINE_OS_RAND_H
|
||||
#define TDENGINE_OS_RAND_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// TAOS_OS_FUNC_RAND
|
||||
uint32_t taosRand(void);
|
||||
void taosRandStr(char* str, int32_t size);
|
||||
uint32_t taosSafeRand(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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 TDENGINE_OS_SEMPHONE_H
|
||||
#define TDENGINE_OS_SEMPHONE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_SEMPHONE
|
||||
#define tsem_t sem_t
|
||||
#define tsem_init sem_init
|
||||
#define tsem_wait sem_wait
|
||||
#define tsem_post sem_post
|
||||
#define tsem_destroy sem_destroy
|
||||
#endif
|
||||
|
||||
// TAOS_OS_FUNC_SEMPHONE_PTHREAD
|
||||
bool taosCheckPthreadValid(pthread_t thread);
|
||||
int64_t taosGetPthreadId();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* 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 TDENGINE_OS_SOCKET_H
|
||||
#define TDENGINE_OS_SOCKET_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_SOCKET_OP
|
||||
#define taosSend(sockfd, buf, len, flags) send(sockfd, buf, len, flags)
|
||||
#define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto(sockfd, buf, len, flags, dest_addr, addrlen)
|
||||
#define taosReadSocket(fd, buf, len) read(fd, buf, len)
|
||||
#define taosWriteSocket(fd, buf, len) write(fd, buf, len)
|
||||
#define taosCloseSocket(x) \
|
||||
{ \
|
||||
if (FD_VALID(x)) { \
|
||||
close(x); \
|
||||
x = FD_INITIALIZER; \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
|
||||
#define taosClose(x) taosCloseSocket(x)
|
||||
|
||||
#ifdef TAOS_RANDOM_NETWORK_FAIL
|
||||
#ifdef TAOS_RANDOM_NETWORK_FAIL_TEST
|
||||
ssize_t taosSendRandomFail(int sockfd, const void *buf, size_t len, int flags);
|
||||
ssize_t taosSendToRandomFail(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);
|
||||
ssize_t taosReadSocketRandomFail(int fd, void *buf, size_t count);
|
||||
ssize_t taosWriteSocketRandomFail(int fd, const void *buf, size_t count);
|
||||
#undef taosSend
|
||||
#undef taosSendto
|
||||
#undef taosReadSocket
|
||||
#undef taosWriteSocket
|
||||
#define taosSend(sockfd, buf, len, flags) taosSendRandomFail(sockfd, buf, len, flags)
|
||||
#define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) taosSendToRandomFail(sockfd, buf, len, flags, dest_addr, addrlen)
|
||||
#define taosReadSocket(fd, buf, len) taosReadSocketRandomFail(fd, buf, len)
|
||||
#define taosWriteSocket(fd, buf, len) taosWriteSocketRandomFail(fd, buf, len)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// TAOS_OS_FUNC_SOCKET
|
||||
int taosSetNonblocking(int sock, int on);
|
||||
void taosBlockSIGPIPE();
|
||||
|
||||
// TAOS_OS_FUNC_SOCKET_SETSOCKETOPT
|
||||
int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,391 +0,0 @@
|
|||
/*
|
||||
* 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 TDENGINE_OS_SPEC_H
|
||||
#define TDENGINE_OS_SPEC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define tclose(x) taosCloseSocket(x)
|
||||
#define tfree(x) \
|
||||
do { \
|
||||
if (x) { \
|
||||
free((void *)(x)); \
|
||||
x = 0; \
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
#define tstrncpy(dst, src, size) \
|
||||
do { \
|
||||
strncpy((dst), (src), (size)); \
|
||||
(dst)[(size)-1] = 0; \
|
||||
} while (0);
|
||||
|
||||
#ifndef STDERR_FILENO
|
||||
#define STDERR_FILENO (2)
|
||||
#endif
|
||||
|
||||
#define FD_VALID(x) ((x) > STDERR_FILENO)
|
||||
#define FD_INITIALIZER ((int32_t)-1)
|
||||
|
||||
#define WCHAR wchar_t
|
||||
|
||||
#define POINTER_SHIFT(p, b) ((void *)((char *)(p) + (b)))
|
||||
#define POINTER_DISTANCE(p1, p2) ((char *)(p1) - (char *)(p2))
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define ASSERT(x) assert(x)
|
||||
#else
|
||||
#define ASSERT(x)
|
||||
#endif
|
||||
|
||||
#ifdef UNUSED
|
||||
#undefine UNUSED
|
||||
#endif
|
||||
#define UNUSED(x) ((void)(x))
|
||||
|
||||
#ifdef UNUSED_FUNC
|
||||
#undefine UNUSED_FUNC
|
||||
#endif
|
||||
|
||||
#ifdef UNUSED_PARAM
|
||||
#undef UNUSED_PARAM
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define UNUSED_PARAM(x) _UNUSED##x __attribute__((unused))
|
||||
#define UNUSED_FUNC __attribute__((unused))
|
||||
#else
|
||||
#define UNUSED_PARAM(x) x
|
||||
#define UNUSED_FUNC
|
||||
#endif
|
||||
|
||||
#ifdef tListLen
|
||||
#undefine tListLen
|
||||
#endif
|
||||
#define tListLen(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define FORCE_INLINE inline __attribute__((always_inline))
|
||||
#else
|
||||
#define FORCE_INLINE
|
||||
#endif
|
||||
|
||||
#define DEFAULT_UNICODE_ENCODEC "UCS-4LE"
|
||||
|
||||
#define DEFAULT_COMP(x, y) \
|
||||
do { \
|
||||
if ((x) == (y)) { \
|
||||
return 0; \
|
||||
} else { \
|
||||
return (x) < (y) ? -1 : 1; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ALIGN_NUM(n, align) (((n) + ((align)-1)) & (~((align)-1)))
|
||||
|
||||
// align to 8bytes
|
||||
#define ALIGN8(n) ALIGN_NUM(n, 8)
|
||||
|
||||
#define POW2(x) ((x) * (x))
|
||||
|
||||
#ifndef TAOS_OS_FUNC_MATH
|
||||
#define SWAP(a, b, c) \
|
||||
do { \
|
||||
typeof(a) __tmp = (a); \
|
||||
(a) = (b); \
|
||||
(b) = __tmp; \
|
||||
} while (0)
|
||||
|
||||
#define MAX(a, b) \
|
||||
({ \
|
||||
typeof(a) __a = (a); \
|
||||
typeof(b) __b = (b); \
|
||||
(__a > __b) ? __a : __b; \
|
||||
})
|
||||
|
||||
#define MIN(a, b) \
|
||||
({ \
|
||||
typeof(a) __a = (a); \
|
||||
typeof(b) __b = (b); \
|
||||
(__a < __b) ? __a : __b; \
|
||||
})
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_DEF_TIME
|
||||
#define MILLISECOND_PER_SECOND ((int64_t)1000L)
|
||||
#endif
|
||||
#define MILLISECOND_PER_MINUTE (MILLISECOND_PER_SECOND * 60)
|
||||
#define MILLISECOND_PER_HOUR (MILLISECOND_PER_MINUTE * 60)
|
||||
#define MILLISECOND_PER_DAY (MILLISECOND_PER_HOUR * 24)
|
||||
#define MILLISECOND_PER_WEEK (MILLISECOND_PER_DAY * 7)
|
||||
#define MILLISECOND_PER_MONTH (MILLISECOND_PER_DAY * 30)
|
||||
#define MILLISECOND_PER_YEAR (MILLISECOND_PER_DAY * 365)
|
||||
|
||||
#ifndef TAOS_OS_FUNC_SEMPHONE
|
||||
#define tsem_t sem_t
|
||||
#define tsem_init sem_init
|
||||
#define tsem_wait sem_wait
|
||||
#define tsem_post sem_post
|
||||
#define tsem_destroy sem_destroy
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_ATOMIC
|
||||
#define atomic_load_8(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_16(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_32(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_64(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_ptr(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_store_8(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_store_16(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_store_32(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_store_64(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_store_ptr(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_exchange_8(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_exchange_16(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_exchange_32(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_exchange_64(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_exchange_ptr(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_val_compare_exchange_8 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_16 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_32 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_64 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_ptr __sync_val_compare_and_swap
|
||||
|
||||
#define atomic_add_fetch_8(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_add_fetch_16(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_add_fetch_32(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_add_fetch_64(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_add_fetch_ptr(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_add_8(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_16(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_32(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_64(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_ptr(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_sub_fetch_8(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_sub_fetch_16(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_sub_fetch_32(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_sub_fetch_64(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_sub_fetch_ptr(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_sub_8(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_16(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_32(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_64(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_ptr(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_and_fetch_8(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_and_fetch_16(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_and_fetch_32(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_and_fetch_64(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_and_fetch_ptr(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_and_8(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_16(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_32(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_64(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_ptr(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_or_fetch_8(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_or_fetch_16(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_or_fetch_32(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_or_fetch_64(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_or_fetch_ptr(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_or_8(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_16(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_32(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_64(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_ptr(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_xor_fetch_8(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_xor_fetch_16(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_xor_fetch_32(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_xor_fetch_64(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_xor_fetch_ptr(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_xor_8(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_16(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_32(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_64(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_ptr(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#endif
|
||||
|
||||
ssize_t taosTReadImp(int fd, void *buf, size_t count);
|
||||
ssize_t taosTWriteImp(int fd, void *buf, size_t count);
|
||||
ssize_t taosTSendFileImp(int dfd, int sfd, off_t *offset, size_t size);
|
||||
#ifndef TAOS_OS_FUNC_FILE_OP
|
||||
#define taosTRead(fd, buf, count) taosTReadImp(fd, buf, count)
|
||||
#define taosTWrite(fd, buf, count) taosTWriteImp(fd, buf, count)
|
||||
#define taosLSeek(fd, offset, whence) lseek(fd, offset, whence)
|
||||
#define taosTSendFile(dfd, sfd, offset, size) taosTSendFileImp(dfd, sfd, offset, size)
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_NETWORK
|
||||
#define taosSend(sockfd, buf, len, flags) send(sockfd, buf, len, flags)
|
||||
#define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto(sockfd, buf, len, flags, dest_addr, addrlen)
|
||||
#define taosReadSocket(fd, buf, len) read(fd, buf, len)
|
||||
#define taosWriteSocket(fd, buf, len) write(fd, buf, len)
|
||||
#define taosCloseSocket(x) \
|
||||
{ \
|
||||
if (FD_VALID(x)) { \
|
||||
close(x); \
|
||||
x = FD_INITIALIZER; \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_LZ4
|
||||
#define BUILDIN_CLZL(val) __builtin_clzl(val)
|
||||
#define BUILDIN_CTZL(val) __builtin_ctzl(val)
|
||||
#define BUILDIN_CLZ(val) __builtin_clz(val)
|
||||
#define BUILDIN_CTZ(val) __builtin_ctz(val)
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_WCHAR
|
||||
#define twcslen wcslen
|
||||
#endif
|
||||
|
||||
#undef threadlocal
|
||||
#ifdef _ISOC11_SOURCE
|
||||
#define threadlocal _Thread_local
|
||||
#elif defined(__APPLE__)
|
||||
#define threadlocal
|
||||
#elif defined(__GNUC__) && !defined(threadlocal)
|
||||
#define threadlocal __thread
|
||||
#else
|
||||
#define threadlocal
|
||||
#endif
|
||||
|
||||
void osInit();
|
||||
|
||||
// TAOS_OS_FUNC_PTHREAD
|
||||
bool taosCheckPthreadValid(pthread_t thread);
|
||||
int64_t taosGetPthreadId();
|
||||
|
||||
// TAOS_OS_FUNC_SOCKET
|
||||
int taosSetNonblocking(int sock, int on);
|
||||
int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen);
|
||||
void taosBlockSIGPIPE();
|
||||
|
||||
// TAOS_OS_FUNC_SYSINFO
|
||||
void taosGetSystemInfo();
|
||||
void taosPrintOsInfo();
|
||||
void taosKillSystem();
|
||||
int tSystem(const char * cmd) ;
|
||||
|
||||
// TAOS_OS_FUNC_CORE
|
||||
void taosSetCoreDump();
|
||||
|
||||
// TAOS_OS_FUNC_UTIL
|
||||
int64_t tsosStr2int64(char *str);
|
||||
|
||||
// TAOS_OS_FUNC_TIMER
|
||||
void taosMsleep(int mseconds);
|
||||
int taosInitTimer(void (*callback)(int), int ms);
|
||||
void taosUninitTimer();
|
||||
|
||||
// TAOS_OS_FUNC_RAND
|
||||
uint32_t taosRand(void);
|
||||
void taosRandStr(char* str, int32_t size);
|
||||
uint32_t trand(void);
|
||||
|
||||
// TAOS_OS_FUNC_FILE
|
||||
void getTmpfilePath(const char *fileNamePrefix, char *dstPath);
|
||||
int32_t taosFileRename(char *fullPath, char *suffix, char delimiter, char **dstPath);
|
||||
|
||||
// USE_LIBICONV
|
||||
int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs);
|
||||
bool taosMbsToUcs4(char *mbs, size_t mbs_len, char *ucs4, int32_t ucs4_max_len, size_t *len);
|
||||
int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes);
|
||||
bool taosValidateEncodec(const char *encodec);
|
||||
char * taosCharsetReplace(char *charsetstr);
|
||||
|
||||
// TAOS_OS_FUNC_MALLOC
|
||||
#define TAOS_ALLOC_MODE_DEFAULT 0
|
||||
#define TAOS_ALLOC_MODE_RANDOM_FAIL 1
|
||||
#define TAOS_ALLOC_MODE_DETECT_LEAK 2
|
||||
void taosSetAllocMode(int mode, const char *path, bool autoDump);
|
||||
void taosDumpMemoryLeak();
|
||||
void * tmalloc(size_t size);
|
||||
void * tcalloc(size_t nmemb, size_t size);
|
||||
size_t tsizeof(void *ptr);
|
||||
void tmemset(void *ptr, int c);
|
||||
void * trealloc(void *ptr, size_t size);
|
||||
void tzfree(void *ptr);
|
||||
|
||||
// TAOS_OS_FUNC_DIR
|
||||
void taosRemoveDir(char *rootDir);
|
||||
int taosMkDir(const char *pathname, mode_t mode);
|
||||
void taosMvDir(char* destDir, char *srcDir);
|
||||
|
||||
#ifdef TAOS_RANDOM_FILE_FAIL
|
||||
void taosSetRandomFileFailFactor(int factor);
|
||||
void taosSetRandomFileFailOutput(const char *path);
|
||||
ssize_t taosReadFileRandomFail(int fd, void *buf, size_t count, const char *file, uint32_t line);
|
||||
ssize_t taosWriteFileRandomFail(int fd, void *buf, size_t count, const char *file, uint32_t line);
|
||||
off_t taosLSeekRandomFail(int fd, off_t offset, int whence, const char *file, uint32_t line);
|
||||
#undef taosTRead
|
||||
#undef taosTWrite
|
||||
#undef taosLSeek
|
||||
#define taosTRead(fd, buf, count) taosReadFileRandomFail(fd, buf, count, __FILE__, __LINE__)
|
||||
#define taosTWrite(fd, buf, count) taosWriteFileRandomFail(fd, buf, count, __FILE__, __LINE__)
|
||||
#define taosLSeek(fd, offset, whence) taosLSeekRandomFail(fd, offset, whence, __FILE__, __LINE__)
|
||||
#endif
|
||||
|
||||
#ifdef TAOS_RANDOM_NETWORK_FAIL
|
||||
ssize_t taosSendRandomFail(int sockfd, const void *buf, size_t len, int flags);
|
||||
ssize_t taosSendToRandomFail(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);
|
||||
ssize_t taosReadSocketRandomFail(int fd, void *buf, size_t count);
|
||||
ssize_t taosWriteSocketRandomFail(int fd, const void *buf, size_t count);
|
||||
#undef taosSend
|
||||
#undef taosSendto
|
||||
#undef taosReadSocket
|
||||
#undef taosWriteSocket
|
||||
#define taosSend(sockfd, buf, len, flags) taosSendRandomFail(sockfd, buf, len, flags)
|
||||
#define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) taosSendToRandomFail(sockfd, buf, len, flags, dest_addr, addrlen)
|
||||
#define taosReadSocket(fd, buf, len) taosReadSocketRandomFail(fd, buf, len)
|
||||
#define taosWriteSocket(fd, buf, len) taosWriteSocketRandomFail(fd, buf, len)
|
||||
#endif
|
||||
|
||||
#ifdef TAOS_MEM_CHECK
|
||||
void * taos_malloc(size_t size, const char *file, uint32_t line);
|
||||
void * taos_calloc(size_t num, size_t size, const char *file, uint32_t line);
|
||||
void * taos_realloc(void *ptr, size_t size, const char *file, uint32_t line);
|
||||
void taos_free(void *ptr, const char *file, uint32_t line);
|
||||
char * taos_strdup(const char *str, const char *file, uint32_t line);
|
||||
char * taos_strndup(const char *str, size_t size, const char *file, uint32_t line);
|
||||
ssize_t taos_getline(char **lineptr, size_t *n, FILE *stream, const char *file, uint32_t line);
|
||||
#define malloc(size) taos_malloc(size, __FILE__, __LINE__)
|
||||
#define calloc(num, size) taos_calloc(num, size, __FILE__, __LINE__)
|
||||
#define realloc(ptr, size) taos_realloc(ptr, size, __FILE__, __LINE__)
|
||||
#define free(ptr) taos_free(ptr, __FILE__, __LINE__)
|
||||
#define strdup(str) taos_strdup(str, __FILE__, __LINE__)
|
||||
#define strndup(str, size) taos_strndup(str, size, __FILE__, __LINE__)
|
||||
#define getline(lineptr, n, stream) taos_getline(lineptr, n, stream, __FILE__, __LINE__)
|
||||
#endif // TAOS_MEM_CHECK
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* 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 TDENGINE_OS_STRING_H
|
||||
#define TDENGINE_OS_STRING_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_STRING_STRDUP
|
||||
#define taosStrdupImp(str) strdup(str)
|
||||
#define taosStrndupImp(str, size) strndup(str, size)
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_STRING_GETLINE
|
||||
#define taosGetlineImp(lineptr, n, stream) getline(lineptr, n , stream)
|
||||
#else
|
||||
int taosGetlineImp(char **lineptr, size_t *n, FILE *stream);
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_STRING_WCHAR
|
||||
#define twcslen wcslen
|
||||
#endif
|
||||
|
||||
#define tstrncpy(dst, src, size) \
|
||||
do { \
|
||||
strncpy((dst), (src), (size)); \
|
||||
(dst)[(size)-1] = 0; \
|
||||
} while (0);
|
||||
|
||||
#ifndef TAOS_OS_FUNC_STRING_STR2INT64
|
||||
int64_t tsosStr2int64(char *str);
|
||||
#endif
|
||||
|
||||
// USE_LIBICONV
|
||||
int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs);
|
||||
bool taosMbsToUcs4(char *mbs, size_t mbs_len, char *ucs4, int32_t ucs4_max_len, size_t *len);
|
||||
int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes);
|
||||
bool taosValidateEncodec(const char *encodec);
|
||||
char * taosCharsetReplace(char *charsetstr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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 TDENGINE_OS_SYSINFO_H
|
||||
#define TDENGINE_OS_SYSINFO_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// TAOS_OS_FUNC_SYSINFO
|
||||
void taosGetSystemInfo();
|
||||
bool taosGetProcIO(float *readKB, float *writeKB);
|
||||
bool taosGetBandSpeed(float *bandSpeedKb);
|
||||
bool taosGetDisk();
|
||||
bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) ;
|
||||
bool taosGetProcMemory(float *memoryUsedMB) ;
|
||||
bool taosGetSysMemory(float *memoryUsedMB);
|
||||
void taosPrintOsInfo();
|
||||
int taosSystem(const char * cmd) ;
|
||||
void taosKillSystem();
|
||||
|
||||
// TAOS_OS_FUNC_SYSINFO_CORE
|
||||
void taosSetCoreDump();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -13,8 +13,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_TTIME_H
|
||||
#define TDENGINE_TTIME_H
|
||||
#ifndef TDENGINE_OS_TIME_H
|
||||
#define TDENGINE_OS_TIME_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -23,6 +23,16 @@ extern "C" {
|
|||
#include "os.h"
|
||||
#include "taosdef.h"
|
||||
|
||||
#ifndef TAOS_OS_FUNC_TIME_DEF
|
||||
#define MILLISECOND_PER_SECOND ((int64_t)1000L)
|
||||
#endif
|
||||
#define MILLISECOND_PER_MINUTE (MILLISECOND_PER_SECOND * 60)
|
||||
#define MILLISECOND_PER_HOUR (MILLISECOND_PER_MINUTE * 60)
|
||||
#define MILLISECOND_PER_DAY (MILLISECOND_PER_HOUR * 24)
|
||||
#define MILLISECOND_PER_WEEK (MILLISECOND_PER_DAY * 7)
|
||||
#define MILLISECOND_PER_MONTH (MILLISECOND_PER_DAY * 30)
|
||||
#define MILLISECOND_PER_YEAR (MILLISECOND_PER_DAY * 365)
|
||||
|
||||
//@return timestamp in second
|
||||
int32_t taosGetTimestampSec();
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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 TDENGINE_OS_TIMER_H
|
||||
#define TDENGINE_OS_TIMER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// TAOS_OS_FUNC_TIMER
|
||||
void taosMsleep(int mseconds);
|
||||
int taosInitTimer(void (*callback)(int), int ms);
|
||||
void taosUninitTimer();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,376 @@
|
|||
/*
|
||||
* 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 TDENGINE_PLATFORM_WINDOWS_H
|
||||
#define TDENGINE_PLATFORM_WINDOWS_H
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <direct.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <float.h>
|
||||
#include <locale.h>
|
||||
#include <intrin.h>
|
||||
#include <io.h>
|
||||
#include <math.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <inttypes.h>
|
||||
#include "winsock2.h"
|
||||
#include <WS2tcpip.h>
|
||||
#include <winbase.h>
|
||||
#include <Winsock2.h>
|
||||
#include <process.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define TAOS_OS_FUNC_ATOMIC
|
||||
|
||||
#define TAOS_OS_FUNC_LZ4
|
||||
int32_t BUILDIN_CLZL(uint64_t val);
|
||||
int32_t BUILDIN_CLZ(uint32_t val);
|
||||
int32_t BUILDIN_CTZL(uint64_t val);
|
||||
int32_t BUILDIN_CTZ(uint32_t val);
|
||||
|
||||
#define TAOS_OS_FUNC_DIR
|
||||
|
||||
#define TAOS_OS_FUNC_FILE
|
||||
#define TAOS_OS_FUNC_FILE_SENDIFLE
|
||||
#define taosFSendFile(outfile, infile, offset, count) taosFSendFileImp(outfile, infile, offset, size)
|
||||
#define taosTSendFile(dfd, sfd, offset, size) taosTSendFileImp(dfd, sfd, offset, size)
|
||||
#define TAOS_OS_FUNC_FILE_GETTMPFILEPATH
|
||||
|
||||
#define TAOS_OS_FUNC_MATH
|
||||
#define SWAP(a, b, c) \
|
||||
do { \
|
||||
c __tmp = (c)(a); \
|
||||
(a) = (c)(b); \
|
||||
(b) = __tmp; \
|
||||
} while (0)
|
||||
#define MAX(a,b) (((a)>(b))?(a):(b))
|
||||
#define MIN(a,b) (((a)<(b))?(a):(b))
|
||||
|
||||
#define TAOS_OS_FUNC_SEMPHONE_PTHREAD
|
||||
|
||||
#define TAOS_OS_FUNC_SOCKET
|
||||
#define TAOS_OS_FUNC_SOCKET_SETSOCKETOPT
|
||||
#define TAOS_OS_FUNC_SOCKET_OP
|
||||
#define taosSend(sockfd, buf, len, flags) send(sockfd, buf, len, flags)
|
||||
#define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto(sockfd, buf, len, flags, dest_addr, addrlen)
|
||||
#define taosWriteSocket(fd, buf, len) send(fd, buf, len, 0)
|
||||
#define taosReadSocket(fd, buf, len) recv(fd, buf, len, 0)
|
||||
#define taosCloseSocket(fd) closesocket(fd)
|
||||
|
||||
#define TAOS_OS_FUNC_STRING_WCHAR
|
||||
#define TAOS_OS_FUNC_STRING_GETLINE
|
||||
#define TAOS_OS_FUNC_STRING_STR2INT64
|
||||
#ifdef _TD_GO_DLL_
|
||||
int64_t tsosStr2int64(char *str);
|
||||
uint64_t htonll(uint64_t val);
|
||||
#else
|
||||
#define tsosStr2int64 _atoi64
|
||||
#endif
|
||||
#define TAOS_OS_FUNC_STRING_STRDUP
|
||||
#define taosStrdupImp(str) _strdup(str)
|
||||
#define taosStrndupImp(str, size) _strndup(str, size)
|
||||
|
||||
#define TAOS_OS_FUNC_SYSINFO
|
||||
|
||||
#define TAOS_OS_FUNC_TIME_DEF
|
||||
#ifdef _TD_GO_DLL_
|
||||
#define MILLISECOND_PER_SECOND (1000LL)
|
||||
#else
|
||||
#define MILLISECOND_PER_SECOND (1000i64)
|
||||
#endif
|
||||
|
||||
#define TAOS_OS_FUNC_TIMER_SLEEP
|
||||
#define TAOS_OS_FUNC_TIMER
|
||||
|
||||
// specific
|
||||
typedef int (*__compar_fn_t)(const void *, const void *);
|
||||
#define ssize_t int
|
||||
#define bzero(ptr, size) memset((ptr), 0, (size))
|
||||
#define mkdir(pathname, mode) _mkdir(pathname)
|
||||
#define strcasecmp _stricmp
|
||||
#define strncasecmp _strnicmp
|
||||
#define wcsncasecmp _wcsnicmp
|
||||
#define strtok_r strtok_s
|
||||
#define snprintf _snprintf
|
||||
#define in_addr_t unsigned long
|
||||
#define socklen_t int
|
||||
#define htobe64 htonll
|
||||
#define twrite write
|
||||
#define getpid _getpid
|
||||
|
||||
int gettimeofday(struct timeval *tv, struct timezone *tz);
|
||||
struct tm *localtime_r(const time_t *timep, struct tm *result);
|
||||
char * strptime(const char *buf, const char *fmt, struct tm *tm);
|
||||
char * strsep(char **stringp, const char *delim);
|
||||
char * getpass(const char *prefix);
|
||||
int flock(int fd, int option);
|
||||
int fsync(int filedes);
|
||||
char * strndup(const char *s, size_t n);
|
||||
|
||||
// for function open in stat.h
|
||||
#define S_IRWXU _S_IREAD
|
||||
#define S_IRWXG _S_IWRITE
|
||||
#define S_IRWXO _S_IWRITE
|
||||
|
||||
// for access function in io.h
|
||||
#define F_OK 00 //Existence only
|
||||
#define W_OK 02 //Write - only
|
||||
#define R_OK 04 //Read - only
|
||||
#define X_OK 06 //Read and write
|
||||
|
||||
// for send function in tsocket.c
|
||||
#define MSG_NOSIGNAL 0
|
||||
#define SO_NO_CHECK 0x1234
|
||||
#define SOL_TCP 0x1234
|
||||
#define TCP_KEEPCNT 0x1234
|
||||
#define TCP_KEEPIDLE 0x1234
|
||||
#define TCP_KEEPINTVL 0x1234
|
||||
|
||||
#define LOCK_EX 1
|
||||
#define LOCK_NB 2
|
||||
#define LOCK_UN 3
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 256
|
||||
#endif
|
||||
|
||||
//for signal, not dispose
|
||||
#define SIGALRM 1234
|
||||
typedef int sigset_t;
|
||||
struct sigaction {
|
||||
void (*sa_handler)(int);
|
||||
};
|
||||
int sigaction(int, struct sigaction *, void *);
|
||||
|
||||
typedef struct {
|
||||
int we_wordc;
|
||||
char **we_wordv;
|
||||
int we_offs;
|
||||
char wordPos[20];
|
||||
} wordexp_t;
|
||||
int wordexp(const char *words, wordexp_t *pwordexp, int flags);
|
||||
void wordfree(wordexp_t *pwordexp);
|
||||
|
||||
#define TAOS_OS_FUNC_ATOMIC
|
||||
#define atomic_load_8(ptr) (*(char volatile*)(ptr))
|
||||
#define atomic_load_16(ptr) (*(short volatile*)(ptr))
|
||||
#define atomic_load_32(ptr) (*(long volatile*)(ptr))
|
||||
#define atomic_load_64(ptr) (*(__int64 volatile*)(ptr))
|
||||
#define atomic_load_ptr(ptr) (*(void* volatile*)(ptr))
|
||||
|
||||
#define atomic_store_8(ptr, val) ((*(char volatile*)(ptr)) = (char)(val))
|
||||
#define atomic_store_16(ptr, val) ((*(short volatile*)(ptr)) = (short)(val))
|
||||
#define atomic_store_32(ptr, val) ((*(long volatile*)(ptr)) = (long)(val))
|
||||
#define atomic_store_64(ptr, val) ((*(__int64 volatile*)(ptr)) = (__int64)(val))
|
||||
#define atomic_store_ptr(ptr, val) ((*(void* volatile*)(ptr)) = (void*)(val))
|
||||
|
||||
#define atomic_exchange_8(ptr, val) _InterlockedExchange8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_exchange_16(ptr, val) _InterlockedExchange16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_exchange_32(ptr, val) _InterlockedExchange((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_exchange_64(ptr, val) _InterlockedExchange64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#define atomic_exchange_ptr(ptr, val) _InterlockedExchangePointer((void* volatile*)(ptr), (void*)(val))
|
||||
|
||||
#ifdef _TD_GO_DLL_
|
||||
#define atomic_val_compare_exchange_8 __sync_val_compare_and_swap
|
||||
#else
|
||||
#define atomic_val_compare_exchange_8(ptr, oldval, newval) _InterlockedCompareExchange8((char volatile*)(ptr), (char)(newval), (char)(oldval))
|
||||
#endif
|
||||
#define atomic_val_compare_exchange_16(ptr, oldval, newval) _InterlockedCompareExchange16((short volatile*)(ptr), (short)(newval), (short)(oldval))
|
||||
#define atomic_val_compare_exchange_32(ptr, oldval, newval) _InterlockedCompareExchange((long volatile*)(ptr), (long)(newval), (long)(oldval))
|
||||
#define atomic_val_compare_exchange_64(ptr, oldval, newval) _InterlockedCompareExchange64((__int64 volatile*)(ptr), (__int64)(newval), (__int64)(oldval))
|
||||
#define atomic_val_compare_exchange_ptr(ptr, oldval, newval) _InterlockedCompareExchangePointer((void* volatile*)(ptr), (void*)(newval), (void*)(oldval))
|
||||
|
||||
char interlocked_add_fetch_8(char volatile *ptr, char val);
|
||||
short interlocked_add_fetch_16(short volatile *ptr, short val);
|
||||
long interlocked_add_fetch_32(long volatile *ptr, long val);
|
||||
__int64 interlocked_add_fetch_64(__int64 volatile *ptr, __int64 val);
|
||||
|
||||
#define atomic_add_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_add_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_add_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_add_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#ifdef _WIN64
|
||||
#define atomic_add_fetch_ptr atomic_add_fetch_64
|
||||
#else
|
||||
#define atomic_add_fetch_ptr atomic_add_fetch_32
|
||||
#endif
|
||||
|
||||
#ifdef _TD_GO_DLL_
|
||||
#define atomic_fetch_add_8 __sync_fetch_and_ad
|
||||
#define atomic_fetch_add_16 __sync_fetch_and_add
|
||||
#else
|
||||
#define atomic_fetch_add_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_fetch_add_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), (short)(val))
|
||||
#endif
|
||||
#define atomic_fetch_add_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_fetch_add_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#ifdef _WIN64
|
||||
#define atomic_fetch_add_ptr atomic_fetch_add_64
|
||||
#else
|
||||
#define atomic_fetch_add_ptr atomic_fetch_add_32
|
||||
#endif
|
||||
|
||||
#define atomic_sub_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), -(char)(val))
|
||||
#define atomic_sub_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), -(short)(val))
|
||||
#define atomic_sub_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), -(long)(val))
|
||||
#define atomic_sub_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), -(__int64)(val))
|
||||
#ifdef _WIN64
|
||||
#define atomic_sub_fetch_ptr atomic_sub_fetch_64
|
||||
#else
|
||||
#define atomic_sub_fetch_ptr atomic_sub_fetch_32
|
||||
#endif
|
||||
|
||||
#define atomic_fetch_sub_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), -(char)(val))
|
||||
#define atomic_fetch_sub_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), -(short)(val))
|
||||
#define atomic_fetch_sub_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), -(long)(val))
|
||||
#define atomic_fetch_sub_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), -(__int64)(val))
|
||||
#ifdef _WIN64
|
||||
#define atomic_fetch_sub_ptr atomic_fetch_sub_64
|
||||
#else
|
||||
#define atomic_fetch_sub_ptr atomic_fetch_sub_32
|
||||
#endif
|
||||
|
||||
#ifndef _TD_GO_DLL_
|
||||
char interlocked_and_fetch_8(char volatile* ptr, char val);
|
||||
short interlocked_and_fetch_16(short volatile* ptr, short val);
|
||||
#endif
|
||||
long interlocked_and_fetch_32(long volatile* ptr, long val);
|
||||
__int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val);
|
||||
|
||||
#ifndef _TD_GO_DLL_
|
||||
#define atomic_and_fetch_8(ptr, val) interlocked_and_fetch_8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_and_fetch_16(ptr, val) interlocked_and_fetch_16((short volatile*)(ptr), (short)(val))
|
||||
#endif
|
||||
#define atomic_and_fetch_32(ptr, val) interlocked_and_fetch_32((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_and_fetch_64(ptr, val) interlocked_and_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#ifdef _WIN64
|
||||
#define atomic_and_fetch_ptr atomic_and_fetch_64
|
||||
#else
|
||||
#define atomic_and_fetch_ptr atomic_and_fetch_32
|
||||
#endif
|
||||
#ifndef _TD_GO_DLL_
|
||||
#define atomic_fetch_and_8(ptr, val) _InterlockedAnd8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_fetch_and_16(ptr, val) _InterlockedAnd16((short volatile*)(ptr), (short)(val))
|
||||
#endif
|
||||
#define atomic_fetch_and_32(ptr, val) _InterlockedAnd((long volatile*)(ptr), (long)(val))
|
||||
|
||||
#ifdef _M_IX86
|
||||
__int64 interlocked_fetch_and_64(__int64 volatile* ptr, __int64 val);
|
||||
#define atomic_fetch_and_64(ptr, val) interlocked_fetch_and_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#else
|
||||
#define atomic_fetch_and_64(ptr, val) _InterlockedAnd64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#endif
|
||||
|
||||
#ifdef _WIN64
|
||||
#define atomic_fetch_and_ptr atomic_fetch_and_64
|
||||
#else
|
||||
#define atomic_fetch_and_ptr atomic_fetch_and_32
|
||||
#endif
|
||||
#ifndef _TD_GO_DLL_
|
||||
char interlocked_or_fetch_8(char volatile* ptr, char val);
|
||||
short interlocked_or_fetch_16(short volatile* ptr, short val);
|
||||
#endif
|
||||
long interlocked_or_fetch_32(long volatile* ptr, long val);
|
||||
__int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val);
|
||||
|
||||
#ifndef _TD_GO_DLL_
|
||||
#define atomic_or_fetch_8(ptr, val) interlocked_or_fetch_8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_or_fetch_16(ptr, val) interlocked_or_fetch_16((short volatile*)(ptr), (short)(val))
|
||||
#endif
|
||||
#define atomic_or_fetch_32(ptr, val) interlocked_or_fetch_32((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_or_fetch_64(ptr, val) interlocked_or_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#ifdef _WIN64
|
||||
#define atomic_or_fetch_ptr atomic_or_fetch_64
|
||||
#else
|
||||
#define atomic_or_fetch_ptr atomic_or_fetch_32
|
||||
#endif
|
||||
#ifndef _TD_GO_DLL_
|
||||
#define atomic_fetch_or_8(ptr, val) _InterlockedOr8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_fetch_or_16(ptr, val) _InterlockedOr16((short volatile*)(ptr), (short)(val))
|
||||
#endif
|
||||
#define atomic_fetch_or_32(ptr, val) _InterlockedOr((long volatile*)(ptr), (long)(val))
|
||||
|
||||
#ifdef _M_IX86
|
||||
__int64 interlocked_fetch_or_64(__int64 volatile* ptr, __int64 val);
|
||||
#define atomic_fetch_or_64(ptr, val) interlocked_fetch_or_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#else
|
||||
#define atomic_fetch_or_64(ptr, val) _InterlockedOr64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#endif
|
||||
|
||||
#ifdef _WIN64
|
||||
#define atomic_fetch_or_ptr atomic_fetch_or_64
|
||||
#else
|
||||
#define atomic_fetch_or_ptr atomic_fetch_or_32
|
||||
#endif
|
||||
|
||||
#ifndef _TD_GO_DLL_
|
||||
char interlocked_xor_fetch_8(char volatile* ptr, char val);
|
||||
short interlocked_xor_fetch_16(short volatile* ptr, short val);
|
||||
#endif
|
||||
long interlocked_xor_fetch_32(long volatile* ptr, long val);
|
||||
__int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val);
|
||||
|
||||
#ifndef _TD_GO_DLL_
|
||||
#define atomic_xor_fetch_8(ptr, val) interlocked_xor_fetch_8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_xor_fetch_16(ptr, val) interlocked_xor_fetch_16((short volatile*)(ptr), (short)(val))
|
||||
#endif
|
||||
#define atomic_xor_fetch_32(ptr, val) interlocked_xor_fetch_32((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_xor_fetch_64(ptr, val) interlocked_xor_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#ifdef _WIN64
|
||||
#define atomic_xor_fetch_ptr atomic_xor_fetch_64
|
||||
#else
|
||||
#define atomic_xor_fetch_ptr atomic_xor_fetch_32
|
||||
#endif
|
||||
|
||||
#ifndef _TD_GO_DLL_
|
||||
#define atomic_fetch_xor_8(ptr, val) _InterlockedXor8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_fetch_xor_16(ptr, val) _InterlockedXor16((short volatile*)(ptr), (short)(val))
|
||||
#endif
|
||||
#define atomic_fetch_xor_32(ptr, val) _InterlockedXor((long volatile*)(ptr), (long)(val))
|
||||
|
||||
#ifdef _M_IX86
|
||||
__int64 interlocked_fetch_xor_64(__int64 volatile* ptr, __int64 val);
|
||||
#define atomic_fetch_xor_64(ptr, val) interlocked_fetch_xor_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#else
|
||||
#define atomic_fetch_xor_64(ptr, val) _InterlockedXor64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#endif
|
||||
|
||||
#ifdef _WIN64
|
||||
#define atomic_fetch_xor_ptr atomic_fetch_xor_64
|
||||
#else
|
||||
#define atomic_fetch_xor_ptr atomic_fetch_xor_32
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* 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 TDENGINE_PLATFORM_WINDOWS32_H
|
||||
#define TDENGINE_PLATFORM_WINDOWS32_H
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <direct.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <float.h>
|
||||
#include <locale.h>
|
||||
#include <intrin.h>
|
||||
#include <io.h>
|
||||
#include <math.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <inttypes.h>
|
||||
#include "winsock2.h"
|
||||
#include <WS2tcpip.h>
|
||||
#include <winbase.h>
|
||||
#include <Winsock2.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,424 +0,0 @@
|
|||
/*
|
||||
* 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 TDENGINE_PLATFORM_WINDOWS_H
|
||||
#define TDENGINE_PLATFORM_WINDOWS_H
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <direct.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <float.h>
|
||||
#include <locale.h>
|
||||
#include <intrin.h>
|
||||
#include <io.h>
|
||||
#include <math.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <inttypes.h>
|
||||
#include "winsock2.h"
|
||||
#include <WS2tcpip.h>
|
||||
#include <winbase.h>
|
||||
#include <Winsock2.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define TAOS_OS_FUNC_WCHAR
|
||||
|
||||
// for function open in stat.h
|
||||
#define S_IRWXU _S_IREAD
|
||||
#define S_IRWXG _S_IWRITE
|
||||
#define S_IRWXO _S_IWRITE
|
||||
|
||||
// for access function in io.h
|
||||
#define F_OK 00 //Existence only
|
||||
#define W_OK 02 //Write - only
|
||||
#define R_OK 04 //Read - only
|
||||
#define X_OK 06 //Read and write
|
||||
|
||||
// for send function in tsocket.c
|
||||
#define MSG_NOSIGNAL 0
|
||||
#define SO_NO_CHECK 0x1234
|
||||
#define SOL_TCP 0x1234
|
||||
#define TCP_KEEPCNT 0x1234
|
||||
#define TCP_KEEPIDLE 0x1234
|
||||
#define TCP_KEEPINTVL 0x1234
|
||||
|
||||
#define LOCK_EX 1
|
||||
#define LOCK_NB 2
|
||||
#define LOCK_UN 3
|
||||
|
||||
#define bzero(ptr, size) memset((ptr), 0, (size))
|
||||
#define mkdir(pathname, mode) _mkdir(pathname)
|
||||
#define strcasecmp _stricmp
|
||||
#define strncasecmp _strnicmp
|
||||
#define wcsncasecmp _wcsnicmp
|
||||
#define strtok_r strtok_s
|
||||
#ifdef _TD_GO_DLL_
|
||||
int64_t tsosStr2int64(char *str);
|
||||
uint64_t htonll(uint64_t val);
|
||||
#else
|
||||
#define tsosStr2int64 _atoi64
|
||||
#endif
|
||||
|
||||
#define snprintf _snprintf
|
||||
#define in_addr_t unsigned long
|
||||
#define socklen_t int
|
||||
#define htobe64 htonll
|
||||
#define twrite write
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 256
|
||||
#endif
|
||||
|
||||
#define taosCloseSocket(fd) closesocket(fd)
|
||||
#define taosWriteSocket(fd, buf, len) send(fd, buf, len, 0)
|
||||
#define taosReadSocket(fd, buf, len) recv(fd, buf, len, 0)
|
||||
|
||||
#if defined(_M_ARM) || defined(_M_ARM64)
|
||||
|
||||
/* the '__iso_volatile' functions does not use a memory fence, so these
|
||||
* definitions are incorrect, comment out as we don't support Windows on
|
||||
* ARM at present.
|
||||
|
||||
#define atomic_load_8(ptr) __iso_volatile_load8((const volatile __int8*)(ptr))
|
||||
#define atomic_load_16(ptr) __iso_volatile_load16((const volatile __int16*)(ptr))
|
||||
#define atomic_load_32(ptr) __iso_volatile_load32((const volatile __int32*)(ptr))
|
||||
#define atomic_load_64(ptr) __iso_volatile_load64((const volatile __int64*)(ptr))
|
||||
|
||||
#define atomic_store_8(ptr, val) __iso_volatile_store8((volatile __int8*)(ptr), (__int8)(val))
|
||||
#define atomic_store_16(ptr, val) __iso_volatile_store16((volatile __int16*)(ptr), (__int16)(val))
|
||||
#define atomic_store_32(ptr, val) __iso_volatile_store32((volatile __int32*)(ptr), (__int32)(val))
|
||||
#define atomic_store_64(ptr, val) __iso_volatile_store64((volatile __int64*)(ptr), (__int64)(val))
|
||||
|
||||
#ifdef _M_ARM64
|
||||
#define atomic_load_ptr atomic_load_64
|
||||
#define atomic_store_ptr atomic_store_64
|
||||
#else
|
||||
#define atomic_load_ptr atomic_load_32
|
||||
#define atomic_store_ptr atomic_store_32
|
||||
#endif
|
||||
*/
|
||||
#else
|
||||
|
||||
#define atomic_load_8(ptr) (*(char volatile*)(ptr))
|
||||
#define atomic_load_16(ptr) (*(short volatile*)(ptr))
|
||||
#define atomic_load_32(ptr) (*(long volatile*)(ptr))
|
||||
#define atomic_load_64(ptr) (*(__int64 volatile*)(ptr))
|
||||
#define atomic_load_ptr(ptr) (*(void* volatile*)(ptr))
|
||||
|
||||
#define atomic_store_8(ptr, val) ((*(char volatile*)(ptr)) = (char)(val))
|
||||
#define atomic_store_16(ptr, val) ((*(short volatile*)(ptr)) = (short)(val))
|
||||
#define atomic_store_32(ptr, val) ((*(long volatile*)(ptr)) = (long)(val))
|
||||
#define atomic_store_64(ptr, val) ((*(__int64 volatile*)(ptr)) = (__int64)(val))
|
||||
#define atomic_store_ptr(ptr, val) ((*(void* volatile*)(ptr)) = (void*)(val))
|
||||
|
||||
#endif
|
||||
|
||||
#define atomic_exchange_8(ptr, val) _InterlockedExchange8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_exchange_16(ptr, val) _InterlockedExchange16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_exchange_32(ptr, val) _InterlockedExchange((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_exchange_64(ptr, val) _InterlockedExchange64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#define atomic_exchange_ptr(ptr, val) _InterlockedExchangePointer((void* volatile*)(ptr), (void*)(val))
|
||||
|
||||
#ifdef _TD_GO_DLL_
|
||||
#define atomic_val_compare_exchange_8 __sync_val_compare_and_swap
|
||||
#else
|
||||
#define atomic_val_compare_exchange_8(ptr, oldval, newval) _InterlockedCompareExchange8((char volatile*)(ptr), (char)(newval), (char)(oldval))
|
||||
#endif
|
||||
|
||||
#define atomic_val_compare_exchange_16(ptr, oldval, newval) _InterlockedCompareExchange16((short volatile*)(ptr), (short)(newval), (short)(oldval))
|
||||
#define atomic_val_compare_exchange_32(ptr, oldval, newval) _InterlockedCompareExchange((long volatile*)(ptr), (long)(newval), (long)(oldval))
|
||||
#define atomic_val_compare_exchange_64(ptr, oldval, newval) _InterlockedCompareExchange64((__int64 volatile*)(ptr), (__int64)(newval), (__int64)(oldval))
|
||||
#define atomic_val_compare_exchange_ptr(ptr, oldval, newval) _InterlockedCompareExchangePointer((void* volatile*)(ptr), (void*)(newval), (void*)(oldval))
|
||||
|
||||
char interlocked_add_fetch_8(char volatile *ptr, char val);
|
||||
short interlocked_add_fetch_16(short volatile *ptr, short val);
|
||||
long interlocked_add_fetch_32(long volatile *ptr, long val);
|
||||
__int64 interlocked_add_fetch_64(__int64 volatile *ptr, __int64 val);
|
||||
|
||||
#define atomic_add_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_add_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_add_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_add_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#ifdef _WIN64
|
||||
#define atomic_add_fetch_ptr atomic_add_fetch_64
|
||||
#else
|
||||
#define atomic_add_fetch_ptr atomic_add_fetch_32
|
||||
#endif
|
||||
#ifdef _TD_GO_DLL_
|
||||
#define atomic_fetch_add_8 __sync_fetch_and_ad
|
||||
#define atomic_fetch_add_16 __sync_fetch_and_add
|
||||
#else
|
||||
#define atomic_fetch_add_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_fetch_add_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), (short)(val))
|
||||
#endif
|
||||
|
||||
#define atomic_fetch_add_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_fetch_add_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#ifdef _WIN64
|
||||
#define atomic_fetch_add_ptr atomic_fetch_add_64
|
||||
#else
|
||||
#define atomic_fetch_add_ptr atomic_fetch_add_32
|
||||
#endif
|
||||
|
||||
#define atomic_sub_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), -(char)(val))
|
||||
#define atomic_sub_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), -(short)(val))
|
||||
#define atomic_sub_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), -(long)(val))
|
||||
#define atomic_sub_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), -(__int64)(val))
|
||||
#ifdef _WIN64
|
||||
#define atomic_sub_fetch_ptr atomic_sub_fetch_64
|
||||
#else
|
||||
#define atomic_sub_fetch_ptr atomic_sub_fetch_32
|
||||
#endif
|
||||
|
||||
#define atomic_fetch_sub_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), -(char)(val))
|
||||
#define atomic_fetch_sub_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), -(short)(val))
|
||||
#define atomic_fetch_sub_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), -(long)(val))
|
||||
#define atomic_fetch_sub_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), -(__int64)(val))
|
||||
#ifdef _WIN64
|
||||
#define atomic_fetch_sub_ptr atomic_fetch_sub_64
|
||||
#else
|
||||
#define atomic_fetch_sub_ptr atomic_fetch_sub_32
|
||||
#endif
|
||||
#ifndef _TD_GO_DLL_
|
||||
char interlocked_and_fetch_8(char volatile* ptr, char val);
|
||||
short interlocked_and_fetch_16(short volatile* ptr, short val);
|
||||
#endif
|
||||
long interlocked_and_fetch_32(long volatile* ptr, long val);
|
||||
__int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val);
|
||||
|
||||
#ifndef _TD_GO_DLL_
|
||||
#define atomic_and_fetch_8(ptr, val) interlocked_and_fetch_8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_and_fetch_16(ptr, val) interlocked_and_fetch_16((short volatile*)(ptr), (short)(val))
|
||||
#endif
|
||||
#define atomic_and_fetch_32(ptr, val) interlocked_and_fetch_32((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_and_fetch_64(ptr, val) interlocked_and_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#ifdef _WIN64
|
||||
#define atomic_and_fetch_ptr atomic_and_fetch_64
|
||||
#else
|
||||
#define atomic_and_fetch_ptr atomic_and_fetch_32
|
||||
#endif
|
||||
#ifndef _TD_GO_DLL_
|
||||
#define atomic_fetch_and_8(ptr, val) _InterlockedAnd8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_fetch_and_16(ptr, val) _InterlockedAnd16((short volatile*)(ptr), (short)(val))
|
||||
#endif
|
||||
#define atomic_fetch_and_32(ptr, val) _InterlockedAnd((long volatile*)(ptr), (long)(val))
|
||||
|
||||
#ifdef _M_IX86
|
||||
__int64 interlocked_fetch_and_64(__int64 volatile* ptr, __int64 val);
|
||||
#define atomic_fetch_and_64(ptr, val) interlocked_fetch_and_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#else
|
||||
#define atomic_fetch_and_64(ptr, val) _InterlockedAnd64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#endif
|
||||
|
||||
#ifdef _WIN64
|
||||
#define atomic_fetch_and_ptr atomic_fetch_and_64
|
||||
#else
|
||||
#define atomic_fetch_and_ptr atomic_fetch_and_32
|
||||
#endif
|
||||
#ifndef _TD_GO_DLL_
|
||||
char interlocked_or_fetch_8(char volatile* ptr, char val);
|
||||
short interlocked_or_fetch_16(short volatile* ptr, short val);
|
||||
#endif
|
||||
long interlocked_or_fetch_32(long volatile* ptr, long val);
|
||||
__int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val);
|
||||
|
||||
#ifndef _TD_GO_DLL_
|
||||
#define atomic_or_fetch_8(ptr, val) interlocked_or_fetch_8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_or_fetch_16(ptr, val) interlocked_or_fetch_16((short volatile*)(ptr), (short)(val))
|
||||
#endif
|
||||
#define atomic_or_fetch_32(ptr, val) interlocked_or_fetch_32((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_or_fetch_64(ptr, val) interlocked_or_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#ifdef _WIN64
|
||||
#define atomic_or_fetch_ptr atomic_or_fetch_64
|
||||
#else
|
||||
#define atomic_or_fetch_ptr atomic_or_fetch_32
|
||||
#endif
|
||||
#ifndef _TD_GO_DLL_
|
||||
#define atomic_fetch_or_8(ptr, val) _InterlockedOr8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_fetch_or_16(ptr, val) _InterlockedOr16((short volatile*)(ptr), (short)(val))
|
||||
#endif
|
||||
#define atomic_fetch_or_32(ptr, val) _InterlockedOr((long volatile*)(ptr), (long)(val))
|
||||
|
||||
#ifdef _M_IX86
|
||||
__int64 interlocked_fetch_or_64(__int64 volatile* ptr, __int64 val);
|
||||
#define atomic_fetch_or_64(ptr, val) interlocked_fetch_or_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#else
|
||||
#define atomic_fetch_or_64(ptr, val) _InterlockedOr64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#endif
|
||||
|
||||
#ifdef _WIN64
|
||||
#define atomic_fetch_or_ptr atomic_fetch_or_64
|
||||
#else
|
||||
#define atomic_fetch_or_ptr atomic_fetch_or_32
|
||||
#endif
|
||||
|
||||
#ifndef _TD_GO_DLL_
|
||||
char interlocked_xor_fetch_8(char volatile* ptr, char val);
|
||||
short interlocked_xor_fetch_16(short volatile* ptr, short val);
|
||||
#endif
|
||||
long interlocked_xor_fetch_32(long volatile* ptr, long val);
|
||||
__int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val);
|
||||
|
||||
#ifndef _TD_GO_DLL_
|
||||
#define atomic_xor_fetch_8(ptr, val) interlocked_xor_fetch_8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_xor_fetch_16(ptr, val) interlocked_xor_fetch_16((short volatile*)(ptr), (short)(val))
|
||||
#endif
|
||||
#define atomic_xor_fetch_32(ptr, val) interlocked_xor_fetch_32((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_xor_fetch_64(ptr, val) interlocked_xor_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#ifdef _WIN64
|
||||
#define atomic_xor_fetch_ptr atomic_xor_fetch_64
|
||||
#else
|
||||
#define atomic_xor_fetch_ptr atomic_xor_fetch_32
|
||||
#endif
|
||||
|
||||
#ifndef _TD_GO_DLL_
|
||||
#define atomic_fetch_xor_8(ptr, val) _InterlockedXor8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_fetch_xor_16(ptr, val) _InterlockedXor16((short volatile*)(ptr), (short)(val))
|
||||
#endif
|
||||
#define atomic_fetch_xor_32(ptr, val) _InterlockedXor((long volatile*)(ptr), (long)(val))
|
||||
|
||||
#ifdef _M_IX86
|
||||
__int64 interlocked_fetch_xor_64(__int64 volatile* ptr, __int64 val);
|
||||
#define atomic_fetch_xor_64(ptr, val) interlocked_fetch_xor_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#else
|
||||
#define atomic_fetch_xor_64(ptr, val) _InterlockedXor64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#endif
|
||||
|
||||
#ifdef _WIN64
|
||||
#define atomic_fetch_xor_ptr atomic_fetch_xor_64
|
||||
#else
|
||||
#define atomic_fetch_xor_ptr atomic_fetch_xor_32
|
||||
#endif
|
||||
|
||||
#define SWAP(a, b, c) \
|
||||
do { \
|
||||
c __tmp = (c)(a); \
|
||||
(a) = (c)(b); \
|
||||
(b) = __tmp; \
|
||||
} while (0)
|
||||
|
||||
#define MAX(a,b) (((a)>(b))?(a):(b))
|
||||
#define MIN(a,b) (((a)<(b))?(a):(b))
|
||||
|
||||
#ifdef _TD_GO_DLL_
|
||||
#define MILLISECOND_PER_SECOND (1000LL)
|
||||
#else
|
||||
#define MILLISECOND_PER_SECOND (1000i64)
|
||||
#endif
|
||||
|
||||
#define tsem_t sem_t
|
||||
#define tsem_init sem_init
|
||||
#define tsem_wait sem_wait
|
||||
#define tsem_post sem_post
|
||||
#define tsem_destroy sem_destroy
|
||||
|
||||
void osInit();
|
||||
|
||||
int getline(char **lineptr, size_t *n, FILE *stream);
|
||||
|
||||
int taosWinSetTimer(int ms, void(*callback)(int));
|
||||
|
||||
int gettimeofday(struct timeval *tv, struct timezone *tz);
|
||||
|
||||
struct tm *localtime_r(const time_t *timep, struct tm *result);
|
||||
|
||||
char *strptime(const char *buf, const char *fmt, struct tm *tm);
|
||||
|
||||
bool taosCheckPthreadValid(pthread_t thread);
|
||||
|
||||
void taosResetPthread(pthread_t *thread);
|
||||
|
||||
int64_t taosGetPthreadId();
|
||||
|
||||
int taosSetNonblocking(int sock, int on);
|
||||
|
||||
int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen);
|
||||
|
||||
|
||||
void taosPrintOsInfo();
|
||||
|
||||
void taosGetSystemInfo();
|
||||
|
||||
void taosKillSystem();
|
||||
|
||||
int32_t BUILDIN_CLZL(uint64_t val);
|
||||
int32_t BUILDIN_CLZ(uint32_t val);
|
||||
int32_t BUILDIN_CTZL(uint64_t val);
|
||||
int32_t BUILDIN_CTZ(uint32_t val);
|
||||
|
||||
//for signal, not dispose
|
||||
#define SIGALRM 1234
|
||||
typedef int sigset_t;
|
||||
|
||||
struct sigaction {
|
||||
void (*sa_handler)(int);
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int we_wordc;
|
||||
char **we_wordv;
|
||||
int we_offs;
|
||||
char wordPos[20];
|
||||
} wordexp_t;
|
||||
|
||||
int wordexp(const char *words, wordexp_t *pwordexp, int flags);
|
||||
|
||||
void wordfree(wordexp_t *pwordexp);
|
||||
|
||||
int flock(int fd, int option);
|
||||
|
||||
int fsync(int filedes);
|
||||
|
||||
char *getpass(const char *prefix);
|
||||
|
||||
char *strsep(char **stringp, const char *delim);
|
||||
|
||||
typedef int(*__compar_fn_t)(const void *, const void *);
|
||||
|
||||
int sigaction(int, struct sigaction *, void *);
|
||||
|
||||
void sleep(int mseconds);
|
||||
|
||||
bool taosSkipSocketCheck();
|
||||
|
||||
int fsendfile(FILE* out_file, FILE* in_file, int64_t* offset, int32_t count);
|
||||
|
||||
#define ssize_t int
|
||||
|
||||
#define strdup _strdup
|
||||
|
||||
char *strndup(const char *s, size_t n);
|
||||
|
||||
void taosSetCoreDump();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -16,7 +16,6 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tglobal.h"
|
||||
#include "tulog.h"
|
||||
|
||||
void osInit() {
|
||||
strcpy(configDir, "/etc/taos");
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||
AUX_SOURCE_DIRECTORY(. SRC)
|
||||
|
||||
ADD_LIBRARY(os ${SRC})
|
|
@ -16,15 +16,14 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tglobal.h"
|
||||
#include "tulog.h"
|
||||
|
||||
void osInit() {
|
||||
strcpy(configDir, "/etc/taos");
|
||||
strcpy(configDir, "~/TDengine/cfg");
|
||||
strcpy(tsVnodeDir, "");
|
||||
strcpy(tsDnodeDir, "");
|
||||
strcpy(tsMnodeDir, "");
|
||||
strcpy(tsDataDir, "/var/lib/taos");
|
||||
strcpy(tsLogDir, "~/TDengineLog");
|
||||
strcpy(tsScriptDir, "/etc/taos");
|
||||
strcpy(tsDataDir, "~/TDengine/data");
|
||||
strcpy(tsLogDir, "~/TDengine/log");
|
||||
strcpy(tsScriptDir, "~/TDengine/cfg");
|
||||
strcpy(tsOsName, "Darwin");
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tulog.h"
|
||||
|
||||
#define _SEND_FILE_STEP_ 1000
|
||||
|
||||
int taosFSendFileImp(FILE* out_file, FILE* in_file, int64_t* offset, int32_t count) {
|
||||
fseek(in_file, (int32_t)(*offset), 0);
|
||||
int writeLen = 0;
|
||||
uint8_t buffer[_SEND_FILE_STEP_] = { 0 };
|
||||
|
||||
for (int len = 0; len < (count - _SEND_FILE_STEP_); len += _SEND_FILE_STEP_) {
|
||||
size_t rlen = fread(buffer, 1, _SEND_FILE_STEP_, in_file);
|
||||
if (rlen <= 0) {
|
||||
return writeLen;
|
||||
}
|
||||
else if (rlen < _SEND_FILE_STEP_) {
|
||||
fwrite(buffer, 1, rlen, out_file);
|
||||
return (int)(writeLen + rlen);
|
||||
}
|
||||
else {
|
||||
fwrite(buffer, 1, _SEND_FILE_STEP_, in_file);
|
||||
writeLen += _SEND_FILE_STEP_;
|
||||
}
|
||||
}
|
||||
|
||||
int remain = count - writeLen;
|
||||
if (remain > 0) {
|
||||
size_t rlen = fread(buffer, 1, remain, in_file);
|
||||
if (rlen <= 0) {
|
||||
return writeLen;
|
||||
}
|
||||
else {
|
||||
fwrite(buffer, 1, remain, out_file);
|
||||
writeLen += remain;
|
||||
}
|
||||
}
|
||||
|
||||
return writeLen;
|
||||
}
|
||||
|
||||
ssize_t taosTSendFileImp(int dfd, int sfd, off_t *offset, size_t size) {
|
||||
uError("not implemented yet");
|
||||
return -1;
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
|
||||
int tsem_init(dispatch_semaphore_t *sem, int pshared, unsigned int value) {
|
||||
*sem = dispatch_semaphore_create(value);
|
||||
if (*sem == NULL) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int tsem_wait(dispatch_semaphore_t *sem) {
|
||||
dispatch_semaphore_wait(*sem, DISPATCH_TIME_FOREVER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tsem_post(dispatch_semaphore_t *sem) {
|
||||
dispatch_semaphore_signal(*sem);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tsem_destroy(dispatch_semaphore_t *sem) {
|
||||
return 0;
|
||||
}
|
|
@ -16,23 +16,14 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
|
||||
void getTmpfilePath(const char *fileNamePrefix, char *dstPath) {
|
||||
const char* tdengineTmpFileNamePrefix = "tdengine-";
|
||||
char tmpPath[PATH_MAX];
|
||||
int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen) {
|
||||
if (level == SOL_SOCKET && optname == SO_SNDBUF) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *tmpDir = getenv("tmp");
|
||||
if (tmpDir == NULL) {
|
||||
tmpDir = "";
|
||||
if (level == SOL_SOCKET && optname == SO_RCVBUF) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
strcpy(tmpPath, tmpDir);
|
||||
strcat(tmpPath, tdengineTmpFileNamePrefix);
|
||||
if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) {
|
||||
strcat(tmpPath, fileNamePrefix);
|
||||
strcat(tmpPath, "-%d-%s");
|
||||
}
|
||||
|
||||
char rand[8] = {0};
|
||||
taosRandStr(rand, tListLen(rand) - 1);
|
||||
snprintf(dstPath, PATH_MAX, tmpPath, getpid(), rand);
|
||||
|
||||
return setsockopt(socketfd, level, optname, optval, (socklen_t)optlen);
|
||||
}
|
|
@ -16,11 +16,7 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
|
||||
#ifndef TAOS_OS_FUNC_UTIL
|
||||
|
||||
int64_t tsosStr2int64(char *str) {
|
||||
char *endptr = NULL;
|
||||
return strtoll(str, &endptr, 10);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#include "tulog.h"
|
||||
|
||||
static void taosGetSystemTimezone() {
|
||||
// get and set default timezone
|
||||
SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone");
|
||||
if (cfg_timezone && cfg_timezone->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) {
|
||||
char *tz = getenv("TZ");
|
||||
if (tz == NULL || strlen(tz) == 0) {
|
||||
strcpy(tsTimezone, "not configured");
|
||||
}
|
||||
else {
|
||||
strcpy(tsTimezone, tz);
|
||||
}
|
||||
cfg_timezone->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT;
|
||||
uInfo("timezone not configured, use default");
|
||||
}
|
||||
}
|
||||
|
||||
static void taosGetSystemLocale() {
|
||||
// get and set default locale
|
||||
SGlobalCfg *cfg_locale = taosGetConfigOption("locale");
|
||||
if (cfg_locale && cfg_locale->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) {
|
||||
char *locale = setlocale(LC_CTYPE, "chs");
|
||||
if (locale != NULL) {
|
||||
strncpy(tsLocale, locale, TSDB_LOCALE_LEN - 1);
|
||||
cfg_locale->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT;
|
||||
uInfo("locale not configured, set to default:%s", tsLocale);
|
||||
}
|
||||
}
|
||||
|
||||
SGlobalCfg *cfg_charset = taosGetConfigOption("charset");
|
||||
if (cfg_charset && cfg_charset->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) {
|
||||
strcpy(tsCharset, "cp936");
|
||||
cfg_charset->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT;
|
||||
uInfo("charset not configured, set to default:%s", tsCharset);
|
||||
}
|
||||
}
|
||||
|
||||
void taosPrintOsInfo() {}
|
||||
|
||||
void taosKillSystem() {
|
||||
uError("function taosKillSystem, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void taosGetSystemInfo() {
|
||||
taosGetSystemTimezone();
|
||||
taosGetSystemLocale();
|
||||
}
|
||||
|
||||
bool taosGetDisk() { return true; }
|
||||
|
||||
bool taosGetProcIO(float *readKB, float *writeKB) {
|
||||
*readKB = 0;
|
||||
*writeKB = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool taosGetBandSpeed(float *bandSpeedKb) {
|
||||
*bandSpeedKb = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) {
|
||||
*sysCpuUsage = 0;
|
||||
*procCpuUsage = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool taosGetProcMemory(float *memoryUsedMB) {
|
||||
*memoryUsedMB = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool taosGetSysMemory(float *memoryUsedMB) {
|
||||
*memoryUsedMB = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
int taosSystem(const char *cmd) {
|
||||
uError("un support funtion");
|
||||
return -1;
|
||||
}
|
||||
|
||||
void taosSetCoreDump() {}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
|
||||
int taosInitTimer(void (*callback)(int), int ms) {
|
||||
signal(SIGALRM, callback);
|
||||
|
||||
struct itimerval tv;
|
||||
tv.it_interval.tv_sec = 0; /* my timer resolution */
|
||||
tv.it_interval.tv_usec = 1000 * ms; // resolution is in msecond
|
||||
tv.it_value = tv.it_interval;
|
||||
|
||||
setitimer(ITIMER_REAL, &tv, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void taosUninitTimer() {
|
||||
struct itimerval tv = { 0 };
|
||||
setitimer(ITIMER_REAL, &tv, NULL);
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF (TD_DARWIN_64)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||
INCLUDE_DIRECTORIES(inc)
|
||||
AUX_SOURCE_DIRECTORY(src SRC)
|
||||
ADD_LIBRARY(os ${SRC})
|
||||
ENDIF ()
|
||||
|
|
@ -1,370 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "os.h"
|
||||
#include "taosdef.h"
|
||||
#include "tglobal.h"
|
||||
#include "tconfig.h"
|
||||
#include "ttimer.h"
|
||||
#include "tulog.h"
|
||||
#include "tutil.h"
|
||||
|
||||
int64_t tsosStr2int64(char *str) {
|
||||
char *endptr = NULL;
|
||||
return strtoll(str, &endptr, 10);
|
||||
}
|
||||
|
||||
/*
|
||||
to make taosMsleep work,
|
||||
signal SIGALRM shall be blocked in the calling thread,
|
||||
|
||||
sigset_t set;
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, SIGALRM);
|
||||
pthread_sigmask(SIG_BLOCK, &set, NULL);
|
||||
*/
|
||||
void taosMsleep(int mseconds) {
|
||||
struct timeval timeout;
|
||||
int seconds, useconds;
|
||||
|
||||
seconds = mseconds / 1000;
|
||||
useconds = (mseconds % 1000) * 1000;
|
||||
timeout.tv_sec = seconds;
|
||||
timeout.tv_usec = useconds;
|
||||
|
||||
/* sigset_t set; */
|
||||
/* sigemptyset(&set); */
|
||||
/* sigaddset(&set, SIGALRM); */
|
||||
/* pthread_sigmask(SIG_BLOCK, &set, NULL); */
|
||||
|
||||
select(0, NULL, NULL, NULL, &timeout);
|
||||
|
||||
/* pthread_sigmask(SIG_UNBLOCK, &set, NULL); */
|
||||
}
|
||||
|
||||
bool taosCheckPthreadValid(pthread_t thread) { return thread != 0; }
|
||||
|
||||
void taosResetPthread(pthread_t *thread) { *thread = 0; }
|
||||
|
||||
int64_t taosGetPthreadId() { return (int64_t)pthread_self(); }
|
||||
|
||||
/*
|
||||
* Function to get the private ip address of current machine. If get IP
|
||||
* successfully, return 0, else, return -1. The return values is ip.
|
||||
*
|
||||
* Use:
|
||||
* if (taosGetPrivateIp(ip) != 0) {
|
||||
* perror("Fail to get private IP address\n");
|
||||
* exit(EXIT_FAILURE);
|
||||
* }
|
||||
*/
|
||||
int taosGetPrivateIp(char *const ip) {
|
||||
bool hasLoCard = false;
|
||||
|
||||
struct ifaddrs *ifaddr, *ifa;
|
||||
int family, s;
|
||||
char host[NI_MAXHOST];
|
||||
|
||||
if (getifaddrs(&ifaddr) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Walk through linked list, maintaining head pointer so we can free list later */
|
||||
int flag = 0;
|
||||
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
|
||||
if (ifa->ifa_addr == NULL) continue;
|
||||
|
||||
family = ifa->ifa_addr->sa_family;
|
||||
if (strcmp("lo", ifa->ifa_name) == 0) {
|
||||
hasLoCard = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (family == AF_INET) {
|
||||
/* printf("%-8s", ifa->ifa_name); */
|
||||
s = getnameinfo(ifa->ifa_addr, (family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6),
|
||||
host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
|
||||
if (s != 0) {
|
||||
freeifaddrs(ifaddr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
strcpy(ip, host);
|
||||
flag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
freeifaddrs(ifaddr);
|
||||
if (flag) {
|
||||
return 0;
|
||||
} else {
|
||||
if (hasLoCard) {
|
||||
uInfo("no net card was found, use lo:127.0.0.1 as default");
|
||||
strcpy(ip, "127.0.0.1");
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int taosSetNonblocking(int sock, int on) {
|
||||
int flags = 0;
|
||||
if ((flags = fcntl(sock, F_GETFL, 0)) < 0) {
|
||||
uError("fcntl(F_GETFL) error: %d (%s)\n", errno, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (on)
|
||||
flags |= O_NONBLOCK;
|
||||
else
|
||||
flags &= ~O_NONBLOCK;
|
||||
|
||||
if ((flags = fcntl(sock, F_SETFL, flags)) < 0) {
|
||||
uError("fcntl(F_SETFL) error: %d (%s)\n", errno, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen) {
|
||||
if (level == SOL_SOCKET && optname == SO_SNDBUF) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (level == SOL_SOCKET && optname == SO_RCVBUF) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return setsockopt(socketfd, level, optname, optval, (socklen_t)optlen);
|
||||
}
|
||||
|
||||
int taosInitTimer(void (*callback)(int), int ms) {
|
||||
signal(SIGALRM, callback);
|
||||
|
||||
struct itimerval tv;
|
||||
tv.it_interval.tv_sec = 0; /* my timer resolution */
|
||||
tv.it_interval.tv_usec = 1000 * ms; // resolution is in msecond
|
||||
tv.it_value = tv.it_interval;
|
||||
|
||||
setitimer(ITIMER_REAL, &tv, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void taosUninitTimer() {
|
||||
struct itimerval tv = { 0 };
|
||||
setitimer(ITIMER_REAL, &tv, NULL);
|
||||
}
|
||||
|
||||
void taosGetSystemTimezone() {
|
||||
// get and set default timezone
|
||||
SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone");
|
||||
if (cfg_timezone && cfg_timezone->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) {
|
||||
char *tz = getenv("TZ");
|
||||
if (tz == NULL || strlen(tz) == 0) {
|
||||
strcpy(tsTimezone, "not configured");
|
||||
}
|
||||
else {
|
||||
strcpy(tsTimezone, tz);
|
||||
}
|
||||
cfg_timezone->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT;
|
||||
uInfo("timezone not configured, use default");
|
||||
}
|
||||
}
|
||||
|
||||
void taosGetSystemLocale() {
|
||||
// get and set default locale
|
||||
SGlobalCfg *cfg_locale = taosGetConfigOption("locale");
|
||||
if (cfg_locale && cfg_locale->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) {
|
||||
char *locale = setlocale(LC_CTYPE, "chs");
|
||||
if (locale != NULL) {
|
||||
tstrncpy(tsLocale, locale, sizeof(tsLocale));
|
||||
cfg_locale->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT;
|
||||
uInfo("locale not configured, set to default:%s", tsLocale);
|
||||
}
|
||||
}
|
||||
|
||||
SGlobalCfg *cfg_charset = taosGetConfigOption("charset");
|
||||
if (cfg_charset && cfg_charset->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) {
|
||||
strcpy(tsCharset, "cp936");
|
||||
cfg_charset->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT;
|
||||
uInfo("charset not configured, set to default:%s", tsCharset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void taosPrintOsInfo() {}
|
||||
|
||||
void taosKillSystem() {
|
||||
uError("function taosKillSystem, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
bool taosGetDisk() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void taosGetSystemInfo() {
|
||||
taosGetSystemTimezone();
|
||||
taosGetSystemLocale();
|
||||
}
|
||||
|
||||
void *taosInitTcpClient(char *ip, uint16_t port, char *flabel, int num, void *fp, void *shandle) {
|
||||
uError("function taosInitTcpClient is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void taosCloseTcpClientConnection(void *chandle) {
|
||||
uError("function taosCloseTcpClientConnection is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void *taosOpenTcpClientConnection(void *shandle, void *thandle, char *ip, uint16_t port) {
|
||||
uError("function taosOpenTcpClientConnection is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int taosSendTcpClientData(unsigned int ip, uint16_t port, char *data, int len, void *chandle) {
|
||||
uError("function taosSendTcpClientData is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void taosCleanUpTcpClient(void *chandle) {
|
||||
uError("function taosCleanUpTcpClient is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void taosCloseTcpServerConnection(void *chandle) {
|
||||
uError("function taosCloseTcpServerConnection is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void taosCleanUpTcpServer(void *handle) {
|
||||
uError("function taosCleanUpTcpServer is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void *taosInitTcpServer(char *ip, uint16_t port, char *label, int numOfThreads, void *fp, void *shandle) {
|
||||
uError("function taosInitTcpServer is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int taosSendTcpServerData(unsigned int ip, uint16_t port, char *data, int len, void *chandle) {
|
||||
uError("function taosSendTcpServerData is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void taosFreeMsgHdr(void *hdr) {
|
||||
uError("function taosFreeMsgHdr is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int taosMsgHdrSize(void *hdr) {
|
||||
uError("function taosMsgHdrSize is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void taosSendMsgHdr(void *hdr, int fd) {
|
||||
uError("function taosSendMsgHdr is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void taosInitMsgHdr(void **hdr, void *dest, int maxPkts) {
|
||||
uError("function taosInitMsgHdr is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void taosSetMsgHdrData(void *hdr, char *data, int dataLen) {
|
||||
uError("function taosSetMsgHdrData is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
bool taosSkipSocketCheck() {
|
||||
return true;
|
||||
}
|
||||
|
||||
int tsem_init(dispatch_semaphore_t *sem, int pshared, unsigned int value) {
|
||||
*sem = dispatch_semaphore_create(value);
|
||||
if (*sem == NULL) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int tsem_wait(dispatch_semaphore_t *sem) {
|
||||
dispatch_semaphore_wait(*sem, DISPATCH_TIME_FOREVER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tsem_post(dispatch_semaphore_t *sem) {
|
||||
dispatch_semaphore_signal(*sem);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tsem_destroy(dispatch_semaphore_t *sem) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t __sync_val_load_32(int32_t *ptr) {
|
||||
return __atomic_load_n(ptr, __ATOMIC_ACQUIRE);
|
||||
}
|
||||
|
||||
void __sync_val_restore_32(int32_t *ptr, int32_t newval) {
|
||||
__atomic_store_n(ptr, newval, __ATOMIC_RELEASE);
|
||||
}
|
||||
|
||||
#define _SEND_FILE_STEP_ 1000
|
||||
|
||||
int fsendfile(FILE* out_file, FILE* in_file, int64_t* offset, int32_t count) {
|
||||
fseek(in_file, (int32_t)(*offset), 0);
|
||||
int writeLen = 0;
|
||||
uint8_t buffer[_SEND_FILE_STEP_] = { 0 };
|
||||
|
||||
for (int len = 0; len < (count - _SEND_FILE_STEP_); len += _SEND_FILE_STEP_) {
|
||||
size_t rlen = fread(buffer, 1, _SEND_FILE_STEP_, in_file);
|
||||
if (rlen <= 0) {
|
||||
return writeLen;
|
||||
}
|
||||
else if (rlen < _SEND_FILE_STEP_) {
|
||||
fwrite(buffer, 1, rlen, out_file);
|
||||
return (int)(writeLen + rlen);
|
||||
}
|
||||
else {
|
||||
fwrite(buffer, 1, _SEND_FILE_STEP_, in_file);
|
||||
writeLen += _SEND_FILE_STEP_;
|
||||
}
|
||||
}
|
||||
|
||||
int remain = count - writeLen;
|
||||
if (remain > 0) {
|
||||
size_t rlen = fread(buffer, 1, remain, in_file);
|
||||
if (rlen <= 0) {
|
||||
return writeLen;
|
||||
}
|
||||
else {
|
||||
fwrite(buffer, 1, remain, out_file);
|
||||
writeLen += remain;
|
||||
}
|
||||
}
|
||||
|
||||
return writeLen;
|
||||
}
|
||||
|
||||
void taosSetCoreDump() {}
|
|
@ -1,97 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#include "tulog.h"
|
||||
#include "tsystem.h"
|
||||
|
||||
#ifndef TAOS_OS_FUNC_CORE
|
||||
|
||||
int _sysctl(struct __sysctl_args *args );
|
||||
|
||||
void taosSetCoreDump() {
|
||||
if (0 == tsEnableCoreFile) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. set ulimit -c unlimited
|
||||
struct rlimit rlim;
|
||||
struct rlimit rlim_new;
|
||||
if (getrlimit(RLIMIT_CORE, &rlim) == 0) {
|
||||
uInfo("the old unlimited para: rlim_cur=%" PRIu64 ", rlim_max=%" PRIu64, rlim.rlim_cur, rlim.rlim_max);
|
||||
rlim_new.rlim_cur = RLIM_INFINITY;
|
||||
rlim_new.rlim_max = RLIM_INFINITY;
|
||||
if (setrlimit(RLIMIT_CORE, &rlim_new) != 0) {
|
||||
uInfo("set unlimited fail, error: %s", strerror(errno));
|
||||
rlim_new.rlim_cur = rlim.rlim_max;
|
||||
rlim_new.rlim_max = rlim.rlim_max;
|
||||
(void)setrlimit(RLIMIT_CORE, &rlim_new);
|
||||
}
|
||||
}
|
||||
|
||||
if (getrlimit(RLIMIT_CORE, &rlim) == 0) {
|
||||
uInfo("the new unlimited para: rlim_cur=%" PRIu64 ", rlim_max=%" PRIu64, rlim.rlim_cur, rlim.rlim_max);
|
||||
}
|
||||
|
||||
#ifndef _TD_ARM_
|
||||
// 2. set the path for saving core file
|
||||
struct __sysctl_args args;
|
||||
int old_usespid = 0;
|
||||
size_t old_len = 0;
|
||||
int new_usespid = 1;
|
||||
size_t new_len = sizeof(new_usespid);
|
||||
|
||||
int name[] = {CTL_KERN, KERN_CORE_USES_PID};
|
||||
|
||||
memset(&args, 0, sizeof(struct __sysctl_args));
|
||||
args.name = name;
|
||||
args.nlen = sizeof(name)/sizeof(name[0]);
|
||||
args.oldval = &old_usespid;
|
||||
args.oldlenp = &old_len;
|
||||
args.newval = &new_usespid;
|
||||
args.newlen = new_len;
|
||||
|
||||
old_len = sizeof(old_usespid);
|
||||
|
||||
if (syscall(SYS__sysctl, &args) == -1) {
|
||||
uInfo("_sysctl(kern_core_uses_pid) set fail: %s", strerror(errno));
|
||||
}
|
||||
|
||||
uInfo("The old core_uses_pid[%" PRIu64 "]: %d", old_len, old_usespid);
|
||||
|
||||
|
||||
old_usespid = 0;
|
||||
old_len = 0;
|
||||
memset(&args, 0, sizeof(struct __sysctl_args));
|
||||
args.name = name;
|
||||
args.nlen = sizeof(name)/sizeof(name[0]);
|
||||
args.oldval = &old_usespid;
|
||||
args.oldlenp = &old_len;
|
||||
|
||||
old_len = sizeof(old_usespid);
|
||||
|
||||
if (syscall(SYS__sysctl, &args) == -1) {
|
||||
uInfo("_sysctl(kern_core_uses_pid) get fail: %s", strerror(errno));
|
||||
}
|
||||
|
||||
uInfo("The new core_uses_pid[%" PRIu64 "]: %d", old_len, old_usespid);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -60,9 +60,8 @@ void taosMvDir(char* destDir, char *srcDir) {
|
|||
|
||||
//(void)snprintf(shellCmd, 1024, "cp -rf %s %s", srcDir, destDir);
|
||||
(void)snprintf(shellCmd, 1024, "mv %s %s", srcDir, destDir);
|
||||
tSystem(shellCmd);
|
||||
taosSystem(shellCmd);
|
||||
uInfo("shell cmd:%s is executed", shellCmd);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
|
@ -15,27 +15,26 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "ttime.h"
|
||||
|
||||
#ifndef TAOS_OS_FUNC_FILE
|
||||
#ifndef TAOS_OS_FUNC_FILE_GETTMPFILEPATH
|
||||
void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath) {
|
||||
const char *tdengineTmpFileNamePrefix = "tdengine-";
|
||||
|
||||
void getTmpfilePath(const char *fileNamePrefix, char *dstPath) {
|
||||
const char* tdengineTmpFileNamePrefix = "tdengine-";
|
||||
|
||||
char tmpPath[PATH_MAX];
|
||||
char tmpPath[PATH_MAX];
|
||||
char *tmpDir = "/tmp/";
|
||||
|
||||
|
||||
strcpy(tmpPath, tmpDir);
|
||||
strcat(tmpPath, tdengineTmpFileNamePrefix);
|
||||
if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) {
|
||||
strcat(tmpPath, fileNamePrefix);
|
||||
strcat(tmpPath, "-%d-%s");
|
||||
}
|
||||
|
||||
|
||||
char rand[8] = {0};
|
||||
taosRandStr(rand, tListLen(rand) - 1);
|
||||
snprintf(dstPath, PATH_MAX, tmpPath, getpid(), rand);
|
||||
}
|
||||
#endif
|
||||
|
||||
// rename file name
|
||||
int32_t taosFileRename(char *fullPath, char *suffix, char delimiter, char **dstPath) {
|
||||
|
@ -65,4 +64,74 @@ int32_t taosFileRename(char *fullPath, char *suffix, char delimiter, char **dstP
|
|||
return rename(fullPath, *dstPath);
|
||||
}
|
||||
|
||||
ssize_t taosTReadImp(int fd, void *buf, size_t count) {
|
||||
size_t leftbytes = count;
|
||||
ssize_t readbytes;
|
||||
char * tbuf = (char *)buf;
|
||||
|
||||
while (leftbytes > 0) {
|
||||
readbytes = read(fd, (void *)tbuf, leftbytes);
|
||||
if (readbytes < 0) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} else if (readbytes == 0) {
|
||||
return (ssize_t)(count - leftbytes);
|
||||
}
|
||||
|
||||
leftbytes -= readbytes;
|
||||
tbuf += readbytes;
|
||||
}
|
||||
|
||||
return (ssize_t)count;
|
||||
}
|
||||
|
||||
ssize_t taosTWriteImp(int fd, void *buf, size_t n) {
|
||||
size_t nleft = n;
|
||||
ssize_t nwritten = 0;
|
||||
char * tbuf = (char *)buf;
|
||||
|
||||
while (nleft > 0) {
|
||||
nwritten = write(fd, (void *)tbuf, nleft);
|
||||
if (nwritten < 0) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
nleft -= nwritten;
|
||||
tbuf += nwritten;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
#ifndef TAOS_OS_FUNC_FILE_SENDIFLE
|
||||
ssize_t taosTSendFileImp(int dfd, int sfd, off_t *offset, size_t size) {
|
||||
size_t leftbytes = size;
|
||||
ssize_t sentbytes;
|
||||
|
||||
while (leftbytes > 0) {
|
||||
/*
|
||||
* TODO : Think to check if file is larger than 1GB
|
||||
*/
|
||||
// if (leftbytes > 1000000000) leftbytes = 1000000000;
|
||||
sentbytes = sendfile(dfd, sfd, offset, leftbytes);
|
||||
if (sentbytes == -1) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} else if (sentbytes == 0) {
|
||||
return (ssize_t)(size - leftbytes);
|
||||
}
|
||||
|
||||
leftbytes -= sentbytes;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
#endif
|
|
@ -1,88 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
|
||||
ssize_t taosTReadImp(int fd, void *buf, size_t count) {
|
||||
size_t leftbytes = count;
|
||||
ssize_t readbytes;
|
||||
char * tbuf = (char *)buf;
|
||||
|
||||
while (leftbytes > 0) {
|
||||
readbytes = read(fd, (void *)tbuf, leftbytes);
|
||||
if (readbytes < 0) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} else if (readbytes == 0) {
|
||||
return (ssize_t)(count - leftbytes);
|
||||
}
|
||||
|
||||
leftbytes -= readbytes;
|
||||
tbuf += readbytes;
|
||||
}
|
||||
|
||||
return (ssize_t)count;
|
||||
}
|
||||
|
||||
ssize_t taosTSendFileImp(int dfd, int sfd, off_t *offset, size_t size) {
|
||||
size_t leftbytes = size;
|
||||
ssize_t sentbytes;
|
||||
|
||||
while (leftbytes > 0) {
|
||||
/*
|
||||
* TODO : Think to check if file is larger than 1GB
|
||||
*/
|
||||
//if (leftbytes > 1000000000) leftbytes = 1000000000;
|
||||
sentbytes = sendfile(dfd, sfd, offset, leftbytes);
|
||||
if (sentbytes == -1) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
} else if (sentbytes == 0) {
|
||||
return (ssize_t)(size - leftbytes);
|
||||
}
|
||||
|
||||
leftbytes -= sentbytes;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
ssize_t taosTWriteImp(int fd, void *buf, size_t n) {
|
||||
size_t nleft = n;
|
||||
ssize_t nwritten = 0;
|
||||
char *tbuf = (char *)buf;
|
||||
|
||||
while (nleft > 0) {
|
||||
nwritten = write(fd, (void *)tbuf, nleft);
|
||||
if (nwritten < 0) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
nleft -= nwritten;
|
||||
tbuf += nwritten;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
|
||||
#ifndef TAOS_OS_FUNC_MALLOC
|
||||
|
||||
void *tmalloc(size_t size) {
|
||||
if (size <= 0) return NULL;
|
||||
|
||||
void *ret = malloc(size + sizeof(size_t));
|
||||
if (ret == NULL) return NULL;
|
||||
|
||||
*(size_t *)ret = size;
|
||||
|
||||
return (void *)((char *)ret + sizeof(size_t));
|
||||
}
|
||||
|
||||
void *tcalloc(size_t nmemb, size_t size) {
|
||||
size_t tsize = nmemb * size;
|
||||
void * ret = tmalloc(tsize);
|
||||
if (ret == NULL) return NULL;
|
||||
|
||||
tmemset(ret, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t tsizeof(void *ptr) { return (ptr) ? (*(size_t *)((char *)ptr - sizeof(size_t))) : 0; }
|
||||
|
||||
void tmemset(void *ptr, int c) { memset(ptr, c, tsizeof(ptr)); }
|
||||
|
||||
void * trealloc(void *ptr, size_t size) {
|
||||
if (ptr == NULL) return tmalloc(size);
|
||||
|
||||
if (size <= tsizeof(ptr)) return ptr;
|
||||
|
||||
void * tptr = (void *)((char *)ptr - sizeof(size_t));
|
||||
size_t tsize = size + sizeof(size_t);
|
||||
tptr = realloc(tptr, tsize);
|
||||
if (tptr == NULL) return NULL;
|
||||
|
||||
*(size_t *)tptr = size;
|
||||
|
||||
return (void *)((char *)tptr + sizeof(size_t));
|
||||
}
|
||||
|
||||
void tzfree(void *ptr) {
|
||||
if (ptr) {
|
||||
free((void *)((char *)ptr - sizeof(size_t)));
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
#ifdef TAOS_MEM_CHECK
|
||||
|
||||
static int allocMode = TAOS_ALLOC_MODE_DEFAULT;
|
||||
static ETaosMemoryAllocMode allocMode = TAOS_ALLOC_MODE_DEFAULT;
|
||||
static FILE* fpAllocLog = NULL;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -62,7 +62,7 @@ static void* realloc_random(void* ptr, size_t size, const char* file, uint32_t l
|
|||
|
||||
static char* strdup_random(const char* str, const char* file, uint32_t line) {
|
||||
size_t len = strlen(str);
|
||||
return random_alloc_fail(len + 1, file, line) ? NULL : strdup(str);
|
||||
return random_alloc_fail(len + 1, file, line) ? NULL : taosStrdupImp(str);
|
||||
}
|
||||
|
||||
static char* strndup_random(const char* str, size_t size, const char* file, uint32_t line) {
|
||||
|
@ -70,11 +70,11 @@ static char* strndup_random(const char* str, size_t size, const char* file, uint
|
|||
if (len > size) {
|
||||
len = size;
|
||||
}
|
||||
return random_alloc_fail(len + 1, file, line) ? NULL : strndup(str, len);
|
||||
return random_alloc_fail(len + 1, file, line) ? NULL : taosStrndupImp(str, len);
|
||||
}
|
||||
|
||||
static ssize_t getline_random(char **lineptr, size_t *n, FILE *stream, const char* file, uint32_t line) {
|
||||
return random_alloc_fail(*n, file, line) ? -1 : getline(lineptr, n, stream);
|
||||
return random_alloc_fail(*n, file, line) ? -1 : taosGetlineImp(lineptr, n, stream);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -242,7 +242,7 @@ static char* strndup_detect_leak(const char* str, size_t size, const char* file,
|
|||
static ssize_t getline_detect_leak(char **lineptr, size_t *n, FILE *stream, const char* file, uint32_t line) {
|
||||
char* buf = NULL;
|
||||
size_t bufSize = 0;
|
||||
ssize_t size = getline(&buf, &bufSize, stream);
|
||||
ssize_t size = taosGetlineImp(&buf, &bufSize, stream);
|
||||
if (size != -1) {
|
||||
if (*n < size + 1) {
|
||||
void* p = realloc_detect_leak(*lineptr, size + 1, file, line);
|
||||
|
@ -372,7 +372,7 @@ void taos_free(void* ptr, const char* file, uint32_t line) {
|
|||
char* taos_strdup(const char* str, const char* file, uint32_t line) {
|
||||
switch (allocMode) {
|
||||
case TAOS_ALLOC_MODE_DEFAULT:
|
||||
return strdup(str);
|
||||
return taosStrdupImp(str);
|
||||
|
||||
case TAOS_ALLOC_MODE_RANDOM_FAIL:
|
||||
return strdup_random(str, file, line);
|
||||
|
@ -380,13 +380,13 @@ char* taos_strdup(const char* str, const char* file, uint32_t line) {
|
|||
case TAOS_ALLOC_MODE_DETECT_LEAK:
|
||||
return strdup_detect_leak(str, file, line);
|
||||
}
|
||||
return strdup(str);
|
||||
return taosStrdupImp(str);
|
||||
}
|
||||
|
||||
char* taos_strndup(const char* str, size_t size, const char* file, uint32_t line) {
|
||||
switch (allocMode) {
|
||||
case TAOS_ALLOC_MODE_DEFAULT:
|
||||
return strndup(str, size);
|
||||
return taosStrndupImp(str, size);
|
||||
|
||||
case TAOS_ALLOC_MODE_RANDOM_FAIL:
|
||||
return strndup_random(str, size, file, line);
|
||||
|
@ -394,13 +394,13 @@ char* taos_strndup(const char* str, size_t size, const char* file, uint32_t line
|
|||
case TAOS_ALLOC_MODE_DETECT_LEAK:
|
||||
return strndup_detect_leak(str, size, file, line);
|
||||
}
|
||||
return strndup(str, size);
|
||||
return taosStrndupImp(str, size);
|
||||
}
|
||||
|
||||
ssize_t taos_getline(char **lineptr, size_t *n, FILE *stream, const char* file, uint32_t line) {
|
||||
switch (allocMode) {
|
||||
case TAOS_ALLOC_MODE_DEFAULT:
|
||||
return getline(lineptr, n, stream);
|
||||
return taosGetlineImp(lineptr, n, stream);
|
||||
|
||||
case TAOS_ALLOC_MODE_RANDOM_FAIL:
|
||||
return getline_random(lineptr, n, stream, file, line);
|
||||
|
@ -408,7 +408,7 @@ ssize_t taos_getline(char **lineptr, size_t *n, FILE *stream, const char* file,
|
|||
case TAOS_ALLOC_MODE_DETECT_LEAK:
|
||||
return getline_detect_leak(lineptr, n, stream, file, line);
|
||||
}
|
||||
return getline(lineptr, n, stream);
|
||||
return taosGetlineImp(lineptr, n, stream);
|
||||
}
|
||||
|
||||
static void close_alloc_log() {
|
||||
|
@ -472,3 +472,48 @@ void taosDumpMemoryLeak() {
|
|||
}
|
||||
|
||||
#endif // TAOS_MEM_CHECK
|
||||
|
||||
void *taosTMalloc(size_t size) {
|
||||
if (size <= 0) return NULL;
|
||||
|
||||
void *ret = malloc(size + sizeof(size_t));
|
||||
if (ret == NULL) return NULL;
|
||||
|
||||
*(size_t *)ret = size;
|
||||
|
||||
return (void *)((char *)ret + sizeof(size_t));
|
||||
}
|
||||
|
||||
void *taosTCalloc(size_t nmemb, size_t size) {
|
||||
size_t tsize = nmemb * size;
|
||||
void * ret = taosTMalloc(tsize);
|
||||
if (ret == NULL) return NULL;
|
||||
|
||||
taosTMemset(ret, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t taosTSizeof(void *ptr) { return (ptr) ? (*(size_t *)((char *)ptr - sizeof(size_t))) : 0; }
|
||||
|
||||
void taosTMemset(void *ptr, int c) { memset(ptr, c, taosTSizeof(ptr)); }
|
||||
|
||||
void * taosTRealloc(void *ptr, size_t size) {
|
||||
if (ptr == NULL) return taosTMalloc(size);
|
||||
|
||||
if (size <= taosTSizeof(ptr)) return ptr;
|
||||
|
||||
void * tptr = (void *)((char *)ptr - sizeof(size_t));
|
||||
size_t tsize = size + sizeof(size_t);
|
||||
tptr = realloc(tptr, tsize);
|
||||
if (tptr == NULL) return NULL;
|
||||
|
||||
*(size_t *)tptr = size;
|
||||
|
||||
return (void *)((char *)tptr + sizeof(size_t));
|
||||
}
|
||||
|
||||
void taosTZfree(void *ptr) {
|
||||
if (ptr) {
|
||||
free((void *)((char *)ptr - sizeof(size_t)));
|
||||
}
|
||||
}
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
uint32_t taosRand(void) { return rand(); }
|
||||
|
||||
uint32_t trand(void) {
|
||||
uint32_t taosSafeRand(void) {
|
||||
int fd;
|
||||
int seed;
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
|
||||
#ifndef TAOS_OS_FUNC_PTHREAD
|
||||
#ifndef TAOS_OS_FUNC_SEMPHONE_PTHREAD
|
||||
|
||||
bool taosCheckPthreadValid(pthread_t thread) { return thread != 0; }
|
||||
int64_t taosGetPthreadId() { return (int64_t)pthread_self(); }
|
|
@ -39,10 +39,6 @@ int taosSetNonblocking(int sock, int on) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen) {
|
||||
return setsockopt(socketfd, level, optname, optval, (socklen_t)optlen);
|
||||
}
|
||||
|
||||
void taosBlockSIGPIPE() {
|
||||
sigset_t signal_mask;
|
||||
sigemptyset(&signal_mask);
|
||||
|
@ -53,4 +49,12 @@ void taosBlockSIGPIPE() {
|
|||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_SOCKET_SETSOCKETOPT
|
||||
|
||||
int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen) {
|
||||
return setsockopt(socketfd, level, optname, optval, (socklen_t)optlen);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -16,14 +16,18 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tglobal.h"
|
||||
#include "taosdef.h"
|
||||
|
||||
#ifndef TAOS_OS_FUNC_WCHAR
|
||||
#ifndef TAOS_OS_FUNC_STRING_STR2INT64
|
||||
int64_t tsosStr2int64(char *str) {
|
||||
char *endptr = NULL;
|
||||
return strtoll(str, &endptr, 10);
|
||||
}
|
||||
#endif
|
||||
|
||||
int tasoUcs4Compare(void* f1_ucs4, void *f2_ucs4, int bytes) {
|
||||
#ifndef TAOS_OS_FUNC_STRING_WCHAR
|
||||
int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes) {
|
||||
return wcsncmp((wchar_t *)f1_ucs4, (wchar_t *)f2_ucs4, bytes / TSDB_NCHAR_SIZE);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef USE_LIBICONV
|
||||
|
@ -120,4 +124,4 @@ char *taosCharsetReplace(char *charsetstr) {
|
|||
}
|
||||
|
||||
return strdup(charsetstr);
|
||||
}
|
||||
}
|
|
@ -18,8 +18,6 @@
|
|||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#include "tulog.h"
|
||||
#include "tsystem.h"
|
||||
#include "taosdef.h"
|
||||
|
||||
#ifndef TAOS_OS_FUNC_SYSINFO
|
||||
|
||||
|
@ -63,7 +61,7 @@ bool taosGetProcMemory(float *memoryUsedMB) {
|
|||
size_t len;
|
||||
char * line = NULL;
|
||||
while (!feof(fp)) {
|
||||
tfree(line);
|
||||
taosTFree(line);
|
||||
len = 0;
|
||||
getline(&line, &len, fp);
|
||||
if (line == NULL) {
|
||||
|
@ -85,7 +83,7 @@ bool taosGetProcMemory(float *memoryUsedMB) {
|
|||
sscanf(line, "%s %" PRId64, tmp, &memKB);
|
||||
*memoryUsedMB = (float)((double)memKB / 1024);
|
||||
|
||||
tfree(line);
|
||||
taosTFree(line);
|
||||
fclose(fp);
|
||||
return true;
|
||||
}
|
||||
|
@ -109,7 +107,7 @@ static bool taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
|
|||
char cpu[10] = {0};
|
||||
sscanf(line, "%s %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64, cpu, &cpuInfo->user, &cpuInfo->nice, &cpuInfo->system, &cpuInfo->idle);
|
||||
|
||||
tfree(line);
|
||||
taosTFree(line);
|
||||
fclose(fp);
|
||||
return true;
|
||||
}
|
||||
|
@ -138,7 +136,7 @@ static bool taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
tfree(line);
|
||||
taosTFree(line);
|
||||
fclose(fp);
|
||||
return true;
|
||||
}
|
||||
|
@ -378,7 +376,7 @@ static bool taosGetCardInfo(int64_t *bytes) {
|
|||
*bytes += (rbytes + tbytes);
|
||||
}
|
||||
|
||||
tfree(line);
|
||||
taosTFree(line);
|
||||
fclose(fp);
|
||||
|
||||
return true;
|
||||
|
@ -433,7 +431,7 @@ static bool taosReadProcIO(int64_t *readbyte, int64_t *writebyte) {
|
|||
int readIndex = 0;
|
||||
|
||||
while (!feof(fp)) {
|
||||
tfree(line);
|
||||
taosTFree(line);
|
||||
len = 0;
|
||||
getline(&line, &len, fp);
|
||||
if (line == NULL) {
|
||||
|
@ -451,7 +449,7 @@ static bool taosReadProcIO(int64_t *readbyte, int64_t *writebyte) {
|
|||
if (readIndex >= 2) break;
|
||||
}
|
||||
|
||||
tfree(line);
|
||||
taosTFree(line);
|
||||
fclose(fp);
|
||||
|
||||
if (readIndex < 2) {
|
||||
|
@ -543,12 +541,12 @@ void taosKillSystem() {
|
|||
kill(tsProcId, 2);
|
||||
}
|
||||
|
||||
int tSystem(const char *cmd) {
|
||||
int taosSystem(const char *cmd) {
|
||||
FILE *fp;
|
||||
int res;
|
||||
char buf[1024];
|
||||
if (cmd == NULL) {
|
||||
uError("tSystem cmd is NULL!\n");
|
||||
uError("taosSystem cmd is NULL!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -570,4 +568,75 @@ int tSystem(const char *cmd) {
|
|||
}
|
||||
}
|
||||
|
||||
int _sysctl(struct __sysctl_args *args );
|
||||
void taosSetCoreDump() {
|
||||
if (0 == tsEnableCoreFile) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. set ulimit -c unlimited
|
||||
struct rlimit rlim;
|
||||
struct rlimit rlim_new;
|
||||
if (getrlimit(RLIMIT_CORE, &rlim) == 0) {
|
||||
uInfo("the old unlimited para: rlim_cur=%" PRIu64 ", rlim_max=%" PRIu64, rlim.rlim_cur, rlim.rlim_max);
|
||||
rlim_new.rlim_cur = RLIM_INFINITY;
|
||||
rlim_new.rlim_max = RLIM_INFINITY;
|
||||
if (setrlimit(RLIMIT_CORE, &rlim_new) != 0) {
|
||||
uInfo("set unlimited fail, error: %s", strerror(errno));
|
||||
rlim_new.rlim_cur = rlim.rlim_max;
|
||||
rlim_new.rlim_max = rlim.rlim_max;
|
||||
(void)setrlimit(RLIMIT_CORE, &rlim_new);
|
||||
}
|
||||
}
|
||||
|
||||
if (getrlimit(RLIMIT_CORE, &rlim) == 0) {
|
||||
uInfo("the new unlimited para: rlim_cur=%" PRIu64 ", rlim_max=%" PRIu64, rlim.rlim_cur, rlim.rlim_max);
|
||||
}
|
||||
|
||||
#ifndef _TD_ARM_
|
||||
// 2. set the path for saving core file
|
||||
struct __sysctl_args args;
|
||||
int old_usespid = 0;
|
||||
size_t old_len = 0;
|
||||
int new_usespid = 1;
|
||||
size_t new_len = sizeof(new_usespid);
|
||||
|
||||
int name[] = {CTL_KERN, KERN_CORE_USES_PID};
|
||||
|
||||
memset(&args, 0, sizeof(struct __sysctl_args));
|
||||
args.name = name;
|
||||
args.nlen = sizeof(name)/sizeof(name[0]);
|
||||
args.oldval = &old_usespid;
|
||||
args.oldlenp = &old_len;
|
||||
args.newval = &new_usespid;
|
||||
args.newlen = new_len;
|
||||
|
||||
old_len = sizeof(old_usespid);
|
||||
|
||||
if (syscall(SYS__sysctl, &args) == -1) {
|
||||
uInfo("_sysctl(kern_core_uses_pid) set fail: %s", strerror(errno));
|
||||
}
|
||||
|
||||
uInfo("The old core_uses_pid[%" PRIu64 "]: %d", old_len, old_usespid);
|
||||
|
||||
|
||||
old_usespid = 0;
|
||||
old_len = 0;
|
||||
memset(&args, 0, sizeof(struct __sysctl_args));
|
||||
args.name = name;
|
||||
args.nlen = sizeof(name)/sizeof(name[0]);
|
||||
args.oldval = &old_usespid;
|
||||
args.oldlenp = &old_len;
|
||||
|
||||
old_len = sizeof(old_usespid);
|
||||
|
||||
if (syscall(SYS__sysctl, &args) == -1) {
|
||||
uInfo("_sysctl(kern_core_uses_pid) get fail: %s", strerror(errno));
|
||||
}
|
||||
|
||||
uInfo("The new core_uses_pid[%" PRIu64 "]: %d", old_len, old_usespid);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -17,13 +17,10 @@
|
|||
#define _XOPEN_SOURCE
|
||||
#define _DEFAULT_SOURCE
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "os.h"
|
||||
#include "taosdef.h"
|
||||
#include "ttime.h"
|
||||
#include "tutil.h"
|
||||
|
||||
/*
|
||||
* mktime64 - Converts date to seconds.
|
||||
* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
|
|
@ -15,42 +15,11 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "taosdef.h"
|
||||
#include "tglobal.h"
|
||||
#include "ttimer.h"
|
||||
#include "tulog.h"
|
||||
|
||||
#ifndef TAOS_OS_FUNC_TIMER
|
||||
|
||||
/*
|
||||
to make taosMsleep work,
|
||||
signal SIGALRM shall be blocked in the calling thread,
|
||||
|
||||
sigset_t set;
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, SIGALRM);
|
||||
pthread_sigmask(SIG_BLOCK, &set, NULL);
|
||||
*/
|
||||
void taosMsleep(int mseconds) {
|
||||
struct timeval timeout;
|
||||
int seconds, useconds;
|
||||
|
||||
seconds = mseconds / 1000;
|
||||
useconds = (mseconds % 1000) * 1000;
|
||||
timeout.tv_sec = seconds;
|
||||
timeout.tv_usec = useconds;
|
||||
|
||||
/* sigset_t set; */
|
||||
/* sigemptyset(&set); */
|
||||
/* sigaddset(&set, SIGALRM); */
|
||||
/* pthread_sigmask(SIG_BLOCK, &set, NULL); */
|
||||
|
||||
select(0, NULL, NULL, NULL, &timeout);
|
||||
|
||||
/* pthread_sigmask(SIG_UNBLOCK, &set, NULL); */
|
||||
}
|
||||
|
||||
|
||||
static void taosDeleteTimer(void *tharg) {
|
||||
timer_t *pTimer = tharg;
|
||||
timer_delete(*pTimer);
|
||||
|
@ -129,4 +98,35 @@ void taosUninitTimer() {
|
|||
pthread_join(timerThread, NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_TIMER_SLEEP
|
||||
/*
|
||||
to make taosMsleep work,
|
||||
signal SIGALRM shall be blocked in the calling thread,
|
||||
|
||||
sigset_t set;
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, SIGALRM);
|
||||
pthread_sigmask(SIG_BLOCK, &set, NULL);
|
||||
*/
|
||||
void taosMsleep(int mseconds) {
|
||||
struct timeval timeout;
|
||||
int seconds, useconds;
|
||||
|
||||
seconds = mseconds / 1000;
|
||||
useconds = (mseconds % 1000) * 1000;
|
||||
timeout.tv_sec = seconds;
|
||||
timeout.tv_usec = useconds;
|
||||
|
||||
/* sigset_t set; */
|
||||
/* sigemptyset(&set); */
|
||||
/* sigaddset(&set, SIGALRM); */
|
||||
/* pthread_sigmask(SIG_BLOCK, &set, NULL); */
|
||||
|
||||
select(0, NULL, NULL, NULL, &timeout);
|
||||
|
||||
/* pthread_sigmask(SIG_UNBLOCK, &set, NULL); */
|
||||
}
|
||||
|
||||
#endif
|
|
@ -9,4 +9,3 @@ AUX_SOURCE_DIRECTORY(. SRC)
|
|||
|
||||
ADD_LIBRARY(os ${SRC})
|
||||
TARGET_LINK_LIBRARIES(os m rt)
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tglobal.h"
|
||||
#include "tulog.h"
|
||||
|
||||
void osInit() {
|
||||
strcpy(configDir, "/etc/taos");
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/pthread)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/iconv)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/regex)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||
AUX_SOURCE_DIRECTORY(. SRC)
|
||||
|
||||
ADD_LIBRARY(os ${SRC})
|
||||
|
||||
TARGET_LINK_LIBRARIES(os winmm IPHLPAPI ws2_32)
|
|
@ -0,0 +1,172 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "taosdef.h"
|
||||
#include "tglobal.h"
|
||||
#include "ttimer.h"
|
||||
#include "tulog.h"
|
||||
#include "tutil.h"
|
||||
|
||||
// add
|
||||
char interlocked_add_fetch_8(char volatile* ptr, char val) {
|
||||
#ifdef _TD_GO_DLL_
|
||||
return __sync_fetch_and_add(ptr, val) + val;
|
||||
#else
|
||||
return _InterlockedExchangeAdd8(ptr, val) + val;
|
||||
#endif
|
||||
}
|
||||
|
||||
short interlocked_add_fetch_16(short volatile* ptr, short val) {
|
||||
#ifdef _TD_GO_DLL_
|
||||
return __sync_fetch_and_add(ptr, val) + val;
|
||||
#else
|
||||
return _InterlockedExchangeAdd16(ptr, val) + val;
|
||||
#endif
|
||||
}
|
||||
|
||||
long interlocked_add_fetch_32(long volatile* ptr, long val) {
|
||||
return _InterlockedExchangeAdd(ptr, val) + val;
|
||||
}
|
||||
|
||||
__int64 interlocked_add_fetch_64(__int64 volatile* ptr, __int64 val) {
|
||||
return _InterlockedExchangeAdd64(ptr, val) + val;
|
||||
}
|
||||
|
||||
// and
|
||||
#ifndef _TD_GO_DLL_
|
||||
char interlocked_and_fetch_8(char volatile* ptr, char val) {
|
||||
return _InterlockedAnd8(ptr, val) & val;
|
||||
}
|
||||
|
||||
short interlocked_and_fetch_16(short volatile* ptr, short val) {
|
||||
return _InterlockedAnd16(ptr, val) & val;
|
||||
}
|
||||
#endif
|
||||
|
||||
long interlocked_and_fetch_32(long volatile* ptr, long val) {
|
||||
return _InterlockedAnd(ptr, val) & val;
|
||||
}
|
||||
|
||||
#ifndef _M_IX86
|
||||
|
||||
__int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val) {
|
||||
return _InterlockedAnd64(ptr, val) & val;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
__int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val) {
|
||||
__int64 old, res;
|
||||
do {
|
||||
old = *ptr;
|
||||
res = old & val;
|
||||
} while(_InterlockedCompareExchange64(ptr, res, old) != old);
|
||||
return res;
|
||||
}
|
||||
|
||||
__int64 interlocked_fetch_and_64(__int64 volatile* ptr, __int64 val) {
|
||||
__int64 old;
|
||||
do {
|
||||
old = *ptr;
|
||||
} while(_InterlockedCompareExchange64(ptr, old & val, old) != old);
|
||||
return old;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// or
|
||||
#ifndef _TD_GO_DLL_
|
||||
char interlocked_or_fetch_8(char volatile* ptr, char val) {
|
||||
return _InterlockedOr8(ptr, val) | val;
|
||||
}
|
||||
|
||||
short interlocked_or_fetch_16(short volatile* ptr, short val) {
|
||||
return _InterlockedOr16(ptr, val) | val;
|
||||
}
|
||||
#endif
|
||||
long interlocked_or_fetch_32(long volatile* ptr, long val) {
|
||||
return _InterlockedOr(ptr, val) | val;
|
||||
}
|
||||
|
||||
#ifndef _M_IX86
|
||||
|
||||
__int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val) {
|
||||
return _InterlockedOr64(ptr, val) & val;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
__int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val) {
|
||||
__int64 old, res;
|
||||
do {
|
||||
old = *ptr;
|
||||
res = old | val;
|
||||
} while(_InterlockedCompareExchange64(ptr, res, old) != old);
|
||||
return res;
|
||||
}
|
||||
|
||||
__int64 interlocked_fetch_or_64(__int64 volatile* ptr, __int64 val) {
|
||||
__int64 old;
|
||||
do {
|
||||
old = *ptr;
|
||||
} while(_InterlockedCompareExchange64(ptr, old | val, old) != old);
|
||||
return old;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// xor
|
||||
#ifndef _TD_GO_DLL_
|
||||
char interlocked_xor_fetch_8(char volatile* ptr, char val) {
|
||||
return _InterlockedXor8(ptr, val) ^ val;
|
||||
}
|
||||
|
||||
short interlocked_xor_fetch_16(short volatile* ptr, short val) {
|
||||
return _InterlockedXor16(ptr, val) ^ val;
|
||||
}
|
||||
#endif
|
||||
long interlocked_xor_fetch_32(long volatile* ptr, long val) {
|
||||
return _InterlockedXor(ptr, val) ^ val;
|
||||
}
|
||||
|
||||
#ifndef _M_IX86
|
||||
|
||||
__int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val) {
|
||||
return _InterlockedXor64(ptr, val) ^ val;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
__int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val) {
|
||||
__int64 old, res;
|
||||
do {
|
||||
old = *ptr;
|
||||
res = old ^ val;
|
||||
} while(_InterlockedCompareExchange64(ptr, res, old) != old);
|
||||
return res;
|
||||
}
|
||||
|
||||
__int64 interlocked_fetch_xor_64(__int64 volatile* ptr, __int64 val) {
|
||||
__int64 old;
|
||||
do {
|
||||
old = *ptr;
|
||||
} while(_InterlockedCompareExchange64(ptr, old ^ val, old) != old);
|
||||
return old;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
|
||||
void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath) {
|
||||
const char* tdengineTmpFileNamePrefix = "tdengine-";
|
||||
char tmpPath[PATH_MAX];
|
||||
|
||||
char *tmpDir = getenv("tmp");
|
||||
if (tmpDir == NULL) {
|
||||
tmpDir = "";
|
||||
}
|
||||
|
||||
strcpy(tmpPath, tmpDir);
|
||||
strcat(tmpPath, tdengineTmpFileNamePrefix);
|
||||
if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) {
|
||||
strcat(tmpPath, fileNamePrefix);
|
||||
strcat(tmpPath, "-%d-%s");
|
||||
}
|
||||
|
||||
char rand[8] = {0};
|
||||
taosRandStr(rand, tListLen(rand) - 1);
|
||||
snprintf(dstPath, PATH_MAX, tmpPath, getpid(), rand);
|
||||
}
|
||||
|
||||
#define _SEND_FILE_STEP_ 1000
|
||||
|
||||
int taosFSendFileImp(FILE* out_file, FILE* in_file, int64_t* offset, int32_t count) {
|
||||
fseek(in_file, (int32_t)(*offset), 0);
|
||||
int writeLen = 0;
|
||||
uint8_t buffer[_SEND_FILE_STEP_] = { 0 };
|
||||
|
||||
for (int len = 0; len < (count - _SEND_FILE_STEP_); len += _SEND_FILE_STEP_) {
|
||||
size_t rlen = fread(buffer, 1, _SEND_FILE_STEP_, in_file);
|
||||
if (rlen <= 0) {
|
||||
return writeLen;
|
||||
}
|
||||
else if (rlen < _SEND_FILE_STEP_) {
|
||||
fwrite(buffer, 1, rlen, out_file);
|
||||
return (int)(writeLen + rlen);
|
||||
}
|
||||
else {
|
||||
fwrite(buffer, 1, _SEND_FILE_STEP_, in_file);
|
||||
writeLen += _SEND_FILE_STEP_;
|
||||
}
|
||||
}
|
||||
|
||||
int remain = count - writeLen;
|
||||
if (remain > 0) {
|
||||
size_t rlen = fread(buffer, 1, remain, in_file);
|
||||
if (rlen <= 0) {
|
||||
return writeLen;
|
||||
}
|
||||
else {
|
||||
fwrite(buffer, 1, remain, out_file);
|
||||
writeLen += remain;
|
||||
}
|
||||
}
|
||||
|
||||
return writeLen;
|
||||
}
|
||||
|
||||
ssize_t taosTSendFileImp(int dfd, int sfd, off_t *offset, size_t size) {
|
||||
uError("taosTSendFileImp no implemented yet");
|
||||
return 0;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue