@@ -234,7 +234,11 @@ 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 ;
@@ -250,7 +254,11 @@ pub fn get_mwindow_size() -> Result<libc::size_t, Error> {
250
254
}
251
255
252
256
/// Set the maximum mmap window size
253
- pub fn set_mwindow_size ( size : libc:: size_t ) -> Result < ( ) , Error > {
257
+ ///
258
+ /// # Safety
259
+ /// This function is modifying a C global without synchronization, so it is not
260
+ /// thread safe, and should only be called before any thread is spawned.
261
+ pub unsafe fn set_mwindow_size ( size : libc:: size_t ) -> Result < ( ) , Error > {
254
262
crate :: init ( ) ;
255
263
256
264
unsafe {
@@ -264,7 +272,11 @@ pub fn set_mwindow_size(size: libc::size_t) -> Result<(), Error> {
264
272
}
265
273
266
274
/// 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 > {
275
+ ///
276
+ /// # Safety
277
+ /// This function is reading a C global without synchronization, so it is not
278
+ /// thread safe, and should only be called before any thread is spawned.
279
+ pub unsafe fn get_mwindow_mapped_limit ( ) -> Result < libc:: size_t , Error > {
268
280
crate :: init ( ) ;
269
281
270
282
let mut limit = 0 ;
@@ -281,7 +293,11 @@ pub fn get_mwindow_mapped_limit() -> Result<libc::size_t, Error> {
281
293
282
294
/// Set the maximum amount of memory that can be mapped at any time
283
295
/// by the library.
284
- pub fn set_mwindow_mapped_limit ( limit : libc:: size_t ) -> Result < ( ) , Error > {
296
+ ///
297
+ /// # Safety
298
+ /// This function is modifying a C global without synchronization, so it is not
299
+ /// thread safe, and should only be called before any thread is spawned.
300
+ pub unsafe fn set_mwindow_mapped_limit ( limit : libc:: size_t ) -> Result < ( ) , Error > {
285
301
crate :: init ( ) ;
286
302
287
303
unsafe {
@@ -296,7 +312,11 @@ pub fn set_mwindow_mapped_limit(limit: libc::size_t) -> Result<(), Error> {
296
312
297
313
/// Get the maximum number of files that will be mapped at any time by the
298
314
/// library.
299
- pub fn get_mwindow_file_limit ( ) -> Result < libc:: size_t , Error > {
315
+ ///
316
+ /// # Safety
317
+ /// This function is reading a C global without synchronization, so it is not
318
+ /// thread safe, and should only be called before any thread is spawned.
319
+ pub unsafe fn get_mwindow_file_limit ( ) -> Result < libc:: size_t , Error > {
300
320
crate :: init ( ) ;
301
321
302
322
let mut limit = 0 ;
@@ -313,7 +333,11 @@ pub fn get_mwindow_file_limit() -> Result<libc::size_t, Error> {
313
333
314
334
/// Set the maximum number of files that can be mapped at any time
315
335
/// by the library. The default (0) is unlimited.
316
- pub fn set_mwindow_file_limit ( limit : libc:: size_t ) -> Result < ( ) , Error > {
336
+ ///
337
+ /// # Safety
338
+ /// This function is modifying a C global without synchronization, so it is not
339
+ /// thread safe, and should only be called before any thread is spawned.
340
+ pub unsafe fn set_mwindow_file_limit ( limit : libc:: size_t ) -> Result < ( ) , Error > {
317
341
crate :: init ( ) ;
318
342
319
343
unsafe {
@@ -337,19 +361,25 @@ mod test {
337
361
338
362
#[ test]
339
363
fn mwindow_size ( ) {
340
- assert ! ( set_mwindow_size( 1024 ) . is_ok( ) ) ;
341
- assert ! ( get_mwindow_size( ) . unwrap( ) == 1024 ) ;
364
+ unsafe {
365
+ assert ! ( set_mwindow_size( 1024 ) . is_ok( ) ) ;
366
+ assert ! ( get_mwindow_size( ) . unwrap( ) == 1024 ) ;
367
+ }
342
368
}
343
369
344
370
#[ test]
345
371
fn mwindow_mapped_limit ( ) {
346
- assert ! ( set_mwindow_mapped_limit( 1024 ) . is_ok( ) ) ;
347
- assert ! ( get_mwindow_mapped_limit( ) . unwrap( ) == 1024 ) ;
372
+ unsafe {
373
+ assert ! ( set_mwindow_mapped_limit( 1024 ) . is_ok( ) ) ;
374
+ assert ! ( get_mwindow_mapped_limit( ) . unwrap( ) == 1024 ) ;
375
+ }
348
376
}
349
377
350
378
#[ test]
351
379
fn mwindow_file_limit ( ) {
352
- assert ! ( set_mwindow_file_limit( 1024 ) . is_ok( ) ) ;
353
- assert ! ( get_mwindow_file_limit( ) . unwrap( ) == 1024 ) ;
380
+ unsafe {
381
+ assert ! ( set_mwindow_file_limit( 1024 ) . is_ok( ) ) ;
382
+ assert ! ( get_mwindow_file_limit( ) . unwrap( ) == 1024 ) ;
383
+ }
354
384
}
355
385
}
0 commit comments