source: trunk/libs/newlib/src/newlib/libc/stdlib/mlock.c @ 471

Last change on this file since 471 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
Line 
1#ifndef MALLOC_PROVIDED
2/*
3FUNCTION
4<<__malloc_lock>>, <<__malloc_unlock>>---lock malloc pool
5
6INDEX
7        __malloc_lock
8INDEX
9        __malloc_unlock
10
11SYNOPSIS
12        #include <malloc.h>
13        void __malloc_lock (struct _reent *<[reent]>);
14        void __malloc_unlock (struct _reent *<[reent]>);
15
16DESCRIPTION
17The <<malloc>> family of routines call these functions when they need to lock
18the memory pool.  The version of these routines supplied in the library use
19the lock API defined in sys/lock.h.  If multiple threads of execution can
20call <<malloc>>, or if <<malloc>> can be called reentrantly, then you need to
21define your own versions of these functions in order to safely lock the
22memory pool during a call.  If you do not, the memory pool may become
23corrupted.
24
25A call to <<malloc>> may call <<__malloc_lock>> recursively; that is,
26the sequence of calls may go <<__malloc_lock>>, <<__malloc_lock>>,
27<<__malloc_unlock>>, <<__malloc_unlock>>.  Any implementation of these
28routines must be careful to avoid causing a thread to wait for a lock
29that 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
39void
40__malloc_lock (ptr)
41     struct _reent *ptr;
42{
43#ifndef __SINGLE_THREAD__
44  __lock_acquire_recursive (__malloc_recursive_mutex);
45#endif
46}
47
48void
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.