/[radius]/radius/lib/mem.c
ViewVC logotype

Diff of /radius/lib/mem.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by gray, Fri Apr 18 05:27:09 2003 UTC revision 1.9 by gray, Wed Apr 30 08:38:29 2003 UTC
# Line 1  Line 1 
1  /* This file is part of GNU RADIUS.  /* This file is part of GNU Radius.
2     Copyright (C) 2000,2001 Sergey Poznyakoff     Copyright (C) 2000,2001,2002,2003 Sergey Poznyakoff
3        
4     This program is free software; you can redistribute it and/or modify     GNU Radius is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.     (at your option) any later version.
8        
9     This program is distributed in the hope that it will be useful,     GNU Radius is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.     GNU General Public License for more details.
13        
14     You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software Foundation,     along with GNU Radius; if not, write to the Free Software Foundation,
16     Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */     Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17    
 #ifndef lint  
 static char rcsid[] =  
 "$Id$";  
 #endif  
   
18  #define RADIUS_MODULE_MEM_C  #define RADIUS_MODULE_MEM_C
19    
20  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
# Line 83  static size_t mem_effective_size(size_t Line 78  static size_t mem_effective_size(size_t
78          sizeof(Align_t)*((size + sizeof(Align_t) - 1) / sizeof(Align_t))          sizeof(Align_t)*((size + sizeof(Align_t) - 1) / sizeof(Align_t))
79    
80  size_t  size_t
81  mem_effective_size(size)  mem_effective_size(size_t size)
         size_t size;  
82  {  {
83          if (size < ENTRY_SIZE)          if (size < ENTRY_SIZE)
84                  size = ENTRY_SIZE;                  size = ENTRY_SIZE;
# Line 125  alloc_class_mem() Line 119  alloc_class_mem()
119  #define free_class mem_free  #define free_class mem_free
120    
121  Bucketclass  Bucketclass
122  alloc_class(size)  alloc_class(size_t size)
         size_t size;  
123  {  {
124          Bucketclass bcp;          Bucketclass bcp;
125          count_t count;          count_t count;
# Line 160  alloc_class(size) Line 153  alloc_class(size)
153    
154    
155  Bucket  Bucket
156  alloc_bucket(class)  alloc_bucket(Bucketclass class)
         Bucketclass class;  
157  {  {
158          Bucket bp;          Bucket bp;
159          union {          union {
# Line 210  alloc_bucket(class) Line 202  alloc_bucket(class)
202   */   */
203    
204  void *  void *
205  mem_alloc_nl(size)  mem_alloc_nl(size_t size)
         size_t size;  
206  {  {
207          Bucketclass class_ptr;          Bucketclass class_ptr;
208          Entry ptr;          Entry ptr;
# Line 245  mem_alloc_nl(size) Line 236  mem_alloc_nl(size)
236  }  }
237    
238  void *  void *
239  mem_alloc(size)  mem_alloc(size_t size)
         size_t size;  
240  {  {
241          void *p;          void *p;
242          mem_lock();          mem_lock();
# Line 256  mem_alloc(size) Line 246  mem_alloc(size)
246  }  }
247    
248  void  void
249  put_back(class, ptr)  put_back(Bucketclass class, void *ptr)
         Bucketclass class;  
         void *ptr;  
250  {  {
251          Entry eptr = (Entry)ptr;          Entry eptr = (Entry)ptr;
252    
# Line 273  put_back(class, ptr) Line 261  put_back(class, ptr)
261  }  }
262    
263  void  void
264  mem_free(ptr)  mem_free(void *ptr)
         void *ptr;  
265  {  {
266          Bucketclass class;          Bucketclass class;
267          Bucket bucket;          Bucket bucket;
# Line 302  mem_free(ptr) Line 289  mem_free(ptr)
289  /* Allocate COUNT contiguous objects of size SIZE  /* Allocate COUNT contiguous objects of size SIZE
290   */   */
291  void *  void *
292  mem_calloc(count, size)  mem_calloc(count_t count, size_t size)
         count_t count;  
         size_t size;  
293  {  {
294          Bucketclass class_ptr;          Bucketclass class_ptr;
295          Entry       first, last;          Entry       first, last;
# Line 404  again: Line 389  again:
389   * allocated using mem_calloc().   * allocated using mem_calloc().
390   */   */
391  void  void
392  mem_cfree(ptr, count)  mem_cfree(void *ptr, count_t count)
         void *ptr;  
         count_t count;  
393  {  {
394          Bucketclass class;          Bucketclass class;
395          Bucket bucket;          Bucket bucket;
# Line 425  mem_cfree(ptr, count) Line 408  mem_cfree(ptr, count)
408  }  }
409    
410  void  void
411  put_back_cont(class, ptr, count)  put_back_cont(Bucketclass class, void *ptr, count_t count)
         Bucketclass class;  
         void *ptr;  
         count_t count;  
412  {  {
413          int   i;          int   i;
414          Entry sptr = (Entry)ptr;          Entry sptr = (Entry)ptr;
# Line 492  LOCK_DECLARE(string_lock) Line 472  LOCK_DECLARE(string_lock)
472  /* string_alloc(): Allocate a string of given length  /* string_alloc(): Allocate a string of given length
473   */   */
474  char *  char *
475  string_alloc(length)  string_alloc(size_t length)
         size_t length;  
476  {  {
477          count_t count;          count_t count;
478          STRHDR  *p;          STRHDR  *p;
# Line 513  string_alloc(length) Line 492  string_alloc(length)
492   * STRVAL and store the latter into it.   * STRVAL and store the latter into it.
493   */   */
494  char *  char *
495  string_create(strval)  string_create(char *strval)
         char *strval;  
496  {  {
497          char *p;          char *p;
498          if (!strval)          if (!strval)
# Line 526  string_create(strval) Line 504  string_create(strval)
504  /* string_dup(): create a copy of existing string object  /* string_dup(): create a copy of existing string object
505   */   */
506  char *  char *
507  string_dup(str)  string_dup(char *str)
         char *str;  
508  {  {
509          STRHDR *hp;          STRHDR *hp;
510    
# Line 547  string_dup(str) Line 524  string_dup(str)
524   * with the new string value.   * with the new string value.
525   */   */
526  char *  char *
527  string_replace(str, string_value)  string_replace(char **str, char *string_value)
         char **str;  
         char *string_value;  
528  {  {
529          int length = strlen(string_value);          int length = strlen(string_value);
530          STRHDR *hp;          STRHDR *hp;
# Line 574  string_replace(str, string_value) Line 549  string_replace(str, string_value)
549   * and deallocate the object when the counter becomes zero   * and deallocate the object when the counter becomes zero
550   */   */
551  void  void
552  string_free(str)  string_free(char *str)
         char *str;  
553  {  {
554          STRHDR *hp;          STRHDR *hp;
555    
# Line 594  string_free(str) Line 568  string_free(str)
568   */   */
569    
570  void  void
571  mem_get_stat(stat)  mem_get_stat(MEM_STAT *stat)
         MEM_STAT *stat;  
572  {  {
573          Bucketclass class;          Bucketclass class;
574                    
# Line 619  mem_get_stat(stat) Line 592  mem_get_stat(stat)
592  }  }
593    
594  int  int
595  mem_stat_enumerate(fun, closure)  mem_stat_enumerate(int (*fun)(), void *closure)
         int (*fun)();  
         void *closure;  
596  {  {
597          CLASS_STAT stat;          CLASS_STAT stat;
598          Bucketclass class;          Bucketclass class;
# Line 641  mem_stat_enumerate(fun, closure) Line 612  mem_stat_enumerate(fun, closure)
612    
613  #ifdef MAINTAINER_MODE  #ifdef MAINTAINER_MODE
614  int  int
615  check_cont(class)  check_cont(Bucketclass class)
         Bucketclass class;  
616  {  {
617          Entry ep, prev;          Entry ep, prev;
618                    

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26