• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/ap/gpl/iserver/alsa-lib-1.0.26/src/

Lines Matching defs:*

2  *  IPC SHM area manager
3 * Copyright (c) 2003 by Jaroslav Kysela <perex@perex.cz>
5 * This library is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as
7 * published by the Free Software Foundation; either version 2.1 of
8 * the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <stdio.h>
22 #include <malloc.h>
23 #include <string.h>
24 #include <errno.h>
25 #include <sys/poll.h>
26 #include <sys/mman.h>
27 #include <sys/shm.h>
28 #include "list.h"
30 #ifndef DOC_HIDDEN
31 struct snd_shm_area {
32 struct list_head list;
33 int shmid;
34 void *ptr;
35 int share;
37 #endif
39 static LIST_HEAD(shm_areas);
42 * \brief Create a shm area record
43 * \param shmid IPC SHM ID
44 * \param ptr the shared area pointer
45 * \return The allocated shm area record, NULL if fail
47 * Allocates a shared area record with the given SHM ID and pointer.
48 * The record has a reference counter, which is initialized to 1 by this function.
50 struct snd_shm_area *snd_shm_area_create(int shmid, void *ptr)
52 struct snd_shm_area *area = malloc(sizeof(*area));
53 if (area) {
54 area->shmid = shmid;
55 area->ptr = ptr;
56 area->share = 1;
57 list_add_tail(&area->list, &shm_areas);
59 return area;
63 * \brief Increase the reference counter of shm area record
64 * \param area shm area record
65 * \return the shm area record (identical with the argument)
67 * Increases the reference counter of the given shared area record.
69 struct snd_shm_area *snd_shm_area_share(struct snd_shm_area *area)
71 if (area == NULL)
72 return NULL;
73 area->share++;
74 return area;
78 * \brief Release the shared area record
79 * \param area the shared are record
80 * \return 0 if successful, or a negative error code
82 * Decreases the reference counter of the given shared area record, and
83 * releases the resources automaticall if it reaches to 0.
85 int snd_shm_area_destroy(struct snd_shm_area *area)
87 if (area == NULL)
88 return -ENOENT;
89 if (--area->share)
90 return 0;
91 list_del(&area->list);
92 shmdt(area->ptr);
93 free(area);
94 return 0;
97 void snd_shm_area_destructor(void) __attribute__ ((destructor));
99 void snd_shm_area_destructor(void)
101 struct list_head *pos;
102 struct snd_shm_area *area;
104 list_for_each(pos, &shm_areas) {
105 area = list_entry(pos, struct snd_shm_area, list);
106 shmdt(area->ptr);