Skip to content

Commit

Permalink
utilities: Split thread internal callback function
Browse files Browse the repository at this point in the history
__try is used in pthread_cleanup_push when CLEANUP_SET is used as the
pthread cleanup model. That can't be used in functions with objects that
have destructors, so move it into a separate function.

Prevents compile errors on non-release Windows builds if other things in
the internal callback function change.
  • Loading branch information
turtleli committed Oct 7, 2019
1 parent cc52be1 commit aee571e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions common/include/Utilities/PersistentThread.h
Expand Up @@ -200,6 +200,7 @@ class pxThread
void _ThreadCleanup();

static void *_internal_callback(void *func);
static void internal_callback_helper(void *func);
static void _pt_callback_cleanup(void *handle);
};
}
13 changes: 11 additions & 2 deletions common/src/Utilities/ThreadTools.cpp
Expand Up @@ -685,12 +685,21 @@ void *Threading::pxThread::_internal_callback(void *itsme)
{
if (!pxAssertDev(itsme != NULL, wxNullChar))
return NULL;
pxThread &owner = *((pxThread *)itsme);

internal_callback_helper(itsme);
return nullptr;
}

// __try is used in pthread_cleanup_push when CLEANUP_SEH is used as the cleanup model.
// That can't be used in a function that has objects that require unwinding (compile
// error C2712), so move it into a separate function.
void Threading::pxThread::internal_callback_helper(void *itsme)
{
pxThread &owner = *static_cast<pxThread *>(itsme);

pthread_cleanup_push(_pt_callback_cleanup, itsme);
owner._internal_execute();
pthread_cleanup_pop(true);
return NULL;
}

void Threading::pxThread::_DoSetThreadName(const wxString &name)
Expand Down

0 comments on commit aee571e

Please sign in to comment.