LIST_HEAD(ecm_section_list, ecm_section);
static struct cwc_queue cwcs;
static pthread_cond_t cwc_config_changed;
+static pthread_mutex_t cwc_mutex;
static char *crypt_md5(const char *pw, const char *salt);
/**
int cwc_writer_running;
struct cwc_message_queue cwc_writeq;
- TAILQ_ENTRY(cwc) cwc_link; /* Linkage protected via global_lock */
+ TAILQ_ENTRY(cwc) cwc_link; /* Linkage protected via cwc_mutex */
struct cwc_service_list cwc_services;
"Obtained key for for service \"%s\" in %lld ms, from %s",
t->s_svcname, delay, ct->cs_cwc->cwc_hostname);
- pthread_mutex_lock(&t->s_stream_mutex);
ct->cs_keystate = CS_RESOLVED;
memcpy(ct->cs_cw, msg + 3, 16);
ct->cs_pending_cw_update = 1;
- pthread_mutex_unlock(&t->s_stream_mutex);
}
}
/**
* Handle running reply
- * global_lock is held
+ * cwc_mutex is held
*/
static int
cwc_running_reply(cwc_t *cwc, uint8_t msgtype, uint8_t *msg, int len)
{
int r;
- pthread_mutex_unlock(&global_lock);
+ pthread_mutex_unlock(&cwc_mutex);
r = tcp_read_timeout(cwc->cwc_fd, buf, len, timeout);
- pthread_mutex_lock(&global_lock);
+ pthread_mutex_lock(&cwc_mutex);
if(cwc_must_break(cwc))
return ECONNABORTED;
struct timespec ts;
int attempts = 0;
- pthread_mutex_lock(&global_lock);
+ pthread_mutex_lock(&cwc_mutex);
while(cwc->cwc_running) {
while(cwc->cwc_running && cwc->cwc_enabled == 0)
- pthread_cond_wait(&cwc->cwc_cond, &global_lock);
+ pthread_cond_wait(&cwc->cwc_cond, &cwc_mutex);
snprintf(hostname, sizeof(hostname), "%s", cwc->cwc_hostname);
port = cwc->cwc_port;
tvhlog(LOG_INFO, "cwc", "Attemping to connect to %s:%d", hostname, port);
- pthread_mutex_unlock(&global_lock);
+ pthread_mutex_unlock(&cwc_mutex);
fd = tcp_connect(hostname, port, errbuf, sizeof(errbuf), 10);
- pthread_mutex_lock(&global_lock);
+ pthread_mutex_lock(&cwc_mutex);
if(fd == -1) {
attempts++;
"%s: Automatic connection attempt in in %d seconds",
cwc->cwc_hostname, d);
- pthread_cond_timedwait(&cwc_config_changed, &global_lock, &ts);
+ pthread_cond_timedwait(&cwc_config_changed, &cwc_mutex, &ts);
}
tvhlog(LOG_INFO, "cwc", "%s destroyed", cwc->cwc_hostname);
free((void *)cwc->cwc_hostname);
free(cwc);
- pthread_mutex_unlock(&global_lock);
+ pthread_mutex_unlock(&cwc_mutex);
return NULL;
}
{
cwc_t *cwc;
- lock_assert(&global_lock);
+ pthread_mutex_lock(&cwc_mutex);
TAILQ_FOREACH(cwc, &cwcs, cwc_link) {
if(cwc->cwc_forward_emm && cwc->cwc_writer_running) {
}
}
}
+ pthread_mutex_unlock(&cwc_mutex);
}
}
/**
- *
+ * t->s_streaming_mutex is held
*/
static void
cwc_table_input(struct th_descrambler *td, struct service *t,
}
/**
- * global_lock is held
+ * cwc_mutex is held
* s_stream_mutex is held
*/
static void
/**
* Check if our CAID's matches, and if so, link
*
- * global_lock is held
+ * global_lock is held. Not that we care about that, but either way, it is.
*/
void
cwc_service_start(service_t *t)
cwc_service_t *ct;
th_descrambler_t *td;
- lock_assert(&global_lock);
+ pthread_mutex_lock(&cwc_mutex);
TAILQ_FOREACH(cwc, &cwcs, cwc_link) {
if(cwc->cwc_caid == 0)
continue;
service_nicename(t), cwc->cwc_hostname, cwc->cwc_port);
}
+ pthread_mutex_unlock(&cwc_mutex);
}
static void
cwc_destroy(cwc_t *cwc)
{
- lock_assert(&global_lock);
+ pthread_mutex_lock(&cwc_mutex);
TAILQ_REMOVE(&cwcs, cwc, cwc_link);
cwc->cwc_running = 0;
pthread_cond_signal(&cwc->cwc_cond);
+ pthread_mutex_unlock(&cwc_mutex);
}
if((cwc = cwc_entry_find(id, maycreate)) == NULL)
return NULL;
- lock_assert(&global_lock);
-
if((s = htsmsg_get_str(values, "username")) != NULL) {
free(cwc->cwc_username);
cwc->cwc_username = strdup(s);
.dtc_record_delete = cwc_entry_delete,
.dtc_read_access = ACCESS_ADMIN,
.dtc_write_access = ACCESS_ADMIN,
+ .dtc_mutex = &cwc_mutex,
};
dtable_t *dt;
TAILQ_INIT(&cwcs);
-
+ pthread_mutex_init(&cwc_mutex, NULL);
pthread_cond_init(&cwc_config_changed, NULL);
dt = dtable_create(&cwc_dtc, "cwc", NULL);