| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #ifndef PROCLIST_H |
| #define PROCLIST_H |
|
|
| #include "storage/proc.h" |
| #include "storage/proclist_types.h" |
|
|
| |
| |
| |
| static inline void |
| proclist_init(proclist_head *list) |
| { |
| list->head = list->tail = INVALID_PGPROCNO; |
| } |
|
|
| |
| |
| |
| static inline bool |
| proclist_is_empty(const proclist_head *list) |
| { |
| return list->head == INVALID_PGPROCNO; |
| } |
|
|
| |
| |
| |
| |
| static inline proclist_node * |
| proclist_node_get(int procno, size_t node_offset) |
| { |
| char *entry = (char *) GetPGProcByNumber(procno); |
|
|
| return (proclist_node *) (entry + node_offset); |
| } |
|
|
| |
| |
| |
| static inline void |
| proclist_push_head_offset(proclist_head *list, int procno, size_t node_offset) |
| { |
| proclist_node *node = proclist_node_get(procno, node_offset); |
|
|
| Assert(node->next == 0 && node->prev == 0); |
|
|
| if (list->head == INVALID_PGPROCNO) |
| { |
| Assert(list->tail == INVALID_PGPROCNO); |
| node->next = node->prev = INVALID_PGPROCNO; |
| list->head = list->tail = procno; |
| } |
| else |
| { |
| Assert(list->tail != INVALID_PGPROCNO); |
| Assert(list->head != procno); |
| Assert(list->tail != procno); |
| node->next = list->head; |
| proclist_node_get(node->next, node_offset)->prev = procno; |
| node->prev = INVALID_PGPROCNO; |
| list->head = procno; |
| } |
| } |
|
|
| |
| |
| |
| static inline void |
| proclist_push_tail_offset(proclist_head *list, int procno, size_t node_offset) |
| { |
| proclist_node *node = proclist_node_get(procno, node_offset); |
|
|
| Assert(node->next == 0 && node->prev == 0); |
|
|
| if (list->tail == INVALID_PGPROCNO) |
| { |
| Assert(list->head == INVALID_PGPROCNO); |
| node->next = node->prev = INVALID_PGPROCNO; |
| list->head = list->tail = procno; |
| } |
| else |
| { |
| Assert(list->head != INVALID_PGPROCNO); |
| Assert(list->head != procno); |
| Assert(list->tail != procno); |
| node->prev = list->tail; |
| proclist_node_get(node->prev, node_offset)->next = procno; |
| node->next = INVALID_PGPROCNO; |
| list->tail = procno; |
| } |
| } |
|
|
| |
| |
| |
| static inline void |
| proclist_delete_offset(proclist_head *list, int procno, size_t node_offset) |
| { |
| proclist_node *node = proclist_node_get(procno, node_offset); |
|
|
| Assert(node->next != 0 || node->prev != 0); |
|
|
| if (node->prev == INVALID_PGPROCNO) |
| { |
| Assert(list->head == procno); |
| list->head = node->next; |
| } |
| else |
| proclist_node_get(node->prev, node_offset)->next = node->next; |
|
|
| if (node->next == INVALID_PGPROCNO) |
| { |
| Assert(list->tail == procno); |
| list->tail = node->prev; |
| } |
| else |
| proclist_node_get(node->next, node_offset)->prev = node->prev; |
|
|
| node->next = node->prev = 0; |
| } |
|
|
| |
| |
| |
| |
| |
| static inline bool |
| proclist_contains_offset(const proclist_head *list, int procno, |
| size_t node_offset) |
| { |
| const proclist_node *node = proclist_node_get(procno, node_offset); |
|
|
| |
| if (node->prev == 0 && node->next == 0) |
| return false; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| Assert(node->prev != INVALID_PGPROCNO || list->head == procno); |
| Assert(node->next != INVALID_PGPROCNO || list->tail == procno); |
|
|
| return true; |
| } |
|
|
| |
| |
| |
| static inline PGPROC * |
| proclist_pop_head_node_offset(proclist_head *list, size_t node_offset) |
| { |
| PGPROC *proc; |
|
|
| Assert(!proclist_is_empty(list)); |
| proc = GetPGProcByNumber(list->head); |
| proclist_delete_offset(list, list->head, node_offset); |
| return proc; |
| } |
|
|
| |
| |
| |
| |
| #define proclist_delete(list, procno, link_member) \ |
| proclist_delete_offset((list), (procno), offsetof(PGPROC, link_member)) |
| #define proclist_push_head(list, procno, link_member) \ |
| proclist_push_head_offset((list), (procno), offsetof(PGPROC, link_member)) |
| #define proclist_push_tail(list, procno, link_member) \ |
| proclist_push_tail_offset((list), (procno), offsetof(PGPROC, link_member)) |
| #define proclist_pop_head_node(list, link_member) \ |
| proclist_pop_head_node_offset((list), offsetof(PGPROC, link_member)) |
| #define proclist_contains(list, procno, link_member) \ |
| proclist_contains_offset((list), (procno), offsetof(PGPROC, link_member)) |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| #define proclist_foreach_modify(iter, lhead, link_member) \ |
| for (AssertVariableIsOfTypeMacro(iter, proclist_mutable_iter), \ |
| AssertVariableIsOfTypeMacro(lhead, proclist_head *), \ |
| (iter).cur = (lhead)->head, \ |
| (iter).next = (iter).cur == INVALID_PGPROCNO ? INVALID_PGPROCNO : \ |
| proclist_node_get((iter).cur, \ |
| offsetof(PGPROC, link_member))->next; \ |
| (iter).cur != INVALID_PGPROCNO; \ |
| (iter).cur = (iter).next, \ |
| (iter).next = (iter).cur == INVALID_PGPROCNO ? INVALID_PGPROCNO : \ |
| proclist_node_get((iter).cur, \ |
| offsetof(PGPROC, link_member))->next) |
|
|
| #endif |
|
|