Commit 6979ad47 authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

don't mess-up the list by clearing linked cells.

parent 981be8bc
...@@ -434,9 +434,8 @@ void space_regrid(struct space *s, int verbose) { ...@@ -434,9 +434,8 @@ void space_regrid(struct space *s, int verbose) {
// message( "rebuilding upper-level cells took %.3f %s." , // message( "rebuilding upper-level cells took %.3f %s." ,
// clocks_from_ticks(double)(getticks() - tic), clocks_getunit()); // clocks_from_ticks(double)(getticks() - tic), clocks_getunit());
} /* re-build upper-level cells? */ } /* re-build upper-level cells? */
else {/* Otherwise, just clean up the cells. */
else { /* Otherwise, just clean up the cells. */
/* Free the old cells, if they were allocated. */ /* Free the old cells, if they were allocated. */
threadpool_map(&s->e->threadpool, space_rebuild_recycle_mapper, threadpool_map(&s->e->threadpool, space_rebuild_recycle_mapper,
...@@ -1623,16 +1622,13 @@ void space_split_mapper(void *map_data, int num_cells, void *extra_data) { ...@@ -1623,16 +1622,13 @@ void space_split_mapper(void *map_data, int num_cells, void *extra_data) {
} }
/** /**
* @brief Return a used cell to the buffer od unused sub-cells. * @brief Return a used cell to the buffer of unused sub-cells.
* *
* @param s The #space. * @param s The #space.
* @param c The #cell. * @param c The #cell.
*/ */
void space_recycle(struct space *s, struct cell *c) { void space_recycle(struct space *s, struct cell *c) {
/* Lock the space. */
lock_lock(&s->lock);
/* Clear the cell. */ /* Clear the cell. */
if (lock_destroy(&c->lock) != 0) error("Failed to destroy spinlock."); if (lock_destroy(&c->lock) != 0) error("Failed to destroy spinlock.");
...@@ -1642,6 +1638,9 @@ void space_recycle(struct space *s, struct cell *c) { ...@@ -1642,6 +1638,9 @@ void space_recycle(struct space *s, struct cell *c) {
/* Clear the cell data. */ /* Clear the cell data. */
bzero(c, sizeof(struct cell)); bzero(c, sizeof(struct cell));
/* Lock the space. */
lock_lock(&s->lock);
/* Hook this cell into the buffer. */ /* Hook this cell into the buffer. */
c->next = s->cells_sub; c->next = s->cells_sub;
s->cells_sub = c; s->cells_sub = c;
...@@ -1651,6 +1650,16 @@ void space_recycle(struct space *s, struct cell *c) { ...@@ -1651,6 +1650,16 @@ void space_recycle(struct space *s, struct cell *c) {
lock_unlock_blind(&s->lock); lock_unlock_blind(&s->lock);
} }
/**
* @brief Return a list of used cells to the buffer of unused sub-cells.
*
* @param s The #space.
* @param list_begin Pointer to the first #cell in the linked list of
* cells joined by their @c next pointers.
* @param list_begin Pointer to the last #cell in the linked list of
* cells joined by their @c next pointers. It is assumed that this
* cell's @c next pointer is @c NULL.
*/
void space_recycle_list(struct space *s, struct cell *list_begin, void space_recycle_list(struct space *s, struct cell *list_begin,
struct cell *list_end) { struct cell *list_end) {
...@@ -1662,10 +1671,10 @@ void space_recycle_list(struct space *s, struct cell *list_begin, ...@@ -1662,10 +1671,10 @@ void space_recycle_list(struct space *s, struct cell *list_begin,
if (lock_destroy(&c->lock) != 0) error("Failed to destroy spinlock."); if (lock_destroy(&c->lock) != 0) error("Failed to destroy spinlock.");
/* Clear this cell's sort arrays. */ /* Clear this cell's sort arrays. */
if (c->sort != NULL) free(c->sort); if (c->sort != NULL) {
free(c->sort);
/* Clear the cell data. */ c->sort = NULL;
bzero(c, sizeof(struct cell)); }
/* Count this cell. */ /* Count this cell. */
count += 1; count += 1;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment