@@ -234,94 +234,106 @@ where
234234}
235235
236236/// Get the maximum mmap window size
237- pub fn get_mwindow_size ( ) -> Result < libc:: size_t , Error > {
237+ ///
238+ /// # Safety
239+ /// This function is reading a C global without synchronization, so it is not
240+ /// thread safe, and should only be called before any thread is spawned.
241+ pub unsafe fn get_mwindow_size ( ) -> Result < libc:: size_t , Error > {
238242 crate :: init ( ) ;
239243
240244 let mut size = 0 ;
241245
242- unsafe {
243- try_call ! ( raw:: git_libgit2_opts(
244- raw:: GIT_OPT_GET_MWINDOW_SIZE as libc:: c_int,
245- & mut size
246- ) ) ;
247- }
246+ try_call ! ( raw:: git_libgit2_opts(
247+ raw:: GIT_OPT_GET_MWINDOW_SIZE as libc:: c_int,
248+ & mut size
249+ ) ) ;
248250
249251 Ok ( size)
250252}
251253
252254/// Set the maximum mmap window size
253- pub fn set_mwindow_size ( size : libc:: size_t ) -> Result < ( ) , Error > {
255+ ///
256+ /// # Safety
257+ /// This function is modifying a C global without synchronization, so it is not
258+ /// thread safe, and should only be called before any thread is spawned.
259+ pub unsafe fn set_mwindow_size ( size : libc:: size_t ) -> Result < ( ) , Error > {
254260 crate :: init ( ) ;
255261
256- unsafe {
257- try_call ! ( raw:: git_libgit2_opts(
258- raw:: GIT_OPT_SET_MWINDOW_SIZE as libc:: c_int,
259- size
260- ) ) ;
261- }
262+ try_call ! ( raw:: git_libgit2_opts(
263+ raw:: GIT_OPT_SET_MWINDOW_SIZE as libc:: c_int,
264+ size
265+ ) ) ;
262266
263267 Ok ( ( ) )
264268}
265269
266270/// Get the maximum memory that will be mapped in total by the library
267- pub fn get_mwindow_mapped_limit ( ) -> Result < libc:: size_t , Error > {
271+ ///
272+ /// # Safety
273+ /// This function is reading a C global without synchronization, so it is not
274+ /// thread safe, and should only be called before any thread is spawned.
275+ pub unsafe fn get_mwindow_mapped_limit ( ) -> Result < libc:: size_t , Error > {
268276 crate :: init ( ) ;
269277
270278 let mut limit = 0 ;
271279
272- unsafe {
273- try_call ! ( raw:: git_libgit2_opts(
274- raw:: GIT_OPT_GET_MWINDOW_MAPPED_LIMIT as libc:: c_int,
275- & mut limit
276- ) ) ;
277- }
280+ try_call ! ( raw:: git_libgit2_opts(
281+ raw:: GIT_OPT_GET_MWINDOW_MAPPED_LIMIT as libc:: c_int,
282+ & mut limit
283+ ) ) ;
278284
279285 Ok ( limit)
280286}
281287
282288/// Set the maximum amount of memory that can be mapped at any time
283289/// by the library.
284- pub fn set_mwindow_mapped_limit ( limit : libc:: size_t ) -> Result < ( ) , Error > {
290+ ///
291+ /// # Safety
292+ /// This function is modifying a C global without synchronization, so it is not
293+ /// thread safe, and should only be called before any thread is spawned.
294+ pub unsafe fn set_mwindow_mapped_limit ( limit : libc:: size_t ) -> Result < ( ) , Error > {
285295 crate :: init ( ) ;
286296
287- unsafe {
288- try_call ! ( raw:: git_libgit2_opts(
289- raw:: GIT_OPT_SET_MWINDOW_MAPPED_LIMIT as libc:: c_int,
290- limit
291- ) ) ;
292- }
297+ try_call ! ( raw:: git_libgit2_opts(
298+ raw:: GIT_OPT_SET_MWINDOW_MAPPED_LIMIT as libc:: c_int,
299+ limit
300+ ) ) ;
293301
294302 Ok ( ( ) )
295303}
296304
297305/// Get the maximum number of files that will be mapped at any time by the
298306/// library.
299- pub fn get_mwindow_file_limit ( ) -> Result < libc:: size_t , Error > {
307+ ///
308+ /// # Safety
309+ /// This function is reading a C global without synchronization, so it is not
310+ /// thread safe, and should only be called before any thread is spawned.
311+ pub unsafe fn get_mwindow_file_limit ( ) -> Result < libc:: size_t , Error > {
300312 crate :: init ( ) ;
301313
302314 let mut limit = 0 ;
303315
304- unsafe {
305- try_call ! ( raw:: git_libgit2_opts(
306- raw:: GIT_OPT_GET_MWINDOW_FILE_LIMIT as libc:: c_int,
307- & mut limit
308- ) ) ;
309- }
316+ try_call ! ( raw:: git_libgit2_opts(
317+ raw:: GIT_OPT_GET_MWINDOW_FILE_LIMIT as libc:: c_int,
318+ & mut limit
319+ ) ) ;
310320
311321 Ok ( limit)
312322}
313323
314324/// Set the maximum number of files that can be mapped at any time
315325/// by the library. The default (0) is unlimited.
316- pub fn set_mwindow_file_limit ( limit : libc:: size_t ) -> Result < ( ) , Error > {
326+ ///
327+ /// # Safety
328+ /// This function is modifying a C global without synchronization, so it is not
329+ /// thread safe, and should only be called before any thread is spawned.
330+ pub unsafe fn set_mwindow_file_limit ( limit : libc:: size_t ) -> Result < ( ) , Error > {
317331 crate :: init ( ) ;
318332
319- unsafe {
320- try_call ! ( raw:: git_libgit2_opts(
321- raw:: GIT_OPT_SET_MWINDOW_FILE_LIMIT as libc:: c_int,
322- limit
323- ) ) ;
324- }
333+ try_call ! ( raw:: git_libgit2_opts(
334+ raw:: GIT_OPT_SET_MWINDOW_FILE_LIMIT as libc:: c_int,
335+ limit
336+ ) ) ;
325337
326338 Ok ( ( ) )
327339}
@@ -337,19 +349,25 @@ mod test {
337349
338350 #[ test]
339351 fn mwindow_size ( ) {
340- assert ! ( set_mwindow_size( 1024 ) . is_ok( ) ) ;
341- assert ! ( get_mwindow_size( ) . unwrap( ) == 1024 ) ;
352+ unsafe {
353+ assert ! ( set_mwindow_size( 1024 ) . is_ok( ) ) ;
354+ assert ! ( get_mwindow_size( ) . unwrap( ) == 1024 ) ;
355+ }
342356 }
343357
344358 #[ test]
345359 fn mwindow_mapped_limit ( ) {
346- assert ! ( set_mwindow_mapped_limit( 1024 ) . is_ok( ) ) ;
347- assert ! ( get_mwindow_mapped_limit( ) . unwrap( ) == 1024 ) ;
360+ unsafe {
361+ assert ! ( set_mwindow_mapped_limit( 1024 ) . is_ok( ) ) ;
362+ assert ! ( get_mwindow_mapped_limit( ) . unwrap( ) == 1024 ) ;
363+ }
348364 }
349365
350366 #[ test]
351367 fn mwindow_file_limit ( ) {
352- assert ! ( set_mwindow_file_limit( 1024 ) . is_ok( ) ) ;
353- assert ! ( get_mwindow_file_limit( ) . unwrap( ) == 1024 ) ;
368+ unsafe {
369+ assert ! ( set_mwindow_file_limit( 1024 ) . is_ok( ) ) ;
370+ assert ! ( get_mwindow_file_limit( ) . unwrap( ) == 1024 ) ;
371+ }
354372 }
355373}
0 commit comments