node_set.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright [2021] JD.com, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef __DTC_NODE_SET_H
  17. #define __DTC_NODE_SET_H
  18. #include <stdint.h>
  19. #include "namespace.h"
  20. #include "global.h"
  21. #include "nodegroup/ng_list.h"
  22. DTC_BEGIN_NAMESPACE
  23. enum attr_type {
  24. NEXT_NODE = 0,
  25. TIME_LIST = 1,
  26. VD_HANDLE = 2,
  27. DIRTY_BMP = 3,
  28. };
  29. typedef enum attr_type ATTR_TYPE_T;
  30. //nodeset释放掉的node链表
  31. struct ng_delete {
  32. uint16_t top;
  33. uint16_t count;
  34. };
  35. typedef struct ng_delete NG_DELE_T;
  36. //nodeset属性
  37. struct ng_attr {
  38. uint32_t count;
  39. uint32_t offset[0];
  40. };
  41. typedef struct ng_attr NG_ATTR_T;
  42. class Node;
  43. struct node_set {
  44. public:
  45. NG_LIST_T ng_list;
  46. NG_DELE_T ng_dele;
  47. uint16_t ng_free;
  48. uint8_t ng_rsv[2]; //保留空间
  49. NODE_ID_T ng_nid;
  50. NG_ATTR_T ng_attr;
  51. private:
  52. Node allocate_node(void); // 分配一个Node
  53. int release_node(Node); // 释放一个Node
  54. bool is_full(void); // NodeGroup是否已经分配完
  55. int do_init(NODE_ID_T id); // NodeGroup初始化
  56. int system_reserved_init(); // 系统保留的NG初始化
  57. // this routine return:
  58. // 0, passed, empty lru present
  59. // 1, passed, empty lru created
  60. // <0, integrity error
  61. int system_reserved_check(); // 系统保留的NG一致性检查
  62. static uint32_t Size(void); // 返回nodegroup的总大小
  63. private:
  64. //属性操作接口,供CNode访问
  65. NODE_ID_T node_id(int idx) const;
  66. NODE_ID_T &next_node_id(int idx); // attr1] -> 下一个Node的NodeID
  67. NODE_ID_T *node_lru(int idx); // attr[2] -> LRU链表
  68. MEM_HANDLE_T &vd_handle(int idx); // attr[3] -> 数据handle
  69. bool is_dirty(int idx); // attr[4] -> 脏位图
  70. void set_dirty(int idx);
  71. void clr_dirty(int idx);
  72. //返回每种属性块的起始地址
  73. template <class T> T *__CAST__(ATTR_TYPE_T t)
  74. {
  75. return (T *)((char *)this + ng_attr.offset[t]);
  76. }
  77. private:
  78. static uint32_t attr_count(void); // 支持的属性个数
  79. static uint32_t attr_size(void); // 所有属性的内存大小
  80. static uint32_t base_header_size(void); // 除开属性外,Nodegroup的大小
  81. static const uint32_t NG_ATTR_SIZE[];
  82. friend class Node;
  83. friend class NGInfo;
  84. };
  85. typedef struct node_set NODE_SET;
  86. DTC_END_NAMESPACE
  87. #endif