Last change
on this file since 577 was
444,
checked in by satin@…, 6 years ago
|
add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc
|
File size:
1.4 KB
|
Rev | Line | |
---|
[444] | 1 | #ifndef MALLOC_PROVIDED |
---|
| 2 | /* |
---|
| 3 | FUNCTION |
---|
| 4 | <<__malloc_lock>>, <<__malloc_unlock>>---lock malloc pool |
---|
| 5 | |
---|
| 6 | INDEX |
---|
| 7 | __malloc_lock |
---|
| 8 | INDEX |
---|
| 9 | __malloc_unlock |
---|
| 10 | |
---|
| 11 | SYNOPSIS |
---|
| 12 | #include <malloc.h> |
---|
| 13 | void __malloc_lock (struct _reent *<[reent]>); |
---|
| 14 | void __malloc_unlock (struct _reent *<[reent]>); |
---|
| 15 | |
---|
| 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. |
---|
| 24 | |
---|
| 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. |
---|
| 30 | */ |
---|
| 31 | |
---|
| 32 | #include <malloc.h> |
---|
| 33 | #include <sys/lock.h> |
---|
| 34 | |
---|
| 35 | #ifndef __SINGLE_THREAD__ |
---|
| 36 | __LOCK_INIT_RECURSIVE(static, __malloc_recursive_mutex); |
---|
| 37 | #endif |
---|
| 38 | |
---|
| 39 | void |
---|
| 40 | __malloc_lock (ptr) |
---|
| 41 | struct _reent *ptr; |
---|
| 42 | { |
---|
| 43 | #ifndef __SINGLE_THREAD__ |
---|
| 44 | __lock_acquire_recursive (__malloc_recursive_mutex); |
---|
| 45 | #endif |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | void |
---|
| 49 | __malloc_unlock (ptr) |
---|
| 50 | struct _reent *ptr; |
---|
| 51 | { |
---|
| 52 | #ifndef __SINGLE_THREAD__ |
---|
| 53 | __lock_release_recursive (__malloc_recursive_mutex); |
---|
| 54 | #endif |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.