Declare object pools with a single macro
55405e9d1255ae331fbec03af6a195950253c718
1 parent
51f18c51
swm.c
+21 -94
| 820 | 820 | } |
|
| 821 | 821 | fprintf(stderr, "swm: %s pool exhausted (limit %zu)\n", pool->name, pool->capacity); |
|
| 822 | 822 | return nullptr; |
|
| 823 | 823 | } |
|
| 824 | 824 | ||
| 825 | + | /* Define a fixed-capacity pool along with the storage it hands out. */ |
|
| 826 | + | #define POOL(name, type, capacity) \ |
|
| 827 | + | static type name##_items[capacity]; \ |
|
| 828 | + | static bool name##_used[capacity]; \ |
|
| 829 | + | static pool_t name##_pool = { name##_items, name##_used, (capacity), sizeof(type), #name } |
|
| 830 | + | ||
| 825 | 831 | static void pool_release(pool_t *pool, void *item) { |
|
| 826 | 832 | size_t index = ((char *)item - (char *)pool->items) / pool->item_size; |
|
| 827 | 833 | ||
| 828 | 834 | pool->used[index] = false; |
|
| 829 | 835 | memset(item, 0, pool->item_size); |
|
| 830 | 836 | } |
|
| 831 | 837 | ||
| 832 | - | static client_t client_items[MAX_CLIENTS]; |
|
| 833 | - | static monitor_t monitor_items[MAX_MONITORS]; |
|
| 834 | - | static layer_surface_t layer_surface_items[MAX_LAYER_SURFACES]; |
|
| 835 | - | static keyboard_group_t keyboard_group_items[MAX_KEYBOARD_GROUPS]; |
|
| 836 | - | static pointer_constraint_t pointer_constraint_items[MAX_POINTER_CONSTRAINTS]; |
|
| 837 | - | static text_input_t text_input_items[MAX_TEXT_INPUTS]; |
|
| 838 | - | static input_popup_t input_popup_items[MAX_INPUT_POPUPS]; |
|
| 839 | - | static popup_t popup_items[MAX_POPUPS]; |
|
| 840 | - | static session_lock_t session_lock_items[MAX_SESSION_LOCKS]; |
|
| 841 | - | static pending_spawn_t pending_spawn_items[MAX_PENDING_SPAWNS]; |
|
| 842 | - | static window_state_t window_state_items[MAX_WINDOW_STATES]; |
|
| 843 | - | static static_listener_t static_listener_items[MAX_STATIC_LISTENERS]; |
|
| 844 | - | static workspace_manager_t workspace_manager_items[MAX_WS_MANAGERS]; |
|
| 845 | - | static workspace_handle_t workspace_handle_items[MAX_WS_HANDLES]; |
|
| 846 | - | static metadata_manager_t metadata_manager_items[MAX_WS_MANAGERS]; |
|
| 847 | - | ||
| 848 | - | static bool client_used[MAX_CLIENTS], monitor_used[MAX_MONITORS]; |
|
| 849 | - | static bool layer_surface_used[MAX_LAYER_SURFACES], keyboard_group_used[MAX_KEYBOARD_GROUPS]; |
|
| 850 | - | static bool pointer_constraint_used[MAX_POINTER_CONSTRAINTS], text_input_used[MAX_TEXT_INPUTS]; |
|
| 851 | - | static bool input_popup_used[MAX_INPUT_POPUPS], session_lock_used[MAX_SESSION_LOCKS]; |
|
| 852 | - | static bool popup_used[MAX_POPUPS]; |
|
| 853 | - | static bool pending_spawn_used[MAX_PENDING_SPAWNS], window_state_used[MAX_WINDOW_STATES]; |
|
| 854 | - | static bool static_listener_used[MAX_STATIC_LISTENERS], workspace_manager_used[MAX_WS_MANAGERS]; |
|
| 855 | - | static bool workspace_handle_used[MAX_WS_HANDLES], metadata_manager_used[MAX_WS_MANAGERS]; |
|
| 856 | - | ||
| 857 | - | static pool_t client_pool = { |
|
| 858 | - | client_items, client_used, LENGTH(client_items), sizeof *client_items, "client" |
|
| 859 | - | }; |
|
| 860 | - | static pool_t monitor_pool = { |
|
| 861 | - | monitor_items, monitor_used, LENGTH(monitor_items), sizeof *monitor_items, "monitor" |
|
| 862 | - | }; |
|
| 863 | - | static pool_t layer_surface_pool = { layer_surface_items, |
|
| 864 | - | layer_surface_used, |
|
| 865 | - | LENGTH(layer_surface_items), |
|
| 866 | - | sizeof *layer_surface_items, |
|
| 867 | - | "layer_surface" }; |
|
| 868 | - | static pool_t keyboard_group_pool = { keyboard_group_items, |
|
| 869 | - | keyboard_group_used, |
|
| 870 | - | LENGTH(keyboard_group_items), |
|
| 871 | - | sizeof *keyboard_group_items, |
|
| 872 | - | "keyboard_group" }; |
|
| 873 | - | static pool_t pointer_constraint_pool = { pointer_constraint_items, |
|
| 874 | - | pointer_constraint_used, |
|
| 875 | - | LENGTH(pointer_constraint_items), |
|
| 876 | - | sizeof *pointer_constraint_items, |
|
| 877 | - | "pointer_constraint" }; |
|
| 878 | - | static pool_t text_input_pool = { text_input_items, |
|
| 879 | - | text_input_used, |
|
| 880 | - | LENGTH(text_input_items), |
|
| 881 | - | sizeof *text_input_items, |
|
| 882 | - | "text_input" }; |
|
| 883 | - | static pool_t input_popup_pool = { input_popup_items, |
|
| 884 | - | input_popup_used, |
|
| 885 | - | LENGTH(input_popup_items), |
|
| 886 | - | sizeof *input_popup_items, |
|
| 887 | - | "input_popup" }; |
|
| 888 | - | static pool_t session_lock_pool = { session_lock_items, |
|
| 889 | - | session_lock_used, |
|
| 890 | - | LENGTH(session_lock_items), |
|
| 891 | - | sizeof *session_lock_items, |
|
| 892 | - | "session_lock" }; |
|
| 893 | - | static pool_t pending_spawn_pool = { pending_spawn_items, |
|
| 894 | - | pending_spawn_used, |
|
| 895 | - | LENGTH(pending_spawn_items), |
|
| 896 | - | sizeof *pending_spawn_items, |
|
| 897 | - | "pending_spawn" }; |
|
| 898 | - | static pool_t window_state_pool = { window_state_items, |
|
| 899 | - | window_state_used, |
|
| 900 | - | LENGTH(window_state_items), |
|
| 901 | - | sizeof *window_state_items, |
|
| 902 | - | "window_state" }; |
|
| 903 | - | static pool_t static_listener_pool = { static_listener_items, |
|
| 904 | - | static_listener_used, |
|
| 905 | - | LENGTH(static_listener_items), |
|
| 906 | - | sizeof *static_listener_items, |
|
| 907 | - | "static_listener" }; |
|
| 908 | - | static pool_t workspace_manager_pool = { workspace_manager_items, |
|
| 909 | - | workspace_manager_used, |
|
| 910 | - | LENGTH(workspace_manager_items), |
|
| 911 | - | sizeof *workspace_manager_items, |
|
| 912 | - | "workspace_manager" }; |
|
| 913 | - | static pool_t workspace_handle_pool = { workspace_handle_items, |
|
| 914 | - | workspace_handle_used, |
|
| 915 | - | LENGTH(workspace_handle_items), |
|
| 916 | - | sizeof *workspace_handle_items, |
|
| 917 | - | "workspace_handle" }; |
|
| 918 | - | static pool_t metadata_manager_pool = { metadata_manager_items, |
|
| 919 | - | metadata_manager_used, |
|
| 920 | - | LENGTH(metadata_manager_items), |
|
| 921 | - | sizeof *metadata_manager_items, |
|
| 922 | - | "metadata_manager" }; |
|
| 923 | - | static pool_t popup_pool = { |
|
| 924 | - | popup_items, popup_used, LENGTH(popup_items), sizeof *popup_items, "popup" |
|
| 925 | - | }; |
|
| 838 | + | POOL(client, client_t, MAX_CLIENTS); |
|
| 839 | + | POOL(monitor, monitor_t, MAX_MONITORS); |
|
| 840 | + | POOL(layer_surface, layer_surface_t, MAX_LAYER_SURFACES); |
|
| 841 | + | POOL(keyboard_group, keyboard_group_t, MAX_KEYBOARD_GROUPS); |
|
| 842 | + | POOL(pointer_constraint, pointer_constraint_t, MAX_POINTER_CONSTRAINTS); |
|
| 843 | + | POOL(text_input, text_input_t, MAX_TEXT_INPUTS); |
|
| 844 | + | POOL(input_popup, input_popup_t, MAX_INPUT_POPUPS); |
|
| 845 | + | POOL(popup, popup_t, MAX_POPUPS); |
|
| 846 | + | POOL(session_lock, session_lock_t, MAX_SESSION_LOCKS); |
|
| 847 | + | POOL(pending_spawn, pending_spawn_t, MAX_PENDING_SPAWNS); |
|
| 848 | + | POOL(window_state, window_state_t, MAX_WINDOW_STATES); |
|
| 849 | + | POOL(static_listener, static_listener_t, MAX_STATIC_LISTENERS); |
|
| 850 | + | POOL(workspace_manager, workspace_manager_t, MAX_WS_MANAGERS); |
|
| 851 | + | POOL(workspace_handle, workspace_handle_t, MAX_WS_HANDLES); |
|
| 852 | + | POOL(metadata_manager, metadata_manager_t, MAX_WS_MANAGERS); |
|
| 926 | 853 | ||
| 927 | 854 | /* Backend-specific client operations. */ |
|
| 928 | 855 | /* Client helpers shared by the XDG shell and Xwayland implementations. These |
|
| 929 | 856 | * are inline so unused helpers are omitted for builds that disable a backend. */ |
|
| 930 | 857 |