fieker-DuValspielwiese
Last change
on this file since 2c694a2 was
416465,
checked in by Olaf Bachmann <obachman@…>, 25 years ago
|
* bug-fixes from work with Thomas
git-svn-id: file:///usr/local/Singular/svn/trunk@3826 2c84dea3-7e68-4137-9b89-c4e89433aadc
|
-
Property mode set to
100644
|
File size:
1.5 KB
|
Line | |
---|
1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id: mmpage.c,v 1.5 1999-11-15 17:20:25 obachman Exp $ */ |
---|
5 | |
---|
6 | /* |
---|
7 | * ABSTRACT: |
---|
8 | */ |
---|
9 | |
---|
10 | #define _POSIX_SOURCE 1 |
---|
11 | |
---|
12 | #include <stdio.h> |
---|
13 | #include <stdlib.h> |
---|
14 | #include "mod2.h" |
---|
15 | #include "mmprivate.h" |
---|
16 | #ifdef HAVE_MALLOC_H |
---|
17 | #include "malloc.h" |
---|
18 | #endif |
---|
19 | |
---|
20 | #include "mmpage.h" |
---|
21 | #include "mmemory.h" |
---|
22 | |
---|
23 | static void* mm_FreePages = NULL; |
---|
24 | static int mm_NumberOfFreePages = 0; |
---|
25 | |
---|
26 | void* mmGetPage() |
---|
27 | { |
---|
28 | void* page; |
---|
29 | |
---|
30 | #ifndef PAGE_DEBUG |
---|
31 | if (mm_FreePages != NULL) |
---|
32 | { |
---|
33 | page = mm_FreePages; |
---|
34 | mm_FreePages = *((void**)mm_FreePages); |
---|
35 | mm_NumberOfFreePages--; |
---|
36 | return page; |
---|
37 | } |
---|
38 | else |
---|
39 | #endif |
---|
40 | return mmVallocFromSystem(SIZE_OF_PAGE); |
---|
41 | } |
---|
42 | |
---|
43 | void mmFreePage(void* page) |
---|
44 | { |
---|
45 | assume(page != NULL); |
---|
46 | *((void**)page) = mm_FreePages; |
---|
47 | mm_FreePages = page; |
---|
48 | mm_NumberOfFreePages++; |
---|
49 | } |
---|
50 | |
---|
51 | void mmReleaseFreePages() |
---|
52 | { |
---|
53 | #ifndef PAGE_DEBUG |
---|
54 | void** next; |
---|
55 | |
---|
56 | while (mm_FreePages != NULL) |
---|
57 | { |
---|
58 | next = *((void**)mm_FreePages); |
---|
59 | mmVfreeToSystem(mm_FreePages, SIZE_OF_PAGE); |
---|
60 | mm_FreePages = next; |
---|
61 | } |
---|
62 | mm_NumberOfFreePages = 0; |
---|
63 | #endif |
---|
64 | } |
---|
65 | |
---|
66 | int mmIsAddrOnFreePage(void* addr) |
---|
67 | { |
---|
68 | void* page = mm_FreePages; |
---|
69 | while (page != NULL) |
---|
70 | { |
---|
71 | if (mmIsAddrOnPage(addr, page)) return 1; |
---|
72 | page = *((void**) page); |
---|
73 | } |
---|
74 | return 0; |
---|
75 | } |
---|
76 | |
---|
77 | int mmGetNumberOfFreePages() |
---|
78 | { |
---|
79 | return mm_NumberOfFreePages; |
---|
80 | } |
---|
81 | |
---|
82 | int mmGetNumberOfAllocatedPages() |
---|
83 | { |
---|
84 | return mm_bytesValloc / SIZE_OF_PAGE; |
---|
85 | } |
---|
86 | |
---|
87 | int mmGetNumberOfUsedPages() |
---|
88 | { |
---|
89 | return mmGetNumberOfAllocatedPages() - mm_NumberOfFreePages; |
---|
90 | } |
---|
91 | |
---|
92 | |
---|
Note: See
TracBrowser
for help on using the repository browser.