OSDN Git Service

8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef list
[pg-rex/syncrep.git] / src / include / storage / fsm_internals.h
1 /*-------------------------------------------------------------------------
2  *
3  * fsm_internal.h
4  *        internal functions for free space map
5  *
6  *
7  * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $PostgreSQL: pgsql/src/include/storage/fsm_internals.h,v 1.3 2009/06/11 14:49:12 momjian Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef FSM_INTERNALS_H
15 #define FSM_INTERNALS_H
16
17 #include "storage/buf.h"
18 #include "storage/bufpage.h"
19 #include "lib/stringinfo.h"
20
21 /*
22  * Structure of a FSM page. See src/backend/storage/freespace/README for
23  * details.
24  */
25 typedef struct
26 {
27         /*
28          * fsm_search_avail() tries to spread the load of multiple backends by
29          * returning different pages to different backends in a round-robin
30          * fashion. fp_next_slot points to the next slot to be returned (assuming
31          * there's enough space on it for the request). It's defined as an int,
32          * because it's updated without an exclusive lock. uint16 would be more
33          * appropriate, but int is more likely to be atomically
34          * fetchable/storable.
35          */
36         int                     fp_next_slot;
37
38         /*
39          * fp_nodes contains the binary tree, stored in array. The first
40          * NonLeafNodesPerPage elements are upper nodes, and the following
41          * LeafNodesPerPage elements are leaf nodes. Unused nodes are zero.
42          */
43         uint8           fp_nodes[1];
44 } FSMPageData;
45
46 typedef FSMPageData *FSMPage;
47
48 /*
49  * Number of non-leaf and leaf nodes, and nodes in total, on an FSM page.
50  * These definitions are internal to fsmpage.c.
51  */
52 #define NodesPerPage (BLCKSZ - MAXALIGN(SizeOfPageHeaderData) - \
53                                           offsetof(FSMPageData, fp_nodes))
54
55 #define NonLeafNodesPerPage (BLCKSZ / 2 - 1)
56 #define LeafNodesPerPage (NodesPerPage - NonLeafNodesPerPage)
57
58 /*
59  * Number of FSM "slots" on a FSM page. This is what should be used
60  * outside fsmpage.c.
61  */
62 #define SlotsPerFSMPage LeafNodesPerPage
63
64 /* Prototypes for functions in fsmpage.c */
65 extern int fsm_search_avail(Buffer buf, uint8 min_cat, bool advancenext,
66                                  bool exclusive_lock_held);
67 extern uint8 fsm_get_avail(Page page, int slot);
68 extern uint8 fsm_get_max_avail(Page page);
69 extern bool fsm_set_avail(Page page, int slot, uint8 value);
70 extern bool fsm_truncate_avail(Page page, int nslots);
71 extern bool fsm_rebuild_page(Page page);
72
73 #endif   /* FSM_INTERNALS_H */