[LibOS] Move helper threads' status checking after lock acquisition

This commit is contained in:
borysp
2019-10-18 02:43:41 -07:00
committed by Dmitrii Kuvaiskii
parent 6866bdb2c6
commit f71bd2ca84
2 changed files with 20 additions and 5 deletions
+11 -1
View File
@@ -849,8 +849,13 @@ static int create_ipc_helper(void) {
* problematic for the thread itself to release its own resources e.g. stack).
*/
struct shim_thread* terminate_ipc_helper(void) {
if (ipc_helper_state != HELPER_ALIVE)
/* First check if thread is alive. */
lock(&ipc_helper_lock);
if (ipc_helper_state != HELPER_ALIVE) {
unlock(&ipc_helper_lock);
return NULL;
}
unlock(&ipc_helper_lock);
/* NOTE: Graphene doesn't have an abstraction of a queue of pending signals
* between communicating processes (instead all communication is done over
@@ -867,6 +872,11 @@ struct shim_thread* terminate_ipc_helper(void) {
DkThreadDelayExecution(500);
lock(&ipc_helper_lock);
if (ipc_helper_state != HELPER_ALIVE) {
unlock(&ipc_helper_lock);
return NULL;
}
struct shim_thread* ret = ipc_helper_thread;
if (ret)
get_thread(ret);
+9 -4
View File
@@ -114,8 +114,10 @@ int64_t install_async_event(PAL_HANDLE object, uint64_t time,
if (async_helper_state == HELPER_NOTALIVE) {
int ret = create_async_helper();
if (ret < 0)
if (ret < 0) {
unlock(&async_helper_lock);
return ret;
}
}
unlock(&async_helper_lock);
@@ -306,10 +308,13 @@ static int create_async_helper(void) {
* problematic for the thread itself to release its own resources e.g. stack).
*/
struct shim_thread* terminate_async_helper(void) {
if (async_helper_state != HELPER_ALIVE)
return NULL;
lock(&async_helper_lock);
if (async_helper_state != HELPER_ALIVE) {
unlock(&async_helper_lock);
return NULL;
}
struct shim_thread* ret = async_helper_thread;
if (ret)
get_thread(ret);