vnodeMemAllocator.h 1.5 KB
Newer Older
H
more  
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * 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_VNODE_MEM_ALLOCATOR_H_
#define _TD_VNODE_MEM_ALLOCATOR_H_

H
more  
Hongze Cheng 已提交
19
#include "os.h"
H
refact  
Hongze Cheng 已提交
20

H
more  
Hongze Cheng 已提交
21 22 23 24
#ifdef __cplusplus
extern "C" {
#endif

H
refact  
Hongze Cheng 已提交
25
typedef struct SVArenaNode {
H
more  
Hongze Cheng 已提交
26
  TD_SLIST_NODE(SVArenaNode);
H
more  
Hongze Cheng 已提交
27
  uint64_t size;  // current node size
H
more  
Hongze Cheng 已提交
28 29
  void *   ptr;
  char     data[];
H
refact  
Hongze Cheng 已提交
30
} SVArenaNode;
H
more  
Hongze Cheng 已提交
31

H
refact  
Hongze Cheng 已提交
32
typedef struct SVMemAllocator {
H
more  
Hongze Cheng 已提交
33
  T_REF_DECLARE()
H
more  
Hongze Cheng 已提交
34
  TD_DLIST_NODE(SVMemAllocator);
H
more  
Hongze Cheng 已提交
35 36 37 38 39
  uint64_t     capacity;
  uint64_t     ssize;
  uint64_t     lsize;
  SVArenaNode *pNode;
  TD_SLIST(SVArenaNode) nlist;
H
refact  
Hongze Cheng 已提交
40
} SVMemAllocator;
H
more  
Hongze Cheng 已提交
41 42 43 44 45 46

SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize);
void            vmaDestroy(SVMemAllocator *pVMA);
void            vmaReset(SVMemAllocator *pVMA);
void *          vmaMalloc(SVMemAllocator *pVMA, uint64_t size);
void            vmaFree(SVMemAllocator *pVMA, void *ptr);
H
more  
Hongze Cheng 已提交
47
bool            vmaIsFull(SVMemAllocator *pVMA);
H
refact  
Hongze Cheng 已提交
48

H
more  
Hongze Cheng 已提交
49 50 51 52 53
#ifdef __cplusplus
}
#endif

#endif /*_TD_VNODE_MEM_ALLOCATOR_H_*/