Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SWIFT
SWIFTsim
Commits
6a12eeae
Commit
6a12eeae
authored
Feb 22, 2017
by
Matthieu Schaller
Browse files
Added the functions to lock/unlock a cell's multipole representation
parent
1c7e15cb
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/cell.c
View file @
6a12eeae
...
...
@@ -453,6 +453,70 @@ int cell_glocktree(struct cell *c) {
}
}
/**
* @brief Lock a cell for access to its #multipole and hold its parents.
*
* @param c The #cell.
* @return 0 on success, 1 on failure
*/
int
cell_mlocktree
(
struct
cell
*
c
)
{
TIMER_TIC
/* First of all, try to lock this cell. */
if
(
c
->
mhold
||
lock_trylock
(
&
c
->
mlock
)
!=
0
)
{
TIMER_TOC
(
timer_locktree
);
return
1
;
}
/* Did somebody hold this cell in the meantime? */
if
(
c
->
mhold
)
{
/* Unlock this cell. */
if
(
lock_unlock
(
&
c
->
mlock
)
!=
0
)
error
(
"Failed to unlock cell."
);
/* Admit defeat. */
TIMER_TOC
(
timer_locktree
);
return
1
;
}
/* Climb up the tree and lock/hold/unlock. */
struct
cell
*
finger
;
for
(
finger
=
c
->
parent
;
finger
!=
NULL
;
finger
=
finger
->
parent
)
{
/* Lock this cell. */
if
(
lock_trylock
(
&
finger
->
mlock
)
!=
0
)
break
;
/* Increment the hold. */
atomic_inc
(
&
finger
->
mhold
);
/* Unlock the cell. */
if
(
lock_unlock
(
&
finger
->
mlock
)
!=
0
)
error
(
"Failed to unlock cell."
);
}
/* If we reached the top of the tree, we're done. */
if
(
finger
==
NULL
)
{
TIMER_TOC
(
timer_locktree
);
return
0
;
}
/* Otherwise, we hit a snag. */
else
{
/* Undo the holds up to finger. */
for
(
struct
cell
*
finger2
=
c
->
parent
;
finger2
!=
finger
;
finger2
=
finger2
->
parent
)
atomic_dec
(
&
finger2
->
mhold
);
/* Unlock this cell. */
if
(
lock_unlock
(
&
c
->
mlock
)
!=
0
)
error
(
"Failed to unlock cell."
);
/* Admit defeat. */
TIMER_TOC
(
timer_locktree
);
return
1
;
}
}
/**
* @brief Lock a cell for access to its array of #spart and hold its parents.
*
...
...
@@ -555,6 +619,25 @@ void cell_gunlocktree(struct cell *c) {
TIMER_TOC
(
timer_locktree
);
}
/**
* @brief Unlock a cell's parents for access to its #multipole.
*
* @param c The #cell.
*/
void
cell_munlocktree
(
struct
cell
*
c
)
{
TIMER_TIC
/* First of all, try to unlock this cell. */
if
(
lock_unlock
(
&
c
->
mlock
)
!=
0
)
error
(
"Failed to unlock cell."
);
/* Climb up the tree and unhold the parents. */
for
(
struct
cell
*
finger
=
c
->
parent
;
finger
!=
NULL
;
finger
=
finger
->
parent
)
atomic_dec
(
&
finger
->
mhold
);
TIMER_TOC
(
timer_locktree
);
}
/**
* @brief Unlock a cell's parents for access to #spart array.
*
...
...
src/cell.h
View file @
6a12eeae
...
...
@@ -257,6 +257,9 @@ struct cell {
/*! Spin lock for various uses (#gpart case). */
swift_lock_type
glock
;
/*! Spin lock for various uses (#multipole case). */
swift_lock_type
mlock
;
/*! Spin lock for various uses (#spart case). */
swift_lock_type
slock
;
...
...
@@ -281,6 +284,9 @@ struct cell {
/*! Is the #gpart data of this cell being used in a sub-cell? */
int
ghold
;
/*! Is the #multipole data of this cell being used in a sub-cell? */
int
mhold
;
/*! Is the #spart data of this cell being used in a sub-cell? */
int
shold
;
...
...
@@ -311,6 +317,8 @@ int cell_locktree(struct cell *c);
void
cell_unlocktree
(
struct
cell
*
c
);
int
cell_glocktree
(
struct
cell
*
c
);
void
cell_gunlocktree
(
struct
cell
*
c
);
int
cell_mlocktree
(
struct
cell
*
c
);
void
cell_munlocktree
(
struct
cell
*
c
);
int
cell_slocktree
(
struct
cell
*
c
);
void
cell_sunlocktree
(
struct
cell
*
c
);
int
cell_pack
(
struct
cell
*
c
,
struct
pcell
*
pc
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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