more
This commit is contained in:
parent
194ffc9438
commit
e4535ab88a
|
@ -1,12 +1,14 @@
|
||||||
#if !defined(_TD_CACHE_H_)
|
#if !defined(_TD_CACHE_H_)
|
||||||
#define _TD_CACHE_H_
|
#define _TD_CACHE_H_
|
||||||
|
|
||||||
|
#define TD_MIN_CACHE_BLOCK_SIZE 1024*1024 /* 1M */
|
||||||
|
#define TD_MAX_CACHE_BLOCK_SIZE 64*1024*1024 /* 64M */
|
||||||
|
|
||||||
typedef void cache_pool_t;
|
typedef void cache_pool_t;
|
||||||
|
|
||||||
typedef struct SCacheBlock
|
typedef struct SCacheBlock
|
||||||
{
|
{
|
||||||
SCacheBlock *next;
|
int32_t blockId;
|
||||||
SCacheBlock *prev;
|
|
||||||
char data[];
|
char data[];
|
||||||
} SCacheBlock;
|
} SCacheBlock;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
// A doubly linked list
|
||||||
|
#if !defined(_TD_DLIST_H_)
|
||||||
|
#define _TD_DLIST_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
SListNode *prev;
|
||||||
|
SListNode *next;
|
||||||
|
void * data;
|
||||||
|
} SListNode;
|
||||||
|
|
||||||
|
// Doubly linked list
|
||||||
|
typedef struct {
|
||||||
|
SListNode *head;
|
||||||
|
SListNode *tail;
|
||||||
|
int32_t length;
|
||||||
|
} SDList;
|
||||||
|
|
||||||
|
// ----- Set operation
|
||||||
|
#define TD_GET_DLIST_LENGTH(pDList) (((SDList *)pDList)->length)
|
||||||
|
#define TD_GET_DLIST_HEAD(pDList) (((SDList *)pDList)->head)
|
||||||
|
#define TD_GET_DLIST_TAIL(pDList) (((SDList *)pDList)->tail)
|
||||||
|
|
||||||
|
#define TD_GET_DLIST_NEXT_NODE(pDNode) (((SListNode *)pDNode)->next)
|
||||||
|
#define TD_GET_DLIST_PREV_NODE(pDNode) (((SListNode *)pDNode)->prev)
|
||||||
|
#define TD_GET_DLIST_NODE_DATA(pDNode) (((SListNode *)pDNode)->data)
|
||||||
|
|
||||||
|
#endif // _TD_DLIST_H_
|
|
@ -4,11 +4,19 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
|
#include "dlist.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int64_t blockId;
|
||||||
|
SCacheBlock *pBlock
|
||||||
|
} STSDBCacheBlock;
|
||||||
|
|
||||||
|
// Use a doublely linked list to implement this
|
||||||
typedef struct STSDBCache {
|
typedef struct STSDBCache {
|
||||||
int64_t blockId; // A block ID counter
|
int64_t blockId; // A block ID counter
|
||||||
SCacheBlock *blockList;
|
SDList *cacheList;
|
||||||
} STSDBCache;
|
} STSDBCache;
|
||||||
|
|
||||||
|
STSDBCache *tsdbCreateCache();
|
||||||
|
|
||||||
#endif // _TD_TSDBCACHE_H_
|
#endif // _TD_TSDBCACHE_H_
|
||||||
|
|
Loading…
Reference in New Issue