refact
This commit is contained in:
parent
1871969132
commit
9c188c53ff
|
@ -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 @@
|
||||||
|
|
||||||
#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" {
|
||||||
|
|
||||||
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()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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 _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_*/
|
|
@ -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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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) {
|
||||||
// TODO
|
// TODO
|
||||||
free(pTsdbMemTable);
|
free(pTsdbMemTable);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int tsdbMemTableWriteBatch(STsdbMemTable *pTsdbMemTable, void *batch) {
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue