Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
60fb6bfc
Commit
60fb6bfc
authored
Mar 24, 2008
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sub-page allocations work, still some FIXMEs to go.
parent
3d34b48f
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
447 additions
and
75 deletions
+447
-75
alloc/alloc.c
alloc/alloc.c
+418
-63
alloc/test/run.c
alloc/test/run.c
+29
-12
No files found.
alloc/alloc.c
View file @
60fb6bfc
This diff is collapsed.
Click to expand it.
alloc/test/run.c
View file @
60fb6bfc
...
...
@@ -24,13 +24,32 @@ static bool unique(void *p[], unsigned int num)
return
true
;
}
static
bool
free_every_second_one
(
void
*
mem
,
unsigned
int
num
,
void
*
p
[])
{
unsigned
int
i
;
/* Free every second one. */
for
(
i
=
0
;
i
<
num
;
i
+=
2
)
{
alloc_free
(
mem
,
POOL_SIZE
,
p
[
i
]);
if
(
!
alloc_check
(
mem
,
POOL_SIZE
))
return
false
;
}
for
(
i
=
1
;
i
<
num
;
i
+=
2
)
{
alloc_free
(
mem
,
POOL_SIZE
,
p
[
i
]);
if
(
!
alloc_check
(
mem
,
POOL_SIZE
))
return
false
;
}
return
true
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
void
*
mem
;
unsigned
int
i
,
num
,
max_size
;
void
*
p
[
POOL_SIZE
];
plan_tests
(
1
41
);
plan_tests
(
1
33
);
/* FIXME: Needs to be page aligned for now. */
posix_memalign
(
&
mem
,
getpagesize
(),
POOL_SIZE
);
...
...
@@ -85,15 +104,7 @@ int main(int argc, char *argv[])
/* Uniqueness check */
ok1
(
unique
(
p
,
num
));
/* Free every second one. */
for
(
i
=
0
;
i
<
num
;
i
+=
2
)
{
alloc_free
(
mem
,
POOL_SIZE
,
p
[
i
]);
ok1
(
alloc_check
(
mem
,
POOL_SIZE
));
}
for
(
i
=
1
;
i
<
num
;
i
+=
2
)
{
alloc_free
(
mem
,
POOL_SIZE
,
p
[
i
]);
ok1
(
alloc_check
(
mem
,
POOL_SIZE
));
}
ok1
(
free_every_second_one
(
mem
,
num
,
p
));
ok1
(
alloc_check
(
mem
,
POOL_SIZE
));
/* Should be able to reallocate max size. */
...
...
@@ -111,14 +122,14 @@ int main(int argc, char *argv[])
ok1
(
alloc_check
(
mem
,
POOL_SIZE
));
/* Alignment constraints should be met, as long as powers of two */
for
(
i
=
0
;
i
<
POOL_ORD
-
2
/* FIXME: Should be -1 */
;
i
++
)
{
for
(
i
=
0
;
i
<
POOL_ORD
-
1
;
i
++
)
{
p
[
i
]
=
alloc_get
(
mem
,
POOL_SIZE
,
i
,
1
<<
i
);
ok1
(
p
[
i
]);
ok1
(((
unsigned
long
)
p
[
i
]
%
(
1
<<
i
))
==
0
);
ok1
(
alloc_check
(
mem
,
POOL_SIZE
));
}
for
(
i
=
0
;
i
<
POOL_ORD
-
2
/* FIXME: Should be -1 */
;
i
++
)
{
for
(
i
=
0
;
i
<
POOL_ORD
-
1
;
i
++
)
{
alloc_free
(
mem
,
POOL_SIZE
,
p
[
i
]);
ok1
(
alloc_check
(
mem
,
POOL_SIZE
));
}
...
...
@@ -132,5 +143,11 @@ int main(int argc, char *argv[])
ok1
(
alloc_check
(
mem
,
POOL_SIZE
));
}
/* Alignment check for a 0-byte allocation. Corner case. */
p
[
0
]
=
alloc_get
(
mem
,
POOL_SIZE
,
0
,
1
<<
(
POOL_ORD
-
1
));
ok1
(
alloc_check
(
mem
,
POOL_SIZE
));
alloc_free
(
mem
,
POOL_SIZE
,
p
[
0
]);
ok1
(
alloc_check
(
mem
,
POOL_SIZE
));
return
exit_status
();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment