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