提交 9c188c53 编写于 作者: H Hongze Cheng

refact

上级 18719691
...@@ -22,27 +22,28 @@ ...@@ -22,27 +22,28 @@
extern "C" { extern "C" {
#endif #endif
#define AMALLOC_APIS \
void *(*malloc)(void *, size_t size); \
void *(*calloc)(void *, size_t nmemb, size_t size); \
void *(*realloc)(void *, size_t size); \
void (*free)(void *ptr);
// Interfaces to implement // Interfaces to implement
typedef struct { typedef struct {
void *(*malloc)(void *, size_t size); AMALLOC_APIS
void *(*calloc)(void *, size_t nmemb, size_t size);
void (*free)(void *ptr, size_t size); // Do we need to set size in the allocated memory?
void *(*realloc)(void *ptr, size_t size);
} SMemAllocatorIf; } SMemAllocatorIf;
typedef struct { typedef struct {
void * impl; void *impl;
SMemAllocatorIf interface; AMALLOC_APIS
} SMemAllocator; } SMemAllocator;
#define amalloc(allocator, size) \ #define amalloc(allocator, size) ((allocator) ? (*((allocator)->malloc))((allocator)->impl, (size)) : malloc(size))
((allocator) ? (*((allocator)->interface.malloc))((allocator)->impl, (size)) : malloc(size))
#define acalloc(allocator, nmemb, size) \ #define acalloc(allocator, nmemb, size) \
((allocator) ? (*((allocator)->interface.calloc))((allocator)->impl, (nmemb), (size)) : calloc((nmemb), (size))) ((allocator) ? (*((allocator)->calloc))((allocator)->impl, (nmemb), (size)) : calloc((nmemb), (size)))
#define arealloc(allocator, ptr, size) \ #define arealloc(allocator, ptr, size) \
((allocator) ? (*((allocator)->interface.realloc))((allocator)->impl, (ptr), (size)) : realloc((ptr), (size))) ((allocator) ? (*((allocator)->realloc))((allocator)->impl, (ptr), (size)) : realloc((ptr), (size)))
#define afree(allocator, ptr, size) \ #define afree(allocator, ptr, size) ((allocator) ? (*((allocator)->free))((allocator)->impl, (ptr), (size)) : free(ptr))
((allocator) ? (*((allocator)->interface.free))((allocator)->impl, (ptr), (size)) : free(ptr))
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "tdef.h" #include "tdef.h"
#include "thash.h" #include "thash.h"
#include "amalloc.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -25,12 +26,16 @@ extern "C" { ...@@ -25,12 +26,16 @@ extern "C" {
typedef struct STsdbMemTable STsdbMemTable; typedef struct STsdbMemTable STsdbMemTable;
STsdbMemTable *tsdbMemTableCreate(SMemAllocator *);
void tsdbMemTableDestroy(STsdbMemTable *);
int tsdbMemTableWriteBatch(STsdbMemTable *pTsdbMemTable, void *batch);
/* --------------------- For compile and test only --------------------- */ /* --------------------- For compile and test only --------------------- */
struct STsdbMemTable { struct STsdbMemTable {
TSKEY minKey; TSKEY minKey;
TSKEY maxKey; TSKEY maxKey;
SHashObj *tData; // uid --> SSkipList SHashObj * tData; // uid --> SSkipList
void * mallocator; SMemAllocator *ma;
T_REF_DECLARE() T_REF_DECLARE()
}; };
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_TSDB_WRITE_BATCH_H_
#define _TD_TSDB_WRITE_BATCH_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef struct STsdbWriteBatch STsdbWriteBatch;
/* ------------------------- ------------------------- */
struct STsdbWriteBatch {
// TODO
};
#ifdef __cplusplus
}
#endif
#endif /*_TD_TSDB_WRITE_BATCH_H_*/
\ No newline at end of file
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "tsdbMemTable.h" #include "tsdbMemTable.h"
STsdbMemTable *tsdbMemTableCreate(void *mallocator) { STsdbMemTable *tsdbMemTableCreate(SMemAllocator *ma) {
STsdbMemTable *pTsdbMemTable = NULL; STsdbMemTable *pTsdbMemTable = NULL;
pTsdbMemTable = (STsdbMemTable *)malloc(sizeof(*pTsdbMemTable)); pTsdbMemTable = (STsdbMemTable *)malloc(sizeof(*pTsdbMemTable));
...@@ -24,6 +24,13 @@ STsdbMemTable *tsdbMemTableCreate(void *mallocator) { ...@@ -24,6 +24,13 @@ STsdbMemTable *tsdbMemTableCreate(void *mallocator) {
} }
// TODO // TODO
pTsdbMemTable->minKey = TSKEY_INITIAL_VAL;
pTsdbMemTable->maxKey = TSKEY_INITIAL_VAL;
pTsdbMemTable->ma = ma;
pTsdbMemTable->tData = taosHashInit(1024, taosIntHash_64, true /* TODO */, HASH_NO_LOCK);
if (pTsdbMemTable->tData == NULL) {
// TODO
}
return pTsdbMemTable; return pTsdbMemTable;
} }
...@@ -33,4 +40,10 @@ void tsdbMemTableDestroy(STsdbMemTable *pTsdbMemTable) { ...@@ -33,4 +40,10 @@ void tsdbMemTableDestroy(STsdbMemTable *pTsdbMemTable) {
// TODO // TODO
free(pTsdbMemTable); free(pTsdbMemTable);
} }
}
int tsdbMemTableWriteBatch(STsdbMemTable *pTsdbMemTable, void *batch) {
// TODO
return 0;
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册