vnodeMemAllocator.h 1.8 KB
Newer Older
H
refact  
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
Hongze Cheng 已提交
19
#include "os.h"
H
refact  
Hongze Cheng 已提交
20

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

H
Hongze Cheng 已提交
25 26 27 28 29 30 31 32 33 34 35
typedef struct SVnodeMemAllocator SVnodeMemAllocator;

SVnodeMemAllocator *VMACreate(size_t size /* base size */, size_t ssize /* step size */,
                              size_t threshold /* threshold size when full*/);
void                VMADestroy(SVnodeMemAllocator *pvma);
void                VMAReset(SVnodeMemAllocator *pvma);
void *              VMAMalloc(SVnodeMemAllocator *pvma, size_t size);
void                VMAFree(SVnodeMemAllocator *pvma, void *ptr);
bool                VMAIsFull(SVnodeMemAllocator *pvma);

// ------------------ FOR TEST ONLY ------------------
H
refact  
Hongze Cheng 已提交
36
typedef struct SVMANode {
H
Hongze Cheng 已提交
37 38 39 40
  struct SVMANode *prev;
  size_t           tsize;
  size_t           used;
  char             data[];
H
refact  
Hongze Cheng 已提交
41
} SVMANode;
H
Hongze Cheng 已提交
42 43 44 45 46 47 48 49 50

struct SVnodeMemAllocator {
  bool      full;       // if allocator is full
  size_t    threshold;  // threshold;
  size_t    ssize;      // step size to allocate
  SVMANode *inuse;      // inuse node to allocate
  SVMANode  node;       // basic node to use
};

H
refact  
Hongze Cheng 已提交
51 52 53 54 55
#ifdef __cplusplus
}
#endif

#endif /*_TD_VNODE_MEM_ALLOCATOR_H_*/