Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Xin Wang
codes-dev
Commits
100a45c3
Commit
100a45c3
authored
Jul 22, 2015
by
Jonathan Jenkins
Browse files
second pass at rc-stack implementation
parent
d752b32a
Changes
4
Hide whitespace changes
Inline
Side-by-side
codes/rc-stack.h
View file @
100a45c3
...
...
@@ -28,29 +28,26 @@
struct
rc_stack
;
void
rc_stack_create
(
struct
rc_stack
**
s
);
/* setting free_data to non-zero will free the data associated with each entry
*/
void
rc_stack_destroy
(
int
free_data
,
struct
rc_stack
*
s
);
void
rc_stack_destroy
(
struct
rc_stack
*
s
);
/* push data to the stack with time given by tw_now(lp) */
/* push data to the stack with time given by tw_now(lp).
* a NULL free function will do nothing with the data on GC
* (useful for debugging) */
void
rc_stack_push
(
tw_lp
*
lp
,
tw_lp
const
*
lp
,
void
*
data
,
void
(
*
free_fn
)(
void
*
),
struct
rc_stack
*
s
);
/* pop data from the stack for rc (tw_error if stack empty) */
void
*
rc_stack_pop
(
struct
rc_stack
*
s
);
/* get the number of entries on the stack (mostly for debug) */
int
rc_stack_count
(
struct
rc_stack
*
s
);
int
rc_stack_count
(
struct
rc_stack
const
*
s
);
/* remove entries from the stack with generation time < GVT (lp->pe->GVT)
*
* setting free_data to non-zero will free the associated data */
void
rc_stack_gc
(
tw_lp
*
lp
,
int
free_data
,
struct
rc_stack
*
s
);
/* remove entries from the stack with generation time < GVT (lp->pe->GVT).
* a NULL lp causes a delete-all */
void
rc_stack_gc
(
tw_lp
const
*
lp
,
struct
rc_stack
*
s
);
#endif
/* end of include guard: RC-STACK_H */
...
...
src/Makefile.subdir
View file @
100a45c3
...
...
@@ -58,7 +58,8 @@ nobase_include_HEADERS = \
codes/resource-lp.h
\
codes/local-storage-model.h
\
codes/rc-stack.h
\
codes/codes-jobmap.h
codes/codes-jobmap.h
\
codes/codes-callback.h
#codes/codes-nw-workload.h
...
...
src/util/rc-stack.c
View file @
100a45c3
...
...
@@ -12,6 +12,7 @@
typedef
struct
rc_entry_s
{
tw_stime
time
;
void
*
data
;
void
(
*
free_fn
)(
void
*
);
struct
qlist_head
ql
;
}
rc_entry
;
...
...
@@ -29,35 +30,21 @@ void rc_stack_create(struct rc_stack **s){
*
s
=
ss
;
}
void
rc_stack_destroy
(
int
free_data
,
struct
rc_stack
*
s
)
{
#define FREE_ENTRY(_e, _free_data)\
do { \
if (_e != NULL){\
rc_entry *r = qlist_entry(_e, rc_entry, ql);\
if (_free_data) free(r->data);\
free(r);\
} \
} while(0)
struct
qlist_head
*
ent
,
*
ent_prev
=
NULL
;
qlist_for_each
(
ent
,
&
s
->
head
)
{
FREE_ENTRY
(
ent_prev
,
free_data
);
ent_prev
=
ent
;
}
FREE_ENTRY
(
ent_prev
,
free_data
);
void
rc_stack_destroy
(
struct
rc_stack
*
s
)
{
rc_stack_gc
(
NULL
,
s
);
free
(
s
);
#undef FREE_ENTRY
}
void
rc_stack_push
(
tw_lp
*
lp
,
tw_lp
const
*
lp
,
void
*
data
,
void
(
*
free_fn
)(
void
*
),
struct
rc_stack
*
s
){
rc_entry
*
ent
=
(
rc_entry
*
)
malloc
(
sizeof
(
*
ent
));
assert
(
ent
);
ent
->
time
=
tw_now
(
lp
);
ent
->
data
=
data
;
ent
->
free_fn
=
free_fn
;
qlist_add_tail
(
&
ent
->
ql
,
&
s
->
head
);
s
->
count
++
;
}
...
...
@@ -76,15 +63,15 @@ void* rc_stack_pop(struct rc_stack *s){
return
ret
;
}
int
rc_stack_count
(
struct
rc_stack
*
s
)
{
return
s
->
count
;
}
int
rc_stack_count
(
struct
rc_stack
const
*
s
)
{
return
s
->
count
;
}
void
rc_stack_gc
(
tw_lp
*
lp
,
int
free_data
,
struct
rc_stack
*
s
)
{
void
rc_stack_gc
(
tw_lp
const
*
lp
,
struct
rc_stack
*
s
)
{
struct
qlist_head
*
ent
=
s
->
head
.
next
;
while
(
ent
!=
&
s
->
head
)
{
rc_entry
*
r
=
qlist_entry
(
ent
,
rc_entry
,
ql
);
if
(
r
->
time
<
lp
->
pe
->
GVT
){
if
(
lp
==
NULL
||
r
->
time
<
lp
->
pe
->
GVT
){
qlist_del
(
ent
);
if
(
free_
data
)
free
(
r
->
data
);
if
(
r
->
free_
fn
)
r
->
free
_fn
(
r
->
data
);
free
(
r
);
s
->
count
--
;
ent
=
s
->
head
.
next
;
...
...
tests/rc-stack-test.c
View file @
100a45c3
...
...
@@ -25,23 +25,28 @@ int main(int argc, char *argv[])
rc_stack_create
(
&
s
);
assert
(
s
!=
NULL
);
int
*
a
=
malloc
(
sizeof
(
*
a
));
int
*
b
=
malloc
(
sizeof
(
*
b
));
int
*
c
=
malloc
(
sizeof
(
*
c
));
*
a
=
1
;
*
b
=
2
;
*
c
=
3
;
int
*
a
,
*
b
,
*
c
;
#define ALLOC_ALL() \
do { \
a = malloc(sizeof(*a)); \
b = malloc(sizeof(*b)); \
c = malloc(sizeof(*c)); \
*a = 1; \
*b = 2; \
*c = 3; \
} while (0)
#define PUSH_ALL() \
do { \
kp.last_time = 1.0; \
rc_stack_push(&lp, a, s); \
rc_stack_push(&lp, a,
free,
s); \
kp.last_time = 2.0; \
rc_stack_push(&lp, b, s); \
rc_stack_push(&lp, b,
free,
s); \
kp.last_time = 3.0; \
rc_stack_push(&lp, c, s); \
rc_stack_push(&lp, c,
free,
s); \
} while (0)
ALLOC_ALL
();
PUSH_ALL
();
void
*
dat
;
...
...
@@ -57,16 +62,18 @@ int main(int argc, char *argv[])
PUSH_ALL
();
/* garbage collect the first two (NOT freeing the pointers first) */
pe
.
GVT
=
2
.
5
;
rc_stack_gc
(
&
lp
,
0
,
s
);
rc_stack_gc
(
&
lp
,
s
);
assert
(
1
==
rc_stack_count
(
s
));
dat
=
rc_stack_pop
(
s
);
assert
(
c
==
dat
);
assert
(
0
==
rc_stack_count
(
s
));
free
(
dat
);
/* destroy everything */
ALLOC_ALL
();
PUSH_ALL
();
rc_stack_destroy
(
1
,
s
);
rc_stack_destroy
(
s
);
return
0
;
}
...
...
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