@@ -234,94 +234,106 @@ where
234
234
}
235
235
236
236
/// 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 > {
238
242
crate :: init ( ) ;
239
243
240
244
let mut size = 0 ;
241
245
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
+ ) ) ;
248
250
249
251
Ok ( size)
250
252
}
251
253
252
254
/// 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 > {
254
260
crate :: init ( ) ;
255
261
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
+ ) ) ;
262
266
263
267
Ok ( ( ) )
264
268
}
265
269
266
270
/// 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 > {
268
276
crate :: init ( ) ;
269
277
270
278
let mut limit = 0 ;
271
279
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
+ ) ) ;
278
284
279
285
Ok ( limit)
280
286
}
281
287
282
288
/// Set the maximum amount of memory that can be mapped at any time
283
289
/// 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 > {
285
295
crate :: init ( ) ;
286
296
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
+ ) ) ;
293
301
294
302
Ok ( ( ) )
295
303
}
296
304
297
305
/// Get the maximum number of files that will be mapped at any time by the
298
306
/// 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 > {
300
312
crate :: init ( ) ;
301
313
302
314
let mut limit = 0 ;
303
315
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
+ ) ) ;
310
320
311
321
Ok ( limit)
312
322
}
313
323
314
324
/// Set the maximum number of files that can be mapped at any time
315
325
/// 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 > {
317
331
crate :: init ( ) ;
318
332
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
+ ) ) ;
325
337
326
338
Ok ( ( ) )
327
339
}
@@ -337,19 +349,25 @@ mod test {
337
349
338
350
#[ test]
339
351
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
+ }
342
356
}
343
357
344
358
#[ test]
345
359
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
+ }
348
364
}
349
365
350
366
#[ test]
351
367
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
+ }
354
372
}
355
373
}
0 commit comments