]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Keep CWC in a separate lock domain to avoid waiting for global_lock
authorAndreas Öman <andreas@lonelycoder.com>
Tue, 25 Jan 2011 21:48:01 +0000 (22:48 +0100)
committerAndreas Öman <andreas@lonelycoder.com>
Tue, 25 Jan 2011 21:58:00 +0000 (22:58 +0100)
src/access.c
src/capmt.c
src/channels.c
src/cwc.c
src/dtable.h
src/dvb/dvb_satconf.c
src/dvr/dvr_autorec.c
src/webui/extjs.c

index 6de0d728d03568515c482673389d5934969436c0..e04f7ad5128014b6c15ee21408071b2371bd4be8 100644 (file)
@@ -409,6 +409,7 @@ static const dtable_class_t access_dtc = {
   .dtc_record_delete  = access_record_delete,
   .dtc_read_access = ACCESS_ADMIN,
   .dtc_write_access = ACCESS_ADMIN,
+  .dtc_mutex = &global_lock,
 };
 
 /**
index 0a0cefecf37f3d79c524cdd66cf4f4c177d2655b..18cdf2dae45b6e058d49354ef7d542126e06054e 100644 (file)
@@ -841,6 +841,7 @@ static const dtable_class_t capmt_dtc = {
   .dtc_record_delete  = capmt_entry_delete,
   .dtc_read_access = ACCESS_ADMIN,
   .dtc_write_access = ACCESS_ADMIN,
+  .dtc_mutex = &global_lock,
 };
 
 /**
index 8dd409f9f3bc611f80e8b31de983b4003ae4f6cb..f13e0ed4699868d2853666c0dd3690bff9c083e0 100644 (file)
@@ -858,6 +858,7 @@ static const dtable_class_t channel_tags_dtc = {
   .dtc_record_delete  = channel_tag_record_delete,
   .dtc_read_access = ACCESS_ADMIN,
   .dtc_write_access = ACCESS_ADMIN,
+  .dtc_mutex = &global_lock,
 };
 
 
index 8eb098fef98cc1d57aa56514ef183e59f08d7934..d3dd460abdc824a6f9434ddfdc96e80e7499a415 100644 (file)
--- a/src/cwc.c
+++ b/src/cwc.c
@@ -95,6 +95,7 @@ TAILQ_HEAD(cwc_message_queue, cwc_message);
 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);
 
 /**
@@ -202,7 +203,7 @@ typedef struct cwc {
   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;
 
@@ -770,18 +771,16 @@ handle_ecm_reply(cwc_service_t *ct, ecm_section_t *es, uint8_t *msg,
             "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)
@@ -836,9 +835,9 @@ cwc_read(cwc_t *cwc, void *buf, size_t len, int timeout)
 {
   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;
@@ -1031,23 +1030,23 @@ cwc_thread(void *aux)
   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++;
@@ -1092,7 +1091,7 @@ cwc_thread(void *aux)
           "%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);
@@ -1110,7 +1109,7 @@ cwc_thread(void *aux)
   free((void *)cwc->cwc_hostname);
   free(cwc);
 
-  pthread_mutex_unlock(&global_lock);
+  pthread_mutex_unlock(&cwc_mutex);
   return NULL;
 }
 
@@ -1164,7 +1163,7 @@ cwc_emm(uint8_t *data, int len)
 {
   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) {
@@ -1189,6 +1188,7 @@ cwc_emm(uint8_t *data, int len)
       }
     }
   }
+  pthread_mutex_unlock(&cwc_mutex);
 }
 
 
@@ -1447,7 +1447,7 @@ cwc_emm_viaccess(cwc_t *cwc, uint8_t *data, int mlen)
 }
 
 /**
- *
+ * t->s_streaming_mutex is held
  */
 static void
 cwc_table_input(struct th_descrambler *td, struct service *t,
@@ -1667,7 +1667,7 @@ cwc_descramble(th_descrambler_t *td, service_t *t, struct elementary_stream *st,
 }
 
 /**
- * global_lock is held
+ * cwc_mutex is held
  * s_stream_mutex is held
  */
 static void 
@@ -1715,7 +1715,7 @@ cwc_find_stream_by_caid(service_t *t, int caid)
 /**
  * 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)
@@ -1724,7 +1724,7 @@ 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;
@@ -1753,6 +1753,7 @@ cwc_service_start(service_t *t)
           service_nicename(t), cwc->cwc_hostname, cwc->cwc_port);
 
   }
+  pthread_mutex_unlock(&cwc_mutex);
 }
 
 
@@ -1762,10 +1763,11 @@ cwc_service_start(service_t *t)
 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);
 }
 
 
@@ -1890,8 +1892,6 @@ cwc_entry_update(void *opaque, const char *id, htsmsg_t *values, int maycreate)
   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);
@@ -2025,6 +2025,7 @@ static const dtable_class_t cwc_dtc = {
   .dtc_record_delete  = cwc_entry_delete,
   .dtc_read_access = ACCESS_ADMIN,
   .dtc_write_access = ACCESS_ADMIN,
+  .dtc_mutex = &cwc_mutex,
 };
 
 
@@ -2038,7 +2039,7 @@ cwc_init(void)
   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);
index fd0b422d31c733f22ec97c6af0e95ab086ed18d1..5a480ac299b820888d64643768e8cd624e71c831 100644 (file)
@@ -40,6 +40,8 @@ typedef struct dtable_class {
   int dtc_read_access;
   int dtc_write_access;
 
+  pthread_mutex_t *dtc_mutex;
+
 } dtable_class_t;
 
 
index 964754ea61791ba57362391e6531ce3dd0291f53..6a41e35ce10eb1e5b3e40ed28f69255c1ae0e504 100644 (file)
@@ -218,6 +218,7 @@ static const dtable_class_t satconf_dtc = {
   .dtc_record_delete  = satconf_entry_delete,
   .dtc_read_access    = ACCESS_ADMIN,
   .dtc_write_access   = ACCESS_ADMIN,
+  .dtc_mutex = &global_lock,
 };
 
 
index 91f18fa5b04c0bcd7c36cbe1622a9eef478e0f2f..bd3e148bc21b77b3abdd83dc470c5da936121449 100644 (file)
@@ -403,6 +403,7 @@ static const dtable_class_t autorec_dtc = {
   .dtc_record_delete  = autorec_record_delete,
   .dtc_read_access = ACCESS_RECORDER,
   .dtc_write_access = ACCESS_RECORDER,
+  .dtc_mutex = &global_lock,
 };
 
 /**
index 7b5041cb63fad4f7681fd1c200cc8c9448196e59..d6c1caafad10c568c278918ec8a34f17a2d735f9 100644 (file)
@@ -230,7 +230,7 @@ extjs_tablemgr(http_connection_t *hc, const char *remain, void *opaque)
 
   in = entries != NULL ? htsmsg_json_deserialize(entries) : NULL;
 
-  pthread_mutex_lock(&global_lock);
+  pthread_mutex_lock(dt->dt_dtc->dtc_mutex);
 
   if(!strcmp(op, "create")) {
     if(http_access_verify(hc, dt->dt_dtc->dtc_write_access))
@@ -264,15 +264,15 @@ extjs_tablemgr(http_connection_t *hc, const char *remain, void *opaque)
 
   } else {
   bad:
-    pthread_mutex_unlock(&global_lock);
+    pthread_mutex_lock(dt->dt_dtc->dtc_mutex);
     return HTTP_STATUS_BAD_REQUEST;
 
   noaccess:
-    pthread_mutex_unlock(&global_lock);
+    pthread_mutex_lock(dt->dt_dtc->dtc_mutex);
     return HTTP_STATUS_BAD_REQUEST;
   }
 
-  pthread_mutex_unlock(&global_lock);
+  pthread_mutex_lock(dt->dt_dtc->dtc_mutex);
 
   if(in != NULL)
     htsmsg_destroy(in);