Matheus Tavares | 04155bd | 2021-04-18 21:14:53 -0300 | [diff] [blame] | 1 | #ifndef PARALLEL_CHECKOUT_H |
| 2 | #define PARALLEL_CHECKOUT_H |
| 3 | |
Matheus Tavares | e9e8adf | 2021-04-18 21:14:54 -0300 | [diff] [blame] | 4 | #include "convert.h" |
| 5 | |
Matheus Tavares | 04155bd | 2021-04-18 21:14:53 -0300 | [diff] [blame] | 6 | struct cache_entry; |
| 7 | struct checkout; |
Matheus Tavares | 1c4d6f4 | 2021-04-18 21:14:56 -0300 | [diff] [blame] | 8 | struct progress; |
Matheus Tavares | e9e8adf | 2021-04-18 21:14:54 -0300 | [diff] [blame] | 9 | |
| 10 | /**************************************************************** |
| 11 | * Users of parallel checkout |
| 12 | ****************************************************************/ |
Matheus Tavares | 04155bd | 2021-04-18 21:14:53 -0300 | [diff] [blame] | 13 | |
| 14 | enum pc_status { |
| 15 | PC_UNINITIALIZED = 0, |
| 16 | PC_ACCEPTING_ENTRIES, |
| 17 | PC_RUNNING, |
| 18 | }; |
| 19 | |
| 20 | enum pc_status parallel_checkout_status(void); |
Matheus Tavares | 7531e4b | 2021-04-18 21:14:55 -0300 | [diff] [blame] | 21 | void get_parallel_checkout_configs(int *num_workers, int *threshold); |
Matheus Tavares | 04155bd | 2021-04-18 21:14:53 -0300 | [diff] [blame] | 22 | |
| 23 | /* |
| 24 | * Put parallel checkout into the PC_ACCEPTING_ENTRIES state. Should be used |
| 25 | * only when in the PC_UNINITIALIZED state. |
| 26 | */ |
| 27 | void init_parallel_checkout(void); |
| 28 | |
| 29 | /* |
| 30 | * Return -1 if parallel checkout is currently not accepting entries or if the |
| 31 | * entry is not eligible for parallel checkout. Otherwise, enqueue the entry |
| 32 | * for later write and return 0. |
| 33 | */ |
Matheus Tavares | 611c778 | 2022-07-14 08:49:12 -0300 | [diff] [blame] | 34 | int enqueue_checkout(struct cache_entry *ce, struct conv_attrs *ca, |
| 35 | int *checkout_counter); |
Matheus Tavares | 1c4d6f4 | 2021-04-18 21:14:56 -0300 | [diff] [blame] | 36 | size_t pc_queue_size(void); |
Matheus Tavares | 04155bd | 2021-04-18 21:14:53 -0300 | [diff] [blame] | 37 | |
Matheus Tavares | 7531e4b | 2021-04-18 21:14:55 -0300 | [diff] [blame] | 38 | /* |
| 39 | * Write all the queued entries, returning 0 on success. If the number of |
| 40 | * entries is smaller than the specified threshold, the operation is performed |
| 41 | * sequentially. |
| 42 | */ |
Matheus Tavares | 1c4d6f4 | 2021-04-18 21:14:56 -0300 | [diff] [blame] | 43 | int run_parallel_checkout(struct checkout *state, int num_workers, int threshold, |
| 44 | struct progress *progress, unsigned int *progress_cnt); |
Matheus Tavares | 04155bd | 2021-04-18 21:14:53 -0300 | [diff] [blame] | 45 | |
Matheus Tavares | e9e8adf | 2021-04-18 21:14:54 -0300 | [diff] [blame] | 46 | /**************************************************************** |
| 47 | * Interface with checkout--worker |
| 48 | ****************************************************************/ |
| 49 | |
| 50 | enum pc_item_status { |
| 51 | PC_ITEM_PENDING = 0, |
| 52 | PC_ITEM_WRITTEN, |
| 53 | /* |
| 54 | * The entry could not be written because there was another file |
| 55 | * already present in its path or leading directories. Since |
| 56 | * checkout_entry_ca() removes such files from the working tree before |
| 57 | * enqueueing the entry for parallel checkout, it means that there was |
| 58 | * a path collision among the entries being written. |
| 59 | */ |
| 60 | PC_ITEM_COLLIDED, |
| 61 | PC_ITEM_FAILED, |
| 62 | }; |
| 63 | |
| 64 | struct parallel_checkout_item { |
| 65 | /* |
| 66 | * In main process ce points to a istate->cache[] entry. Thus, it's not |
| 67 | * owned by us. In workers they own the memory, which *must be* released. |
| 68 | */ |
| 69 | struct cache_entry *ce; |
| 70 | struct conv_attrs ca; |
| 71 | size_t id; /* position in parallel_checkout.items[] of main process */ |
Matheus Tavares | 611c778 | 2022-07-14 08:49:12 -0300 | [diff] [blame] | 72 | int *checkout_counter; |
Matheus Tavares | e9e8adf | 2021-04-18 21:14:54 -0300 | [diff] [blame] | 73 | |
| 74 | /* Output fields, sent from workers. */ |
| 75 | enum pc_item_status status; |
| 76 | struct stat st; |
| 77 | }; |
| 78 | |
| 79 | /* |
| 80 | * The fixed-size portion of `struct parallel_checkout_item` that is sent to the |
| 81 | * workers. Following this will be 2 strings: ca.working_tree_encoding and |
| 82 | * ce.name; These are NOT null terminated, since we have the size in the fixed |
| 83 | * portion. |
| 84 | * |
| 85 | * Note that not all fields of conv_attrs and cache_entry are passed, only the |
| 86 | * ones that will be required by the workers to smudge and write the entry. |
| 87 | */ |
| 88 | struct pc_item_fixed_portion { |
| 89 | size_t id; |
| 90 | struct object_id oid; |
| 91 | unsigned int ce_mode; |
| 92 | enum convert_crlf_action crlf_action; |
| 93 | int ident; |
| 94 | size_t working_tree_encoding_len; |
| 95 | size_t name_len; |
| 96 | }; |
| 97 | |
| 98 | /* |
| 99 | * The fields of `struct parallel_checkout_item` that are returned by the |
| 100 | * workers. Note: `st` must be the last one, as it is omitted on error. |
| 101 | */ |
| 102 | struct pc_item_result { |
| 103 | size_t id; |
| 104 | enum pc_item_status status; |
| 105 | struct stat st; |
| 106 | }; |
| 107 | |
| 108 | #define PC_ITEM_RESULT_BASE_SIZE offsetof(struct pc_item_result, st) |
| 109 | |
| 110 | void write_pc_item(struct parallel_checkout_item *pc_item, |
| 111 | struct checkout *state); |
| 112 | |
Matheus Tavares | 04155bd | 2021-04-18 21:14:53 -0300 | [diff] [blame] | 113 | #endif /* PARALLEL_CHECKOUT_H */ |