util_mem.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef __SOUND_UTIL_MEM_H
  2. #define __SOUND_UTIL_MEM_H
  3. /*
  4. * Copyright (C) 2000 Takashi Iwai <tiwai@suse.de>
  5. *
  6. * Generic memory management routines for soundcard memory allocation
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. typedef struct snd_util_memblk snd_util_memblk_t;
  23. typedef struct snd_util_memhdr snd_util_memhdr_t;
  24. typedef unsigned int snd_util_unit_t;
  25. /*
  26. * memory block
  27. */
  28. struct snd_util_memblk {
  29. snd_util_unit_t size; /* size of this block */
  30. snd_util_unit_t offset; /* zero-offset of this block */
  31. struct list_head list; /* link */
  32. };
  33. #define snd_util_memblk_argptr(blk) (void*)((char*)(blk) + sizeof(snd_util_memblk_t))
  34. /*
  35. * memory management information
  36. */
  37. struct snd_util_memhdr {
  38. snd_util_unit_t size; /* size of whole data */
  39. struct list_head block; /* block linked-list header */
  40. int nblocks; /* # of allocated blocks */
  41. snd_util_unit_t used; /* used memory size */
  42. int block_extra_size; /* extra data size of chunk */
  43. struct semaphore block_mutex; /* lock */
  44. };
  45. /*
  46. * prototypes
  47. */
  48. snd_util_memhdr_t *snd_util_memhdr_new(int memsize);
  49. void snd_util_memhdr_free(snd_util_memhdr_t *hdr);
  50. snd_util_memblk_t *snd_util_mem_alloc(snd_util_memhdr_t *hdr, int size);
  51. int snd_util_mem_free(snd_util_memhdr_t *hdr, snd_util_memblk_t *blk);
  52. int snd_util_mem_avail(snd_util_memhdr_t *hdr);
  53. /* functions without mutex */
  54. snd_util_memblk_t *__snd_util_mem_alloc(snd_util_memhdr_t *hdr, int size);
  55. void __snd_util_mem_free(snd_util_memhdr_t *hdr, snd_util_memblk_t *blk);
  56. snd_util_memblk_t *__snd_util_memblk_new(snd_util_memhdr_t *hdr, snd_util_unit_t units, struct list_head *prev);
  57. #endif /* __SOUND_UTIL_MEM_H */