Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /*
  2. FUNCTION
  3. <<__malloc_lock>>, <<__malloc_unlock>>---lock malloc pool
  4.  
  5. INDEX
  6.         __malloc_lock
  7. INDEX
  8.         __malloc_unlock
  9.  
  10. ANSI_SYNOPSIS
  11.         #include <malloc.h>
  12.         void __malloc_lock (struct _reent *<[reent]>);
  13.         void __malloc_unlock (struct _reent *<[reent]>);
  14.  
  15. TRAD_SYNOPSIS
  16.         void __malloc_lock(<[reent]>)
  17.         struct _reent *<[reent]>;
  18.  
  19.         void __malloc_unlock(<[reent]>)
  20.         struct _reent *<[reent]>;
  21.  
  22. DESCRIPTION
  23. The <<malloc>> family of routines call these functions when they need to lock
  24. the memory pool.  The version of these routines supplied in the library use
  25. the lock API defined in sys/lock.h.  If multiple threads of execution can
  26. call <<malloc>>, or if <<malloc>> can be called reentrantly, then you need to
  27. define your own versions of these functions in order to safely lock the
  28. memory pool during a call.  If you do not, the memory pool may become
  29. corrupted.
  30.  
  31. A call to <<malloc>> may call <<__malloc_lock>> recursively; that is,
  32. the sequence of calls may go <<__malloc_lock>>, <<__malloc_lock>>,
  33. <<__malloc_unlock>>, <<__malloc_unlock>>.  Any implementation of these
  34. routines must be careful to avoid causing a thread to wait for a lock
  35. that it already holds.
  36. */
  37.  
  38. #include <malloc.h>
  39. #include <sys/lock.h>
  40.  
  41. __LOCK_INIT_RECURSIVE(static, __malloc_lock_object);
  42.  
  43. void
  44. __malloc_lock (ptr)
  45.      struct _reent *ptr;
  46. {
  47.   __lock_acquire_recursive (__malloc_lock_object);
  48. }
  49.  
  50. void
  51. __malloc_unlock (ptr)
  52.      struct _reent *ptr;
  53. {
  54.   __lock_release_recursive (__malloc_lock_object);
  55. }
  56.  
  57.