Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
359 | serge | 1 | /**************************************************************************** |
2 | * |
||
3 | * Open Watcom Project |
||
4 | * |
||
5 | * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
||
6 | * |
||
7 | * ======================================================================== |
||
8 | * |
||
9 | * This file contains Original Code and/or Modifications of Original |
||
10 | * Code as defined in and that are subject to the Sybase Open Watcom |
||
11 | * Public License version 1.0 (the 'License'). You may not use this file |
||
12 | * except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
||
13 | * ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
||
14 | * provided with the Original Code and Modifications, and is also |
||
15 | * available at www.sybase.com/developer/opensource. |
||
16 | * |
||
17 | * The Original Code and all software distributed under the License are |
||
18 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
||
19 | * EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
||
20 | * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
||
21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
||
22 | * NON-INFRINGEMENT. Please see the License for the specific language |
||
23 | * governing rights and limitations under the License. |
||
24 | * |
||
25 | * ======================================================================== |
||
26 | * |
||
27 | * Description: Implementation of near free() and _nfree(). |
||
28 | * |
||
29 | ****************************************************************************/ |
||
30 | |||
31 | |||
32 | //#include "dll.h" // needs to be first |
||
33 | #include "variety.h" |
||
34 | #include |
||
35 | #include |
||
36 | #include "heap.h" |
||
37 | #include "heapacc.h" |
||
38 | |||
39 | |||
40 | #if defined(__SMALL_DATA__) |
||
41 | |||
42 | _WCRTLINK void free( void *stg ) |
||
43 | { |
||
44 | _nfree( stg ); |
||
45 | } |
||
46 | |||
47 | #endif |
||
48 | |||
49 | struct miniheapblkp _WCNEAR *__MiniHeapFreeRover; |
||
50 | |||
51 | _WCRTLINK void _nfree( void _WCNEAR *stg ) |
||
52 | { |
||
53 | mheapptr p1,p2; |
||
54 | |||
55 | if( !stg ) |
||
56 | return; |
||
57 | |||
58 | _AccessNHeap(); |
||
59 | do { |
||
60 | // first try some likely locations |
||
61 | p1 = __MiniHeapFreeRover; |
||
62 | if( p1 ) { |
||
63 | if( (PTR)p1 <= (PTR)stg && (PTR)p1+p1->len > (PTR)stg ) { |
||
64 | break; |
||
65 | } |
||
66 | p2 = p1; |
||
67 | p1 = p1->prev; |
||
68 | if( p1 ) { |
||
69 | if( (PTR)p1 <= (PTR)stg && (PTR)p1+p1->len > (PTR)stg ) { |
||
70 | break; |
||
71 | } |
||
72 | } |
||
73 | p1 = p2->next; |
||
74 | if( p1 ) { |
||
75 | if( (PTR)p1 <= (PTR)stg && (PTR)p1+p1->len > (PTR)stg ) { |
||
76 | break; |
||
77 | } |
||
78 | } |
||
79 | } |
||
80 | p1 = __MiniHeapRover; |
||
81 | if( p1 ) { |
||
82 | if( (PTR)p1 <= (PTR)stg && (PTR)p1+p1->len > (PTR)stg ) { |
||
83 | break; |
||
84 | } |
||
85 | p2 = p1; |
||
86 | p1 = p1->prev; |
||
87 | if( p1 ) { |
||
88 | if( (PTR)p1 <= (PTR)stg && (PTR)p1+p1->len > (PTR)stg ) { |
||
89 | break; |
||
90 | } |
||
91 | } |
||
92 | p1 = p2->next; |
||
93 | if( p1 ) { |
||
94 | if( (PTR)p1 <= (PTR)stg && (PTR)p1+p1->len > (PTR)stg ) { |
||
95 | break; |
||
96 | } |
||
97 | } |
||
98 | } |
||
99 | |||
100 | // not found near rover, so search the list |
||
101 | for( p1 = __nheapbeg; p1; p1 = p1->next ) { |
||
102 | if( (PTR)p1 <= (PTR)stg && (PTR)p1+p1->len > (PTR)stg ) { |
||
103 | // break twice! |
||
104 | goto found_it; |
||
105 | } |
||
106 | } |
||
107 | |||
108 | // this pointer is not in the heap |
||
109 | _ReleaseNHeap(); |
||
110 | return; |
||
111 | } while( 0 ); |
||
112 | |||
113 | found_it: |
||
114 | // we found the miniheap, free the storage |
||
115 | __MemFree( (unsigned)stg, _DGroup(), (unsigned) p1 ); |
||
116 | __MiniHeapFreeRover = p1; |
||
117 | if( p1 < __MiniHeapRover ) { |
||
118 | if( p1->largest_blk > __LargestSizeB4MiniHeapRover ) { |
||
119 | __LargestSizeB4MiniHeapRover = p1->largest_blk; |
||
120 | } |
||
121 | } |
||
122 | _ReleaseNHeap(); |
||
123 | }>=>=>=>=>=>=>=> |