1 /*
2  * Copyright (C) the libgit2 contributors. All rights reserved.
3  *
4  * This file is part of libgit2, distributed under the GNU GPL v2 with
5  * a Linking Exception. For full terms see the included COPYING file.
6  */
7 
8 #ifndef INCLUDE_mwindow__
9 #define INCLUDE_mwindow__
10 
11 #include "common.h"
12 
13 #include "map.h"
14 #include "vector.h"
15 
16 typedef struct git_mwindow {
17 	struct git_mwindow *next;
18 	git_map window_map;
19 	git_off_t offset;
20 	size_t last_used;
21 	size_t inuse_cnt;
22 } git_mwindow;
23 
24 typedef struct git_mwindow_file {
25 	git_mwindow *windows;
26 	int fd;
27 	git_off_t size;
28 } git_mwindow_file;
29 
30 typedef struct git_mwindow_ctl {
31 	size_t mapped;
32 	unsigned int open_windows;
33 	unsigned int mmap_calls;
34 	unsigned int peak_open_windows;
35 	size_t peak_mapped;
36 	size_t used_ctr;
37 	git_vector windowfiles;
38 } git_mwindow_ctl;
39 
40 int git_mwindow_contains(git_mwindow *win, git_off_t offset);
41 void git_mwindow_free_all(git_mwindow_file *mwf); /* locks */
42 void git_mwindow_free_all_locked(git_mwindow_file *mwf); /* run under lock */
43 unsigned char *git_mwindow_open(git_mwindow_file *mwf, git_mwindow **cursor, git_off_t offset, size_t extra, unsigned int *left);
44 int git_mwindow_file_register(git_mwindow_file *mwf);
45 void git_mwindow_file_deregister(git_mwindow_file *mwf);
46 void git_mwindow_close(git_mwindow **w_cursor);
47 
48 extern int git_mwindow_global_init(void);
49 
50 struct git_pack_file; /* just declaration to avoid cyclical includes */
51 int git_mwindow_get_pack(struct git_pack_file **out, const char *path);
52 void git_mwindow_put_pack(struct git_pack_file *pack);
53 
54 #endif
55