source: roaraudio/roard/memlock.c @ 4234:ee0035abd1ff

Last change on this file since 4234:ee0035abd1ff was 4234:ee0035abd1ff, checked in by phi, 14 years ago

done some work on the memlock functions

File size: 2.3 KB
Line 
1//memlock.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010
5 *
6 *  This file is part of roard a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include "roard.h"
27
28#define MAX_SEGMENTS 16
29
30struct memlock {
31 int level;
32 void * addr;
33 size_t len;
34};
35
36static struct memlock memlock_table[MAX_SEGMENTS];
37
38static volatile int memlock_table_inited = 0;
39
40static void memlock_table_init (void) {
41 if ( memlock_table_inited )
42  return;
43
44 memset(memlock_table, 0, sizeof(memlock_table));
45
46 memlock_table_inited = 1;
47
48 memlock_register(MEMLOCK_MEDIUM, memlock_table, sizeof(memlock_table));
49}
50
51int memlock_register(int level, void * addr, size_t len) {
52 int i;
53
54 if ( !memlock_table_inited )
55  memlock_table_init();
56
57 for (i = 0; i < MAX_SEGMENTS; i++) {
58  if ( memlock_table[i].addr == NULL ) {
59   memlock_table[i].level = level;
60   memlock_table[i].addr  = addr;
61   memlock_table[i].len   = len;
62   return 0;
63  }
64 }
65
66 return -1;
67}
68
69int memlock_str2level(const char * str) {
70 if ( str == NULL )
71  return -1;
72
73 if ( !strcasecmp(str, "none") ) {
74  return MEMLOCK_NONE;
75 } else if ( !strcasecmp(str, "low") ) {
76  return MEMLOCK_LOW;
77 } else if ( !strcasecmp(str, "medium") ) {
78  return MEMLOCK_MEDIUM;
79 } else if ( !strcasecmp(str, "all") ) {
80  return MEMLOCK_ALL;
81 } else if ( !strcasecmp(str, "default") ) {
82  return MEMLOCK_DEFAULT;
83 } else {
84  return -1;
85 }
86}
87
88int memlock_set_level(int level) {
89 static int old_level = MEMLOCK_NONE;
90
91 if ( !memlock_table_inited )
92  memlock_table_init();
93
94 if ( level == old_level )
95  return 0;
96
97 return -1;
98}
99
100void memlock_unload() {
101}
102
103void memlock_reload() {
104}
105
106//ll
Note: See TracBrowser for help on using the repository browser.