Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/nfcandroid_nfc_hidlimpl/halimpl/tml/phTmlNfc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,9 @@ void phTmlNfc_CleanUp(void) {
*******************************************************************************/
NFCSTATUS phTmlNfc_Shutdown(void) {
NFCSTATUS wShutdownStatus = NFCSTATUS_SUCCESS;
// Timeout (in seconds) when joining threads. must be greater than NCI_CMD_RSP_TIMEOUT_MS defined in the kernel driver
#define NXP_THREAD_JOIN_TO 3;
struct timespec ts;

/* Check whether TML is Initialized */
if (NULL != gpphTmlNfc_Context) {
Expand All @@ -643,11 +646,23 @@ NFCSTATUS phTmlNfc_Shutdown(void) {
sem_post(&gpphTmlNfc_Context->postMsgSemaphore);
usleep(1000);
pthread_mutex_destroy(&gpphTmlNfc_Context->readInfoUpdateMutex);
if (0 != pthread_join(gpphTmlNfc_Context->readerThread, (void**)NULL)) {
NXPLOG_TML_E("Fail to kill reader thread!");
//Try to stop the reader thread... if not possible then cancel it
clock_gettime(CLOCK_REALTIME, &ts);
ts.tv_sec += NXP_THREAD_JOIN_TO;
if (0 != pthread_timedjoin_np(gpphTmlNfc_Context->readerThread, (void**)NULL, &ts) ) {
pthread_cancel(gpphTmlNfc_Context->readerThread);
if (0 != pthread_join(gpphTmlNfc_Context->readerThread, (void**)NULL)) {
NXPLOG_TML_E("Fail to kill reader thread!");
}
}
if (0 != pthread_join(gpphTmlNfc_Context->writerThread, (void**)NULL)) {
NXPLOG_TML_E("Fail to kill writer thread!");
// Try to stop the writer thread... if not possible then cancel it
clock_gettime(CLOCK_REALTIME, &ts);
ts.tv_sec += NXP_THREAD_JOIN_TO;
if (0 != pthread_timedjoin_np(gpphTmlNfc_Context->writerThread, (void**)NULL, &ts) ) {
pthread_cancel(gpphTmlNfc_Context->writerThread);
if (0 != pthread_join(gpphTmlNfc_Context->writerThread, (void**)NULL)) {
NXPLOG_TML_E("Fail to kill writer thread!");
}
}
NXPLOG_TML_D("bThreadDone == 0");

Expand Down