Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
capmt: fix the mutexes and do reconfigure faster, fixes#2344
  • Loading branch information
perexg committed Oct 5, 2014
1 parent c434bc4 commit bd91b96
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/descrambler/capmt.c
Expand Up @@ -1469,12 +1469,16 @@ capmt_thread(void *aux)
#endif
}

caclient_set_status((caclient_t *)capmt, CACLIENT_STATUS_DISCONNECTED);

pthread_mutex_lock(&capmt->capmt_mutex);
if (capmt->capmt_reconfigure) {
capmt->capmt_reconfigure = 0;
capmt->capmt_running = 1;
pthread_mutex_unlock(&capmt->capmt_mutex);
continue;
}

caclient_set_status((caclient_t *)capmt, CACLIENT_STATUS_DISCONNECTED);
pthread_mutex_unlock(&capmt->capmt_mutex);

/* close opened sockets */
for (i = 0; i < MAX_SOCKETS; i++)
Expand All @@ -1483,7 +1487,12 @@ capmt_thread(void *aux)
if (capmt->capmt_adapters[i].ca_sock >= 0)
close(capmt->capmt_adapters[i].ca_sock);

if (!capmt->capmt_running) continue;
pthread_mutex_lock(&capmt->capmt_mutex);

if (!capmt->capmt_running) {
pthread_mutex_unlock(&capmt->capmt_mutex);
continue;
}

/* schedule reconnection */
if(subscriptions_active() && !fatal) {
Expand All @@ -1497,9 +1506,9 @@ capmt_thread(void *aux)

tvhlog(LOG_INFO, "capmt", "%s: Automatic reconnection attempt in in %d seconds", idnode_get_title(&capmt->cac_id), d);

pthread_mutex_lock(&global_lock);
pthread_cond_timedwait(&capmt->capmt_cond, &global_lock, &ts);
pthread_mutex_unlock(&global_lock);

pthread_mutex_unlock(&capmt->capmt_mutex);
}

tvhlog(LOG_INFO, "capmt", "%s inactive", capmt_name(capmt));
Expand Down

0 comments on commit bd91b96

Please sign in to comment.