TDengine/source/dnode/vnode/impl/inc/vnodeMemAllocator.h

54 lines
1.5 KiB
C
Raw Normal View History

2021-11-08 07:10:42 +00:00
/*
* 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_
2021-12-13 08:31:39 +00:00
#include "os.h"
2021-11-10 13:25:55 +00:00
2021-11-08 07:10:42 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2021-12-22 05:43:32 +00:00
typedef struct SVArenaNode {
2021-12-13 14:21:28 +00:00
TD_SLIST_NODE(SVArenaNode);
2021-12-13 09:57:14 +00:00
uint64_t size; // current node size
2021-12-13 08:31:39 +00:00
void * ptr;
char data[];
2021-12-22 05:43:32 +00:00
} SVArenaNode;
2021-12-13 08:31:39 +00:00
2021-12-22 05:43:32 +00:00
typedef struct SVMemAllocator {
2021-12-14 08:14:08 +00:00
T_REF_DECLARE()
2021-12-13 13:06:33 +00:00
TD_DLIST_NODE(SVMemAllocator);
2021-12-13 14:21:28 +00:00
uint64_t capacity;
uint64_t ssize;
uint64_t lsize;
SVArenaNode *pNode;
TD_SLIST(SVArenaNode) nlist;
2021-12-22 05:43:32 +00:00
} SVMemAllocator;
2021-12-13 08:31:39 +00:00
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);
2021-12-13 09:57:14 +00:00
bool vmaIsFull(SVMemAllocator *pVMA);
2021-11-10 13:25:55 +00:00
2021-11-08 07:10:42 +00:00
#ifdef __cplusplus
}
#endif
#endif /*_TD_VNODE_MEM_ALLOCATOR_H_*/