Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / stdlib / mlock.c
blob23aa10173f812ba274e7da7b46cc48b4a5c8ac9c
1 #ifndef MALLOC_PROVIDED
2 /*
3 FUNCTION
4 <<__malloc_lock>>, <<__malloc_unlock>>---lock malloc pool
6 INDEX
7 __malloc_lock
8 INDEX
9 __malloc_unlock
11 SYNOPSIS
12 #include <malloc.h>
13 void __malloc_lock (struct _reent *<[reent]>);
14 void __malloc_unlock (struct _reent *<[reent]>);
16 DESCRIPTION
17 The <<malloc>> family of routines call these functions when they need to lock
18 the memory pool. The version of these routines supplied in the library use
19 the lock API defined in sys/lock.h. If multiple threads of execution can
20 call <<malloc>>, or if <<malloc>> can be called reentrantly, then you need to
21 define your own versions of these functions in order to safely lock the
22 memory pool during a call. If you do not, the memory pool may become
23 corrupted.
25 A call to <<malloc>> may call <<__malloc_lock>> recursively; that is,
26 the sequence of calls may go <<__malloc_lock>>, <<__malloc_lock>>,
27 <<__malloc_unlock>>, <<__malloc_unlock>>. Any implementation of these
28 routines must be careful to avoid causing a thread to wait for a lock
29 that it already holds.
32 #include <malloc.h>
33 #include <sys/lock.h>
35 #ifndef __SINGLE_THREAD__
36 __LOCK_INIT_RECURSIVE(static, __malloc_recursive_mutex);
37 #endif
39 void
40 __malloc_lock (ptr)
41 struct _reent *ptr;
43 #ifndef __SINGLE_THREAD__
44 __lock_acquire_recursive (__malloc_recursive_mutex);
45 #endif
48 void
49 __malloc_unlock (ptr)
50 struct _reent *ptr;
52 #ifndef __SINGLE_THREAD__
53 __lock_release_recursive (__malloc_recursive_mutex);
54 #endif
57 #endif