]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
initial pthread mutex/cond wrappers to detect deadlocks
authorJaroslav Kysela <perex@perex.cz>
Sat, 27 Oct 2018 20:04:27 +0000 (22:04 +0200)
committerJaroslav Kysela <perex@perex.cz>
Tue, 27 Nov 2018 08:17:29 +0000 (09:17 +0100)
146 files changed:
Makefile
src/access.c
src/api/api_access.c
src/api/api_bouquet.c
src/api/api_caclient.c
src/api/api_channel.c
src/api/api_codec.c
src/api/api_dvr.c
src/api/api_epg.c
src/api/api_epggrab.c
src/api/api_esfilter.c
src/api/api_idnode.c
src/api/api_imagecache.c
src/api/api_input.c
src/api/api_mpegts.c
src/api/api_profile.c
src/api/api_raw.c
src/api/api_service.c
src/api/api_status.c
src/api/api_wizard.c
src/atomic.h
src/avahi.c
src/bouquet.c
src/channels.c
src/compat.h
src/dbus.c
src/descrambler/caclient.c
src/descrambler/capmt.c
src/descrambler/cccam.c
src/descrambler/cclient.c
src/descrambler/cclient.h
src/descrambler/constcw.c
src/descrambler/cwc.c
src/descrambler/descrambler.c
src/descrambler/dvbcam.c
src/descrambler/tsdebugcw.c
src/download.c
src/dvr/dvr_autorec.c
src/dvr/dvr_config.c
src/dvr/dvr_db.c
src/dvr/dvr_inotify.c
src/dvr/dvr_rec.c
src/dvr/dvr_timerec.c
src/dvr/dvr_vfsmgr.c
src/epgdb.c
src/epggrab.c
src/epggrab.h
src/epggrab/module.c
src/epggrab/module/eit.c
src/epggrab/module/opentv.c
src/epggrab/module/xmltv.c
src/epggrab/otamux.c
src/esfilter.c
src/fsmonitor.c
src/htsmsg.h
src/htsp_server.c
src/http.c
src/http.h
src/httpc.c
src/idnode.c
src/idnode.h
src/imagecache.c
src/imagecache.h
src/input.h
src/input/mpegts.h
src/input/mpegts/dvb_psi.c
src/input/mpegts/dvb_psi_pmt.c
src/input/mpegts/iptv/iptv.c
src/input/mpegts/iptv/iptv_file.c
src/input/mpegts/iptv/iptv_http.c
src/input/mpegts/iptv/iptv_libav.c
src/input/mpegts/iptv/iptv_pipe.c
src/input/mpegts/iptv/iptv_private.h
src/input/mpegts/iptv/iptv_rtsp.c
src/input/mpegts/iptv/iptv_udp.c
src/input/mpegts/linuxdvb/linuxdvb_adapter.c
src/input/mpegts/linuxdvb/linuxdvb_ca.c
src/input/mpegts/linuxdvb/linuxdvb_ddci.c
src/input/mpegts/linuxdvb/linuxdvb_en50494.c
src/input/mpegts/linuxdvb/linuxdvb_frontend.c
src/input/mpegts/linuxdvb/linuxdvb_private.h
src/input/mpegts/mpegts_input.c
src/input/mpegts/mpegts_mux.c
src/input/mpegts/mpegts_mux_sched.c
src/input/mpegts/mpegts_network_dvb.c
src/input/mpegts/mpegts_service.c
src/input/mpegts/mpegts_table.c
src/input/mpegts/satip/satip.c
src/input/mpegts/satip/satip_frontend.c
src/input/mpegts/satip/satip_private.h
src/input/mpegts/satip/satip_rtsp.c
src/input/mpegts/scanfile.c
src/input/mpegts/tsdemux.c
src/input/mpegts/tsfile/tsfile.c
src/input/mpegts/tsfile/tsfile_input.c
src/input/mpegts/tsfile/tsfile_private.h
src/input/mpegts/tvhdhomerun/tvhdhomerun.c
src/input/mpegts/tvhdhomerun/tvhdhomerun_frontend.c
src/input/mpegts/tvhdhomerun/tvhdhomerun_private.h
src/intlconv.c
src/lang_codes.c
src/main.c
src/notify.c
src/parsers/message.c
src/parsers/parser_teletext.c
src/parsers/parsers.c
src/profile.c
src/profile.h
src/rtsp.c
src/satip/rtp.c
src/satip/rtsp.c
src/satip/server.c
src/service.c
src/service.h
src/service_mapper.c
src/spawn.c
src/streaming.c
src/streaming.h
src/subscriptions.c
src/tcp.c
src/timeshift.c
src/timeshift/private.h
src/timeshift/timeshift_filemgr.c
src/timeshift/timeshift_reader.c
src/timeshift/timeshift_writer.c
src/tprofile.c
src/transcoding/codec/module.c
src/tvh_locale.c
src/tvh_locale.h
src/tvh_string.h
src/tvh_thread.c [new file with mode: 0644]
src/tvh_thread.h [new file with mode: 0644]
src/tvheadend.h
src/tvhlog.c
src/tvhlog.h
src/tvhpoll.c
src/upnp.c
src/watchdog.c
src/webui/comet.c
src/webui/doc_md.c
src/webui/extjs.c
src/webui/simpleui.c
src/webui/statedump.c
src/webui/webui.c
src/webui/xmltv.c
src/wrappers.c

index 007a35e772856d40d2e01f1722efbc33da7aab8f..41783b546a847232860a17b6d22254d74ebe5ffa 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -218,6 +218,7 @@ SRCS-1 = \
        src/proplib.c \
        src/utils.c \
        src/wrappers.c \
+       src/tvh_thread.c \
        src/tvhvfs.c \
        src/access.c \
        src/tcp.c \
index d0ab44a7d592bc96673f54da44d24f288da5f420..98edee824a39bbca51f887cee44384e9624bf780 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <pthread.h>
+#include "tvheadend.h"
 #include <ctype.h>
-#include <assert.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <netinet/in.h>
 #include <arpa/inet.h>
-#include <sys/socket.h>
-
-#include "tvheadend.h"
 #include "config.h"
 #include "access.h"
 #include "settings.h"
@@ -2493,7 +2481,7 @@ access_done(void)
   passwd_entry_t *pw;
   ipblock_entry_t *ib;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   while ((ae = TAILQ_FIRST(&access_entries)) != NULL)
     access_entry_destroy(ae, 0);
   while ((at = TAILQ_FIRST(&access_tickets)) != NULL)
@@ -2506,5 +2494,5 @@ access_done(void)
   superuser_username = NULL;
   free((void *)superuser_password);
   superuser_password = NULL;
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
index ee5fb56285cc36767de10cdef1c0a53ef0596133..24279b97bb3817018fd11d6c36e5058ad787db43 100644 (file)
@@ -45,10 +45,10 @@ api_passwd_entry_create
   if (!(conf  = htsmsg_get_map(args, "conf")))
     return EINVAL;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   if ((pw = passwd_entry_create(NULL, conf)) != NULL)
     api_idnode_create(resp, &pw->pw_id);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return 0;
 }
@@ -77,10 +77,10 @@ api_ipblock_entry_create
   if (!(conf  = htsmsg_get_map(args, "conf")))
     return EINVAL;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   if ((ib = ipblock_entry_create(NULL, conf)) != NULL)
     api_idnode_create(resp, &ib->ib_id);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return 0;
 }
@@ -149,10 +149,10 @@ api_access_entry_create
   if (!(conf  = htsmsg_get_map(args, "conf")))
     return EINVAL;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   if ((ae = access_entry_create(NULL, conf)) != NULL)
     api_idnode_create(resp, &ae->ae_id);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return 0;
 }
index 4f6a2a7db951c213592db4de2cf0ecad0bf94853..7177d82365e02529ec7fe992b24e15f364417a38 100644 (file)
@@ -34,10 +34,10 @@ api_bouquet_list
   char ubuf[UUID_HEX_SIZE];
 
   l = htsmsg_create_list();
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   RB_FOREACH(bq, &bouquets, bq_link)
     htsmsg_add_msg(l, NULL, htsmsg_create_key_val(idnode_uuid_as_str(&bq->bq_id, ubuf), bq->bq_name ?: ""));
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   *resp = htsmsg_create_map();
   htsmsg_add_msg(*resp, "entries", l);
 
@@ -68,11 +68,11 @@ api_bouquet_create
   if (s == NULL || *s == '\0')
     return EINVAL;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   bq = bouquet_create(NULL, conf, NULL, NULL);
   if (bq)
     api_idnode_create(resp, &bq->bq_id);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return 0;
 }
@@ -92,14 +92,14 @@ bouquet_cb
   if ((uuids = htsmsg_field_get_list(f))) {
     HTSMSG_FOREACH(f, uuids) {
       if (!(uuid = htsmsg_field_get_str(f))) continue;
-      pthread_mutex_lock(&global_lock);
+      tvh_mutex_lock(&global_lock);
       cb(uuid);
-      pthread_mutex_unlock(&global_lock);
+      tvh_mutex_unlock(&global_lock);
     }
   } else if ((uuid = htsmsg_field_get_str(f))) {
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     r = cb(uuid);
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
   } else {
     return -EINVAL;
   }
index e090b2917cbdea8e433ae980c92d666d6e86e54d..a9a81aa3beb2f25c485d59275a1422d81855c488 100644 (file)
@@ -35,7 +35,7 @@ api_caclient_list
   char buf[384];
 
   l = htsmsg_create_list();
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   TAILQ_FOREACH(cac, &caclients, cac_link) {
     e = htsmsg_create_map();
     htsmsg_add_uuid(e, "uuid", &cac->cac_id.in_uuid);
@@ -43,7 +43,7 @@ api_caclient_list
     htsmsg_add_str(e, "status", caclient_get_status(cac));
     htsmsg_add_msg(l, NULL, e);
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   *resp = htsmsg_create_map();
   htsmsg_add_msg(*resp, "entries", l);
   return 0;
@@ -84,13 +84,13 @@ api_caclient_create
     return EINVAL;
   htsmsg_set_str(conf, "class", clazz);
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   cac = caclient_create(NULL, conf, 1);
   if (cac)
     api_idnode_create(resp, &cac->cac_id);
   else
     err = -EINVAL;
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return err;
 }
index a851331d9522f3c91a9a412f35f79113ecc09427..98f6ca8608c1d8a0d9042e56b9984759e1ae2905 100644 (file)
@@ -52,7 +52,7 @@ api_channel_list
   if (numbers && !sort) sort = "numname";
   blank = tvh_gettext_lang(perm->aa_lang_ui, channel_blank_name);
   l = htsmsg_create_list();
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   chlist = channel_get_sorted_list(sort, cfg, &count);
   for (i = 0; i < count; i++) {
     ch = chlist[i];
@@ -66,7 +66,7 @@ api_channel_list
     }
     htsmsg_add_msg(l, NULL, htsmsg_create_key_val(idnode_uuid_as_str(&ch->ch_id, ubuf), name));
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   free(chlist);
   *resp = htsmsg_create_map();
   htsmsg_add_msg(*resp, "entries", l);
@@ -96,11 +96,11 @@ api_channel_create
   if (!(conf  = htsmsg_get_map(args, "conf")))
     return EINVAL;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   ch = channel_create(NULL, conf, NULL);
   if (ch)
     api_idnode_create(resp, &ch->ch_id);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return 0;
 }
@@ -115,9 +115,9 @@ api_channel_rename
   if (!(to = htsmsg_get_str(args, "to")))
     return -EINVAL;
   /* We need the lock since we are altering details */
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   const int num_match = channel_rename_and_save(from, to);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return num_match > 0 ? 0 : -ENOENT;
 }
@@ -132,7 +132,7 @@ api_channel_tag_list
   char buf[128], ubuf[UUID_HEX_SIZE], *name;
 
   l = htsmsg_create_list();
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   TAILQ_FOREACH(ct, &channel_tags, ct_link)
     if (cfg || channel_tag_access(ct, perm, 0)) {
       if (ct->ct_enabled) {
@@ -143,7 +143,7 @@ api_channel_tag_list
       }
       htsmsg_add_msg(l, NULL, htsmsg_create_key_val(idnode_uuid_as_str(&ct->ct_id, ubuf), name));
     }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   *resp = htsmsg_create_map();
   htsmsg_add_msg(*resp, "entries", l);
   return 0;
@@ -171,11 +171,11 @@ api_channel_tag_create
   if (!(conf  = htsmsg_get_map(args, "conf")))
     return EINVAL;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   ct = channel_tag_create(NULL, conf);
   if (ct)
     api_idnode_create(resp, &ct->ct_id);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return 0;
 }
@@ -191,7 +191,7 @@ api_channel_cat_list
   string_list_t *sl = string_list_create();
   const string_list_item_t *item;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   /* Build string_list of all categories the user is allowed
    * to see.
    */
@@ -209,7 +209,7 @@ api_channel_cat_list
       }
     }
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   /* Now we have the unique list, convert it for GUI. */
   RB_FOREACH(item, sl, h_link) {
index d19fca4772d6cdf3713f0f5e0941ca40e4752db5..23cfbd47604142a14535c398bb39bf03497e6655 100644 (file)
@@ -34,7 +34,7 @@ api_codec_list(access_t *perm, void *opaque, const char *op,
     int err = ENOMEM;
 
     if ((list = htsmsg_create_list())) {
-        pthread_mutex_lock(&global_lock);
+        tvh_mutex_lock(&global_lock);
         SLIST_FOREACH(tvh_codec, &tvh_codecs, link) {
             if (!(map = idclass_serialize(tvh_codec_get_class(tvh_codec),
                                           perm->aa_lang_ui))) {
@@ -46,7 +46,7 @@ api_codec_list(access_t *perm, void *opaque, const char *op,
             htsmsg_add_str(map, "title", tvh_codec_get_title(tvh_codec));
             htsmsg_add_msg(list, NULL, map);
         }
-        pthread_mutex_unlock(&global_lock);
+        tvh_mutex_unlock(&global_lock);
         if (list) {
             if ((*resp = htsmsg_create_map())) {
                 htsmsg_add_msg(*resp, "entries", list);
@@ -72,7 +72,7 @@ api_codec_profile_list(access_t *perm, void *opaque, const char *op,
     int err = ENOMEM;
 
     if ((list = htsmsg_create_list())) {
-        pthread_mutex_lock(&global_lock);
+        tvh_mutex_lock(&global_lock);
         LIST_FOREACH(tvh_profile, &tvh_codec_profiles, link) {
             if (!(map = htsmsg_create_map())) {
                 htsmsg_destroy(list);
@@ -87,7 +87,7 @@ api_codec_profile_list(access_t *perm, void *opaque, const char *op,
                            tvh_codec_profile_get_status(tvh_profile));
             htsmsg_add_msg(list, NULL, map);
         }
-        pthread_mutex_unlock(&global_lock);
+        tvh_mutex_unlock(&global_lock);
         if (list) {
             if ((*resp = htsmsg_create_map())) {
                 htsmsg_add_msg(*resp, "entries", list);
@@ -114,9 +114,9 @@ api_codec_profile_create(access_t *perm, void *opaque, const char *op,
     if ((codec_name = htsmsg_get_str(args, "class")) &&
         (conf = htsmsg_get_map(args, "conf"))) {
         htsmsg_set_str(conf, "codec_name", codec_name);
-        pthread_mutex_lock(&global_lock);
+        tvh_mutex_lock(&global_lock);
         err = (err = tvh_codec_profile_create(conf, NULL, 1)) ? -err : 0;
-        pthread_mutex_unlock(&global_lock);
+        tvh_mutex_unlock(&global_lock);
     }
     return err;
 }
index 767371f0092a8c4e51187b9bbadf17c8bba368c4..134cab15b88a35dbd134cc107652a9bc3561a79b 100644 (file)
@@ -55,12 +55,12 @@ api_dvr_config_create
   if (s[0] == '\0')
     return EINVAL;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   if ((cfg = dvr_config_create(NULL, NULL, conf))) {
     api_idnode_create(resp, &cfg->dvr_id);
     dvr_config_changed(cfg);
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return 0;
 }
@@ -140,7 +140,7 @@ api_dvr_entry_create
   if (!(conf = htsmsg_get_map(args, "conf")))
     return EINVAL;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   s1 = htsmsg_get_str(conf, "config_name");
   cfg = dvr_config_find_by_list(perm->aa_dvrcfgs, s1);
   if (cfg) {
@@ -177,7 +177,7 @@ api_dvr_entry_create
     res = 0;
     free(lang);
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return res;
 }
@@ -234,7 +234,7 @@ api_dvr_entry_create_by_event
     config_uuid = htsmsg_get_str(m, "config_uuid");
     de = NULL;
 
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     if ((e = epg_broadcast_find_by_id(strtoll(s, NULL, 10)))) {
       dvr_config_t *cfg = dvr_config_find_by_list(perm->aa_dvrcfgs, config_uuid);
       if (cfg) {
@@ -244,7 +244,7 @@ api_dvr_entry_create_by_event
           idnode_changed(&de->de_id);
       }
     }
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
 
     htsmsg_destroy(conf);
 
@@ -438,7 +438,7 @@ api_dvr_autorec_create
   if (s1 == NULL)
     s1 = htsmsg_get_str(conf, "config_name");
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   cfg = dvr_config_find_by_list(perm->aa_dvrcfgs, s1);
   if (cfg) {
     htsmsg_set_uuid(conf, "config_name", &cfg->dvr_id.in_uuid);
@@ -449,7 +449,7 @@ api_dvr_autorec_create
       dvr_autorec_completed(dae, 0);
     }
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return 0;
 }
@@ -480,7 +480,7 @@ api_dvr_autorec_create_by_series
 
     config_uuid = htsmsg_get_str(m, "config_uuid");
 
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     if ((e = epg_broadcast_find_by_id(strtoll(s, NULL, 10)))) {
       dvr_config_t *cfg = dvr_config_find_by_list(perm->aa_dvrcfgs, config_uuid);
       if (cfg) {
@@ -497,7 +497,7 @@ api_dvr_autorec_create_by_series
         }
       }
     }
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
     count++;
   }
 
@@ -531,13 +531,13 @@ api_dvr_timerec_create
   htsmsg_set_str2(conf, "owner", perm->aa_username);
   htsmsg_set_str2(conf, "creator", perm->aa_representative);
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   dte = dvr_timerec_create(NULL, conf);
   if (dte) {
     api_idnode_create(resp, &dte->dte_id);
     dvr_timerec_check(dte);
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return 0;
 }
index e15d1a382227aa5352fb1c73f3dda8fff649cd18..35a93864d7a7cd0c3ec04b6899f71b7a9eb28c5d 100644 (file)
@@ -484,7 +484,7 @@ api_epg_grid
   limit = htsmsg_get_u32_or_default(args, "limit", 50);
 
   /* Query the EPG */
-  pthread_mutex_lock(&global_lock); 
+  tvh_mutex_lock(&global_lock);
   epg_query(&eq, perm);
 
   /* Build response */
@@ -495,7 +495,7 @@ api_epg_grid
     if (!(e = api_epg_entry(eq.result[i], lang, perm, &blank))) continue;
     htsmsg_add_msg(l, NULL, e);
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   epg_query_free(&eq);
   free(lang);
@@ -598,11 +598,11 @@ api_epg_alternative
 
   /* Main Job */
   lang = access_get_lang(perm, htsmsg_get_str(args, "lang"));
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   e = epg_broadcast_find_by_id(id);
   if (e)
     api_epg_episode_broadcasts(perm, l, lang, e, &entries, e);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   free(lang);
 
   /* Build response */
@@ -628,13 +628,13 @@ api_epg_related
 
   /* Main Job */
   lang = access_get_lang(perm, htsmsg_get_str(args, "lang"));
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   e = epg_broadcast_find_by_id(id);
   serieslink = e->serieslink;
   if (serieslink)
     entries = api_epg_episode_sorted(serieslink, perm, l, lang, e);
 
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   free(lang);
 
   /* Build response */
@@ -663,7 +663,7 @@ api_epg_load
       return -EINVAL;
 
   /* Main Job */
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   lang = access_get_lang(perm, htsmsg_get_str(args, "lang"));
   if (ids) {
     HTSMSG_FOREACH(f, ids) {
@@ -681,7 +681,7 @@ api_epg_load
       entries++;
     }
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   free(lang);
 
   /* Build response */
index a3bec0b2819f4b8e4f00403d274bfc15c1040e64..656c3bfc738fdaaa01c6761bac1dfc433b957ae1 100644 (file)
@@ -39,7 +39,7 @@ api_epggrab_module_list
   htsmsg_t *l = htsmsg_create_list(), *m;
   epggrab_module_t *mod;
   char buf[384];
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   LIST_FOREACH(mod, &epggrab_modules, link) {
     m = htsmsg_create_map();
     htsmsg_add_uuid(m, "uuid", &mod->idnode.in_uuid);
@@ -47,7 +47,7 @@ api_epggrab_module_list
     htsmsg_add_str(m, "title", idnode_get_title(&mod->idnode, perm->aa_lang_ui, buf, sizeof(buf)));
     htsmsg_add_msg(l, NULL, m);
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   *resp = htsmsg_create_map();
   htsmsg_add_msg(*resp, "entries", l);
   return 0;
@@ -61,9 +61,9 @@ api_epggrab_ota_trigger
   if (htsmsg_get_s32(args, "trigger", &s32))
     return EINVAL;
   if (s32 > 0) {
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     epggrab_ota_trigger(s32);
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
   }
   return 0;
 }
@@ -76,9 +76,9 @@ api_epggrab_rerun_internal
   if (htsmsg_get_s32(args, "rerun", &s32))
     return EINVAL;
   if (s32 > 0) {
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     epggrab_rerun_internal();
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
   }
   return 0;
 }
index 7b4d526bd7afa80ac92916056cb728ee9a516ead..d612ec285567b4e54099a5891039b01521ee84d5 100644 (file)
@@ -44,11 +44,11 @@ api_esfilter_create
   if (!(conf  = htsmsg_get_map(args, "conf")))
     return EINVAL;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   esf = esfilter_create(cls, NULL, conf, 1);
   if (esf)
     api_idnode_create(resp, &esf->esf_id);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return 0;
 }
index f2562aa609c0b13b2240f2888d4fe875ed99c153..9715941c9e0cf86e580cbcf1dbc023d0415849ab 100644 (file)
@@ -131,7 +131,7 @@ api_idnode_grid
   api_idnode_grid_conf(perm, args, &conf);
 
   /* Create list */
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   cb(perm, &ins, &conf, args);
 
   /* Sort */
@@ -152,7 +152,7 @@ api_idnode_grid
     if (conf.limit > 0) conf.limit--;
   }
 
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   /* Output */
   *resp = htsmsg_create_map();
@@ -225,9 +225,9 @@ api_idnode_load_by_class
   ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
 {
   int ret;
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   ret = api_idnode_load_by_class0(perm, opaque, op, args, resp);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   return ret;
 }
 
@@ -244,13 +244,13 @@ api_idnode_load
   /* Class based */
   if ((class = htsmsg_get_str(args, "class"))) {
     const idclass_t *idc;
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     idc = idclass_find(class);
     if (idc)
       err = api_idnode_load_by_class0(perm, (void*)idc, NULL, args, resp);
     else
       err = EINVAL;
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
     return err;
   }
   
@@ -268,7 +268,7 @@ api_idnode_load
 
   flist = api_idnode_flist_conf(args, "list");
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 
   /* Multiple */
   if (uuids) {
@@ -328,7 +328,7 @@ api_idnode_load
     htsmsg_destroy(l);
   }
 
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   htsmsg_destroy(flist);
 
@@ -346,9 +346,9 @@ api_idnode_load_simple
 
   /* Class based */
   if ((class = htsmsg_get_str(args, "class"))) {
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     err = api_idnode_load_by_class0(perm, (void*)in->in_class, NULL, args, resp);
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
     return err;
   }
 
@@ -357,7 +357,7 @@ api_idnode_load_simple
 
   flist = api_idnode_flist_conf(args, "list");
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 
   if (!idnode_perm(in, perm, NULL)) {
     l = htsmsg_create_list();
@@ -370,7 +370,7 @@ api_idnode_load_simple
     err = EPERM;
   }
 
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   if (l) {
     *resp = htsmsg_create_map();
@@ -400,7 +400,7 @@ api_idnode_save
     if (!(msg = htsmsg_field_get_map(f)))
       return EINVAL;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 
   /* Single or Foreach */
   if (!msg->hm_islist) {
@@ -469,7 +469,7 @@ api_idnode_save
   // TODO: return updated UUIDs?
 
 exit:
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return err;
 }
@@ -488,7 +488,7 @@ api_idnode_save_simple
   if (!(msg = htsmsg_field_get_map(f)))
       return EINVAL;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 
   /* Single */
   if (!idnode_perm(in, perm, msg)) {
@@ -498,7 +498,7 @@ api_idnode_save_simple
     err = EPERM;
   }
 
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return err;
 }
@@ -526,11 +526,11 @@ api_idnode_tree
   if (isroot && !(root || rootfn))
     return EINVAL;
 
pthread_mutex_lock(&global_lock);
tvh_mutex_lock(&global_lock);
 
   if (!isroot || root) {
     if (!(node = idnode_find(isroot ? root : uuid, NULL, NULL))) {
-      pthread_mutex_unlock(&global_lock);
+      tvh_mutex_unlock(&global_lock);
       return EINVAL;
     }
   }
@@ -541,7 +541,7 @@ api_idnode_tree
   if (isroot && node) {
     htsmsg_t *m;
     if (idnode_perm(node, perm, NULL)) {
-      pthread_mutex_unlock(&global_lock);
+      tvh_mutex_unlock(&global_lock);
       return EINVAL;
     }
     m = idnode_serialize(node, perm->aa_lang_ui);
@@ -568,7 +568,7 @@ api_idnode_tree
       idnode_set_free(v);
     }
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return 0;
 }
@@ -582,7 +582,7 @@ api_idnode_class
   const idclass_t *idc;
   htsmsg_t *flist = api_idnode_flist_conf(args, "list");
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 
   /* Lookup */
   if (!opaque) {
@@ -599,7 +599,7 @@ api_idnode_class
   *resp = idclass_serialize0(idc, flist, 0, perm->aa_lang_ui);
 
 exit:
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   htsmsg_destroy(flist);
 
@@ -634,11 +634,11 @@ api_idnode_handler
     htsmsg_add_str(msg, "__op__", op);
     HTSMSG_FOREACH(f, uuids) {
       if (!(uuid = htsmsg_field_get_string(f))) continue;
-      pthread_mutex_lock(&global_lock);
+      tvh_mutex_lock(&global_lock);
       if ((in = idnode_find(uuid, idc, domain)) != NULL) {
         domain = in->in_domain;
         if (idnode_perm(in, perm, msg)) {
-          pthread_mutex_unlock(&global_lock);
+          tvh_mutex_unlock(&global_lock);
           pcnt++;
           continue;
         }
@@ -647,7 +647,7 @@ api_idnode_handler
           idnode_perm_unset(in);
         cnt++;
       }
-      pthread_mutex_unlock(&global_lock);
+      tvh_mutex_unlock(&global_lock);
       if (destroyed)
         sched_yield(); /* delete penalty */
     }
@@ -659,7 +659,7 @@ api_idnode_handler
   /* Single */
   } else {
     uuid = htsmsg_field_get_string(f);
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     if (!(in   = idnode_find(uuid, idc, NULL))) {
       err = ENOENT;
     } else {
@@ -674,7 +674,7 @@ api_idnode_handler
       }
       htsmsg_destroy(msg);
     }
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
   }
 
 
index 1d1e6bc1adac8f4d63fde5551c2c052c64bbd218..3e6c585f6a64db02e590cd2da077d2b363962ad9 100644 (file)
@@ -33,9 +33,9 @@ api_imagecache_clean
   if (htsmsg_get_bool(args, "clean", &b))
     return EINVAL;
   if (b) {
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     imagecache_clean();
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
   }
   return 0;
 }
@@ -48,9 +48,9 @@ api_imagecache_trigger
   if (htsmsg_get_bool(args, "trigger", &b))
     return EINVAL;
   if (b) {
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     imagecache_trigger();
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
   }
   return 0;
 }
index 7a173ea111a077e44a233081a58a8c8b1732947c..c224fc46a02d8224935f65bafb8a1933d3847054 100644 (file)
@@ -48,9 +48,9 @@ api_input_satip_discover
 
   tvhinfo(LS_SATIP, "Triggered new server discovery");
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   satip_device_discovery_start();
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return err;
 }
index 3e0b28567c818e39847a609bb8eb7d6208dc7a98..d18d30a25221bf8001203057d8e9edda9c86b542 100644 (file)
@@ -44,7 +44,7 @@ api_mpegts_input_network_list
   if (!(uuid = htsmsg_get_str(args, "uuid")))
     return EINVAL;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 
   mi = mpegts_input_find(uuid);
   if (!mi)
@@ -65,7 +65,7 @@ api_mpegts_input_network_list
   htsmsg_add_msg(*resp, "entries", l);
 
 exit:
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return err;
 }
@@ -118,7 +118,7 @@ api_mpegts_network_create
   if (!(conf  = htsmsg_get_map(args, "conf")))
     return EINVAL;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   mn = mpegts_network_build(class, conf);
   if (mn) {
     err = 0;
@@ -126,7 +126,7 @@ api_mpegts_network_create
   } else {
     err = EINVAL;
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return err;
 }
@@ -145,18 +145,18 @@ api_mpegts_network_scan
   if ((uuids = htsmsg_field_get_list(f))) {
     HTSMSG_FOREACH(f, uuids) {
       if (!(uuid = htsmsg_field_get_str(f))) continue;
-      pthread_mutex_lock(&global_lock);
+      tvh_mutex_lock(&global_lock);
       mn = mpegts_network_find(uuid);
       if (mn && mn->mn_scan)
         mn->mn_scan(mn);
-      pthread_mutex_unlock(&global_lock);
+      tvh_mutex_unlock(&global_lock);
     }
   } else if ((uuid = htsmsg_field_get_str(f))) {
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     mn = mpegts_network_find(uuid);
     if (mn && mn->mn_scan)
       mn->mn_scan(mn);
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
     if (!mn)
       return -ENOENT;
   } else {
@@ -178,7 +178,7 @@ api_mpegts_network_muxclass
   if (!(uuid = htsmsg_get_str(args, "uuid")))
     return EINVAL;
   
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   
   if (!(mn  = mpegts_network_find(uuid)))
     goto exit;
@@ -190,7 +190,7 @@ api_mpegts_network_muxclass
   err    = 0;
 
 exit:
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   return err;
 }
 
@@ -209,7 +209,7 @@ api_mpegts_network_muxcreate
   if (!(conf = htsmsg_get_map(args, "conf")))
     return EINVAL;
   
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   
   if (!(mn  = mpegts_network_find(uuid)))
     goto exit;
@@ -221,7 +221,7 @@ api_mpegts_network_muxcreate
   err = 0;
 
 exit:
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   return err;
 }
 
@@ -307,7 +307,7 @@ api_mpegts_mux_sched_create
   if (!(conf  = htsmsg_get_map(args, "conf")))
     return EINVAL;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   mms = mpegts_mux_sched_create(NULL, conf);
   if (mms) {
     err = 0;
@@ -315,7 +315,7 @@ api_mpegts_mux_sched_create
   } else {
     err = EINVAL;
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return err;
 }
index 5b296beb953aada3e36a349b004497c1e4705251..f54fd16bd32ebd747d7701d2b5fa3048ece4b829 100644 (file)
@@ -65,14 +65,14 @@ api_profile_list
 
   sflags |= SUBSCRIPTION_PACKET|SUBSCRIPTION_MPEGTS;
   l = htsmsg_create_list();
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   TAILQ_FOREACH(pro, &profiles, pro_link) {
     idnode_uuid_as_str(&pro->pro_id, ubuf);
     if (!cfg && (!profile_verify(pro, sflags) || !api_profile_find(perm, ubuf)))
       continue;
     htsmsg_add_msg(l, NULL, htsmsg_create_key_val(ubuf, profile_get_name(pro)));
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   *resp = htsmsg_create_map();
   htsmsg_add_msg(*resp, "entries", l);
   return 0;
@@ -87,12 +87,12 @@ api_profile_builders
 
   l = htsmsg_create_list();
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   /* List of available builder classes */
   LIST_FOREACH(pb, &profile_builders, link)
     if ((e = idclass_serialize(pb->clazz, perm->aa_lang_ui)))
       htsmsg_add_msg(l, NULL, e);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   /* Output */
   *resp = htsmsg_create_map();
@@ -116,13 +116,13 @@ api_profile_create
     return EINVAL;
   htsmsg_set_str(conf, "class", clazz);
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   pro = profile_create(NULL, conf, 1);
   if (pro)
     api_idnode_create(resp, &pro->pro_id);
   else
     err = -EINVAL;
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return err;
 }
index 0c26de47b250cd0acbddb87a1a1a717527559601..8f138970935df0483832e5639f17d4848d23de89 100644 (file)
@@ -31,17 +31,17 @@ api_idnode_classes
   const idclass_t *ic;
 
   *resp = htsmsg_create_map();
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   all = idclass_find_all();
   if (all == NULL) {
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
     return EINVAL;
   }
   for (all2 = all; *all2; all2++) {
     ic = *all2;
     htsmsg_add_str(*resp, ic->ic_class, ic->ic_caption ?: "");
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   free(all);
   return 0;
@@ -102,13 +102,13 @@ api_idnode_raw_export
   /* Class based */
   if ((class = htsmsg_get_str(args, "class"))) {
     const idclass_t *idc;
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     idc = idclass_find(class);
     if (idc)
       err = api_idnode_raw_export_by_class0(perm, (void*)idc, NULL, args, resp);
     else
       err = EINVAL;
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
     return err;
   }
   
@@ -119,7 +119,7 @@ api_idnode_raw_export
     if (!(uuid = htsmsg_field_get_str(f)))
       return EINVAL;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   l = htsmsg_create_list();
 
   /* Multiple */
@@ -167,7 +167,7 @@ api_idnode_raw_export
     htsmsg_destroy(l);
   }
 
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return err;
 }
@@ -192,7 +192,7 @@ api_idnode_raw_import
       return EINVAL;
   htsmsg_print(msg);
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 
   /* Single or Foreach */
   if (!msg->hm_islist) {
@@ -261,7 +261,7 @@ api_idnode_raw_import
   // TODO: return updated UUIDs?
 
 exit:
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return err;
 }
index 8d4d7e487bd4a1d3fe232977dd6a515880b9cc9a..baab39385735de4a351622e968b25437ba67e328 100644 (file)
@@ -31,9 +31,9 @@ static int
 api_mapper_stop
   ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
 {
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   service_mapper_stop();
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return 0;
 }
@@ -57,9 +57,9 @@ static int
 api_mapper_status
   ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
 {
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   *resp = api_mapper_status_msg();
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   return 0;
 }
 
@@ -119,16 +119,16 @@ api_service_streams
   if (!(uuid = htsmsg_get_str(args, "uuid")))
     return EINVAL;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 
   /* Couldn't find */
   if (!(s = service_find_by_uuid(uuid))) {
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
     return EINVAL;
   }
 
   /* Build response */
-  pthread_mutex_lock(&s->s_stream_mutex);
+  tvh_mutex_lock(&s->s_stream_mutex);
   st = htsmsg_create_list();
   stf = htsmsg_create_list();
   if (s->s_components.set_pcr_pid) {
@@ -157,7 +157,7 @@ api_service_streams
   htsmsg_add_str(*resp, "name", s->s_nicename);
   if (s->s_hbbtv)
     hbbtv = htsmsg_copy(s->s_hbbtv);
-  pthread_mutex_unlock(&s->s_stream_mutex);
+  tvh_mutex_unlock(&s->s_stream_mutex);
 
   htsmsg_add_msg(*resp, "streams", st);
   htsmsg_add_msg(*resp, "fstreams", stf);
@@ -165,7 +165,7 @@ api_service_streams
     htsmsg_add_msg(*resp, "hbbtv", hbbtv);
 
   /* Done */
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   return 0;
 }
 
@@ -176,9 +176,9 @@ api_service_remove_unseen
   int days = htsmsg_get_s32_or_default(args, "days", 7);
   const char *type = htsmsg_get_str(args, "type");
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   service_remove_unseen(type, days);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   return 0;
 }
 
index ebf8819e2f66a0ec2efa8fb3bb47878f64bbca6a..c8ac14e630dda0fecfff0d493829bba91b4d2e58 100644 (file)
@@ -37,10 +37,10 @@ api_status_inputs
   tvh_input_stream_t *st;
   tvh_input_stream_list_t stl = { 0 };
   
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   TVH_INPUT_FOREACH(ti)
     ti->ti_get_streams(ti, &stl);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   l = htsmsg_create_list();
   while ((st = LIST_FIRST(&stl))) {
@@ -69,13 +69,13 @@ api_status_subscriptions
 
   l = htsmsg_create_list();
   c = 0;
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   LIST_FOREACH(ths, &subscriptions, ths_global_link) {
     e = subscription_create_msg(ths, perm->aa_lang_ui);
     htsmsg_add_msg(l, NULL, e);
     c++;
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   *resp = htsmsg_create_map();
   htsmsg_add_msg(*resp, "entries", l);
@@ -88,9 +88,9 @@ static int
 api_status_connections
   ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
 {
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   *resp = tcp_server_connections();
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   return 0;
 }
 
@@ -112,14 +112,14 @@ api_connections_cancel
     HTSMSG_FOREACH(f, ids) {
       if (htsmsg_field_get_u32(f, &id)) continue;
       if (!id) continue;
-      pthread_mutex_lock(&global_lock);
+      tvh_mutex_lock(&global_lock);
       tcp_connection_cancel(id);
-      pthread_mutex_unlock(&global_lock);
+      tvh_mutex_unlock(&global_lock);
     }
   } else {
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     tcp_connection_cancel(id);
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
   }
   return 0;
 }
@@ -130,14 +130,14 @@ input_clear_stats(const char *uuid)
   tvh_input_instance_t *tii;
   tvh_input_t *ti;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   if ((tii = tvh_input_instance_find_by_uuid(uuid)) != NULL)
     if (tii->tii_clear_stats)
       tii->tii_clear_stats(tii);
   if ((ti = tvh_input_find_by_uuid(uuid)) != NULL)
     if (ti->ti_clear_stats)
       ti->ti_clear_stats(ti);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
 
 static int
index 424fda43c663860ff34d036986c4ef0bb8ffd239..bc80f446fbbdf82e76c7d1c1a5bd22f617bdd64c 100644 (file)
 static int
 wizard_page ( const char *page )
 {
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   if (strcmp(page, config.wizard ?: "")) {
     free(config.wizard);
     config.wizard = page[0] ? strdup(page) : NULL;
     idnode_changed(&config.idnode);
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   return 0;
 }
 
index 08f4e01678bd1b4cdec81eb89a416cd5d5771c55..76e842d4a45dd10ecdcaed77b9155ca1fc293dd4 100644 (file)
@@ -23,7 +23,7 @@
 
 typedef void * volatile * atomic_refptr_t;
 
-extern pthread_mutex_t atomic_lock;
+extern tvh_mutex_t atomic_lock;
 
 /*
  * Atomic FETCH and ADD operation
@@ -36,10 +36,10 @@ atomic_add(volatile int *ptr, int incr)
   return __sync_fetch_and_add(ptr, incr);
 #else
   int ret;
-  pthread_mutex_lock(&atomic_lock);
+  tvh_mutex_lock(&atomic_lock);
   ret = *ptr;
   *ptr += incr;
-  pthread_mutex_unlock(&atomic_lock);
+  tvh_mutex_unlock(&atomic_lock);
   return ret;
 #endif
 }
@@ -51,10 +51,10 @@ atomic_add_u64(volatile uint64_t *ptr, uint64_t incr)
   return __sync_fetch_and_add(ptr, incr);
 #else
   uint64_t ret;
-  pthread_mutex_lock(&atomic_lock);
+  tvh_mutex_lock(&atomic_lock);
   ret = *ptr;
   *ptr += incr;
-  pthread_mutex_unlock(&atomic_lock);
+  tvh_mutex_unlock(&atomic_lock);
   return ret;
 #endif
 }
@@ -66,10 +66,10 @@ atomic_add_s64(volatile int64_t *ptr, int64_t incr)
   return __sync_fetch_and_add(ptr, incr);
 #else
   uint64_t ret;
-  pthread_mutex_lock(&atomic_lock);
+  tvh_mutex_lock(&atomic_lock);
   ret = *ptr;
   *ptr += incr;
-  pthread_mutex_unlock(&atomic_lock);
+  tvh_mutex_unlock(&atomic_lock);
   return ret;
 #endif
 }
@@ -81,10 +81,10 @@ atomic_add_time_t(volatile time_t *ptr, time_t incr)
   return __sync_fetch_and_add(ptr, incr);
 #else
   time_t ret;
-  pthread_mutex_lock(&atomic_lock);
+  tvh_mutex_lock(&atomic_lock);
   ret = *ptr;
   *ptr += incr;
-  pthread_mutex_unlock(&atomic_lock);
+  tvh_mutex_unlock(&atomic_lock);
   return ret;
 #endif
 }
@@ -100,10 +100,10 @@ atomic_pre_add_s64(volatile int64_t *ptr, int64_t incr)
   return __sync_add_and_fetch(ptr, incr);
 #else
   int64_t ret;
-  pthread_mutex_lock(&atomic_lock);
+  tvh_mutex_lock(&atomic_lock);
   *ptr += incr;
   ret = *ptr;
-  pthread_mutex_unlock(&atomic_lock);
+  tvh_mutex_unlock(&atomic_lock);
   return ret;
 #endif
 }
@@ -115,10 +115,10 @@ atomic_pre_add_u64(volatile uint64_t *ptr, uint64_t incr)
   return __sync_add_and_fetch(ptr, incr);
 #else
   uint64_t ret;
-  pthread_mutex_lock(&atomic_lock);
+  tvh_mutex_lock(&atomic_lock);
   *ptr += incr;
   ret = *ptr;
-  pthread_mutex_unlock(&atomic_lock);
+  tvh_mutex_unlock(&atomic_lock);
   return ret;
 #endif
 }
@@ -138,12 +138,12 @@ atomic_pre_add_s64_peak(volatile int64_t *ptr, int64_t incr,
   return ret;
 #else
   int64_t ret;
-  pthread_mutex_lock(&atomic_lock);
+  tvh_mutex_lock(&atomic_lock);
   *ptr += incr;
   ret = *ptr;
   if (*peak < ret)
     *peak = ret;
-  pthread_mutex_unlock(&atomic_lock);
+  tvh_mutex_unlock(&atomic_lock);
   return ret;
 #endif
 }
@@ -159,10 +159,10 @@ atomic_dec(volatile int *ptr, int decr)
   return __sync_fetch_and_sub(ptr, decr);
 #else
   int ret;
-  pthread_mutex_lock(&atomic_lock);
+  tvh_mutex_lock(&atomic_lock);
   ret = *ptr;
   *ptr -= decr;
-  pthread_mutex_unlock(&atomic_lock);
+  tvh_mutex_unlock(&atomic_lock);
   return ret;
 #endif
 }
@@ -174,10 +174,10 @@ atomic_dec_u64(volatile uint64_t *ptr, uint64_t decr)
   return __sync_fetch_and_sub(ptr, decr);
 #else
   uint64_t ret;
-  pthread_mutex_lock(&atomic_lock);
+  tvh_mutex_lock(&atomic_lock);
   ret = *ptr;
   *ptr -= decr;
-  pthread_mutex_unlock(&atomic_lock);
+  tvh_mutex_unlock(&atomic_lock);
   return ret;
 #endif
 }
@@ -189,10 +189,10 @@ atomic_dec_s64(volatile int64_t *ptr, int64_t decr)
   return __sync_fetch_and_sub(ptr, decr);
 #else
   int64_t ret;
-  pthread_mutex_lock(&atomic_lock);
+  tvh_mutex_lock(&atomic_lock);
   ret = *ptr;
   *ptr -= decr;
-  pthread_mutex_unlock(&atomic_lock);
+  tvh_mutex_unlock(&atomic_lock);
   return ret;
 #endif
 }
@@ -208,10 +208,10 @@ atomic_exchange(volatile int *ptr, int val)
   return  __sync_lock_test_and_set(ptr, val);
 #else
   int ret;
-  pthread_mutex_lock(&atomic_lock);
+  tvh_mutex_lock(&atomic_lock);
   ret = *ptr;
   *ptr = val;
-  pthread_mutex_unlock(&atomic_lock);
+  tvh_mutex_unlock(&atomic_lock);
   return ret;
 #endif
 }
@@ -223,10 +223,10 @@ atomic_exchange_u64(volatile uint64_t *ptr, uint64_t val)
   return  __sync_lock_test_and_set(ptr, val);
 #else
   uint64_t ret;
-  pthread_mutex_lock(&atomic_lock);
+  tvh_mutex_lock(&atomic_lock);
   ret = *ptr;
   *ptr = val;
-  pthread_mutex_unlock(&atomic_lock);
+  tvh_mutex_unlock(&atomic_lock);
   return ret;
 #endif
 }
@@ -238,10 +238,10 @@ atomic_exchange_s64(volatile int64_t *ptr, int64_t val)
   return  __sync_lock_test_and_set(ptr, val);
 #else
   int64_t ret;
-  pthread_mutex_lock(&atomic_lock);
+  tvh_mutex_lock(&atomic_lock);
   ret = *ptr;
   *ptr = val;
-  pthread_mutex_unlock(&atomic_lock);
+  tvh_mutex_unlock(&atomic_lock);
   return ret;
 #endif
 }
@@ -253,10 +253,10 @@ atomic_exchange_time_t(volatile time_t *ptr, time_t val)
   return  __sync_lock_test_and_set(ptr, val);
 #else
   time_t ret;
-  pthread_mutex_lock(&atomic_lock);
+  tvh_mutex_lock(&atomic_lock);
   ret = *ptr;
   *ptr = val;
-  pthread_mutex_unlock(&atomic_lock);
+  tvh_mutex_unlock(&atomic_lock);
   return ret;
 #endif
 }
@@ -268,10 +268,10 @@ atomic_exchange_ptr(atomic_refptr_t ptr, void *val)
   return  __sync_lock_test_and_set(ptr, val);
 #else
   void *ret;
-  pthread_mutex_lock(&atomic_lock);
+  tvh_mutex_lock(&atomic_lock);
   ret = *ptr;
   *ptr = val;
-  pthread_mutex_unlock(&atomic_lock);
+  tvh_mutex_unlock(&atomic_lock);
   return ret;
 #endif
 }
@@ -352,12 +352,12 @@ atomic_set_s64_peak(volatile int64_t *ptr, int64_t val, volatile int64_t *peak)
   return ret;
 #else
   int64_t ret;
-  pthread_mutex_lock(&atomic_lock);
+  tvh_mutex_lock(&atomic_lock);
   ret = *ptr;
   *ptr = val;
   if (val > *peak)
     *peak = val;
-  pthread_mutex_unlock(&atomic_lock);
+  tvh_mutex_unlock(&atomic_lock);
   return ret;
 #endif
 }
index 2a2e51568b7574c9160b080dc79242b79a11f7f3..9f22eaff4fae150cbd51e5f2ff38c45d2dc3ca82 100644 (file)
@@ -312,7 +312,7 @@ avahi_init(void)
 {
   if (!avahi_required())
     return;
-  tvhthread_create(&avahi_tid, NULL, avahi_thread, NULL, "avahi");
+  tvh_thread_create(&avahi_tid, NULL, avahi_thread, NULL, "avahi");
 }
 
 void
@@ -321,7 +321,7 @@ avahi_done(void)
   if (!avahi_required())
     return;
   avahi_simple_poll_quit(avahi_asp);
-  pthread_kill(avahi_tid, SIGTERM);
+  tvh_thread_kill(avahi_tid, SIGTERM);
   pthread_join(avahi_tid, NULL);
   avahi_simple_poll_free((AvahiSimplePoll *)avahi_poll);
 }
index 96c01f0d4272ad2e7bbd67e97acb686993a53fac..3afe2a3b8eacea7f418e78808d6e781f10ce5a8a 100644 (file)
@@ -1312,8 +1312,8 @@ bouquet_done(void)
 {
   bouquet_t *bq;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   while ((bq = RB_FIRST(&bouquets)) != NULL)
     bouquet_destroy(bq);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
index 996d81250da8d618bee0f2d0d5f0a542287c0995..c18d0ae347871580289ef3529afc490a347a5a1a 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <pthread.h>
-#include <assert.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
 #include <ctype.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
 
 #include "settings.h"
 #include "config.h"
@@ -1488,11 +1478,11 @@ channel_done ( void )
 {
   channel_t *ch;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   while ((ch = RB_FIRST(&channels)) != NULL)
     channel_delete(ch, 0);
   memoryinfo_unregister(&channels_memoryinfo);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   channel_tag_done();
 }
 
@@ -1978,10 +1968,10 @@ channel_tag_done ( void )
 {
   channel_tag_t *ct;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   while ((ct = TAILQ_FIRST(&channel_tags)) != NULL)
     channel_tag_destroy(ct, 0);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
 
 int
index 142e23a2e777b65ea5920b8e9f96c8be8e9d2f97..24fac806212f08f64a0ed7add286f823866389ce 100644 (file)
 #ifndef TVH_COMPAT_H
 #define TVH_COMPAT_H
 
+#if ENABLE_LOCKOWNER || ENABLE_ANDROID
+#include <sys/syscall.h>
+#endif
+
 #if ENABLE_ANDROID
 #ifndef index
 #define index(...) strchr(__VA_ARGS__)
index d74c0b29a3f84b1c6f5016462486e9f670c6093e..2f752ba7004d80470a706e7fe7d36cd3660fcb5e 100644 (file)
@@ -51,7 +51,7 @@ LIST_HEAD(dbus_rpc_list, dbus_rpc);
 static struct dbus_signal_queue dbus_signals;
 static struct dbus_rpc_list dbus_rpcs;
 static th_pipe_t dbus_pipe;
-static pthread_mutex_t dbus_lock;
+static tvh_mutex_t dbus_lock;
 static int dbus_running;
 static int dbus_session;
 
@@ -76,9 +76,9 @@ dbus_emit_signal(const char *obj_name, const char *sig_name, htsmsg_t *msg)
   strcpy(ds->obj_name + 14, obj_name);
   ds->sig_name = strdup(sig_name);
   ds->msg = msg;
-  pthread_mutex_lock(&dbus_lock);
+  tvh_mutex_lock(&dbus_lock);
   TAILQ_INSERT_TAIL(&dbus_signals, ds, link);
-  pthread_mutex_unlock(&dbus_lock);
+  tvh_mutex_unlock(&dbus_lock);
   unused = write(dbus_pipe.wr, "s", 1); /* do not wait here - no tvh_write() */
 }
 
@@ -273,9 +273,9 @@ dbus_register_rpc_s64(const char *call_name, void *opaque,
   rpc->call_name = strdup(call_name);
   rpc->rpc_s64 = fcn;
   rpc->opaque = opaque;
-  pthread_mutex_lock(&dbus_lock);
+  tvh_mutex_lock(&dbus_lock);
   LIST_INSERT_HEAD(&dbus_rpcs, rpc, link);
-  pthread_mutex_unlock(&dbus_lock);
+  tvh_mutex_unlock(&dbus_lock);
 }
 
 /**
@@ -289,9 +289,9 @@ dbus_register_rpc_str(const char *call_name, void *opaque,
   rpc->call_name = strdup(call_name);
   rpc->rpc_str = fcn;
   rpc->opaque = opaque;
-  pthread_mutex_lock(&dbus_lock);
+  tvh_mutex_lock(&dbus_lock);
   LIST_INSERT_HEAD(&dbus_rpcs, rpc, link);
-  pthread_mutex_unlock(&dbus_lock);
+  tvh_mutex_unlock(&dbus_lock);
 }
 
 /**
@@ -315,11 +315,11 @@ dbus_flush_queue(DBusConnection *conn)
   dbus_sig_t *ds;
 
   while (1) {
-    pthread_mutex_lock(&dbus_lock);
+    tvh_mutex_lock(&dbus_lock);
     ds = TAILQ_FIRST(&dbus_signals);
     if (ds)
       TAILQ_REMOVE(&dbus_signals, ds, link);
-    pthread_mutex_unlock(&dbus_lock);
+    tvh_mutex_unlock(&dbus_lock);
 
     if (ds == NULL)
       break;
@@ -407,11 +407,11 @@ dbus_server_thread(void *aux)
         continue;
       }
 
-      pthread_mutex_lock(&dbus_lock);
+      tvh_mutex_lock(&dbus_lock);
       LIST_FOREACH(rpc, &dbus_rpcs, link)
         if (dbus_message_is_method_call(msg, "org.tvheadend", rpc->call_name))
           break;
-      pthread_mutex_unlock(&dbus_lock);
+      tvh_mutex_unlock(&dbus_lock);
 
       if (rpc)
         dbus_reply_to_rpc(rpc, msg, conn);
@@ -436,7 +436,7 @@ void
 dbus_server_init(int enabled, int session)
 {
   dbus_session = session;
-  pthread_mutex_init(&dbus_lock, NULL);
+  tvh_mutex_init(&dbus_lock, NULL);
   TAILQ_INIT(&dbus_signals);
   LIST_INIT(&dbus_rpcs);
   if (enabled) {
@@ -451,7 +451,7 @@ void
 dbus_server_start(void)
 {
   if (dbus_pipe.wr > 0)
-    tvhthread_create(&dbus_tid, NULL, dbus_server_thread, NULL, "dbus");
+    tvh_thread_create(&dbus_tid, NULL, dbus_server_thread, NULL, "dbus");
 }
 
 void
@@ -463,7 +463,7 @@ dbus_server_done(void)
   atomic_set(&dbus_running, 0);
   if (dbus_pipe.wr > 0) {
     tvh_write(dbus_pipe.wr, "", 1);
-    pthread_kill(dbus_tid, SIGTERM);
+    tvh_thread_kill(dbus_tid, SIGTERM);
     pthread_join(dbus_tid, NULL);
   }
   dbus_flush_queue(NULL);
index d3f4b0fcadfec75c9135da19776913261245d70e..945206224f303b9bb8ba5c616bcd58fde4ecb3ac 100644 (file)
@@ -44,7 +44,7 @@ const idclass_t *caclient_classes[] = {
 };
 
 struct caclient_entry_queue caclients;
-static pthread_mutex_t caclients_mutex;
+static tvh_mutex_t caclients_mutex;
 
 static const idclass_t *
 caclient_class_find(const char *name)
@@ -136,14 +136,14 @@ caclient_create
   }
   if (conf)
     idnode_load(&cac->cac_id, conf);
-  pthread_mutex_lock(&caclients_mutex);
+  tvh_mutex_lock(&caclients_mutex);
   if (cac->cac_index) {
     TAILQ_INSERT_SORTED(&caclients, cac, cac_link, cac_cmp);
   } else {
     TAILQ_INSERT_TAIL(&caclients, cac, cac_link);
     caclient_reindex();
   }
-  pthread_mutex_unlock(&caclients_mutex);
+  tvh_mutex_unlock(&caclients_mutex);
   if (save)
     idnode_changed((idnode_t *)cac);
   cac->cac_conf_changed(cac);
@@ -160,9 +160,9 @@ caclient_delete(caclient_t *cac, int delconf)
   cac->cac_conf_changed(cac);
   if (delconf)
     hts_settings_remove("caclient/%s", idnode_uuid_as_str(&cac->cac_id, ubuf));
-  pthread_mutex_lock(&caclients_mutex);
+  tvh_mutex_lock(&caclients_mutex);
   TAILQ_REMOVE(&caclients, cac, cac_link);
-  pthread_mutex_unlock(&caclients_mutex);
+  tvh_mutex_unlock(&caclients_mutex);
   idnode_unlink(&cac->cac_id);
   if (cac->cac_free)
     cac->cac_free(cac);
@@ -338,11 +338,11 @@ caclient_start ( struct service *t )
 {
   caclient_t *cac;
 
-  pthread_mutex_lock(&caclients_mutex);
+  tvh_mutex_lock(&caclients_mutex);
   TAILQ_FOREACH(cac, &caclients, cac_link)
     if (cac->cac_enabled)
       cac->cac_start(cac, t);
-  pthread_mutex_unlock(&caclients_mutex);
+  tvh_mutex_unlock(&caclients_mutex);
 #if ENABLE_TSDEBUG
   tsdebugcw_service_start(t);
 #endif
@@ -356,11 +356,11 @@ caclient_cat_update
 
   lock_assert(&global_lock);
 
-  pthread_mutex_lock(&caclients_mutex);
+  tvh_mutex_lock(&caclients_mutex);
   TAILQ_FOREACH(cac, &caclients, cac_link)
     if (cac->cac_cat_update && cac->cac_enabled)
       cac->cac_cat_update(cac, mux, data, len);
-  pthread_mutex_unlock(&caclients_mutex);
+  tvh_mutex_unlock(&caclients_mutex);
 }
 
 void
@@ -371,11 +371,11 @@ caclient_caid_update
 
   lock_assert(&global_lock);
 
-  pthread_mutex_lock(&caclients_mutex);
+  tvh_mutex_lock(&caclients_mutex);
   TAILQ_FOREACH(cac, &caclients, cac_link)
     if (cac->cac_caid_update && cac->cac_enabled)
       cac->cac_caid_update(cac, mux, caid, provid, pid, valid);
-  pthread_mutex_unlock(&caclients_mutex);
+  tvh_mutex_unlock(&caclients_mutex);
 }
 
 void
@@ -402,10 +402,10 @@ caclient_foreach(void (*cb)(caclient_t *))
 {
   caclient_t *cac;
 
-  pthread_mutex_lock(&caclients_mutex);
+  tvh_mutex_lock(&caclients_mutex);
   TAILQ_FOREACH(cac, &caclients, cac_link)
     cb(cac);
-  pthread_mutex_unlock(&caclients_mutex);
+  tvh_mutex_unlock(&caclients_mutex);
 }
 
 /*
@@ -418,7 +418,7 @@ caclient_init(void)
   htsmsg_field_t *f;
   const idclass_t **r;
 
-  pthread_mutex_init(&caclients_mutex, NULL);
+  tvh_mutex_init(&caclients_mutex, NULL);
   TAILQ_INIT(&caclients);
   idclass_register(&caclient_class);
 #if ENABLE_TSDEBUG
@@ -442,11 +442,11 @@ caclient_init(void)
     caclient_t *cac;
 
     dvbcam_init();
-    pthread_mutex_lock(&caclients_mutex);
+    tvh_mutex_lock(&caclients_mutex);
     TAILQ_FOREACH(cac, &caclients, cac_link)
       if (idnode_is_instance(&cac->cac_id, &caclient_dvbcam_class))
         break;
-    pthread_mutex_unlock(&caclients_mutex);
+    tvh_mutex_unlock(&caclients_mutex);
     if (cac == NULL) {
       c = htsmsg_create_map();
       htsmsg_add_str(c, "class", "caclient_dvbcam");
@@ -464,8 +464,8 @@ caclient_done(void)
 {
   caclient_t *cac;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   while ((cac = TAILQ_FIRST(&caclients)) != NULL)
     caclient_delete(cac, 0);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
index e0abbd2e582b35904a95f6578a2b33e3be866deb..4bd8047ce5660a74c9e7152b2c3bd1f0cb8dd853 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-
-#include <pthread.h>
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <poll.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <errno.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/socket.h>
 #include <sys/un.h>
-#include <netdb.h>
-#include <netinet/in.h>
 #include <fcntl.h>
 
 #include "tvheadend.h"
@@ -287,7 +272,7 @@ typedef struct capmt {
   capmt_demuxes_t capmt_demuxes;
   capmt_adapter_t capmt_adapters[MAX_CA];
   TAILQ_HEAD(, capmt_message) capmt_writeq;
-  pthread_mutex_t capmt_mutex;
+  tvh_mutex_t capmt_mutex;
   uint8_t         capmt_pmtversion;
 
   /* last key */
@@ -427,11 +412,11 @@ capmt_pid_add(capmt_t *capmt, int adapter, int pid, mpegts_service_t *s)
     mux         = mmi ? mmi->mmi_mux : NULL;
     tvhtrace(LS_CAPMT, "%s: adding pid %d adapter %d, tuner %p, mmi %p, mux %p", capmt_name(capmt), pid, adapter, ca->ca_tuner, mmi, mux);
     if (mux) {
-      pthread_mutex_unlock(&capmt->capmt_mutex);
+      tvh_mutex_unlock(&capmt->capmt_mutex);
       descrambler_open_pid(mux, o,
                            s ? DESCRAMBLER_ECM_PID(pid) : pid,
                            capmt_table_input, (service_t *)s);
-      pthread_mutex_lock(&capmt->capmt_mutex);
+      tvh_mutex_lock(&capmt->capmt_mutex);
     }
   }
 }
@@ -467,9 +452,9 @@ capmt_pid_remove(capmt_t *capmt, int adapter, int pid, uint32_t flags)
     pid = DESCRAMBLER_ECM_PID(pid);
   o->ecm = -1;
   if (mux) {
-    pthread_mutex_unlock(&capmt->capmt_mutex);
+    tvh_mutex_unlock(&capmt->capmt_mutex);
     descrambler_close_pid(mux, o, pid);
-    pthread_mutex_lock(&capmt->capmt_mutex);
+    tvh_mutex_lock(&capmt->capmt_mutex);
   }
   o->pid = PID_UNUSED;
 }
@@ -504,9 +489,9 @@ capmt_pid_flush_adapter(capmt_t *capmt, int adapter)
       o->pid = PID_BLOCKED;
       o->pid_refs = 0;
       if (mux) {
-        pthread_mutex_unlock(&capmt->capmt_mutex);
+        tvh_mutex_unlock(&capmt->capmt_mutex);
         descrambler_close_pid(mux, &ca->ca_pids[i], pid);
-        pthread_mutex_lock(&capmt->capmt_mutex);
+        tvh_mutex_lock(&capmt->capmt_mutex);
       }
       o->pid = PID_UNUSED;
     }
@@ -613,9 +598,9 @@ capmt_socket_close(capmt_t *capmt, int sock_idx)
 static void
 capmt_socket_close_lock(capmt_t *capmt, int sock_idx)
 {
-  pthread_mutex_lock(&capmt->capmt_mutex);
+  tvh_mutex_lock(&capmt->capmt_mutex);
   capmt_socket_close(capmt, sock_idx);
-  pthread_mutex_unlock(&capmt->capmt_mutex);
+  tvh_mutex_unlock(&capmt->capmt_mutex);
 }
 
 /**
@@ -768,11 +753,11 @@ capmt_flush_queue(capmt_t *capmt, int del_only)
   capmt_message_t *msg;
 
   while (1) {
-    pthread_mutex_lock(&capmt->capmt_mutex);
+    tvh_mutex_lock(&capmt->capmt_mutex);
     msg = TAILQ_FIRST(&capmt->capmt_writeq);
     if (msg)
       TAILQ_REMOVE(&capmt->capmt_writeq, msg, cm_link);
-    pthread_mutex_unlock(&capmt->capmt_mutex);
+    tvh_mutex_unlock(&capmt->capmt_mutex);
     if (msg == NULL)
       break;
 
@@ -909,7 +894,7 @@ capmt_service_destroy(th_descrambler_t *td)
 
   mtimer_disarm(&ct->ct_ok_timer);
 
-  pthread_mutex_lock(&capmt->capmt_mutex);
+  tvh_mutex_lock(&capmt->capmt_mutex);
 
   /* send stop to client */
   if (!oscam_new)
@@ -940,7 +925,7 @@ capmt_service_destroy(th_descrambler_t *td)
   if (LIST_EMPTY(&capmt->capmt_services))
     capmt_init_demuxes(capmt);
 
-  pthread_mutex_unlock(&capmt->capmt_mutex);
+  tvh_mutex_unlock(&capmt->capmt_mutex);
 
   free(ct->td_nicename);
   free(ct);
@@ -999,7 +984,7 @@ capmt_set_filter(capmt_t *capmt, int adapter, sbuf_t *sb, int offset)
       filter_index >= MAX_FILTER ||
       pid > 8191)
     return;
-  pthread_mutex_lock(&capmt->capmt_mutex);
+  tvh_mutex_lock(&capmt->capmt_mutex);
   cf = &capmt->capmt_demuxes.filters[demux_index];
   if (cf->max && cf->adapter != adapter)
     goto end;
@@ -1062,7 +1047,7 @@ cont:
   if (cf->max <= filter_index)
     cf->max = filter_index + 1;
 end:
-  pthread_mutex_unlock(&capmt->capmt_mutex);
+  tvh_mutex_unlock(&capmt->capmt_mutex);
 }
 
 static void
@@ -1086,7 +1071,7 @@ capmt_stop_filter(capmt_t *capmt, int adapter, sbuf_t *sb, int offset)
       demux_index >= MAX_INDEX ||
       filter_index >= MAX_FILTER)
     return;
-  pthread_mutex_lock(&capmt->capmt_mutex);
+  tvh_mutex_lock(&capmt->capmt_mutex);
   cf = &capmt->capmt_demuxes.filters[demux_index];
   filter = &cf->dmx[filter_index];
   if (filter->pid != pid)
@@ -1105,7 +1090,7 @@ capmt_stop_filter(capmt_t *capmt, int adapter, sbuf_t *sb, int offset)
     demux_index--;
   capmt->capmt_demuxes.max = demux_index == 255 ? 0 : demux_index + 1;
 end:
-  pthread_mutex_unlock(&capmt->capmt_mutex);
+  tvh_mutex_unlock(&capmt->capmt_mutex);
 }
 
 static void
@@ -1115,7 +1100,7 @@ capmt_notify_server(capmt_t *capmt, capmt_service_t *ct, int force)
   if (capmt_oscam_netproto(capmt))
     capmt_flush_queue(capmt, 0);
 
-  pthread_mutex_lock(&capmt->capmt_mutex);
+  tvh_mutex_lock(&capmt->capmt_mutex);
   if (capmt_oscam_new(capmt)) {
     if (!LIST_EMPTY(&capmt->capmt_services))
       capmt_enumerate_services(capmt, force);
@@ -1126,7 +1111,7 @@ capmt_notify_server(capmt_t *capmt, capmt_service_t *ct, int force)
       LIST_FOREACH(ct, &capmt->capmt_services, ct_link)
         capmt_send_request(ct, CAPMT_LIST_ONLY);
   }
-  pthread_mutex_unlock(&capmt->capmt_mutex);
+  tvh_mutex_unlock(&capmt->capmt_mutex);
 }
 
 #if CONFIG_LINUXDVB
@@ -1137,7 +1122,7 @@ capmt_abort(capmt_t *capmt, int keystate)
   mpegts_service_t *t;
   capmt_service_t *ct;
 
-  pthread_mutex_lock(&capmt->capmt_mutex);
+  tvh_mutex_lock(&capmt->capmt_mutex);
   LIST_FOREACH(ct, &capmt->capmt_services, ct_link) {
     t = (mpegts_service_t *)ct->td_service;
 
@@ -1151,7 +1136,7 @@ capmt_abort(capmt_t *capmt, int keystate)
       descrambler_change_keystate((th_descrambler_t *)ct, keystate, 1);
     }
   }
-  pthread_mutex_unlock(&capmt->capmt_mutex);
+  tvh_mutex_unlock(&capmt->capmt_mutex);
 }
 #endif
 #endif
@@ -1173,7 +1158,7 @@ capmt_process_key(capmt_t *capmt, uint8_t adapter, ca_info_t *cai,
   uint16_t *pids;
   int i, j, pid;
 
-  pthread_mutex_lock(&capmt->capmt_mutex);
+  tvh_mutex_lock(&capmt->capmt_mutex);
   LIST_FOREACH(ct, &capmt->capmt_services, ct_link) {
     t = (mpegts_service_t *)ct->td_service;
 
@@ -1213,7 +1198,7 @@ found:
     ct->ct_ok_flag = 1;
     descrambler_keys((th_descrambler_t *)ct, type, pid, even, odd);
   }
-  pthread_mutex_unlock(&capmt->capmt_mutex);
+  tvh_mutex_unlock(&capmt->capmt_mutex);
 }
 
 static void
@@ -1267,7 +1252,7 @@ capmt_process_notify(capmt_t *capmt, uint8_t adapter,
   mpegts_service_t *t;
   capmt_service_t *ct;
 
-  pthread_mutex_lock(&capmt->capmt_mutex);
+  tvh_mutex_lock(&capmt->capmt_mutex);
   LIST_FOREACH(ct, &capmt->capmt_services, ct_link) {
     t = (mpegts_service_t *)ct->td_service;
 
@@ -1280,7 +1265,7 @@ capmt_process_notify(capmt_t *capmt, uint8_t adapter,
                        cardsystem, pid, ecmtime, hops, reader, from,
                        protocol);
   }
-  pthread_mutex_unlock(&capmt->capmt_mutex);
+  tvh_mutex_unlock(&capmt->capmt_mutex);
 }                     
 
 static int
@@ -1872,7 +1857,7 @@ capmt_thread(void *aux)
 
   while (atomic_get(&capmt->capmt_running)) {
     fatal = 0;
-    pthread_mutex_lock(&capmt->capmt_mutex);
+    tvh_mutex_lock(&capmt->capmt_mutex);
     for (i = 0; i < MAX_CA; i++) {
       ca = &capmt->capmt_adapters[i];
       ca->ca_number = i;
@@ -1891,7 +1876,7 @@ capmt_thread(void *aux)
       capmt->capmt_sock_reconnect[i] = 0;
     }
     capmt_init_demuxes(capmt);
-    pthread_mutex_unlock(&capmt->capmt_mutex);
+    tvh_mutex_unlock(&capmt->capmt_mutex);
 
     /* Accessible */
     if (capmt->capmt_sockfile && !capmt_oscam_network(capmt) &&
@@ -1900,12 +1885,12 @@ capmt_thread(void *aux)
     else
       caclient_set_status((caclient_t *)capmt, CACLIENT_STATUS_READY);
     
-    pthread_mutex_lock(&capmt->capmt_mutex);
+    tvh_mutex_lock(&capmt->capmt_mutex);
 
     while(atomic_get(&capmt->capmt_running) && capmt->cac_enabled == 0)
       tvh_cond_wait(&capmt->capmt_cond, &capmt->capmt_mutex);
 
-    pthread_mutex_unlock(&capmt->capmt_mutex);
+    tvh_mutex_unlock(&capmt->capmt_mutex);
 
     if (!atomic_get(&capmt->capmt_running)) continue;
 
@@ -1965,7 +1950,7 @@ capmt_thread(void *aux)
 #endif
     }
 
-    pthread_mutex_lock(&capmt->capmt_mutex);
+    tvh_mutex_lock(&capmt->capmt_mutex);
 
     caclient_set_status((caclient_t *)capmt, CACLIENT_STATUS_DISCONNECTED);
 
@@ -1982,12 +1967,12 @@ capmt_thread(void *aux)
     if (atomic_get(&capmt->capmt_reconfigure)) {
       atomic_set(&capmt->capmt_reconfigure, 0);
       atomic_set(&capmt->capmt_running, 1);
-      pthread_mutex_unlock(&capmt->capmt_mutex);
+      tvh_mutex_unlock(&capmt->capmt_mutex);
       continue;
     }
 
     if (!atomic_get(&capmt->capmt_running)) {
-      pthread_mutex_unlock(&capmt->capmt_mutex);
+      tvh_mutex_unlock(&capmt->capmt_mutex);
       continue;
     }
 
@@ -2007,7 +1992,7 @@ capmt_thread(void *aux)
         break;
     } while (ERRNO_AGAIN(i) && atomic_get(&capmt->capmt_running));
 
-    pthread_mutex_unlock(&capmt->capmt_mutex);
+    tvh_mutex_unlock(&capmt->capmt_mutex);
   }
 
   tvhinfo(LS_CAPMT, "%s inactive", capmt_name(capmt));
@@ -2031,7 +2016,7 @@ capmt_table_input(void *opaque, int pid, const uint8_t *data, int len, int emm)
   /* Validate */
   if (data == NULL || len > 4096) return;
 
-  pthread_mutex_lock(&capmt->capmt_mutex);
+  tvh_mutex_lock(&capmt->capmt_mutex);
 
   for (demux_index = 0; demux_index < capmt->capmt_demuxes.max; demux_index++) {
     cf = &capmt->capmt_demuxes.filters[demux_index];
@@ -2063,7 +2048,7 @@ capmt_table_input(void *opaque, int pid, const uint8_t *data, int len, int emm)
     }
   }
 
-  pthread_mutex_unlock(&capmt->capmt_mutex);
+  tvh_mutex_unlock(&capmt->capmt_mutex);
 }
 
 static void
@@ -2132,8 +2117,8 @@ capmt_caid_change(th_descrambler_t *td)
   caid_t *c;
   int i, change = 0;
 
-  pthread_mutex_lock(&capmt->capmt_mutex);
-  pthread_mutex_lock(&t->s_stream_mutex);
+  tvh_mutex_lock(&capmt->capmt_mutex);
+  tvh_mutex_lock(&t->s_stream_mutex);
 
   /* add missing A/V PIDs and ECM PIDs */
   i = 0;
@@ -2207,8 +2192,8 @@ capmt_caid_change(th_descrambler_t *td)
       capmt_send_stop(ct);
   }
 
-  pthread_mutex_unlock(&t->s_stream_mutex);
-  pthread_mutex_unlock(&capmt->capmt_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&capmt->capmt_mutex);
 
   if (change)
     capmt_notify_server(capmt, ct, 1);
@@ -2467,8 +2452,8 @@ capmt_service_start(caclient_t *cac, service_t *s)
     tuner = lfe->lfe_adapter->la_dvb_number;
 #endif
 
-  pthread_mutex_lock(&capmt->capmt_mutex);
-  pthread_mutex_lock(&t->s_stream_mutex);
+  tvh_mutex_lock(&capmt->capmt_mutex);
+  tvh_mutex_lock(&t->s_stream_mutex);
 
   LIST_FOREACH(ct, &capmt->capmt_services, ct_link)
     /* skip, if we already have this service */
@@ -2495,7 +2480,7 @@ capmt_service_start(caclient_t *cac, service_t *s)
       tvherror(LS_CAPMT,
                "%s: No free adapter slot available for service \"%s\"",
                capmt_name(capmt), t->s_dvb_svcname);
-      pthread_mutex_unlock(&capmt->capmt_mutex);
+      tvh_mutex_unlock(&capmt->capmt_mutex);
       return;
     }
   }
@@ -2561,8 +2546,8 @@ capmt_service_start(caclient_t *cac, service_t *s)
 fin:
   if (ct)
     mtimer_arm_rel(&ct->ct_ok_timer, capmt_ok_timer_cb, ct, sec2mono(3)/2);
-  pthread_mutex_unlock(&t->s_stream_mutex);
-  pthread_mutex_unlock(&capmt->capmt_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&capmt->capmt_mutex);
 
   if (change)
     capmt_notify_server(capmt, NULL, 0);
@@ -2635,23 +2620,23 @@ capmt_conf_changed(caclient_t *cac)
     if (!atomic_get(&capmt->capmt_running)) {
       atomic_set(&capmt->capmt_running, 1);
       atomic_set(&capmt->capmt_reconfigure, 0);
-      tvhthread_create(&capmt->capmt_tid, NULL, capmt_thread, capmt, "capmt");
+      tvh_thread_create(&capmt->capmt_tid, NULL, capmt_thread, capmt, "capmt");
       return;
     }
-    pthread_mutex_lock(&capmt->capmt_mutex);
+    tvh_mutex_lock(&capmt->capmt_mutex);
     atomic_set(&capmt->capmt_reconfigure, 1);
     tvh_cond_signal(&capmt->capmt_cond, 0);
-    pthread_mutex_unlock(&capmt->capmt_mutex);
+    tvh_mutex_unlock(&capmt->capmt_mutex);
     tvh_write(capmt->capmt_pipe.wr, "", 1);
   } else {
     if (!atomic_get(&capmt->capmt_running))
       return;
-    pthread_mutex_lock(&capmt->capmt_mutex);
+    tvh_mutex_lock(&capmt->capmt_mutex);
     atomic_set(&capmt->capmt_running, 0);
     atomic_set(&capmt->capmt_reconfigure, 0);
     tvh_cond_signal(&capmt->capmt_cond, 0);
     tid = capmt->capmt_tid;
-    pthread_mutex_unlock(&capmt->capmt_mutex);
+    tvh_mutex_unlock(&capmt->capmt_mutex);
     tvh_write(capmt->capmt_pipe.wr, "", 1);
     pthread_join(tid, NULL);
     caclient_set_status(cac, CACLIENT_STATUS_NONE);
@@ -2735,8 +2720,8 @@ caclient_t *capmt_create(void)
 
   capmt->capmt_pmtversion = 1;
 
-  pthread_mutex_init(&capmt->capmt_mutex, NULL);
-  tvh_cond_init(&capmt->capmt_cond);
+  tvh_mutex_init(&capmt->capmt_mutex, NULL);
+  tvh_cond_init(&capmt->capmt_cond, 1);
   TAILQ_INIT(&capmt->capmt_writeq);
   tvh_pipe(O_NONBLOCK, &capmt->capmt_pipe);
 
index 2905e63957b2211aea99ea50bc3e3e98f79e2e7c..cfb3b1fe869ff0e9b958c5c11fcce2ef871b9dc4 100644 (file)
@@ -1047,8 +1047,8 @@ caclient_t *cccam_create(void)
   cccam->cc_subsys = LS_CCCAM;
   cccam->cc_id     = "cccam";
 
-  pthread_mutex_init(&cccam->cc_mutex, NULL);
-  tvh_cond_init(&cccam->cc_cond);
+  tvh_mutex_init(&cccam->cc_mutex, NULL);
+  tvh_cond_init(&cccam->cc_cond, 1);
   cccam->cac_free         = cc_free;
   cccam->cac_start        = cc_service_start;
   cccam->cac_conf_changed = cccam_conf_changed;
index 6cca85353712ac81b7f5d11b5d89ba1b840a8758..3c933135ec0b9fc697f12a89a65605d9288aac21 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <fcntl.h>
 #include <signal.h>
-#include <pthread.h>
+
 #include "tvheadend.h"
 #include "tcp.h"
 #include "cclient.h"
@@ -292,7 +292,7 @@ cc_ecm_reset(th_descrambler_t *th)
   cc_ecm_pid_t *ep;
   cc_ecm_section_t *es;
 
-  pthread_mutex_lock(&cc->cc_mutex);
+  tvh_mutex_lock(&cc->cc_mutex);
   descrambler_change_keystate(th, DS_READY, 1);
   LIST_FOREACH(ep, &ct->cs_ecm_pids, ep_link)
     LIST_FOREACH(es, &ep->ep_sections, es_link) {
@@ -302,7 +302,7 @@ cc_ecm_reset(th_descrambler_t *th)
       es->es_data_len = 0;
     }
   ct->ecm_state = ECM_RESET;
-  pthread_mutex_unlock(&cc->cc_mutex);
+  tvh_mutex_unlock(&cc->cc_mutex);
   return 0;
 }
 
@@ -317,7 +317,7 @@ cc_ecm_idle(th_descrambler_t *th)
   cc_ecm_pid_t *ep;
   cc_ecm_section_t *es;
 
-  pthread_mutex_lock(&cc->cc_mutex);
+  tvh_mutex_lock(&cc->cc_mutex);
   LIST_FOREACH(ep, &ct->cs_ecm_pids, ep_link)
     LIST_FOREACH(es, &ep->ep_sections, es_link) {
       es->es_keystate = ES_IDLE;
@@ -326,7 +326,7 @@ cc_ecm_idle(th_descrambler_t *th)
       es->es_data_len = 0;
     }
   ct->ecm_state = ECM_RESET;
-  pthread_mutex_unlock(&cc->cc_mutex);
+  tvh_mutex_unlock(&cc->cc_mutex);
 }
 
 /**
@@ -445,7 +445,7 @@ forbid:
     es->es_resolved = 1;
 
     es3 = *es;
-    pthread_mutex_unlock(&cc->cc_mutex);
+    tvh_mutex_unlock(&cc->cc_mutex);
     descrambler_keys((th_descrambler_t *)ct, key_type, 0, key_even, key_odd);
     snprintf(chaninfo, sizeof(chaninfo), "%s:%i", cc->cc_hostname, cc->cc_port);
     descrambler_notify((th_descrambler_t *)ct,
@@ -453,7 +453,7 @@ forbid:
                        caid2name(es3.es_caid),
                        es3.es_capid, delay,
                        1, "", chaninfo, cc->cc_id);
-    pthread_mutex_lock(&cc->cc_mutex);
+    tvh_mutex_lock(&cc->cc_mutex);
   }
 }
 
@@ -524,9 +524,9 @@ cc_read(cclient_t *cc, void *buf, size_t len, int timeout)
 {
   int r;
 
-  pthread_mutex_unlock(&cc->cc_mutex);
+  tvh_mutex_unlock(&cc->cc_mutex);
   r = tcp_read_timeout(cc->cc_fd, buf, len, timeout);
-  pthread_mutex_lock(&cc->cc_mutex);
+  tvh_mutex_lock(&cc->cc_mutex);
 
   if (r && tvheadend_is_running())
     tvhwarn(cc->cc_subsys, "%s: read error %d (%s)",
@@ -604,9 +604,9 @@ cc_session(cclient_t *cc)
   tvhpoll_add1(poll, cc->cc_fd, TVHPOLL_IN, &cc->cc_fd);
   mono = mclk() + sec2mono(cc->cc_keepalive_interval);
   while (!cc_must_break(cc)) {
-    pthread_mutex_unlock(&cc->cc_mutex);
+    tvh_mutex_unlock(&cc->cc_mutex);
     r = tvhpoll_wait(poll, &ev, 1, 1000);
-    pthread_mutex_lock(&cc->cc_mutex);
+    tvh_mutex_lock(&cc->cc_mutex);
     if (r == 0)
       continue;
     if (r < 0 && ERRNO_AGAIN(errno))
@@ -665,7 +665,7 @@ cc_thread(void *aux)
   int attempts = 0;
   int64_t mono;
 
-  pthread_mutex_lock(&cc->cc_mutex);
+  tvh_mutex_lock(&cc->cc_mutex);
 
   while(cc->cc_running) {
 
@@ -680,11 +680,11 @@ cc_thread(void *aux)
 
     tvhinfo(cc->cc_subsys, "%s: Attemping to connect to server", cc->cc_name);
 
-    pthread_mutex_unlock(&cc->cc_mutex);
+    tvh_mutex_unlock(&cc->cc_mutex);
 
     fd = tcp_connect(hostname, port, NULL, errbuf, sizeof(errbuf), 10);
 
-    pthread_mutex_lock(&cc->cc_mutex);
+    tvh_mutex_lock(&cc->cc_mutex);
 
     if(fd == -1) {
       attempts++;
@@ -735,7 +735,7 @@ cc_thread(void *aux)
   tvhinfo(cc->cc_subsys, "%s: Inactive, thread exit", cc->cc_name);
   cc_free_cards(cc);
   cc->cc_name = NULL;
-  pthread_mutex_unlock(&cc->cc_mutex);
+  tvh_mutex_unlock(&cc->cc_mutex);
   return NULL;
 }
 
@@ -816,7 +816,7 @@ cc_emm(void *opaque, int pid, const uint8_t *data, int len, int emm)
   if (pcard->cs_mux == NULL)
     return;
   cc = pcard->cs_client;
-  pthread_mutex_lock(&cc->cc_mutex);
+  tvh_mutex_lock(&cc->cc_mutex);
   mux = pcard->cs_mux;
   if (pcard->cs_running && cc->cc_forward_emm && cc->cc_write_running) {
     if (cc->cc_emmex) {
@@ -830,7 +830,7 @@ cc_emm(void *opaque, int pid, const uint8_t *data, int len, int emm)
     emm_filter(&pcard->cs_ra, data, len, mux, cc_emm_send, pcard);
   }
 end_of_job:
-  pthread_mutex_unlock(&cc->cc_mutex);
+  tvh_mutex_unlock(&cc->cc_mutex);
 }
 
 /**
@@ -858,8 +858,8 @@ cc_table_input(void *opaque, int pid, const uint8_t *data, int len, int emm)
   if (len > 4096)
     return;
 
-  pthread_mutex_lock(&cc->cc_mutex);
-  pthread_mutex_lock(&t->s_stream_mutex);
+  tvh_mutex_lock(&cc->cc_mutex);
+  tvh_mutex_lock(&t->s_stream_mutex);
 
   if (ct->td_keystate == DS_IDLE)
     goto end;
@@ -1004,8 +1004,8 @@ found:
   }
 
 end:
-  pthread_mutex_unlock(&t->s_stream_mutex);
-  pthread_mutex_unlock(&cc->cc_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&cc->cc_mutex);
 }
 
 /**
@@ -1043,9 +1043,9 @@ cc_service_destroy(th_descrambler_t *td)
   cc_service_t *ct = (cc_service_t *)td;
   cclient_t *cc = ct->cs_client;
 
-  pthread_mutex_lock(&cc->cc_mutex);
+  tvh_mutex_lock(&cc->cc_mutex);
   cc_service_destroy0(cc, td);
-  pthread_mutex_unlock(&cc->cc_mutex);
+  tvh_mutex_unlock(&cc->cc_mutex);
 }
 
 /**
@@ -1070,8 +1070,8 @@ cc_service_start(caclient_t *cac, service_t *t)
   if (!idnode_is_instance(&t->s_id, &mpegts_service_class))
     return;
 
-  pthread_mutex_lock(&cc->cc_mutex);
-  pthread_mutex_lock(&t->s_stream_mutex);
+  tvh_mutex_lock(&cc->cc_mutex);
+  tvh_mutex_lock(&t->s_stream_mutex);
   LIST_FOREACH(ct, &cc->cc_services, cs_link) {
     if (ct->td_service == t && ct->cs_client == cc)
       break;
@@ -1167,8 +1167,8 @@ add:
              cc->cc_name, service_nicename(t), reuse ? "re" : "", cc->cc_hostname, cc->cc_port);
 
 end:
-  pthread_mutex_unlock(&t->s_stream_mutex);
-  pthread_mutex_unlock(&cc->cc_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&cc->cc_mutex);
 }
 
 /**
@@ -1203,7 +1203,7 @@ cc_caid_update(caclient_t *cac, mpegts_mux_t *mux, uint16_t caid, uint32_t prov,
   tvhtrace(cc->cc_subsys,
            "%s: caid update event - client %s mux %p caid %04x (%i) prov %06x (%i) pid %04x (%i) valid %i",
            cc->cc_name, cac->cac_name, mux, caid, caid, prov, prov, pid, pid, valid);
-  pthread_mutex_lock(&cc->cc_mutex);
+  tvh_mutex_lock(&cc->cc_mutex);
   if (valid < 0 || cc->cc_running) {
     LIST_FOREACH(pcard, &cc->cc_cards, cs_card) {
       if (valid < 0 || pcard->cs_ra.caid == caid) {
@@ -1224,7 +1224,7 @@ cc_caid_update(caclient_t *cac, mpegts_mux_t *mux, uint16_t caid, uint32_t prov,
       }
     }
   }
-  pthread_mutex_unlock(&cc->cc_mutex);
+  tvh_mutex_unlock(&cc->cc_mutex);
 }
 
 /**
@@ -1243,32 +1243,32 @@ cc_conf_changed(caclient_t *cac)
       caclient_set_status(cac, CACLIENT_STATUS_NONE);
       return;
     }
-    pthread_mutex_lock(&cc->cc_mutex);
+    tvh_mutex_lock(&cc->cc_mutex);
     if (!cc->cc_running) {
       cc->cc_running = 1;
       tvh_pipe(O_NONBLOCK, &cc->cc_pipe);
       snprintf(tname, sizeof(tname), "cc-%s", cc->cc_id);
-      tvhthread_create(&cc->cc_tid, NULL, cc_thread, cc, tname);
-      pthread_mutex_unlock(&cc->cc_mutex);
+      tvh_thread_create(&cc->cc_tid, NULL, cc_thread, cc, tname);
+      tvh_mutex_unlock(&cc->cc_mutex);
       return;
     }
     cc->cc_reconfigure = 1;
     if(cc->cc_fd >= 0)
       shutdown(cc->cc_fd, SHUT_RDWR);
     tvh_cond_signal(&cc->cc_cond, 0);
-    pthread_mutex_unlock(&cc->cc_mutex);
+    tvh_mutex_unlock(&cc->cc_mutex);
   } else {
     if (!cc->cc_running)
       return;
-    pthread_mutex_lock(&cc->cc_mutex);
+    tvh_mutex_lock(&cc->cc_mutex);
     cc->cc_running = 0;
     tvh_cond_signal(&cc->cc_cond, 0);
     tid = cc->cc_tid;
     if (cc->cc_fd >= 0)
       shutdown(cc->cc_fd, SHUT_RDWR);
-    pthread_mutex_unlock(&cc->cc_mutex);
+    tvh_mutex_unlock(&cc->cc_mutex);
     tvh_write(cc->cc_pipe.wr, "q", 1);
-    pthread_kill(tid, SIGHUP);
+    tvh_thread_kill(tid, SIGHUP);
     pthread_join(tid, NULL);
     tvh_pipe_close(&cc->cc_pipe);
     caclient_set_status(cac, CACLIENT_STATUS_NONE);
index 8accc403cfe5d55e30c28a2918d47d757a23b504..63a393ea8c5ccafedc8ec772bf922c40d6776750 100644 (file)
@@ -156,7 +156,7 @@ typedef struct cclient {
   /* Thread */
   pthread_t cc_tid;
   tvh_cond_t cc_cond;
-  pthread_mutex_t cc_mutex;
+  tvh_mutex_t cc_mutex;
   th_pipe_t cc_pipe;
 
   /* Database */
index 3462d9ab4ea2927a24995be0aad7616377091bb7..c84b36a748575985fa7a02969a4b5f0ab7e2e875 100644 (file)
@@ -146,7 +146,7 @@ constcw_service_start(caclient_t *cac, service_t *t)
     return;
 
   if (!mt->s_dvb_forcecaid) {
-    pthread_mutex_lock(&t->s_stream_mutex);
+    tvh_mutex_lock(&t->s_stream_mutex);
     TAILQ_FOREACH(st, &t->s_components.set_filter, es_filter_link) {
       LIST_FOREACH(c, &st->es_caids, link) {
         if (c->use && c->caid == ccw->ccw_caid &&
@@ -155,7 +155,7 @@ constcw_service_start(caclient_t *cac, service_t *t)
       }
       if (c) break;
     }
-    pthread_mutex_unlock(&t->s_stream_mutex);
+    tvh_mutex_unlock(&t->s_stream_mutex);
     if (st == NULL)
       return;
   }
@@ -187,9 +187,9 @@ constcw_free(caclient_t *cac)
 
   while((ct = LIST_FIRST(&ccw->ccw_services)) != NULL) {
     service_t *t = ct->td_service;
-    pthread_mutex_lock(&t->s_stream_mutex);
+    tvh_mutex_lock(&t->s_stream_mutex);
     constcw_service_destroy((th_descrambler_t *)ct);
-    pthread_mutex_unlock(&t->s_stream_mutex);
+    tvh_mutex_unlock(&t->s_stream_mutex);
   }
 }
 
index 0ff7053484a500b05a258ca8f7ec249469f51759..5dadb3c128bcc9df778ee43b6e0246944942187e 100644 (file)
@@ -786,8 +786,8 @@ caclient_t *cwc_create(void)
   cwc->cc_subsys = LS_CWC;
   cwc->cc_id     = "newcamd";
 
-  pthread_mutex_init(&cwc->cc_mutex, NULL);
-  tvh_cond_init(&cwc->cc_cond);
+  tvh_mutex_init(&cwc->cc_mutex, NULL);
+  tvh_cond_init(&cwc->cc_cond, 1);
   cwc->cac_free         = cwc_free;
   cwc->cac_start        = cc_service_start;
   cwc->cac_conf_changed = cwc_conf_changed;
index cc2bc94fe5670eb5738b6eb9757147423dc9b58f..debbe56b6e2b2fe041ca5402ba84dbe47b592deb 100644 (file)
@@ -392,7 +392,7 @@ descrambler_service_start ( service_t *t )
 
   }
 
-  pthread_mutex_lock(&t->s_stream_mutex);
+  tvh_mutex_lock(&t->s_stream_mutex);
   ((mpegts_service_t *)t)->s_dvb_mux->mm_descrambler_flush = 0;
   if (t->s_descramble == NULL) {
     t->s_descramble = dr = calloc(1, sizeof(th_descrambler_runtime_t));
@@ -420,7 +420,7 @@ descrambler_service_start ( service_t *t )
     if (t->s_dvb_forcecaid == 0xffff)
       dr->dr_descramble = descrambler_pass;
   }
-  pthread_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
 
   if (t->s_dvb_forcecaid != 0xffff)
     caclient_start(t);
@@ -438,13 +438,13 @@ descrambler_service_stop ( service_t *t )
 
   while ((td = LIST_FIRST(&t->s_descramblers)) != NULL)
     td->td_stop(td);
-  pthread_mutex_lock(&t->s_stream_mutex);
+  tvh_mutex_lock(&t->s_stream_mutex);
   dr = t->s_descramble;
   t->s_descramble = NULL;
   t->s_descrambler = NULL;
   p = t->s_descramble_info;
   t->s_descramble_info = NULL;
-  pthread_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
   free(p);
   if (dr) {
     for (i = 0; i < DESCRAMBLER_MAX_KEYS; i++) {
@@ -538,9 +538,9 @@ descrambler_notify( th_descrambler_t *td,
   strlcpy(di->from, from, sizeof(di->protocol));
   strlcpy(di->protocol, protocol, sizeof(di->protocol));
 
-  pthread_mutex_lock(&t->s_stream_mutex);
+  tvh_mutex_lock(&t->s_stream_mutex);
   descrambler_notify_deliver(t, di);
-  pthread_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
 }
 
 int
@@ -600,7 +600,7 @@ descrambler_change_keystate( th_descrambler_t *td, th_descrambler_keystate_t key
     return;
 
   if (lock)
-    pthread_mutex_lock(&t->s_stream_mutex);
+    tvh_mutex_lock(&t->s_stream_mutex);
   count = failed = resolved = 0;
   LIST_FOREACH(td, &t->s_descramblers, td_service_link) {
     count++;
@@ -618,7 +618,7 @@ descrambler_change_keystate( th_descrambler_t *td, th_descrambler_keystate_t key
   tvhtrace(LS_DESCRAMBLER, "service \"%s\": %d descramblers (%d ok %d failed %d fatal)",
                            t->s_nicename, count, resolved, failed, fatal);
   if (lock)
-    pthread_mutex_unlock(&t->s_stream_mutex);
+    tvh_mutex_unlock(&t->s_stream_mutex);
 }
 
 static struct strtab keytypetab[] = {
@@ -654,16 +654,16 @@ descrambler_keys ( th_descrambler_t *td, int type, uint16_t pid,
     return;
   }
 
-  pthread_mutex_lock(&t->s_stream_mutex);
+  tvh_mutex_lock(&t->s_stream_mutex);
 
   if (pid == 0 && dr->dr_key_multipid) {
     for (j = 0; j < DESCRAMBLER_MAX_KEYS; j++) {
       tk = &dr->dr_keys[j];
       pid2 = tk->key_pid;
       if (pid2) {
-        pthread_mutex_unlock(&t->s_stream_mutex);
+        tvh_mutex_unlock(&t->s_stream_mutex);
         descrambler_keys(td, type, pid2, even, odd);
-        pthread_mutex_lock(&t->s_stream_mutex);
+        tvh_mutex_lock(&t->s_stream_mutex);
       }
     }
     goto end;
@@ -723,9 +723,9 @@ cont:
                dr->dr_key_const ? " (const)" : "");
       descrambler_change_keystate(td, DS_IDLE, 0);
       if (td->td_ecm_idle) {
-        pthread_mutex_unlock(&t->s_stream_mutex);
+        tvh_mutex_unlock(&t->s_stream_mutex);
         td->td_ecm_idle(td);
-        pthread_mutex_lock(&t->s_stream_mutex);
+        tvh_mutex_lock(&t->s_stream_mutex);
       }
       goto end;
     }
@@ -811,7 +811,7 @@ cont:
   }
 
 end:
-  pthread_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
 }
 
 void
@@ -826,7 +826,7 @@ descrambler_flush_table_data( service_t *t )
   if (mux == NULL)
     return;
   tvhtrace(LS_DESCRAMBLER, "flush table data for service \"%s\"", ms->s_dvb_svcname);
-  pthread_mutex_lock(&mux->mm_descrambler_lock);
+  tvh_mutex_lock(&mux->mm_descrambler_lock);
   TAILQ_FOREACH(dt, &mux->mm_descrambler_tables, link) {
     if (dt->table == NULL || dt->table->mt_service != ms)
       continue;
@@ -838,7 +838,7 @@ descrambler_flush_table_data( service_t *t )
           free(des);
       }
   }
-  pthread_mutex_unlock(&mux->mm_descrambler_lock);
+  tvh_mutex_unlock(&mux->mm_descrambler_lock);
 }
 
 static inline void 
@@ -1114,9 +1114,9 @@ descrambler_descramble ( service_t *t,
                                     ((mpegts_service_t *)t)->s_dvb_svcname);
             if (key_late(dr, tk, ki, dd->dd_timestamp)) {
               descrambler_notify_nokey(dr);
-              pthread_mutex_unlock(&t->s_stream_mutex);
+              tvh_mutex_unlock(&t->s_stream_mutex);
               r = ecm_reset(t, dr);
-              pthread_mutex_lock(&t->s_stream_mutex);
+              tvh_mutex_lock(&t->s_stream_mutex);
               if (r) {
                 descrambler_data_cut(dr, tsb2 - sb->sb_data);
                 flush_data = 1;
@@ -1267,7 +1267,7 @@ descrambler_table_callback
     return 0;
   clk = mclk();
   LIST_INIT(&sections);
-  pthread_mutex_lock(&mt->mt_mux->mm_descrambler_lock);
+  tvh_mutex_lock(&mt->mt_mux->mm_descrambler_lock);
   TAILQ_FOREACH(ds, &dt->sections, link) {
     if (!emm) {
       LIST_FOREACH(des, &ds->ecmsecs, link)
@@ -1300,14 +1300,14 @@ descrambler_table_callback
     des->opaque = ds->opaque;
     LIST_INSERT_HEAD(&sections, des, active_link);
   }
-  pthread_mutex_unlock(&mt->mt_mux->mm_descrambler_lock);
+  tvh_mutex_unlock(&mt->mt_mux->mm_descrambler_lock);
 
   LIST_FOREACH(des, &sections, active_link) {
     if (des->changed == 2) {
       des->callback(des->opaque, mt->mt_pid, ptr, len, emm);
       if (!emm) { /* ECM */
         if ((t = mt->mt_service) != NULL) {
-          pthread_mutex_lock(&t->s_stream_mutex);
+          tvh_mutex_lock(&t->s_stream_mutex);
           /* The keys are requested from this moment */
           dr = t->s_descramble;
           if (dr) {
@@ -1335,7 +1335,7 @@ descrambler_table_callback
             tvhtrace(LS_DESCRAMBLER, "ECM message %02x:%02x (section %d, len %d, pid %d) for service \"%s\"",
                      ptr[0], ptr[1], des->number, len, mt->mt_pid, t->s_dvb_svcname);
           }
-          pthread_mutex_unlock(&t->s_stream_mutex);
+          tvh_mutex_unlock(&t->s_stream_mutex);
         } else
           tvhtrace(LS_DESCRAMBLER, "Unknown fast table message %02x (section %d, len %d, pid %d)",
                    ptr[0], des->number, len, mt->mt_pid);
@@ -1358,7 +1358,7 @@ descrambler_table_callback
       }
     } else if (des->changed == 1 && !emm) {
       if ((t = mt->mt_service) != NULL) {
-        pthread_mutex_lock(&t->s_stream_mutex);
+        tvh_mutex_lock(&t->s_stream_mutex);
         if ((dr = t->s_descramble) != NULL) {
           for (i = 0; i < DESCRAMBLER_MAX_KEYS; i++) {
             tk = &dr->dr_keys[i];
@@ -1374,7 +1374,7 @@ descrambler_table_callback
             }
           }
         }
-        pthread_mutex_unlock(&t->s_stream_mutex);
+        tvh_mutex_unlock(&t->s_stream_mutex);
       }
     }
   }
@@ -1438,9 +1438,9 @@ descrambler_open_pid( mpegts_mux_t *mux, void *opaque, int pid,
 {
   int res;
 
-  pthread_mutex_lock(&mux->mm_descrambler_lock);
+  tvh_mutex_lock(&mux->mm_descrambler_lock);
   res = descrambler_open_pid_(mux, opaque, pid, callback, service);
-  pthread_mutex_unlock(&mux->mm_descrambler_lock);
+  tvh_mutex_unlock(&mux->mm_descrambler_lock);
   return res;
 }
 
@@ -1488,9 +1488,9 @@ descrambler_close_pid( mpegts_mux_t *mux, void *opaque, int pid )
 {
   int res;
 
-  pthread_mutex_lock(&mux->mm_descrambler_lock);
+  tvh_mutex_lock(&mux->mm_descrambler_lock);
   res = descrambler_close_pid_(mux, opaque, pid);
-  pthread_mutex_unlock(&mux->mm_descrambler_lock);
+  tvh_mutex_unlock(&mux->mm_descrambler_lock);
   return res;
 }
 
@@ -1506,7 +1506,7 @@ descrambler_flush_tables( mpegts_mux_t *mux )
     return;
   tvhtrace(LS_DESCRAMBLER, "mux %p - flush tables", mux);
   caclient_caid_update(mux, 0, 0, 0, -1);
-  pthread_mutex_lock(&mux->mm_descrambler_lock);
+  tvh_mutex_lock(&mux->mm_descrambler_lock);
   mux->mm_descrambler_flush = 1;
   while ((dt = TAILQ_FIRST(&mux->mm_descrambler_tables)) != NULL) {
     while ((ds = TAILQ_FIRST(&dt->sections)) != NULL) {
@@ -1528,7 +1528,7 @@ descrambler_flush_tables( mpegts_mux_t *mux )
     TAILQ_REMOVE(&mux->mm_descrambler_emms, emm, link);
     free(emm);
   }
-  pthread_mutex_unlock(&mux->mm_descrambler_lock);
+  tvh_mutex_unlock(&mux->mm_descrambler_lock);
 }
 
 static void descrambler_cat_entry
@@ -1537,7 +1537,7 @@ static void descrambler_cat_entry
   mpegts_mux_t *mux = _mux;
   descrambler_emm_t *emm;
   caclient_caid_update(mux, caid, prov, pid, 1);
-  pthread_mutex_lock(&mux->mm_descrambler_lock);
+  tvh_mutex_lock(&mux->mm_descrambler_lock);
   TAILQ_FOREACH(emm, &mux->mm_descrambler_emms, link)
     if (emm->caid == caid && emm->prov == prov) {
       emm->to_be_removed = 0;
@@ -1549,7 +1549,7 @@ static void descrambler_cat_entry
         break; // Only open a PID once
       }
     }
-  pthread_mutex_unlock(&mux->mm_descrambler_lock);
+  tvh_mutex_unlock(&mux->mm_descrambler_lock);
 }
 
 static void descrambler_cat_clean( mpegts_mux_t *mux )
@@ -1560,7 +1560,7 @@ static void descrambler_cat_clean( mpegts_mux_t *mux )
   uint32_t prov;
 
   TAILQ_INIT(&removing);
-  pthread_mutex_lock(&mux->mm_descrambler_lock);
+  tvh_mutex_lock(&mux->mm_descrambler_lock);
   TAILQ_FOREACH(emm, &mux->mm_descrambler_emms, link)
     if (emm->to_be_removed) {
       if (emm->pid != EMM_PID_UNKNOWN) {
@@ -1574,7 +1574,7 @@ static void descrambler_cat_clean( mpegts_mux_t *mux )
       TAILQ_REMOVE(&mux->mm_descrambler_emms, emm, link);
       TAILQ_INSERT_TAIL(&removing, emm, link);
     }
-  pthread_mutex_unlock(&mux->mm_descrambler_lock);
+  tvh_mutex_unlock(&mux->mm_descrambler_lock);
   while ((emm = TAILQ_FIRST(&removing)) != NULL) {
     if (emm->pid != EMM_PID_UNKNOWN)
       caclient_caid_update(mux, emm->caid, emm->prov, emm->pid, 0);
@@ -1591,10 +1591,10 @@ descrambler_cat_data( mpegts_mux_t *mux, const uint8_t *data, int len )
   tvhtrace(LS_DESCRAMBLER, "CAT data (len %d)", len);
   tvhlog_hexdump(LS_DESCRAMBLER, data, len);
   caclient_cat_update(mux, data, len);
-  pthread_mutex_lock(&mux->mm_descrambler_lock);
+  tvh_mutex_lock(&mux->mm_descrambler_lock);
   TAILQ_FOREACH(emm, &mux->mm_descrambler_emms, link)
     emm->to_be_removed = 1;
-  pthread_mutex_unlock(&mux->mm_descrambler_lock);
+  tvh_mutex_unlock(&mux->mm_descrambler_lock);
   dvb_cat_decode(data, len, descrambler_cat_entry, mux);
   descrambler_cat_clean(mux);
 }
@@ -1610,13 +1610,13 @@ descrambler_open_emm( mpegts_mux_t *mux, void *opaque,
 
   if (mux == NULL)
     return 0;
-  pthread_mutex_lock(&mux->mm_descrambler_lock);
+  tvh_mutex_lock(&mux->mm_descrambler_lock);
   if (mux->mm_descrambler_flush)
     goto unlock;
   TAILQ_FOREACH(emm, &mux->mm_descrambler_emms, link) {
     if (emm->caid == caid && emm->prov == prov && emm->opaque == opaque) {
 unlock:
-      pthread_mutex_unlock(&mux->mm_descrambler_lock);
+      tvh_mutex_unlock(&mux->mm_descrambler_lock);
       return 0;
     }
   }
@@ -1639,7 +1639,7 @@ unlock:
              caid, caid, pid, pid);
     descrambler_open_pid_(mux, opaque, pid, callback, NULL);
   }
-  pthread_mutex_unlock(&mux->mm_descrambler_lock);
+  tvh_mutex_unlock(&mux->mm_descrambler_lock);
   return 1;
 }
 
@@ -1651,12 +1651,12 @@ descrambler_close_emm( mpegts_mux_t *mux, void *opaque, int caid, int prov )
 
   if (mux == NULL)
     return 0;
-  pthread_mutex_lock(&mux->mm_descrambler_lock);
+  tvh_mutex_lock(&mux->mm_descrambler_lock);
   TAILQ_FOREACH(emm, &mux->mm_descrambler_emms, link)
     if (emm->caid == caid && emm->prov == prov && emm->opaque == opaque)
       break;
   if (!emm) {
-    pthread_mutex_unlock(&mux->mm_descrambler_lock);
+    tvh_mutex_unlock(&mux->mm_descrambler_lock);
     return 0;
   }
   TAILQ_REMOVE(&mux->mm_descrambler_emms, emm, link);
@@ -1668,7 +1668,7 @@ descrambler_close_emm( mpegts_mux_t *mux, void *opaque, int caid, int prov )
                              caid, caid, prov, prov, pid, pid);
     descrambler_close_pid_(mux, opaque, pid);
   }
-  pthread_mutex_unlock(&mux->mm_descrambler_lock);
+  tvh_mutex_unlock(&mux->mm_descrambler_lock);
   free(emm);
   return 1;
 }
index 461a0146f64c9a7e1df44734c7143189e590b5bd..3fefecf1219f8e7b5aeeebdfea75d25c1333c328 100644 (file)
@@ -74,7 +74,7 @@ typedef struct dvbcam {
 static TAILQ_HEAD(,dvbcam_active_service) dvbcam_active_services;
 static TAILQ_HEAD(,dvbcam_active_cam) dvbcam_active_cams;
 
-static pthread_mutex_t dvbcam_mutex;
+static tvh_mutex_t dvbcam_mutex;
 
 /*
  *
@@ -84,11 +84,11 @@ dvbcam_status_update0(caclient_t *cac)
 {
   int status = CACLIENT_STATUS_NONE;
 
-  pthread_mutex_lock(&dvbcam_mutex);
+  tvh_mutex_lock(&dvbcam_mutex);
   if (TAILQ_FIRST(&dvbcam_active_cams))
     status = CACLIENT_STATUS_CONNECTED;
   caclient_set_status(cac, status);
-  pthread_mutex_unlock(&dvbcam_mutex);
+  tvh_mutex_unlock(&dvbcam_mutex);
 }
 
 /*
@@ -173,7 +173,7 @@ dvbcam_register_cam(linuxdvb_ca_t * lca, uint16_t * caids,
 
   tvhtrace(LS_DVBCAM, "register cam %p caids_count %u", lca->lca_name, caids_count);
 
-  pthread_mutex_lock(&dvbcam_mutex);
+  tvh_mutex_lock(&dvbcam_mutex);
 
   TAILQ_FOREACH(ac, &dvbcam_active_cams, global_link) {
     if (ac->ca == lca) {
@@ -199,7 +199,7 @@ dvbcam_register_cam(linuxdvb_ca_t * lca, uint16_t * caids,
   call_update = ac_first == NULL;
 
 reterr:
-  pthread_mutex_unlock(&dvbcam_mutex);
+  tvh_mutex_unlock(&dvbcam_mutex);
 
   if (call_update)
     dvbcam_status_update();
@@ -218,7 +218,7 @@ dvbcam_unregister_cam(linuxdvb_ca_t *lca)
 
   tvhtrace(LS_DVBCAM, "unregister cam %s", lca->lca_name);
 
-  pthread_mutex_lock(&dvbcam_mutex);
+  tvh_mutex_lock(&dvbcam_mutex);
 
   /* delete entry */
   for (ac = TAILQ_FIRST(&dvbcam_active_cams); ac != NULL; ac = ac_next) {
@@ -239,7 +239,7 @@ dvbcam_unregister_cam(linuxdvb_ca_t *lca)
 
   call_update = TAILQ_EMPTY(&dvbcam_active_cams);
 
-  pthread_mutex_unlock(&dvbcam_mutex);
+  tvh_mutex_unlock(&dvbcam_mutex);
 
   if (call_update)
     dvbcam_status_update();
@@ -288,8 +288,8 @@ dvbcam_pmt_data(mpegts_service_t *s, const uint8_t *ptr, int len)
   uint8_t *capmt;
   size_t capmt_len;
 
-  pthread_mutex_lock(&s->s_stream_mutex);
-  pthread_mutex_lock(&dvbcam_mutex);
+  tvh_mutex_lock(&s->s_stream_mutex);
+  tvh_mutex_lock(&dvbcam_mutex);
 
   /* find this service in the list of active services */
   TAILQ_FOREACH(as, &dvbcam_active_services, global_link)
@@ -343,8 +343,8 @@ dvbcam_pmt_data(mpegts_service_t *s, const uint8_t *ptr, int len)
     tvherror(LS_DVBCAM, "CAPMT unable to build");
   }
 done:
-  pthread_mutex_unlock(&dvbcam_mutex);
-  pthread_mutex_unlock(&s->s_stream_mutex);
+  tvh_mutex_unlock(&dvbcam_mutex);
+  tvh_mutex_unlock(&s->s_stream_mutex);
 }
 
 static void
@@ -357,7 +357,7 @@ dvbcam_service_destroy(th_descrambler_t *td)
   uint8_t *capmt;
   size_t capmt_len;
 
-  pthread_mutex_lock(&dvbcam_mutex);
+  tvh_mutex_lock(&dvbcam_mutex);
   ac = as->ac;
   if (as->last_pmt) {
     if (ac) {
@@ -393,7 +393,7 @@ dvbcam_service_destroy(th_descrambler_t *td)
       break;
     }
   }
-  pthread_mutex_unlock(&dvbcam_mutex);
+  tvh_mutex_unlock(&dvbcam_mutex);
   mpegts_pid_done(&as->ecm_pids);
   mpegts_pid_done(&as->cat_pids);
   free(as->cat_data);
@@ -452,8 +452,8 @@ dvbcam_service_start(caclient_t *cac, service_t *t)
   mpegts_pid_init(&ecm_to_close);
 #endif
 
-  pthread_mutex_lock(&t->s_stream_mutex);
-  pthread_mutex_lock(&dvbcam_mutex);
+  tvh_mutex_lock(&t->s_stream_mutex);
+  tvh_mutex_lock(&dvbcam_mutex);
 
   /* is there already a CAM associated to the service? */
   TAILQ_FOREACH(as, &dvbcam_active_services, global_link) {
@@ -615,16 +615,16 @@ update_pid:
   mpegts_pid_copy(&as->ecm_pids, &ecm_pids);
 #endif
 
-  pthread_mutex_unlock(&dvbcam_mutex);
-  pthread_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&dvbcam_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
 
 #if ENABLE_DDCI
   if (as && as->lddci) {
     mm = ((mpegts_service_t *)t)->s_dvb_mux;
     mi = mm->mm_active ? mm->mm_active->mmi_input : NULL;
     if (mi) {
-      pthread_mutex_lock(&mi->mi_output_lock);
-      pthread_mutex_lock(&t->s_stream_mutex);
+      tvh_mutex_lock(&mi->mi_output_lock);
+      tvh_mutex_lock(&t->s_stream_mutex);
       mpegts_input_open_pid(mi, mm, DVB_CAT_PID, MPS_SERVICE | MPS_NOPOSTDEMUX,
                             MPS_WEIGHT_CAT, t, 0);
       ((mpegts_service_t *)t)->s_cat_opened = 1;
@@ -633,8 +633,8 @@ update_pid:
                              MPS_WEIGHT_CA, t, 0);
       for (i = 0; i < ecm_to_close.count; i++)
         mpegts_input_close_pid(mi, mm, ecm_to_close.pids[i].pid, MPS_SERVICE, t);
-      pthread_mutex_unlock(&t->s_stream_mutex);
-      pthread_mutex_unlock(&mi->mi_output_lock);
+      tvh_mutex_unlock(&t->s_stream_mutex);
+      tvh_mutex_unlock(&mi->mi_output_lock);
       mpegts_mux_update_pids(mm);
     }
   }
@@ -645,8 +645,8 @@ update_pid:
   return;
 
 end:
-  pthread_mutex_unlock(&dvbcam_mutex);
-  pthread_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&dvbcam_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
 }
 
 /*
@@ -705,7 +705,7 @@ dvbcam_cat_update(caclient_t *cac, mpegts_mux_t *mux, const uint8_t *data, int l
     return;
 
   services_count = 0;
-  pthread_mutex_lock(&dvbcam_mutex);
+  tvh_mutex_lock(&dvbcam_mutex);
   /* look for CAID in all services */
   TAILQ_FOREACH(as, &dvbcam_active_services, global_link) {
     if (!as->lddci) continue;
@@ -733,26 +733,26 @@ dvbcam_cat_update(caclient_t *cac, mpegts_mux_t *mux, const uint8_t *data, int l
     } else
       tvherror(LS_DVBCAM, "CAT update error (array overflow)");
   }
-  pthread_mutex_unlock(&dvbcam_mutex);
+  tvh_mutex_unlock(&dvbcam_mutex);
 
   if (services_count > 0) {
     mi = mux->mm_active ? mux->mm_active->mmi_input : NULL;
     if (mi) {
-      pthread_mutex_lock(&mi->mi_output_lock);
+      tvh_mutex_lock(&mi->mi_output_lock);
       for (i = 0; i < services_count; i++) {
         sp = &services[i];
-        pthread_mutex_lock(&sp->service->s_stream_mutex);
+        tvh_mutex_lock(&sp->service->s_stream_mutex);
         for (i = 0; i < sp->to_open.count; i++)
           mpegts_input_open_pid(mi, mux, sp->to_open.pids[i].pid, MPS_SERVICE,
                                MPS_WEIGHT_CAT, sp->service, 0);
         for (i = 0; i < sp->to_close.count; i++)
           mpegts_input_close_pid(mi, mux, sp->to_close.pids[i].pid, MPS_SERVICE,
                                  sp->service);
-        pthread_mutex_unlock(&sp->service->s_stream_mutex);
+        tvh_mutex_unlock(&sp->service->s_stream_mutex);
         mpegts_pid_done(&sp->to_open);
         mpegts_pid_done(&sp->to_close);
       }
-      pthread_mutex_unlock(&mi->mi_output_lock);
+      tvh_mutex_unlock(&mi->mi_output_lock);
       mpegts_mux_update_pids(mux);
     }
   }
@@ -915,7 +915,7 @@ caclient_t *dvbcam_create(void)
 void
 dvbcam_init(void)
 {
-  pthread_mutex_init(&dvbcam_mutex, NULL);
+  tvh_mutex_init(&dvbcam_mutex, NULL);
   TAILQ_INIT(&dvbcam_active_services);
   TAILQ_INIT(&dvbcam_active_cams);
 }
index 1c42dff5be0dd0795018ffda90143927ffbcce91..679c4e3c74be526d88fc3d9df1c1a4430143c78e 100644 (file)
@@ -40,7 +40,7 @@ typedef struct tsdebugcw_request {
   tsdebugcw_service_t *ct;
 } tsdebugcw_request_t;
 
-pthread_mutex_t tsdebugcw_mutex;
+tvh_mutex_t tsdebugcw_mutex;
 TAILQ_HEAD(,tsdebugcw_request) tsdebugcw_requests;
 
 /*
@@ -61,7 +61,7 @@ tsdebugcw_service_destroy(th_descrambler_t *td)
   tsdebugcw_service_t *ct = (tsdebugcw_service_t *)td;
   tsdebugcw_request_t *ctr, *ctrnext;
 
-  pthread_mutex_lock(&tsdebugcw_mutex);
+  tvh_mutex_lock(&tsdebugcw_mutex);
   for (ctr = TAILQ_FIRST(&tsdebugcw_requests); ctr; ctr = ctrnext) {
     ctrnext = TAILQ_NEXT(ctr, link);
     if (ctr->ct == ct) {
@@ -69,7 +69,7 @@ tsdebugcw_service_destroy(th_descrambler_t *td)
       free(ctr);
     }
   }
-  pthread_mutex_unlock(&tsdebugcw_mutex);
+  tvh_mutex_unlock(&tsdebugcw_mutex);
 
   LIST_REMOVE(td, td_service_link);
   free(ct->td_nicename);
@@ -103,10 +103,10 @@ tsdebugcw_service_start(service_t *t)
   td->td_service       = t;
   td->td_stop          = tsdebugcw_service_destroy;
   td->td_ecm_reset     = tsdebugcw_ecm_reset;
-  pthread_mutex_lock(&t->s_stream_mutex);
+  tvh_mutex_lock(&t->s_stream_mutex);
   LIST_INSERT_HEAD(&t->s_descramblers, td, td_service_link);
   descrambler_change_keystate((th_descrambler_t *)td, DS_READY, 0);
-  pthread_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
 }
 
 /*
@@ -135,9 +135,9 @@ tsdebugcw_new_keys(service_t *t, int type, uint16_t pid, uint8_t *odd, uint8_t *
     memcpy(ct->tdcw_key_even, even, keylen);
   ctr = malloc(sizeof(*ctr));
   ctr->ct = ct;
-  pthread_mutex_lock(&tsdebugcw_mutex);
+  tvh_mutex_lock(&tsdebugcw_mutex);
   TAILQ_INSERT_TAIL(&tsdebugcw_requests, ctr, link);
-  pthread_mutex_unlock(&tsdebugcw_mutex);
+  tvh_mutex_unlock(&tsdebugcw_mutex);
 }
 
 /*
@@ -150,11 +150,11 @@ tsdebugcw_go(void)
   tsdebugcw_service_t *ct;
 
   while (1) {
-    pthread_mutex_lock(&tsdebugcw_mutex);
+    tvh_mutex_lock(&tsdebugcw_mutex);
     ctr = TAILQ_FIRST(&tsdebugcw_requests);
     if (ctr)
       TAILQ_REMOVE(&tsdebugcw_requests, ctr, link);
-    pthread_mutex_unlock(&tsdebugcw_mutex);
+    tvh_mutex_unlock(&tsdebugcw_mutex);
     if (!ctr) break;
     ct = ctr->ct;
     descrambler_keys((th_descrambler_t *)ct,
@@ -170,6 +170,6 @@ tsdebugcw_go(void)
 void
 tsdebugcw_init(void)
 {
-  pthread_mutex_init(&tsdebugcw_mutex, NULL);
+  tvh_mutex_init(&tsdebugcw_mutex, NULL);
   TAILQ_INIT(&tsdebugcw_requests);
 }
index ce8a98d6cd79a8f2c4573eb2fcf10d8913b2d37b..5f2b6a9589e095bf344505356a8f6120b6a393f4 100644 (file)
@@ -114,7 +114,7 @@ download_fetch_complete(http_client_t *hc)
       last_url++;
   }
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 
   if (dn->http_client == NULL)
     goto out;
@@ -129,7 +129,7 @@ download_fetch_complete(http_client_t *hc)
   mtimer_arm_rel(&dn->fetch_timer, download_fetch_done, hc, 0);
 
 out:
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   urlreset(&u);
   return 0;
index 528e44035d40f653761e562d8d15bb25d5802c1e..e9ae667bcb9c429f349b8c1d48296840db0140b0 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <pthread.h>
 #include <ctype.h>
-#include <assert.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <errno.h>
-#include <math.h>
-#include <time.h>
 
 #include "tvheadend.h"
 #include "settings.h"
@@ -1421,10 +1411,10 @@ dvr_autorec_done(void)
 {
   dvr_autorec_entry_t *dae;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   while ((dae = TAILQ_FIRST(&autorec_entries)) != NULL)
     autorec_entry_destroy(dae, 0);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
 
 void
index 4ff590d523485288ca473f7ddd27816d5bce2225..cbb9924c51f915384bb51ced9d6358435afc876e 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <pthread.h>
 #include <sys/stat.h>
-#include <unistd.h>
-#include <assert.h>
-#include <string.h>
 
 #include "settings.h"
 
@@ -1547,11 +1543,11 @@ dvr_done(void)
 #if ENABLE_INOTIFY
   dvr_inotify_done();
 #endif
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   dvr_entry_done();
   while ((cfg = LIST_FIRST(&dvrconfigs)) != NULL)
     dvr_config_destroy(cfg, 0);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   dvr_autorec_done();
   dvr_timerec_done();
   dvr_disk_space_done();
index c41256f2f643bb8e5fe868ba9ac94511fd6cdf06..2d6dd0a764fa494440832642536512317e076a50 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <pthread.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <assert.h>
-#include <string.h>
 #include <ctype.h>
-#include <string_list.h>
-
-#include "settings.h"
 
 #include "tvheadend.h"
+#include "settings.h"
 #include "dvr.h"
 #include "htsp_server.h"
 #include "streaming.h"
@@ -4918,7 +4911,7 @@ dvr_entry_file_moved(const char *src, const char *dst)
 
   if (!src || !dst || src[0] == '\0' || dst[0] == '\0' || access(dst, R_OK))
     return r;
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   LIST_FOREACH(de, &dvrentries, de_global_link) {
     if (htsmsg_is_empty(de->de_files)) continue;
     chg = 0;
@@ -4935,7 +4928,7 @@ dvr_entry_file_moved(const char *src, const char *dst)
     if (chg)
       idnode_changed(&de->de_id);
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   return r;
 }
 
index 038e3c09409271dda6b9f7b3333d662d65b3cf96..6311b3b0a7532c7d091f7df83bda95a33a447756 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "tvheadend.h"
-
-#include <unistd.h>
-#include <assert.h>
-#include <poll.h>
-#include <signal.h>
-#include <pthread.h>
 #include <sys/inotify.h>
 #include <sys/stat.h>
+#include <signal.h>
 
+#include "tvheadend.h"
 #include "redblack.h"
 #include "dvr/dvr.h"
 #include "htsp_server.h"
@@ -76,7 +71,7 @@ void dvr_inotify_init ( void )
     return;
   }
 
-  tvhthread_create(&dvr_inotify_tid, NULL, _dvr_inotify_thread, NULL, "dvr-inotify");
+  tvh_thread_create(&dvr_inotify_tid, NULL, _dvr_inotify_thread, NULL, "dvr-inotify");
 }
 
 /**
@@ -86,7 +81,7 @@ void dvr_inotify_done ( void )
 {
   int fd = atomic_exchange(&_inot_fd, -1);
   if (fd >= 0) blacklisted_close(fd);
-  pthread_kill(dvr_inotify_tid, SIGTERM);
+  tvh_thread_kill(dvr_inotify_tid, SIGTERM);
   pthread_join(dvr_inotify_tid, NULL);
   SKEL_FREE(dvr_inotify_entry_skel);
 }
@@ -398,7 +393,7 @@ void* _dvr_inotify_thread ( void *p )
       break;
 
     /* Process */
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     while (i < len) {
       ev = (struct inotify_event *)&buf[i];
       tvhtrace(LS_DVR_INOTIFY, "i=%d len=%d name=%s", i, len, ev->name);
@@ -452,7 +447,7 @@ void* _dvr_inotify_thread ( void *p )
       cookie_prev = cookie;
       tvhdebug(LS_DVR_INOTIFY, "i=%d len=%d cookie_prev=%d from_prev=%s fd=%d EOR", i, len, cookie_prev, from_prev, fromfd_prev);
     }
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
   }
 
   return NULL;
index 047614f736f233f388ae537cec7cf11906980b01..ac361ab7ae7ebbb4a938fb38ff49faf68a6d0185 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <stdarg.h>
-#include <pthread.h>
-#include <assert.h>
-#include <string.h>
-#include <ctype.h>
 #include <sys/stat.h>
-#include <libgen.h> /* basename */
+#include <ctype.h>
 
 #include "tvheadend.h"
 #include "streaming.h"
@@ -164,7 +159,7 @@ dvr_rec_subscribe(dvr_entry_t *de)
   de->de_chain = prch;
 
   atomic_set(&de->de_thread_shutdown, 0);
-  tvhthread_create(&de->de_thread, NULL, dvr_thread, de, "dvr");
+  tvh_thread_create(&de->de_thread, NULL, dvr_thread, de, "dvr");
 
   if (de->de_config->dvr_preproc)
     dvr_spawn_cmd(de, de->de_config->dvr_preproc, NULL, 1);
@@ -1400,7 +1395,7 @@ dvr_thread_global_lock(dvr_entry_t *de, int *run)
     *run = 0;
     return 0;
   }
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   return 1;
 }
 
@@ -1410,7 +1405,7 @@ dvr_thread_global_lock(dvr_entry_t *de, int *run)
 static inline void
 dvr_thread_global_unlock(dvr_entry_t *de)
 {
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   atomic_dec(&de->de_thread_shutdown, 1);
 }
 
@@ -1606,7 +1601,7 @@ dvr_thread(void *aux)
 
   TAILQ_INIT(&backlog);
 
-  pthread_mutex_lock(&sq->sq_mutex);
+  tvh_mutex_lock(&sq->sq_mutex);
   while(run) {
     sm = TAILQ_FIRST(&sq->sq_queue);
     if(sm == NULL) {
@@ -1642,7 +1637,7 @@ dvr_thread(void *aux)
       tvhtrace(LS_DVR, "%s - running flag changed from %d to %d",
                idnode_uuid_as_str(&de->de_id, ubuf), old_epg_running, epg_running);
 
-    pthread_mutex_unlock(&sq->sq_mutex);
+    tvh_mutex_unlock(&sq->sq_mutex);
 
     switch(sm->sm_type) {
 
@@ -1858,9 +1853,9 @@ fin:
     }
 
     streaming_msg_free(sm);
-    pthread_mutex_lock(&sq->sq_mutex);
+    tvh_mutex_lock(&sq->sq_mutex);
   }
-  pthread_mutex_unlock(&sq->sq_mutex);
+  tvh_mutex_unlock(&sq->sq_mutex);
 
   streaming_queue_clear(&backlog);
 
index e840176c5591c980ddfec6a9bdcd9ba5fe023d78..1016b550f65b7b8bd753865de9d0cb0bef5bb9ea 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <pthread.h>
 #include <ctype.h>
-#include <assert.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <errno.h>
-#include <math.h>
-#include <time.h>
 
 #include "tvheadend.h"
 #include "settings.h"
@@ -720,10 +710,10 @@ dvr_timerec_done(void)
 {
   dvr_timerec_entry_t *dte;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   while ((dte = TAILQ_FIRST(&timerec_entries)) != NULL)
     timerec_entry_destroy(dte, 0);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
 
 static void
index f62868f276a81b6dfe036ebb4faabf64d2de281e..b7c0fc4cc22c24165ebda77f007324b6fa0e12c3 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <stdarg.h>
-#include <pthread.h>
-#include <assert.h>
-#include <string.h>
-#include <ctype.h>
 #include <sys/stat.h>
-#include <libgen.h> /* basename */
 
 #include "tvheadend.h"
 #include "dvr.h"
@@ -42,7 +36,7 @@ static int64_t dvr_disk_space_config_lastdelete;
 static int64_t dvr_bfree;
 static int64_t dvr_btotal;
 static int64_t dvr_bused;
-static pthread_mutex_t dvr_disk_space_mutex;
+static tvh_mutex_t dvr_disk_space_mutex;
 static mtimer_t dvr_disk_space_timer;
 static tasklet_t dvr_disk_space_tasklet;
 
@@ -320,7 +314,7 @@ dvr_disk_space_check()
   dvr_vfs_t *dvfs;
   tvh_fsid_t fsid;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 
   dvr_disk_space_config_idx++;
   if (dvr_disk_space_config_idx > dvr_disk_space_config_size)
@@ -382,7 +376,7 @@ checking:
 
   dvr_disk_space_config_size = idx;
 
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
 
 /**
@@ -399,16 +393,16 @@ dvr_get_disk_space_update(const char *path, int locked)
     return;
 
   if (!locked)
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
   dvfs = dvr_vfs_find(NULL, &fsid);
   if (!locked)
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
 
-  pthread_mutex_lock(&dvr_disk_space_mutex);
+  tvh_mutex_lock(&dvr_disk_space_mutex);
   dvr_bfree = diskdata.f_frsize * (int64_t)diskdata.f_bavail;
   dvr_btotal = diskdata.f_frsize * (int64_t)diskdata.f_blocks;
   dvr_bused = dvfs ? dvfs->used_size : 0;
-  pthread_mutex_unlock(&dvr_disk_space_mutex);
+  tvh_mutex_unlock(&dvr_disk_space_mutex);
 }
 
 /**
@@ -501,7 +495,7 @@ void
 dvr_disk_space_init(void)
 {
   dvr_config_t *cfg = dvr_config_find_by_name_default(NULL);
-  pthread_mutex_init(&dvr_disk_space_mutex, NULL);
+  tvh_mutex_init(&dvr_disk_space_mutex, NULL);
   dvr_get_disk_space_update(cfg->dvr_storage, 1);
   mtimer_arm_rel(&dvr_disk_space_timer, dvr_get_disk_space_cb, NULL, sec2mono(5));
 }
@@ -530,7 +524,7 @@ dvr_get_disk_space(int64_t *bfree, int64_t *bused, int64_t *btotal)
 {
   int res = 0;
 
-  pthread_mutex_lock(&dvr_disk_space_mutex);
+  tvh_mutex_lock(&dvr_disk_space_mutex);
   if (dvr_bfree || dvr_btotal) {
     *bfree = dvr_bfree;
     *bused = dvr_bused;
@@ -538,6 +532,6 @@ dvr_get_disk_space(int64_t *bfree, int64_t *bused, int64_t *btotal)
   } else {
     res = -EINVAL;
   }
-  pthread_mutex_unlock(&dvr_disk_space_mutex);
+  tvh_mutex_unlock(&dvr_disk_space_mutex);
   return res;
 }
index 296c00690976be33f5ac9457834a3f5dae0382fc..9e79631eddd660816c938a7fe4fcce4476819be5 100644 (file)
@@ -21,7 +21,6 @@
 #include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <pthread.h>
 #include <signal.h>
 #include <setjmp.h>
 
@@ -252,12 +251,12 @@ void epg_done ( void )
 {
   channel_t *ch;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   CHANNEL_FOREACH(ch)
     epg_channel_unlink(ch);
   epg_skel_done();
   memoryinfo_unregister(&epg_memoryinfo_broadcasts);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
 
 /* **************************************************************************
index bc626c0d51c492d6f72996c7f387372e69b903af..c7313bfd0a4ca7d9d26d83fbf4967d7a2689eeff 100644 (file)
 
 /* Thread protection */
 static int             epggrab_confver;
-pthread_mutex_t        epggrab_mutex;
-static pthread_cond_t  epggrab_cond;
-static pthread_mutex_t epggrab_data_mutex;
-static pthread_cond_t  epggrab_data_cond;
+tvh_mutex_t            epggrab_mutex;
+static tvh_cond_t      epggrab_cond;
+static tvh_mutex_t     epggrab_data_mutex;
+static tvh_cond_t      epggrab_data_cond;
 int                    epggrab_running;
 
 static TAILQ_HEAD(, epggrab_module) epggrab_data_modules;
@@ -103,13 +103,13 @@ static void *_epggrab_internal_thread( void *aux )
 
   /* Time for other jobs */
   while (atomic_get(&epggrab_running)) {
-    pthread_mutex_lock(&epggrab_mutex);
+    tvh_mutex_lock(&epggrab_mutex);
     err = ETIMEDOUT;
     while (atomic_get(&epggrab_running)) {
-      err = pthread_cond_timedwait(&epggrab_cond, &epggrab_mutex, &ts);
+      err = tvh_cond_timedwait_ts(&epggrab_cond, &epggrab_mutex, &ts);
       if (err == ETIMEDOUT) break;
     }
-    pthread_mutex_unlock(&epggrab_mutex);
+    tvh_mutex_unlock(&epggrab_mutex);
     if (err == ETIMEDOUT) break;
   }
 
@@ -118,9 +118,9 @@ static void *_epggrab_internal_thread( void *aux )
   while (atomic_get(&epggrab_running)) {
 
     /* Check for config change */
-    pthread_mutex_lock(&epggrab_mutex);
+    tvh_mutex_lock(&epggrab_mutex);
     while (atomic_get(&epggrab_running) && confver == epggrab_confver) {
-      err = pthread_cond_timedwait(&epggrab_cond, &epggrab_mutex, &ts);
+      err = tvh_cond_timedwait_ts(&epggrab_cond, &epggrab_mutex, &ts);
       if (err == ETIMEDOUT) break;
     }
     confver    = epggrab_confver;
@@ -128,7 +128,7 @@ static void *_epggrab_internal_thread( void *aux )
       ts.tv_sec = t;
     else
       ts.tv_sec += 60;
-    pthread_mutex_unlock(&epggrab_mutex);
+    tvh_mutex_unlock(&epggrab_mutex);
 
     /* Run grabber(s) */
     /* Note: this loop is not protected, assuming static boot allocation */
@@ -147,7 +147,7 @@ void
 epggrab_rerun_internal(void)
 {
   epggrab_confver++;
-  pthread_cond_signal(&epggrab_cond);
+  tvh_cond_signal(&epggrab_cond, 0);
 }
 
 /*
@@ -159,7 +159,7 @@ static void *_epggrab_data_thread( void *aux )
   epggrab_queued_data_t *eq;
 
   while (atomic_get(&epggrab_running)) {
-    pthread_mutex_lock(&epggrab_data_mutex);
+    tvh_mutex_lock(&epggrab_data_mutex);
     do {
       eq = NULL;
       mod = TAILQ_FIRST(&epggrab_data_modules);
@@ -172,16 +172,16 @@ static void *_epggrab_data_thread( void *aux )
         }
       }
       if (eq == NULL)
-        pthread_cond_wait(&epggrab_data_cond, &epggrab_data_mutex);
+        tvh_cond_wait(&epggrab_data_cond, &epggrab_data_mutex);
     } while (eq == NULL && atomic_get(&epggrab_running));
-    pthread_mutex_unlock(&epggrab_data_mutex);
+    tvh_mutex_unlock(&epggrab_data_mutex);
     if (eq) {
       mod->process_data(mod, eq->eq_data, eq->eq_len);
       memoryinfo_free(&epggrab_data_memoryinfo, sizeof(*eq) + eq->eq_len);
       free(eq);
     }
   }
-  pthread_mutex_lock(&epggrab_data_mutex);
+  tvh_mutex_lock(&epggrab_data_mutex);
   while ((mod = TAILQ_FIRST(&epggrab_data_modules)) != NULL) {
     while ((eq = TAILQ_FIRST(&mod->data_queue)) != NULL) {
       TAILQ_REMOVE(&mod->data_queue, eq, eq_link);
@@ -190,7 +190,7 @@ static void *_epggrab_data_thread( void *aux )
     }
     TAILQ_REMOVE(&epggrab_data_modules, mod, qlink);
   }
-  pthread_mutex_unlock(&epggrab_data_mutex);
+  tvh_mutex_unlock(&epggrab_data_mutex);
   return NULL;
 }
 
@@ -213,13 +213,13 @@ void epggrab_queue_data(epggrab_module_t *mod,
   if (len2)
     memcpy(eq->eq_data + len1, data2, len2);
   memoryinfo_alloc(&epggrab_data_memoryinfo, len);
-  pthread_mutex_lock(&epggrab_data_mutex);
+  tvh_mutex_lock(&epggrab_data_mutex);
   if (TAILQ_EMPTY(&mod->data_queue)) {
-    pthread_cond_signal(&epggrab_data_cond);
+    tvh_cond_signal(&epggrab_data_cond, 0);
     TAILQ_INSERT_TAIL(&epggrab_data_modules, mod, qlink);
   }
   TAILQ_INSERT_TAIL(&mod->data_queue, eq, eq_link);
-  pthread_mutex_unlock(&epggrab_data_mutex);
+  tvh_mutex_unlock(&epggrab_data_mutex);
 }
 
 /* **************************************************************************
@@ -312,10 +312,10 @@ epggrab_conf_t epggrab_conf = {
 static void
 epggrab_class_cron_notify(void *self, const char *lang)
 {
-  pthread_mutex_lock(&epggrab_mutex);
+  tvh_mutex_lock(&epggrab_mutex);
   free(epggrab_cron_multi);
   epggrab_cron_multi = cron_multi_set(epggrab_conf.cron);
-  pthread_mutex_unlock(&epggrab_mutex);
+  tvh_mutex_unlock(&epggrab_mutex);
 }
 
 static void
@@ -499,10 +499,10 @@ void epggrab_init ( void )
 
   epggrab_cron_multi              = NULL;
 
-  pthread_mutex_init(&epggrab_mutex, NULL);
-  pthread_mutex_init(&epggrab_data_mutex, NULL);
-  pthread_cond_init(&epggrab_cond, NULL);
-  pthread_cond_init(&epggrab_data_cond, NULL);
+  tvh_mutex_init(&epggrab_mutex, NULL);
+  tvh_mutex_init(&epggrab_data_mutex, NULL);
+  tvh_cond_init(&epggrab_cond, 0);
+  tvh_cond_init(&epggrab_data_cond, 0);
 
   TAILQ_INIT(&epggrab_data_modules);
 
@@ -535,8 +535,8 @@ void epggrab_init ( void )
 
   /* Start internal and data queue grab thread */
   atomic_set(&epggrab_running, 1);
-  tvhthread_create(&epggrab_tid, NULL, _epggrab_internal_thread, NULL, "epggrabi");
-  tvhthread_create(&epggrab_data_tid, NULL, _epggrab_data_thread, NULL, "epgdata");
+  tvh_thread_create(&epggrab_tid, NULL, _epggrab_internal_thread, NULL, "epggrabi");
+  tvh_thread_create(&epggrab_data_tid, NULL, _epggrab_data_thread, NULL, "epgdata");
 }
 
 /*
@@ -547,20 +547,20 @@ void epggrab_done ( void )
   epggrab_module_t *mod;
 
   atomic_set(&epggrab_running, 0);
-  pthread_cond_signal(&epggrab_cond);
-  pthread_cond_signal(&epggrab_data_cond);
+  tvh_cond_signal(&epggrab_cond, 0);
+  tvh_cond_signal(&epggrab_data_cond, 0);
   pthread_join(epggrab_tid, NULL);
   pthread_join(epggrab_data_tid, NULL);
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   while ((mod = LIST_FIRST(&epggrab_modules)) != NULL) {
     idnode_save_check(&mod->idnode, 1);
     idnode_unlink(&mod->idnode);
     LIST_REMOVE(mod, link);
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
     if (mod->done)
       mod->done(mod);
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     epggrab_channel_flush(mod, 0);
     free((void *)mod->id);
     free((void *)mod->saveid);
@@ -579,5 +579,5 @@ void epggrab_done ( void )
   epggrab_conf.ota_cron = NULL;
   epggrab_channel_done();
   memoryinfo_unregister(&epggrab_data_memoryinfo);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
index 1a589b628c66b106c80db779abcf957d44de64e4..1cf532b40d849234d0c9ee8a54e68b945344ad20 100644 (file)
@@ -21,8 +21,6 @@
 
 #include "idnode.h"
 
-#include <pthread.h>
-
 /* **************************************************************************
  * Typedefs/Forward decls
  * *************************************************************************/
@@ -360,7 +358,7 @@ void epggrab_queue_data(epggrab_module_t *mod,
  * Configuration
  */
 extern epggrab_module_list_t epggrab_modules;
-extern pthread_mutex_t       epggrab_mutex;
+extern tvh_mutex_t           epggrab_mutex;
 extern int                   epggrab_running;
 extern int                   epggrab_ota_running;
 
index 559d2ff62ebb7873a7d400f3b0c6af636d4574a0..e47c29c34a18c637d07a878109243ef99a2ff5b1 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <assert.h>
-#include <string.h>
-#include <pthread.h>
-#include <unistd.h>
 #include <signal.h>
-#include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 
@@ -36,6 +31,7 @@
 #include "epg.h"
 #include "epggrab.h"
 #include "epggrab/private.h"
+
 extern gtimer_t epggrab_save_timer;
 
 /* **************************************************************************
@@ -411,7 +407,7 @@ void epggrab_module_parse( void *m, htsmsg_t *data )
   /* Now we've parsed, do we need to save? */
   if (save && epggrab_conf.epgdb_saveafterimport) {
     tvhinfo(mod->subsys, "%s: scheduling save epg timer", mod->id);
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     /* Disarm any existing timer first (from a periodic save). */
     gtimer_disarm(&epggrab_save_timer);
     /* Reschedule for a few minutes away so if the user is
@@ -424,7 +420,7 @@ void epggrab_module_parse( void *m, htsmsg_t *data )
      */
     gtimer_arm_rel(&epggrab_save_timer, epg_save_callback, NULL,
                    60 * 2);
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
   }
 }
 
@@ -632,7 +628,7 @@ epggrab_module_done_socket( void *m )
   shutdown(sock, SHUT_RDWR);
   close(sock);
   if (mod->tid) {
-    pthread_kill(mod->tid, SIGQUIT);
+    tvh_thread_kill(mod->tid, SIGQUIT);
     pthread_join(mod->tid, NULL);
   }
   mod->tid = 0;
@@ -690,7 +686,7 @@ epggrab_module_activate_socket ( void *m, int a )
     pthread_attr_init(&tattr);
     mod->active = 1;
     atomic_set(&mod->sock, sock);
-    tvhthread_create(&mod->tid, &tattr, _epggrab_socket_thread, mod, "epggrabso");
+    tvh_thread_create(&mod->tid, &tattr, _epggrab_socket_thread, mod, "epggrabso");
   }
   return 1;
 }
index 4f71e74573e57d16bf8df63e2a45cc5e852a257a..4304f3b76cf7031bd993dc0ea5d04780127637d5 100644 (file)
@@ -840,7 +840,7 @@ static int _eit_process_event
   _eit_scrape_text(eit_mod, &ev);
 
   if (lock)
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
   svc = (mpegts_service_t *)service_find_by_uuid0(&ed->svc_uuid);
   if (svc && eit_mod->opaque) {
     LIST_FOREACH(ilm, &svc->s_channels, ilm_in1_link) {
@@ -852,7 +852,7 @@ static int _eit_process_event
     }
   }
   if (lock)
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
 
 #if TODO_ADD_EXTRA
   if (ev.extra)    htsmsg_destroy(ev.extra);
@@ -890,9 +890,9 @@ _eit_process_data(void *m, void *data, uint32_t len)
   }
 
   if (save) {
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     epg_updated();
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
   }
 }
 
index c673be24c1b49dd2978e0c5b9dcb8a5ca3a05488..edf106088b2316fa42be0a2df346791c9aac18c9 100644 (file)
@@ -561,9 +561,9 @@ _opentv_process_data
   memcpy(&od, data, sizeof(od));
   data += sizeof(od);
   len -= sizeof(od);
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   opentv_parse_event_section(mod, od.cid, od.mjd, data, len);
-  pthread_mutex_unlock(&global_lock);  
+  tvh_mutex_unlock(&global_lock);  
 }
 
 /* ************************************************************************
index f8169cf032c1dc1155a63747ec9d1f5e134cec38..54becc313d2a138cd0d0a6493c2d5367787ca659 100644 (file)
@@ -965,28 +965,28 @@ static int _xmltv_parse_tv
   if((tags = htsmsg_get_map(body, "tags")) == NULL)
     return 0;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   epggrab_channel_begin_scan(mod);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   HTSMSG_FOREACH(f, tags) {
     save = 0;
     if(!strcmp(htsmsg_field_name(f), "channel")) {
-      pthread_mutex_lock(&global_lock);
+      tvh_mutex_lock(&global_lock);
       save = _xmltv_parse_channel(mod, htsmsg_get_map_by_field(f), stats);
-      pthread_mutex_unlock(&global_lock);
+      tvh_mutex_unlock(&global_lock);
     } else if(!strcmp(htsmsg_field_name(f), "programme")) {
-      pthread_mutex_lock(&global_lock);
+      tvh_mutex_lock(&global_lock);
       save = _xmltv_parse_programme(mod, htsmsg_get_map_by_field(f), stats);
       if (save) epg_updated();
-      pthread_mutex_unlock(&global_lock);
+      tvh_mutex_unlock(&global_lock);
     }
     gsave |= save;
   }
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   epggrab_channel_end_scan(mod);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return gsave;
 }
index a16a2c4b6ac6d26aa571426878274792b199e057..97128efdd2c1bd5d3ae8875cbe5dc5c4f4a62e83 100644 (file)
@@ -54,7 +54,7 @@ gtimer_t                     epggrab_ota_start_timer;
 int                          epggrab_ota_running;
 int                          epggrab_ota_pending_flag;
 
-pthread_mutex_t              epggrab_ota_mutex;
+tvh_mutex_t                  epggrab_ota_mutex;
 
 SKEL_DECLARE(epggrab_ota_mux_skel, epggrab_ota_mux_t);
 SKEL_DECLARE(epggrab_svc_link_skel, epggrab_ota_svc_link_t);
@@ -709,12 +709,12 @@ epggrab_ota_start_cb ( void *p )
 
   epggrab_ota_kick(1);
 
-  pthread_mutex_lock(&epggrab_ota_mutex);
+  tvh_mutex_lock(&epggrab_ota_mutex);
   if (!cron_multi_next(epggrab_ota_cron_multi, gclk(), &next))
     epggrab_ota_next_arm(next);
   else
     tvhwarn(LS_EPGGRAB, "ota cron config invalid or unset");
-  pthread_mutex_unlock(&epggrab_ota_mutex);
+  tvh_mutex_unlock(&epggrab_ota_mutex);
 }
 
 static void
@@ -722,7 +722,7 @@ epggrab_ota_arm ( time_t last )
 {
   time_t next;
 
-  pthread_mutex_lock(&epggrab_ota_mutex);
+  tvh_mutex_lock(&epggrab_ota_mutex);
 
   if (!cron_multi_next(epggrab_ota_cron_multi, time(NULL), &next)) {
     /* do not trigger the next EPG scan for 1/2 hour */
@@ -733,7 +733,7 @@ epggrab_ota_arm ( time_t last )
     tvhwarn(LS_EPGGRAB, "ota cron config invalid or unset");
   }
 
-  pthread_mutex_unlock(&epggrab_ota_mutex);
+  tvh_mutex_unlock(&epggrab_ota_mutex);
 }
 
 /*
@@ -893,7 +893,7 @@ epggrab_ota_init ( void )
   TAILQ_INIT(&epggrab_ota_pending);
   TAILQ_INIT(&epggrab_ota_active);
 
-  pthread_mutex_init(&epggrab_ota_mutex, NULL);
+  tvh_mutex_init(&epggrab_ota_mutex, NULL);
 
   /* Add listener */
   static mpegts_listener_t ml = {
@@ -997,10 +997,10 @@ epggrab_ota_set_cron ( void )
 {
   lock_assert(&global_lock);
 
-  pthread_mutex_lock(&epggrab_ota_mutex);
+  tvh_mutex_lock(&epggrab_ota_mutex);
   free(epggrab_ota_cron_multi);
   epggrab_ota_cron_multi = cron_multi_set(epggrab_conf.ota_cron);
-  pthread_mutex_unlock(&epggrab_ota_mutex);
+  tvh_mutex_unlock(&epggrab_ota_mutex);
   epggrab_ota_arm((time_t)-1);
 }
 
index b1cd3b9bbf2bfbedf73332866bb2a25d6a848b4e..f6584cdcc1f4296076ba142fd06c4943fb1f5406 100644 (file)
@@ -442,7 +442,7 @@ esfilter_build_ca_enum(int provider)
 
   lock_assert(&global_lock);
   TAILQ_FOREACH(s, &service_all, s_all_link) {
-    pthread_mutex_lock(&s->s_stream_mutex);
+    tvh_mutex_lock(&s->s_stream_mutex);
     TAILQ_FOREACH(es, &s->s_components.set_all, es_link) {
       LIST_FOREACH(ca, &es->es_caids, link) {
         v = provider ? ca->providerid : ca->caid;
@@ -453,7 +453,7 @@ esfilter_build_ca_enum(int provider)
           a[count++] = v;
       }
     }
-    pthread_mutex_unlock(&s->s_stream_mutex);
+    tvh_mutex_unlock(&s->s_stream_mutex);
   }
   qsort(a, count, sizeof(uint32_t), esfilter_build_ca_cmp);
 
@@ -1222,10 +1222,10 @@ esfilter_done(void)
   esfilter_t *esf;
   int i;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   for (i = 0; i <= ESF_CLASS_LAST; i++) {
     while ((esf = TAILQ_FIRST(&esfilters[i])) != NULL)
       esfilter_delete(esf, 0);
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
index 557c2c2fb3a67cde313d7fac1e3b68e66c7cff03..b8f66b632bd450798021223adc059e3381b3bf01 100644 (file)
@@ -65,7 +65,7 @@ fsmonitor_thread ( void* p )
       break;
 
     /* Process */
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     i = 0;
     while ( i < c ) {
       ev = (struct inotify_event*)&buf[i];
@@ -95,7 +95,7 @@ fsmonitor_thread ( void* p )
           fsm->fsm_delete(fsm, path);
       }
     }
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
   }
   return NULL;
 }
@@ -110,7 +110,7 @@ fsmonitor_init ( void )
 {
   /* Intialise inotify */
   atomic_set(&fsmonitor_fd, inotify_init1(IN_CLOEXEC));
-  tvhthread_create(&fsmonitor_tid, NULL, fsmonitor_thread, NULL, "fsmonitor");
+  tvh_thread_create(&fsmonitor_tid, NULL, fsmonitor_thread, NULL, "fsmonitor");
 }
 
 /*
@@ -121,7 +121,7 @@ fsmonitor_done ( void )
 {
   int fd = atomic_exchange(&fsmonitor_fd, -1);
   if (fd >= 0) blacklisted_close(fd);
-  pthread_kill(fsmonitor_tid, SIGTERM);
+  tvh_thread_kill(fsmonitor_tid, SIGTERM);
   pthread_join(fsmonitor_tid, NULL);
 }
 
index 5cdcaa48670373fb609b04e72f0ea8d75495a480..d15c547e58b6632c939d619f85a84c66b19a1422 100644 (file)
@@ -75,7 +75,7 @@ typedef struct htsmsg_field {
     } bin;
     htsmsg_t *msg;
     double dbl;
-    int bool;
+    int boolean;
   } u;
 
 #if ENABLE_SLOW_MEMORYINFO
@@ -91,7 +91,7 @@ typedef struct htsmsg_field {
 #define hmf_bin     u.bin.data
 #define hmf_binsize u.bin.len
 #define hmf_dbl     u.dbl
-#define hmf_bool    u.bool
+#define hmf_bool    u.boolean
 
 // backwards compat
 #define htsmsg_get_map_by_field(f) htsmsg_field_get_map(f)
index 9c86805cdf27ab81d6fe39f676179308c37d06d0..04b04c3c29ebec881bb9ab9957630d6feae6c0ab 100644 (file)
@@ -16,6 +16,9 @@
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <fcntl.h>
+#include <sys/stat.h>
+
 #include "tvheadend.h"
 #include "atomic.h"
 #include "config.h"
 #include "timeshift.h"
 #endif
 
-#include <pthread.h>
-#include <assert.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <signal.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <arpa/inet.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <limits.h>
 #include "settings.h"
 
 /* **************************************************************************
@@ -171,7 +156,7 @@ typedef struct htsp_connection {
 
   struct htsp_msg_q_queue htsp_active_output_queues;
 
-  pthread_mutex_t htsp_out_mutex;
+  tvh_mutex_t htsp_out_mutex;
   tvh_cond_t htsp_out_cond;
 
   htsp_msg_q_t htsp_hmq_ctrl;
@@ -342,7 +327,7 @@ htsp_flush_queue(htsp_connection_t *htsp, htsp_msg_q_t *hmq, int dead)
 {
   htsp_msg_t *hm;
 
-  pthread_mutex_lock(&htsp->htsp_out_mutex);
+  tvh_mutex_lock(&htsp->htsp_out_mutex);
 
   if(hmq->hmq_length)
     TAILQ_REMOVE(&htsp->htsp_active_output_queues, hmq, hmq_link);
@@ -356,7 +341,7 @@ htsp_flush_queue(htsp_connection_t *htsp, htsp_msg_q_t *hmq, int dead)
   hmq->hmq_length = 0;
   hmq->hmq_payload = 0;
   hmq->hmq_dead = dead;
-  pthread_mutex_unlock(&htsp->htsp_out_mutex);
+  tvh_mutex_unlock(&htsp->htsp_out_mutex);
 }
 
 /**
@@ -407,7 +392,7 @@ htsp_send(htsp_connection_t *htsp, htsmsg_t *m, pktbuf_t *pb,
     pktbuf_ref_inc(pb);
   hm->hm_payloadsize = payloadsize;
   
-  pthread_mutex_lock(&htsp->htsp_out_mutex);
+  tvh_mutex_lock(&htsp->htsp_out_mutex);
 
   assert(!hmq->hmq_dead);
 
@@ -426,7 +411,7 @@ htsp_send(htsp_connection_t *htsp, htsmsg_t *m, pktbuf_t *pb,
   hmq->hmq_length++;
   hmq->hmq_payload += payloadsize;
   tvh_cond_signal(&htsp->htsp_out_cond, 0);
-  pthread_mutex_unlock(&htsp->htsp_out_mutex);
+  tvh_mutex_unlock(&htsp->htsp_out_mutex);
 }
 
 /**
@@ -744,10 +729,10 @@ htsp_file_open(htsp_connection_t *htsp, const char *path, int fd, dvr_entry_t *d
   struct stat st;
 
   if (fd <= 0) {
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
     fd = tvh_open(path, O_RDONLY, 0);
     tvhdebug(LS_HTSP, "Opening file %s -- %s", path, fd < 0 ? strerror(errno) : "OK");
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     if(fd == -1)
       return htsp_error(htsp, N_("Unable to open file"));
   }
@@ -807,9 +792,9 @@ htsp_file_destroy(htsp_file_t *hf)
   tvhdebug(LS_HTSP, "Closed opened file %s", hf->hf_path);
   LIST_REMOVE(hf, hf_link);
   if (hf->hf_subscription) {
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     subscription_unsubscribe(hf->hf_subscription, UNSUBSCRIBE_FINAL);
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
   }
   free(hf->hf_path);
   close(hf->hf_fd);
@@ -1418,7 +1403,7 @@ htsp_method_api(htsp_connection_t *htsp, htsmsg_t *in)
   const char *remain;
   int r;
 
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   args   = htsmsg_get_map(in, "args");
   remain = htsmsg_get_str(in, "path");
@@ -1451,7 +1436,7 @@ htsp_method_api(htsp_connection_t *htsp, htsmsg_t *in)
 
   htsmsg_destroy(args2);
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   return ret;
 }
 
@@ -2862,7 +2847,7 @@ htsp_method_file_read(htsp_connection_t *htsp, htsmsg_t *in)
 
   fd = hf->hf_fd;
 
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   /* Seek (optional) */
   if (!htsmsg_get_s64(in, "offset", &off))
@@ -2891,7 +2876,7 @@ htsp_method_file_read(htsp_connection_t *htsp, htsmsg_t *in)
   htsmsg_add_bin_alloc(rep, "data", m, r);
 
 error:
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   return e ? htsp_error(htsp, e) : rep;
 }
 
@@ -2924,9 +2909,9 @@ htsp_method_file_close(htsp_connection_t *htsp, htsmsg_t *in)
       dvr_entry_changed(de);
   }
 
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   htsp_file_destroy(hf);
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   return htsmsg_create_map();
 }
 
@@ -2946,13 +2931,13 @@ htsp_method_file_stat(htsp_connection_t *htsp, htsmsg_t *in)
 
   fd = hf->hf_fd;
 
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   rep = htsmsg_create_map();
   if(!fstat(fd, &st)) {
     htsmsg_add_s64(rep, "size", st.st_size);
     htsmsg_add_s64(rep, "mtime", st.st_mtime);
   }
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 
   return rep;
 }
@@ -2989,17 +2974,17 @@ htsp_method_file_seek(htsp_connection_t *htsp, htsmsg_t *in)
   }
 
   fd = hf->hf_fd;
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   if ((off = lseek(fd, off, whence)) < 0) {
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     return htsp_error(htsp, N_("Seek error"));
   }
 
   rep = htsmsg_create_map();
   htsmsg_add_s64(rep, "offset", off);
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   return rep;
 }
 
@@ -3233,7 +3218,7 @@ htsp_read_loop(htsp_connection_t *htsp)
     return 1;
   }
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 
   htsp->htsp_granted_access = access_get_by_addr(htsp->htsp_peer);
   htsp->htsp_granted_access->aa_rights |= ACCESS_HTSP_INTERFACE;
@@ -3241,7 +3226,7 @@ htsp_read_loop(htsp_connection_t *htsp)
   tcp_id = tcp_connection_launch(htsp->htsp_fd, streaming, htsp_server_status,
                                  htsp->htsp_granted_access);
 
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   if (tcp_id == NULL)
     return 0;
@@ -3257,7 +3242,7 @@ readmsg:
     if((r = htsp_read_message(htsp, &m, 0)) != 0)
       break;
 
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     if (htsp_authenticate(htsp, m)) {
       tcp_connection_land(tcp_id);
       tcp_id = tcp_connection_launch(htsp->htsp_fd, streaming, htsp_server_status,
@@ -3282,7 +3267,7 @@ readmsg:
               htsp_methods[i].privmask) !=
                 htsp_methods[i].privmask) {
 
-           pthread_mutex_unlock(&global_lock);
+           tvh_mutex_unlock(&global_lock);
             /* Classic authentication failed delay */
             tvh_safe_usleep(250000);
 
@@ -3321,7 +3306,7 @@ readmsg:
     }
 
 send_reply_with_unlock:
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
 
     if(reply != NULL) /* Methods can do all the replying inline */
       htsp_reply(htsp, m, reply);
@@ -3329,9 +3314,9 @@ send_reply_with_unlock:
     htsmsg_destroy(m);
   }
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   tcp_connection_land(tcp_id);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   return tvheadend_is_running() ? r : 0;
 }
 
@@ -3348,7 +3333,7 @@ htsp_write_scheduler(void *aux)
   size_t dlen;
   int r;
 
-  pthread_mutex_lock(&htsp->htsp_out_mutex);
+  tvh_mutex_lock(&htsp->htsp_out_mutex);
 
   while(htsp->htsp_writer_run) {
 
@@ -3373,12 +3358,12 @@ htsp_write_scheduler(void *aux)
       }
     }
 
-    pthread_mutex_unlock(&htsp->htsp_out_mutex);
+    tvh_mutex_unlock(&htsp->htsp_out_mutex);
 
     if (htsmsg_binary_serialize(hm->hm_msg, &dptr, &dlen, INT32_MAX) != 0) {
       tvhwarn(LS_HTSP, "%s: failed to serialize data", htsp->htsp_logname);
       htsp_msg_destroy(hm);
-      pthread_mutex_lock(&htsp->htsp_out_mutex);
+      tvh_mutex_lock(&htsp->htsp_out_mutex);
       continue;
     }
 
@@ -3386,7 +3371,7 @@ htsp_write_scheduler(void *aux)
 
     r = tvh_write(htsp->htsp_fd, dptr, dlen);
     free(dptr);
-    pthread_mutex_lock(&htsp->htsp_out_mutex);
+    tvh_mutex_lock(&htsp->htsp_out_mutex);
     
     if (r) {
       tvhinfo(LS_HTSP, "%s: Write error -- %s",
@@ -3397,7 +3382,7 @@ htsp_write_scheduler(void *aux)
   // Shutdown socket to make receive thread terminate entire HTSP connection
 
   shutdown(htsp->htsp_fd, SHUT_RDWR);
-  pthread_mutex_unlock(&htsp->htsp_out_mutex);
+  tvh_mutex_unlock(&htsp->htsp_out_mutex);
   return NULL;
 }
 
@@ -3436,10 +3421,10 @@ htsp_serve(int fd, void **opaque, struct sockaddr_storage *source,
   htsp.htsp_writer_run = 1;
 
   LIST_INSERT_HEAD(&htsp_connections, &htsp, htsp_link);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
-  tvhthread_create(&htsp.htsp_writer_thread, NULL,
-                   htsp_write_scheduler, &htsp, "htsp-write");
+  tvh_thread_create(&htsp.htsp_writer_thread, NULL,
+                    htsp_write_scheduler, &htsp, "htsp-write");
 
   /**
    * Reader loop
@@ -3453,7 +3438,7 @@ htsp_serve(int fd, void **opaque, struct sockaddr_storage *source,
    * Ok, we're back, other end disconnected. Clean up stuff.
    */
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 
   /* no async notifications from now */
   if(htsp.htsp_async_mode)
@@ -3470,12 +3455,12 @@ htsp_serve(int fd, void **opaque, struct sockaddr_storage *source,
   while((s = LIST_FIRST(&htsp.htsp_subscriptions)) != NULL)
     htsp_subscription_destroy(&htsp, s);
 
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
-  pthread_mutex_lock(&htsp.htsp_out_mutex);
+  tvh_mutex_lock(&htsp.htsp_out_mutex);
   htsp.htsp_writer_run = 0;
   tvh_cond_signal(&htsp.htsp_out_cond, 0);
-  pthread_mutex_unlock(&htsp.htsp_out_mutex);
+  tvh_mutex_unlock(&htsp.htsp_out_mutex);
 
   pthread_join(htsp.htsp_writer_thread, NULL);
 
@@ -3499,7 +3484,7 @@ htsp_serve(int fd, void **opaque, struct sockaddr_storage *source,
   close(fd);
   
   /* Free memory (leave lock in place, for parent method) */
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   free(htsp.htsp_logname);
   free(htsp.htsp_peername);
   free(htsp.htsp_username);
@@ -3557,12 +3542,12 @@ htsp_register(void)
 void
 htsp_done(void)
 {
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   if (htsp_server_2)
     tcp_server_delete(htsp_server_2);
   if (htsp_server)
     tcp_server_delete(htsp_server);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
 
 /* **************************************************************************
@@ -4060,7 +4045,7 @@ htsp_stream_deliver(htsp_subscription_t *hs, th_pkt_t *pkt)
      * Figure out real time queue delay 
      */
     
-    pthread_mutex_lock(&htsp->htsp_out_mutex);
+    tvh_mutex_lock(&htsp->htsp_out_mutex);
 
     int64_t min_dts = PTS_UNSET;
     int64_t max_dts = PTS_UNSET;
@@ -4085,7 +4070,7 @@ htsp_stream_deliver(htsp_subscription_t *hs, th_pkt_t *pkt)
 
     htsmsg_add_s64(m, "delay", max_dts - min_dts);
 
-    pthread_mutex_unlock(&htsp->htsp_out_mutex);
+    tvh_mutex_unlock(&htsp->htsp_out_mutex);
 
     htsmsg_add_u32(m, "Bdrops", hs->hs_dropstats[PKT_B_FRAME]);
     htsmsg_add_u32(m, "Pdrops", hs->hs_dropstats[PKT_P_FRAME]);
index bd2510e9fd45decdd520244b3daa67a82c90f7de..ab264d7a99af76c1aae4f076fb0f984b196615b3 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <pthread.h>
-#include <assert.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <ctype.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <signal.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <arpa/inet.h>
-#include <openssl/md5.h>
-
 #include "tvheadend.h"
 #include "tcp.h"
 #include "http.h"
@@ -49,7 +33,7 @@
 void *http_server;
 static int http_server_running;
 
-static pthread_mutex_t http_paths_mutex = PTHREAD_MUTEX_INITIALIZER;
+static tvh_mutex_t http_paths_mutex = { .mutex = PTHREAD_MUTEX_INITIALIZER };
 static http_path_list_t http_paths;
 
 static struct strtab HTTP_cmdtab[] = {
@@ -125,7 +109,7 @@ http_resolve(http_connection_t *hc, http_path_t *_hp,
 
   while (1) {
 
-    pthread_mutex_lock(hc->hc_paths_mutex);
+    tvh_mutex_lock(hc->hc_paths_mutex);
     LIST_FOREACH(hp, hc->hc_paths, hp_link) {
       if(!strncmp(path, hp->hp_path, hp->hp_len)) {
         if(path[hp->hp_len] == 0 ||
@@ -138,7 +122,7 @@ http_resolve(http_connection_t *hc, http_path_t *_hp,
       *_hp = *hp;
       hp = _hp;
     }
-    pthread_mutex_unlock(hc->hc_paths_mutex);
+    tvh_mutex_unlock(hc->hc_paths_mutex);
 
     if(hp == NULL)
       return 0;
@@ -237,7 +221,7 @@ static const char *cachemonths[12] = {
 typedef struct http_nonce {
   RB_ENTRY(http_nonce) link;
   mtimer_t expire;
-  char nonce[MD5_DIGEST_LENGTH*2+1];
+  char nonce[16*2+1];
 } http_nonce_t;
 
 static RB_HEAD(, http_nonce) http_nonces;
@@ -269,14 +253,14 @@ http_get_nonce(void)
     snprintf(stamp, sizeof(stamp), "%"PRId64, mono);
     m = md5sum(stamp, 1);
     strlcpy(n->nonce, m, sizeof(stamp));
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     if (RB_INSERT_SORTED(&http_nonces, n, link, http_nonce_cmp)) {
-      pthread_mutex_unlock(&global_lock);
+      tvh_mutex_unlock(&global_lock);
       free(m);
       continue; /* get unique md5 */
     }
     mtimer_arm_rel(&n->expire, http_nonce_timeout, n, sec2mono(30));
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
     break;
   }
   return m;
@@ -290,14 +274,14 @@ http_nonce_exists(const char *nonce)
   if (nonce == NULL)
     return 0;
   strlcpy(tmp.nonce, nonce, sizeof(tmp.nonce));
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   n = RB_FIND(&http_nonces, &tmp, link, http_nonce_cmp);
   if (n) {
     mtimer_arm_rel(&n->expire, http_nonce_timeout, n, sec2mono(2*60));
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
     return 1;
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   return 0;
 }
 
@@ -798,7 +782,7 @@ http_extra_destroy(http_connection_t *hc)
 {
   htsbuf_data_t *hd, *hd_next;
 
-  pthread_mutex_lock(&hc->hc_extra_lock);
+  tvh_mutex_lock(&hc->hc_extra_lock);
   for (hd = TAILQ_FIRST(&hc->hc_extra.hq_q); hd; hd = hd_next) {
     hd_next = TAILQ_NEXT(hd, hd_link);
     if (hd->hd_data_off <= 0) {
@@ -806,7 +790,7 @@ http_extra_destroy(http_connection_t *hc)
       atomic_dec(&hc->hc_extra_chunks, 1);
     }
   }
-  pthread_mutex_unlock(&hc->hc_extra_lock);
+  tvh_mutex_unlock(&hc->hc_extra_lock);
 }
 
 /**
@@ -824,7 +808,7 @@ http_extra_flush(http_connection_t *hc)
   while (1) {
     r = -1;
     serr = 0;
-    pthread_mutex_lock(&hc->hc_extra_lock);
+    tvh_mutex_lock(&hc->hc_extra_lock);
     if (atomic_add(&hc->hc_extra_insend, 0) != 1)
       goto unlock;
     hd = TAILQ_FIRST(&hc->hc_extra.hq_q);
@@ -844,7 +828,7 @@ http_extra_flush(http_connection_t *hc)
       hc->hc_extra.hq_size -= r;
     }
 unlock:
-    pthread_mutex_unlock(&hc->hc_extra_lock);
+    tvh_mutex_unlock(&hc->hc_extra_lock);
 
     if (r < 0) {
       if (ERRNO_AGAIN(serr))
@@ -871,7 +855,7 @@ http_extra_flush_partial(http_connection_t *hc)
 
   atomic_add(&hc->hc_extra_insend, 1);
 
-  pthread_mutex_lock(&hc->hc_extra_lock);
+  tvh_mutex_lock(&hc->hc_extra_lock);
   hd = TAILQ_FIRST(&hc->hc_extra.hq_q);
   if (hd && hd->hd_data_off > 0) {
     data = hd->hd_data;
@@ -881,7 +865,7 @@ http_extra_flush_partial(http_connection_t *hc)
     atomic_dec(&hc->hc_extra_chunks, 1);
     htsbuf_data_free(&hc->hc_extra, hd);
   }
-  pthread_mutex_unlock(&hc->hc_extra_lock);
+  tvh_mutex_unlock(&hc->hc_extra_lock);
   if (data) {
     r = tvh_write(hc->hc_fd, data + off, size - off);
     free(data);
@@ -910,14 +894,14 @@ http_extra_send_prealloc(http_connection_t *hc, const void *data,
                          size_t data_len, int may_discard)
 {
   if (data == NULL) return 0;
-  pthread_mutex_lock(&hc->hc_extra_lock);
+  tvh_mutex_lock(&hc->hc_extra_lock);
   if (!may_discard || hc->hc_extra.hq_size <= 1024*1024) {
     atomic_add(&hc->hc_extra_chunks, 1);
     htsbuf_append_prealloc(&hc->hc_extra, data, data_len);
   } else {
     free((void *)data);
   }
-  pthread_mutex_unlock(&hc->hc_extra_lock);
+  tvh_mutex_unlock(&hc->hc_extra_lock);
   return http_extra_flush(hc);
 }
 
@@ -1640,9 +1624,9 @@ http_path_add_modify(const char *path, void *opaque, http_callback_t *callback,
   hp->hp_accessmask = accessmask;
   hp->hp_path_modify = path_modify;
   hp->hp_flags    = 0;
-  pthread_mutex_lock(&http_paths_mutex);
+  tvh_mutex_lock(&http_paths_mutex);
   LIST_INSERT_HEAD(&http_paths, hp, hp_link);
-  pthread_mutex_unlock(&http_paths_mutex);
+  tvh_mutex_unlock(&http_paths_mutex);
   return hp;
 }
 
@@ -1862,7 +1846,7 @@ http_serve_requests(http_connection_t *hc)
   char *argv[3], *c, *s, *cmdline = NULL, *hdrline = NULL;
   int n, r, delim;
 
-  pthread_mutex_init(&hc->hc_extra_lock, NULL);
+  tvh_mutex_init(&hc->hc_extra_lock, NULL);
   http_arg_init(&hc->hc_args);
   http_arg_init(&hc->hc_req_args);
   htsbuf_queue_init(&spill, 0);
@@ -2000,7 +1984,7 @@ http_serve(int fd, void **opaque, struct sockaddr_storage *peer,
   http_connection_t hc;
 
   /* Note: global_lock held on entry */
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   memset(&hc, 0, sizeof(http_connection_t));
   *opaque = &hc;
 
@@ -2017,7 +2001,7 @@ http_serve(int fd, void **opaque, struct sockaddr_storage *peer,
   close(fd);
 
   // Note: leave global_lock held for parent
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   *opaque = NULL;
 }
 
@@ -2062,22 +2046,22 @@ http_server_done(void)
   http_path_t *hp;
   http_nonce_t *n;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   atomic_set(&http_server_running, 0);
   if (http_server)
     tcp_server_delete(http_server);
   http_server = NULL;
-  pthread_mutex_lock(&http_paths_mutex);
+  tvh_mutex_lock(&http_paths_mutex);
   while ((hp = LIST_FIRST(&http_paths)) != NULL) {
     LIST_REMOVE(hp, hp_link);
     free((void *)hp->hp_path);
     free(hp);
   }
-  pthread_mutex_unlock(&http_paths_mutex);
+  tvh_mutex_unlock(&http_paths_mutex);
   while ((n = RB_FIRST(&http_nonces)) != NULL) {
     mtimer_disarm(&n->expire);
     RB_REMOVE(&http_nonces, n, link);
     free(n);
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
index 18c97c40ebb5dc6cf568ad43c4185e0a6ff8e0a2..f338dcc033d9717ef5d6d9a8effc5e1cefafa0db 100644 (file)
@@ -144,7 +144,7 @@ typedef struct http_connection {
   struct sockaddr_storage *hc_proxy_ip;
   struct sockaddr_storage *hc_local_ip;
 
-  pthread_mutex_t  *hc_paths_mutex;
+  tvh_mutex_t *hc_paths_mutex;
   http_path_list_t *hc_paths;
   int (*hc_process)(struct http_connection *hc, htsbuf_queue_t *spill);
 
@@ -154,7 +154,7 @@ typedef struct http_connection {
   htsbuf_queue_t  hc_reply;
 
   int             hc_extra_insend;
-  pthread_mutex_t hc_extra_lock;
+  tvh_mutex_t     hc_extra_lock;
   int             hc_extra_chunks;
   htsbuf_queue_t  hc_extra;
 
@@ -340,7 +340,7 @@ struct http_client {
 
   TAILQ_ENTRY(http_client) hc_link;
 
-  pthread_mutex_t hc_mutex;
+  tvh_mutex_t  hc_mutex;
 
   int          hc_id;
   int          hc_fd;
index 04d1a90902fd0937bb98a5ee3a4fc7a3c1cf7e1a..8d214bba6f1cfb87c3ecdff695c5c6b881babaa4 100644 (file)
@@ -22,7 +22,6 @@
 #include "tcp.h"
 #include "config.h"
 
-#include <pthread.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <signal.h>
@@ -87,7 +86,7 @@ http_client_testsuite_run( void );
 static int                      http_running;
 static tvhpoll_t               *http_poll;
 static TAILQ_HEAD(,http_client) http_clients;
-static pthread_mutex_t          http_lock;
+static tvh_mutex_t          http_lock;
 static tvh_cond_t               http_cond;
 static th_pipe_t                http_pipe;
 
@@ -164,10 +163,10 @@ http_client_shutdown ( http_client_t *hc, int force, int reconnect )
   if (hc->hc_efd) {
     tvhpoll_rem1(hc->hc_efd, hc->hc_fd);
     if (hc->hc_efd == http_poll && !reconnect) {
-      pthread_mutex_lock(&http_lock);
+      tvh_mutex_lock(&http_lock);
       TAILQ_REMOVE(&http_clients, hc, hc_link);
       hc->hc_efd = NULL;
-      pthread_mutex_unlock(&http_lock);
+      tvh_mutex_unlock(&http_lock);
     } else {
       hc->hc_efd  = NULL;
     }
@@ -175,9 +174,9 @@ http_client_shutdown ( http_client_t *hc, int force, int reconnect )
   if (hc->hc_fd >= 0) {
     if (hc->hc_conn_closed) {
       http_client_get(hc);
-      pthread_mutex_unlock(&hc->hc_mutex);
+      tvh_mutex_unlock(&hc->hc_mutex);
       hc->hc_conn_closed(hc, -hc->hc_result);
-      pthread_mutex_lock(&hc->hc_mutex);
+      tvh_mutex_lock(&hc->hc_mutex);
       http_client_put(hc);
     }
     if (hc->hc_fd >= 0)
@@ -695,9 +694,9 @@ http_client_finish( http_client_t *hc )
 
   if (hc->hc_data_complete) {
     http_client_get(hc);
-    pthread_mutex_unlock(&hc->hc_mutex);
+    tvh_mutex_unlock(&hc->hc_mutex);
     res = hc->hc_data_complete(hc);
-    pthread_mutex_lock(&hc->hc_mutex);
+    tvh_mutex_lock(&hc->hc_mutex);
     http_client_put(hc);
     if (res < 0)
       return http_client_flush(hc, res);
@@ -762,9 +761,9 @@ http_client_data_copy( http_client_t *hc, char *buf, size_t len )
 
   if (hc->hc_data_received) {
     http_client_get(hc);
-    pthread_mutex_unlock(&hc->hc_mutex);
+    tvh_mutex_unlock(&hc->hc_mutex);
     res = hc->hc_data_received(hc, buf, len);
-    pthread_mutex_lock(&hc->hc_mutex);
+    tvh_mutex_lock(&hc->hc_mutex);
     http_client_put(hc);
     if (res < 0)
       return res;
@@ -1090,9 +1089,9 @@ header:
     hc->hc_chunked = strcasecmp(p, "chunked") == 0;
   if (hc->hc_hdr_received) {
     http_client_get(hc);
-    pthread_mutex_unlock(&hc->hc_mutex);
+    tvh_mutex_unlock(&hc->hc_mutex);
     res = hc->hc_hdr_received(hc);
-    pthread_mutex_lock(&hc->hc_mutex);
+    tvh_mutex_lock(&hc->hc_mutex);
     http_client_put(hc);
     if (res < 0)
       return http_client_flush(hc, res);
@@ -1138,9 +1137,9 @@ rtsp_data:
     }
     if (hc->hc_rtp_data_received) {
       http_client_get(hc);
-      pthread_mutex_unlock(&hc->hc_mutex);
+      tvh_mutex_unlock(&hc->hc_mutex);
       res = hc->hc_rtp_data_received(hc, hc->hc_rbuf + r, hc->hc_csize);
-      pthread_mutex_lock(&hc->hc_mutex);
+      tvh_mutex_lock(&hc->hc_mutex);
       http_client_put(hc);
       if (res < 0)
         return res;
@@ -1150,9 +1149,9 @@ rtsp_data:
     res = 0;
     if (hc->hc_rtp_data_complete) {
       http_client_get(hc);
-      pthread_mutex_unlock(&hc->hc_mutex);
+      tvh_mutex_unlock(&hc->hc_mutex);
       res = hc->hc_rtp_data_complete(hc);
-      pthread_mutex_lock(&hc->hc_mutex);
+      tvh_mutex_lock(&hc->hc_mutex);
       http_client_put(hc);
     }
     hc->hc_in_rtp_data = 0;
@@ -1173,9 +1172,9 @@ http_client_run( http_client_t *hc )
 
   if (hc == NULL)
     return 0;
-  pthread_mutex_lock(&hc->hc_mutex);
+  tvh_mutex_lock(&hc->hc_mutex);
   r = http_client_run0(hc);
-  pthread_mutex_unlock(&hc->hc_mutex);
+  tvh_mutex_unlock(&hc->hc_mutex);
   return r;
 }
 
@@ -1360,14 +1359,14 @@ http_client_simple( http_client_t *hc, const url_t *url )
   http_arg_list_t h;
   int r;
 
-  pthread_mutex_lock(&hc->hc_mutex);
+  tvh_mutex_lock(&hc->hc_mutex);
   http_arg_init(&h);
   hc->hc_hdr_create(hc, &h, url, 0);
   free(hc->hc_url);
   hc->hc_url = url->raw ? strdup(url->raw) : NULL;
   r = http_client_send(hc, HTTP_CMD_GET, url->path, url->query,
                        &h, NULL, 0);
-  pthread_mutex_unlock(&hc->hc_mutex);
+  tvh_mutex_unlock(&hc->hc_mutex);
   return r;
 }
 
@@ -1415,29 +1414,29 @@ http_client_thread ( void *p )
         }
         continue;
       }
-      pthread_mutex_lock(&http_lock);
+      tvh_mutex_lock(&http_lock);
       TAILQ_FOREACH(hc, &http_clients, hc_link)
         if (hc == ev.ptr)
           break;
       if (hc == NULL) {
-        pthread_mutex_unlock(&http_lock);
+        tvh_mutex_unlock(&http_lock);
         continue;
       }
       if (hc->hc_shutdown_wait) {
         tvh_cond_signal(&http_cond, 1);
         /* Disable the poll looping for this moment */
         http_client_poll_dir(hc, 0, 0);
-        pthread_mutex_unlock(&http_lock);
+        tvh_mutex_unlock(&http_lock);
         continue;
       }
       hc->hc_running = 1;
-      pthread_mutex_unlock(&http_lock);
+      tvh_mutex_unlock(&http_lock);
       http_client_run(hc);
-      pthread_mutex_lock(&http_lock);
+      tvh_mutex_lock(&http_lock);
       hc->hc_running = 0;
       if (hc->hc_shutdown_wait)
         tvh_cond_signal(&http_cond, 1);
-      pthread_mutex_unlock(&http_lock);
+      tvh_mutex_unlock(&http_lock);
     }
   }
 
@@ -1556,7 +1555,7 @@ http_client_connect
   int r;
 
   hc             = calloc(1, sizeof(http_client_t));
-  pthread_mutex_init(&hc->hc_mutex, NULL);
+  tvh_mutex_init(&hc->hc_mutex, NULL);
   hc->hc_id      = atomic_add(&tally, 1);
   hc->hc_aux     = aux;
   hc->hc_io_size = 1024;
@@ -1569,9 +1568,9 @@ http_client_connect
 
   hc->hc_hdr_create = http_client_basic_args;
 
-  pthread_mutex_lock(&hc->hc_mutex);
+  tvh_mutex_lock(&hc->hc_mutex);
   r = http_client_reconnect(hc, ver, scheme, host, port);
-  pthread_mutex_unlock(&hc->hc_mutex);
+  tvh_mutex_unlock(&hc->hc_mutex);
   if (r < 0) {
     free(hc);
     return NULL;
@@ -1589,13 +1588,13 @@ http_client_register( http_client_t *hc )
   assert(hc->hc_data_received || hc->hc_conn_closed || hc->hc_data_complete);
   assert(hc->hc_efd == NULL);
   
-  pthread_mutex_lock(&http_lock);
+  tvh_mutex_lock(&http_lock);
 
   TAILQ_INSERT_TAIL(&http_clients, hc, hc_link);
 
   hc->hc_efd  = http_poll;
 
-  pthread_mutex_unlock(&http_lock);
+  tvh_mutex_unlock(&http_lock);
 }
 
 /*
@@ -1613,7 +1612,7 @@ http_client_close ( http_client_t *hc )
     return;
 
   if (hc->hc_efd == http_poll) { /* http_client_thread */
-    pthread_mutex_lock(&http_lock);
+    tvh_mutex_lock(&http_lock);
     hc->hc_shutdown_wait = 1;
     while (hc->hc_running)
       tvh_cond_wait(&http_cond, &http_lock);
@@ -1622,13 +1621,13 @@ http_client_close ( http_client_t *hc )
       TAILQ_REMOVE(&http_clients, hc, hc_link);
       hc->hc_efd = NULL;
     }
-    pthread_mutex_unlock(&http_lock);
+    tvh_mutex_unlock(&http_lock);
   }
-  pthread_mutex_lock(&hc->hc_mutex);
+  tvh_mutex_lock(&hc->hc_mutex);
   while (http_client_busy(hc)) {
-    pthread_mutex_unlock(&hc->hc_mutex);
+    tvh_mutex_unlock(&hc->hc_mutex);
     tvh_safe_usleep(10000);
-    pthread_mutex_lock(&hc->hc_mutex);
+    tvh_mutex_lock(&hc->hc_mutex);
   }
   http_client_shutdown(hc, 1, 0);
   http_client_flush(hc, 0);
@@ -1637,8 +1636,8 @@ http_client_close ( http_client_t *hc )
     http_client_cmd_destroy(hc, wcmd);
   http_client_ssl_free(hc);
   rtsp_clear_session(hc);
-  pthread_mutex_unlock(&hc->hc_mutex);
-  pthread_mutex_destroy(&hc->hc_mutex);
+  tvh_mutex_unlock(&hc->hc_mutex);
+  tvh_mutex_destroy(&hc->hc_mutex);
   free(hc->hc_url);
   free(hc->hc_location);
   free(hc->hc_rbuf);
@@ -1649,11 +1648,11 @@ http_client_close ( http_client_t *hc )
   free(hc->hc_rtsp_user);
   free(hc->hc_rtsp_pass);
 #ifdef CLANG_SANITIZER
-  pthread_mutex_lock(&http_lock);
+  tvh_mutex_lock(&http_lock);
 #endif
   free(hc);
 #ifdef CLANG_SANITIZER
-  pthread_mutex_unlock(&http_lock);
+  tvh_mutex_unlock(&http_lock);
 #endif
 }
 
@@ -1666,8 +1665,8 @@ void
 http_client_init ( void )
 {
   /* Setup list */
-  pthread_mutex_init(&http_lock, NULL);
-  tvh_cond_init(&http_cond);
+  tvh_mutex_init(&http_lock, NULL);
+  tvh_cond_init(&http_cond, 1);
   TAILQ_INIT(&http_clients);
 
   /* Setup pipe */
@@ -1679,7 +1678,7 @@ http_client_init ( void )
 
   /* Setup thread */
   atomic_set(&http_running, 1);
-  tvhthread_create(&http_client_tid, NULL, http_client_thread, NULL, "httpc");
+  tvh_thread_create(&http_client_tid, NULL, http_client_thread, NULL, "httpc");
 #if HTTPCLIENT_TESTSUITE
   http_client_testsuite_run();
 #endif
@@ -1694,13 +1693,13 @@ http_client_done ( void )
   tvh_write(http_pipe.wr, "", 1);
   pthread_join(http_client_tid, NULL);
   tvh_pipe_close(&http_pipe);
-  pthread_mutex_lock(&http_lock);
+  tvh_mutex_lock(&http_lock);
   TAILQ_FOREACH(hc, &http_clients, hc_link)
     if (hc->hc_efd == http_poll)
       hc->hc_efd = NULL;
   tvhpoll_destroy(http_poll);
   http_poll = NULL;
-  pthread_mutex_unlock(&http_lock);
+  tvh_mutex_unlock(&http_lock);
 }
 
 /*
index 1d7c2b8c9082fb404b13898b03a3126cd44acbc2..29e4508c1585cc2c91ce40b42eb75e514acbd1bc 100644 (file)
@@ -41,7 +41,7 @@ typedef struct idclass_link
   RB_ENTRY(idclass_link) link;
 } idclass_link_t;
 
-pthread_mutex_t                 idnode_mutex = PTHREAD_MUTEX_INITIALIZER;
+tvh_mutex_t                     idnode_mutex;
 static idnodes_rb_t             idnodes;
 static RB_HEAD(,idclass_link)   idclasses;
 static RB_HEAD(,idclass_link)   idrootclasses;
@@ -52,7 +52,7 @@ static pthread_t  save_tid;
 static int        save_running;
 static mtimer_t   save_timer;
 
-static pthread_mutex_t idnode_lnotify_mutex = PTHREAD_MUTEX_INITIALIZER;
+static tvh_mutex_t idnode_lnotify_mutex = { .mutex = PTHREAD_MUTEX_INITIALIZER };
 static tvh_uuid_set_t  idnode_lnotify_set;
 static tvh_uuid_set_t  idnode_lnotify_title_set;
 
@@ -1951,17 +1951,17 @@ save_thread ( void *aux )
   uuid_set_init(&set, 10);
   uuid_set_init(&tset, 10);
 
-  tvhthread_renice(15);
+  tvh_thread_renice(15);
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 
   while (atomic_get(&save_running)) {
     if ((ise = TAILQ_FIRST(&idnodes_save)) == NULL ||
         ise->ise_reqtime + IDNODE_SAVE_DELAY > mclk()) {
-      pthread_mutex_lock(&idnode_lnotify_mutex);
+      tvh_mutex_lock(&idnode_lnotify_mutex);
       lnotify = !uuid_set_empty(&idnode_lnotify_set) ||
                 !uuid_set_empty(&idnode_lnotify_title_set);
-      pthread_mutex_unlock(&idnode_lnotify_mutex);
+      tvh_mutex_unlock(&idnode_lnotify_mutex);
       if (lnotify)
         goto lnotifygo;
       if (ise)
@@ -1974,16 +1974,16 @@ save_thread ( void *aux )
       m = idnode_savefn(ise->ise_node, filename, sizeof(filename));
       ise->ise_node->in_save = NULL;
       TAILQ_REMOVE(&idnodes_save, ise, ise_link);
-      pthread_mutex_unlock(&global_lock);
+      tvh_mutex_unlock(&global_lock);
       free(ise);
       if (m) {
         hts_settings_save(m, "%s", filename);
         htsmsg_destroy(m);
       }
-      pthread_mutex_lock(&global_lock);
+      tvh_mutex_lock(&global_lock);
     }
 lnotifygo:
-    pthread_mutex_lock(&idnode_lnotify_mutex);
+    tvh_mutex_lock(&idnode_lnotify_mutex);
     if (!uuid_set_empty(&idnode_lnotify_set)) {
       set = idnode_lnotify_set;
       uuid_set_init(&idnode_lnotify_set, 10);
@@ -1992,7 +1992,7 @@ lnotifygo:
       tset = idnode_lnotify_title_set;
       uuid_set_init(&idnode_lnotify_title_set, 10);
     }
-    pthread_mutex_unlock(&idnode_lnotify_mutex);
+    tvh_mutex_unlock(&idnode_lnotify_mutex);
     if (!uuid_set_empty(&set)) {
       UUID_SET_FOREACH(uuid, &set, u32) {
         in = idnode_find0(uuid, NULL, NULL);
@@ -2017,16 +2017,16 @@ lnotifygo:
     m = idnode_savefn(ise->ise_node, filename, sizeof(filename));
     ise->ise_node->in_save = NULL;
     TAILQ_REMOVE(&idnodes_save, ise, ise_link);
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
     free(ise);
     if (m) {
       hts_settings_save(m, "%s", filename);
       htsmsg_destroy(m);
     }
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
   }
 
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   return NULL;
 }
 
@@ -2036,17 +2036,17 @@ lnotifygo:
 
 void idnode_lnotify_changed( void *in )
 {
-  pthread_mutex_lock(&idnode_lnotify_mutex);
+  tvh_mutex_lock(&idnode_lnotify_mutex);
   uuid_set_add(&idnode_lnotify_set, &((idnode_t *)in)->in_uuid);
-  pthread_mutex_unlock(&idnode_lnotify_mutex);
+  tvh_mutex_unlock(&idnode_lnotify_mutex);
   tvh_cond_signal(&save_cond, 0);
 }
 
 void idnode_lnotify_title_changed( void *in )
 {
-  pthread_mutex_lock(&idnode_lnotify_mutex);
+  tvh_mutex_lock(&idnode_lnotify_mutex);
   uuid_set_add(&idnode_lnotify_title_set, &((idnode_t *)in)->in_uuid);
-  pthread_mutex_unlock(&idnode_lnotify_mutex);
+  tvh_mutex_unlock(&idnode_lnotify_mutex);
   tvh_cond_signal(&save_cond, 0);
 }
 
@@ -2057,11 +2057,12 @@ void idnode_lnotify_title_changed( void *in )
 void
 idnode_boot(void)
 {
+  tvh_mutex_init(&idnode_mutex, NULL);
   RB_INIT(&idnodes);
   RB_INIT(&idclasses);
   RB_INIT(&idrootclasses);
   TAILQ_INIT(&idnodes_save);
-  tvh_cond_init(&save_cond);
+  tvh_cond_init(&save_cond, 1);
   uuid_set_init(&idnode_lnotify_set, 10);
   uuid_set_init(&idnode_lnotify_title_set, 10);
 }
@@ -2070,7 +2071,7 @@ void
 idnode_init(void)
 {
   atomic_set(&save_running, 1);
-  tvhthread_create(&save_tid, NULL, save_thread, NULL, "save");
+  tvh_thread_create(&save_tid, NULL, save_thread, NULL, "save");
 }
 
 void
@@ -2078,10 +2079,10 @@ idnode_done(void)
 {
   idclass_link_t *il;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   atomic_set(&save_running, 0);
   tvh_cond_signal(&save_cond, 0);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   pthread_join(save_tid, NULL);
   mtimer_disarm(&save_timer);
 
index d4262f4753bfdf0d03e2f5aa13e5e111a7c3fcbb..1224db7e7beda71aeeb89f92da60aa7b3ef7dffd 100644 (file)
@@ -198,16 +198,16 @@ typedef LIST_HEAD(,idnode_filter_ele) idnode_filter_t;
 
 extern idnode_t tvhlog_conf;
 extern const idclass_t tvhlog_conf_class;
-extern pthread_mutex_t idnode_mutex;
+extern tvh_mutex_t idnode_mutex;
 
 void idnode_boot(void);
 void idnode_init(void);
 void idnode_done(void);
 
 static inline void idnode_lock(void)
-  { pthread_mutex_lock(&idnode_mutex); }
+  { tvh_mutex_lock(&idnode_mutex); }
 static inline void idnode_unlock(void)
-  { pthread_mutex_unlock(&idnode_mutex); }
+  { tvh_mutex_unlock(&idnode_mutex); }
 
 #define IDNODE_SHORT_UUID (1<<0)
 
index a66c5fd2bf151f9dd81543989950477cdfd544e3..937e24bcec2c02a82e07941d13b5dd044537d376 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#define _GNU_SOURCE
-#include <sys/stat.h>
-#include <sys/types.h>
 #include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <pthread.h>
-#include <stdlib.h>
-#include <time.h>
-#include <assert.h>
 
 #include "settings.h"
 #include "tvheadend.h"
@@ -243,7 +233,7 @@ imagecache_new_contents ( imagecache_image_t *img,
   fwrite(data, dsize, 1, fp);
   fclose(fp);
   unlink(path);
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   memcpy(img->sha1, sha1, 20);
   if (!empty) {
     /* change id - contents changed */
@@ -257,7 +247,7 @@ imagecache_new_contents ( imagecache_image_t *img,
       tvherror(LS_IMAGECACHE, "unable to rename file '%s' to '%s'", tpath, path);
   }
   imagecache_image_save(img);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   return r;
 }
 
@@ -285,7 +275,7 @@ imagecache_image_fetch ( imagecache_image_t *img )
   snprintf(tpath, sizeof(tpath), "%s.tmp", path);
   
   /* Fetch (release lock, incase of delays) */
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   urlinit(&url);
 
@@ -331,7 +321,7 @@ imagecache_image_fetch ( imagecache_image_t *img )
 
   /* Process */
 error_lock:
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 error:
   if (NULL != hc) http_client_close(hc);
   urlreset(&url);
@@ -357,7 +347,7 @@ imagecache_thread ( void *p )
 {
   imagecache_image_t *img;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   while (tvheadend_is_running()) {
 
     /* Check we're enabled */
@@ -379,7 +369,7 @@ imagecache_thread ( void *p )
     /* Fetch */
     (void)imagecache_image_fetch(img);
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   return NULL;
 }
@@ -439,7 +429,7 @@ imagecache_init ( void )
 
   /* Create threads */
 #if ENABLE_IMAGECACHE
-  tvh_cond_init(&imagecache_cond);
+  tvh_cond_init(&imagecache_cond, 1);
   TAILQ_INIT(&imagecache_queue);
 #endif
 
@@ -482,7 +472,7 @@ imagecache_init ( void )
 
   /* Start threads */
 #if ENABLE_IMAGECACHE
-  tvhthread_create(&imagecache_tid, NULL, imagecache_thread, NULL, "imagecache");
+  tvh_thread_create(&imagecache_tid, NULL, imagecache_thread, NULL, "imagecache");
 
   /* Re-try timer */
   // TODO: this could be more efficient by being targetted, however
index edb8f9529a3751b99cedd8162a61e4b75a7f8157..c0c91d298e6cc2f2477ac943c7cb246305f64937 100644 (file)
@@ -19,7 +19,7 @@
 #ifndef __IMAGE_CACHE_H__
 #define __IMAGE_CACHE_H__
 
-#include <pthread.h>
+#include "tvh_thread.h"
 #include "idnode.h"
 
 struct imagecache_config {
@@ -34,7 +34,7 @@ struct imagecache_config {
 extern struct imagecache_config imagecache_conf;
 extern const idclass_t imagecache_class;
 
-extern pthread_mutex_t imagecache_mutex;
+extern tvh_mutex_t imagecache_mutex;
 
 void     imagecache_init     ( void );
 void    imagecache_done     ( void );
index d65b516e96663cf7a4093f04490e8172fa7b02e6..a9c96df048d2515c609aee95541789879d035532 100644 (file)
@@ -106,7 +106,7 @@ struct tvh_input_instance {
 
   LIST_ENTRY(tvh_input_instance) tii_input_link;
 
-  pthread_mutex_t          tii_stats_mutex;
+  tvh_mutex_t              tii_stats_mutex;
   tvh_input_stream_stats_t tii_stats;
 
   void (*tii_delete) (tvh_input_instance_t *tii);
index e95b155119ac839e5b68b45733c5e1a3e17f55c5..a11bb501cc007acd98854f83fb9d10ec78d93eae 100644 (file)
@@ -508,13 +508,13 @@ struct mpegts_mux
   int                         mm_num_tables;
   LIST_HEAD(, mpegts_table)   mm_tables;
   TAILQ_HEAD(, mpegts_table)  mm_defer_tables;
-  pthread_mutex_t             mm_tables_lock;
+  tvh_mutex_t                 mm_tables_lock;
   TAILQ_HEAD(, mpegts_table)  mm_table_queue;
 
   LIST_HEAD(, caid)           mm_descrambler_caids;
   TAILQ_HEAD(, descrambler_table) mm_descrambler_tables;
   TAILQ_HEAD(, descrambler_emm) mm_descrambler_emms;
-  pthread_mutex_t             mm_descrambler_lock;
+  tvh_mutex_t                 mm_descrambler_lock;
   int                         mm_descrambler_flush;
 
   /*
@@ -709,7 +709,7 @@ struct mpegts_input
   // Note: this section is protected by mi_input_lock
   pthread_t                       mi_input_tid;
   mtimer_t                        mi_input_thread_start;
-  pthread_mutex_t                 mi_input_lock;
+  tvh_mutex_t                     mi_input_lock;
   tvh_cond_t                      mi_input_cond;
   TAILQ_HEAD(,mpegts_packet)      mi_input_queue;
   uint64_t                        mi_input_queue_size;
@@ -720,7 +720,7 @@ struct mpegts_input
   /* Data processing/output */
   // Note: this lock (mi_output_lock) protects all the remaining
   //       data fields (excluding the callback functions)
-  pthread_mutex_t                 mi_output_lock;
+  tvh_mutex_t                     mi_output_lock;
 
   /* Active sources */
   LIST_HEAD(,mpegts_mux_instance) mi_mux_active;
index 0475384f2381e82c07389a5f70202a89570fd555..aa408489f7e75b54e2b939cb01231a2f2fcd9e71 100644 (file)
@@ -1729,9 +1729,9 @@ dvb_sdt_mux
 
     /* Update nice name */
     if (save2) {
-      pthread_mutex_lock(&s->s_stream_mutex);
+      tvh_mutex_lock(&s->s_stream_mutex);
       service_make_nicename((service_t*)s);
-      pthread_mutex_unlock(&s->s_stream_mutex);
+      tvh_mutex_unlock(&s->s_stream_mutex);
       tvhdebug(mt->mt_subsys, "%s:  nicename %s", mt->mt_name, s->s_nicename);
       save = 1;
     }
@@ -2102,9 +2102,9 @@ dvb_fs_sdt_mux
 
     if (save) {
       /* Update nice name */
-      pthread_mutex_lock(&s->s_stream_mutex);
+      tvh_mutex_lock(&s->s_stream_mutex);
       service_make_nicename((service_t*)s);
-      pthread_mutex_unlock(&s->s_stream_mutex);
+      tvh_mutex_unlock(&s->s_stream_mutex);
       tvhdebug(mt->mt_subsys, "%s:  nicename %s", mt->mt_name, s->s_nicename);
       /* Save changes */
       idnode_changed(&s->s_id);
index 7f0335d03ab2193bec0889171860db8f2903219d..9b39fb3a79c716e268359b8c9d7cfc14c409e152 100644 (file)
@@ -579,7 +579,7 @@ dvb_pmt_callback
   /* Process */
   tvhdebug(mt->mt_subsys, "%s: sid %04X (%d)", mt->mt_name, sid, sid);
   update = 0;
-  pthread_mutex_lock(&s->s_stream_mutex);
+  tvh_mutex_lock(&s->s_stream_mutex);
   update = dvb_psi_parse_pmt(mt, service_nicename((service_t *)s),
                              &s->s_components, ptr, len);
   if (update) {
@@ -607,7 +607,7 @@ dvb_pmt_callback
     mpegts_service_autoenable(s, "PAT and PMT");
     s->s_verified = 1;
   }
-  pthread_mutex_unlock(&s->s_stream_mutex);
+  tvh_mutex_unlock(&s->s_stream_mutex);
   if (restart)
     service_restart((service_t*)s);
   if (update & (PMT_UPDATE_NEW_CA_STREAM|PMT_UPDATE_NEW_CAID|
index a967ede2f4348ed40b5506432651429e6f35f1ef..b73800fd1aa5a09fa4532d2d32ff5ac048af2395 100644 (file)
@@ -17,6 +17,8 @@
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <signal.h>
+
 #include "iptv_private.h"
 #include "tvhpoll.h"
 #include "tcp.h"
 #include "packet.h"
 #include "config.h"
 
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-#include <assert.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include <signal.h>
-#include <pthread.h>
-
 /* **************************************************************************
  * IPTV state
  * *************************************************************************/
 
-pthread_mutex_t iptv_lock;
+tvh_mutex_t iptv_lock;
 
 typedef struct iptv_thread_pool {
   TAILQ_ENTRY(iptv_thread_pool) link;
@@ -152,7 +143,7 @@ iptv_input_is_free ( mpegts_input_t *mi, mpegts_mux_t *mm,
 
   TAILQ_FOREACH(pool, &iptv_tpool, link) {
     mi2 = pool->input;
-    pthread_mutex_lock(&mi2->mi_output_lock);
+    tvh_mutex_lock(&mi2->mi_output_lock);
     LIST_FOREACH(mmi, &mi2->mi_mux_active, mmi_active_link)
       if (mmi->mmi_mux->mm_network == (mpegts_network_t *)in) {
         w = mpegts_mux_instance_weight(mmi);
@@ -162,7 +153,7 @@ iptv_input_is_free ( mpegts_input_t *mi, mpegts_mux_t *mm,
         }
         if (w >= weight) h++; else l++;
       }
-    pthread_mutex_unlock(&mi2->mi_output_lock);
+    tvh_mutex_unlock(&mi2->mi_output_lock);
   }
 
   tvhtrace(LS_IPTV_SUB, "is free[%p]: h = %d, l = %d, rw = %d", mm, h, l, rw);
@@ -391,7 +382,7 @@ iptv_input_start_mux ( mpegts_input_t *mi, mpegts_mux_instance_t *mmi, int weigh
   }
 
   /* Start */
-  pthread_mutex_lock(&iptv_lock);
+  tvh_mutex_lock(&iptv_lock);
   s = im->mm_iptv_url_raw;
   im->mm_iptv_url_raw = raw ? strdup(raw) : NULL;
   if (im->mm_iptv_url_raw) {
@@ -405,7 +396,7 @@ iptv_input_start_mux ( mpegts_input_t *mi, mpegts_mux_instance_t *mmi, int weigh
       im->mm_active  = NULL;
     }
   }
-  pthread_mutex_unlock(&iptv_lock);
+  tvh_mutex_unlock(&iptv_lock);
 
   urlreset(&url);
   free(s);
@@ -445,7 +436,7 @@ iptv_input_stop_mux ( mpegts_input_t *mi, mpegts_mux_instance_t *mmi )
   iptv_thread_pool_t *pool = ((iptv_input_t *)mi)->mi_tpool;
   uint32_t u32;
 
-  pthread_mutex_lock(&iptv_lock);
+  tvh_mutex_lock(&iptv_lock);
 
   mtimer_disarm(&im->im_pause_timer);
 
@@ -463,7 +454,7 @@ iptv_input_stop_mux ( mpegts_input_t *mi, mpegts_mux_instance_t *mmi )
 
   u32 = --pool->streams;
 
-  pthread_mutex_unlock(&iptv_lock);
+  tvh_mutex_unlock(&iptv_lock);
 
   if (u32 == 0)
     iptv_input_thread_manage(iptv_tpool_safe_count(), 0);
@@ -506,7 +497,7 @@ iptv_input_unpause ( void *aux )
   iptv_mux_t *im = aux;
   iptv_input_t *mi;
   int pause;
-  pthread_mutex_lock(&iptv_lock);
+  tvh_mutex_lock(&iptv_lock);
   pause = 0;
   if (im->mm_active) {
     mi = (iptv_input_t *)im->mm_active->mmi_input;
@@ -517,7 +508,7 @@ iptv_input_unpause ( void *aux )
       im->im_handler->pause(mi, im, 0);
     }
   }
-  pthread_mutex_unlock(&iptv_lock);
+  tvh_mutex_unlock(&iptv_lock);
   if (pause)
     mtimer_arm_rel(&im->im_pause_timer, iptv_input_unpause, im, sec2mono(1));
 }
@@ -547,7 +538,7 @@ iptv_input_thread ( void *aux )
     im = ev.ptr;
     r  = 0;
 
-    pthread_mutex_lock(&iptv_lock);
+    tvh_mutex_lock(&iptv_lock);
 
     /* Only when active */
     if (im->mm_active) {
@@ -563,13 +554,13 @@ iptv_input_thread ( void *aux )
         im->im_handler->pause(mi, im, 1);
     }
 
-    pthread_mutex_unlock(&iptv_lock);
+    tvh_mutex_unlock(&iptv_lock);
 
     if (r == 1) {
-      pthread_mutex_lock(&global_lock);
+      tvh_mutex_lock(&global_lock);
       if (im->mm_active)
         mtimer_arm_rel(&im->im_pause_timer, iptv_input_unpause, im, sec2mono(1));
-      pthread_mutex_unlock(&global_lock);
+      tvh_mutex_unlock(&global_lock);
     }
   }
   return NULL;
@@ -1231,14 +1222,14 @@ iptv_input_thread_manage(int count, int force)
     pool = calloc(1, sizeof(*pool));
     pool->poll = tvhpoll_create(10);
     pool->input = iptv_create_input(pool);
-    tvhthread_create(&pool->thread, NULL, iptv_input_thread, pool, "iptv");
+    tvh_thread_create(&pool->thread, NULL, iptv_input_thread, pool, "iptv");
     TAILQ_INSERT_TAIL(&iptv_tpool, pool, link);
     iptv_tpool_count++;
   }
   while (iptv_tpool_count > count) {
     TAILQ_FOREACH(pool, &iptv_tpool, link)
       if (pool->streams == 0 || force) {
-        pthread_kill(pool->thread, SIGTERM);
+        tvh_thread_kill(pool->thread, SIGTERM);
         pthread_join(pool->thread, NULL);
         TAILQ_REMOVE(&iptv_tpool, pool, link);
         mpegts_input_stop_all((mpegts_input_t*)pool->input);
@@ -1256,7 +1247,7 @@ iptv_input_thread_manage(int count, int force)
 void iptv_init ( void )
 {
   TAILQ_INIT(&iptv_tpool);
-  pthread_mutex_init(&iptv_lock, NULL);
+  tvh_mutex_init(&iptv_lock, NULL);
 
   /* Register handlers */
   iptv_http_init();
@@ -1278,14 +1269,14 @@ void iptv_init ( void )
 
 void iptv_done ( void )
 {
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   iptv_input_thread_manage(0, 1);
   assert(TAILQ_EMPTY(&iptv_tpool));
   mpegts_network_unregister_builder(&iptv_auto_network_class);
   mpegts_network_unregister_builder(&iptv_network_class);
   mpegts_network_class_delete(&iptv_auto_network_class, 0);
   mpegts_network_class_delete(&iptv_network_class, 0);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
 
 /******************************************************************************
index 1d86ac6d7b68a9288e58fc2d766cc4b38fe928ab..99089b321ce2edb32b171dc82f878e41957a0e37 100644 (file)
@@ -52,7 +52,7 @@ iptv_file_thread ( void *aux )
 #if defined(PLATFORM_DARWIN)
   fcntl(fd, F_NOCACHE, 1);
 #endif
-  pthread_mutex_lock(&iptv_lock);
+  tvh_mutex_lock(&iptv_lock);
   while (!fp->shutdown && fd > 0) {
     while (!fp->shutdown && pause) {
       mono = mclk() + sec2mono(1);
@@ -65,9 +65,9 @@ iptv_file_thread ( void *aux )
     if (fp->shutdown)
       break;
     pause = 0;
-    pthread_mutex_unlock(&iptv_lock);
+    tvh_mutex_unlock(&iptv_lock);
     r = read(fd, buf, sizeof(buf));
-    pthread_mutex_lock(&iptv_lock);
+    tvh_mutex_lock(&iptv_lock);
     if (r == 0)
       break;
     if (r < 0) {
@@ -85,7 +85,7 @@ iptv_file_thread ( void *aux )
 #endif
     off += r;
   }
-  pthread_mutex_unlock(&iptv_lock);
+  tvh_mutex_unlock(&iptv_lock);
   return NULL;
 }
 
@@ -106,10 +106,10 @@ iptv_file_start
 
   fp = calloc(1, sizeof(*fp));
   fp->fd = fd;
-  tvh_cond_init(&fp->cond);
+  tvh_cond_init(&fp->cond, 1);
   im->im_data = fp;
   iptv_input_mux_started(mi, im);
-  tvhthread_create(&fp->tid, NULL, iptv_file_thread, im, "iptvfile");
+  tvh_thread_create(&fp->tid, NULL, iptv_file_thread, im, "iptvfile");
   return 0;
 }
 
@@ -123,10 +123,10 @@ iptv_file_stop
     close(rd);
   fp->shutdown = 1;
   tvh_cond_signal(&fp->cond, 0);
-  pthread_mutex_unlock(&iptv_lock);
+  tvh_mutex_unlock(&iptv_lock);
   pthread_join(fp->tid, NULL);
   tvh_cond_destroy(&fp->cond);
-  pthread_mutex_lock(&iptv_lock);
+  tvh_mutex_lock(&iptv_lock);
   free(im->im_data);
   im->im_data = NULL;
 }
index db4746cd37b56430133c12b31427e0a93e7ad215..43e0d8da77ee51c471d4afc5bc18b4442c1eaad6 100644 (file)
@@ -73,7 +73,7 @@ iptv_http_safe_global_lock( http_priv_t *hp )
   while (1) {
     if (im->mm_active == NULL || hp->shutdown)
       return 0;
-    r = pthread_mutex_trylock(&global_lock);
+    r = tvh_mutex_trylock(&global_lock);
     if (r == 0)
       break;
     if (r != EBUSY)
@@ -81,7 +81,7 @@ iptv_http_safe_global_lock( http_priv_t *hp )
     sched_yield();
     if (im->mm_active == NULL || hp->shutdown)
       return 0;
-    r = pthread_mutex_trylock(&global_lock);
+    r = tvh_mutex_trylock(&global_lock);
     if (r == 0)
       break;
     if (r == EBUSY)
@@ -254,7 +254,7 @@ iptv_http_header ( http_client_t *hc )
     } else {
       iptv_input_recv_flush(hp->im);
     }
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
     hp->started = 1;
   }
   return 0;
@@ -287,7 +287,7 @@ iptv_http_data
     return 0;
   }
 
-  pthread_mutex_lock(&iptv_lock);
+  tvh_mutex_lock(&iptv_lock);
 
   if (hp->hls_encrypted) {
     off = im->mm_iptv_buffer.sb_ptr;
@@ -308,7 +308,7 @@ iptv_http_data
     memcpy(hp->hls_aes128.tmp + hp->hls_aes128.tmp_len, buf, len);
     hp->hls_aes128.tmp_len += len;
     if (off == im->mm_iptv_buffer.sb_ptr) {
-      pthread_mutex_unlock(&iptv_lock);
+      tvh_mutex_unlock(&iptv_lock);
       return 0;
     }
     buf = im->mm_iptv_buffer.sb_data + im->mm_iptv_buffer.sb_ptr;
@@ -343,12 +343,12 @@ iptv_http_data
     if (iptv_input_recv_packets(im, len) == 1)
       pause = hc->hc_pause = 1;
 
-  pthread_mutex_unlock(&iptv_lock);
+  tvh_mutex_unlock(&iptv_lock);
 
   if (pause && iptv_http_safe_global_lock(hp)) {
     if (im->mm_active && !hp->shutdown)
       mtimer_arm_rel(&im->im_pause_timer, iptv_input_unpause, im, sec2mono(1));
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
   }
   return 0;
 }
@@ -364,10 +364,10 @@ iptv_http_reconnect ( http_client_t *hc, const char *url )
 
   urlinit(&u);
   if (!urlparse(url, &u)) {
-    pthread_mutex_lock(&hc->hc_mutex);
+    tvh_mutex_lock(&hc->hc_mutex);
     hc->hc_keepalive = 0;
     r = http_client_simple_reconnect(hc, &u, HTTP_VERSION_1_1);
-    pthread_mutex_unlock(&hc->hc_mutex);
+    tvh_mutex_unlock(&hc->hc_mutex);
     if (r < 0)
       tvherror(LS_IPTV, "cannot reopen http client: %d'", r);
   } else {
@@ -558,9 +558,9 @@ iptv_http_stop
   http_priv_t *hp = im->im_data;
 
   hp->shutdown = 1;
-  pthread_mutex_unlock(&iptv_lock);
+  tvh_mutex_unlock(&iptv_lock);
   http_client_close(hp->hc);
-  pthread_mutex_lock(&iptv_lock);
+  tvh_mutex_lock(&iptv_lock);
   im->im_data = NULL;
   sbuf_free(&hp->m3u_sbuf);
   sbuf_free(&hp->key_sbuf);
index e7a058a029e9272ed34cea26b08fb5e3a981bb13..300909060fa39b0ca7538dde932eab62f3946f87 100644 (file)
@@ -32,7 +32,7 @@ typedef struct {
   int running;
   int pause;
   pthread_t thread;
-  pthread_mutex_t lock;
+  tvh_mutex_t lock;
   th_pipe_t pipe;
   AVFormatContext *ictx;
   AVFormatContext *octx;
@@ -48,21 +48,21 @@ iptv_libav_write_packet(void *opaque, uint8_t *buf, int buf_size)
   iptv_libav_priv_t *la = opaque;
 
   if (buf_size > 0) {
-    pthread_mutex_lock(&la->lock);
+    tvh_mutex_lock(&la->lock);
     if (la->sbuf.sb_ptr < 5*1024*1024) {
       while (atomic_get(&la->pause)) {
         if (!atomic_get(&la->running))
           goto fin;
-        pthread_mutex_unlock(&la->lock);
+        tvh_mutex_unlock(&la->lock);
         tvh_usleep(500000);
-        pthread_mutex_lock(&la->lock);
+        tvh_mutex_lock(&la->lock);
       }
       sbuf_append(&la->sbuf, buf, buf_size);
       /* notify iptv layer that we have new data to read */
       if (write(la->pipe.wr, "", 1)) {};
     }
 fin:
-    pthread_mutex_unlock(&la->lock);
+    tvh_mutex_unlock(&la->lock);
   }
   return 0;
 }
@@ -180,7 +180,7 @@ iptv_libav_start
   iptv_libav_priv_t *la = calloc(1, sizeof(*la));
 
   assert(raw);
-  pthread_mutex_init(&la->lock, NULL);
+  tvh_mutex_init(&la->lock, NULL);
   im->im_opaque = la;
   if (strncmp(raw, "libav:", 6) == 0)
     raw += 6;
@@ -192,7 +192,7 @@ iptv_libav_start
   atomic_set(&la->running, 1);
   atomic_set(&la->pause, 0);
   sbuf_init(&la->sbuf);
-  tvhthread_create(&la->thread, NULL, iptv_libav_thread, la, "libavinput");
+  tvh_thread_create(&la->thread, NULL, iptv_libav_thread, la, "libavinput");
   if (raw[0])
     iptv_input_mux_started(mi, im);
   return 0;
@@ -206,7 +206,7 @@ iptv_libav_stop
 
   atomic_set(&la->running, 0);
   im->im_opaque = NULL;
-  pthread_kill(la->thread, SIGUSR1);
+  tvh_thread_kill(la->thread, SIGUSR1);
   pthread_join(la->thread, NULL);
   tvh_pipe_close(&la->pipe);
   avformat_close_input(&la->ictx);
@@ -224,12 +224,12 @@ iptv_libav_read ( iptv_input_t *mi, iptv_mux_t *im )
 
   if (la == NULL)
     return 0;
-  pthread_mutex_lock(&la->lock);
+  tvh_mutex_lock(&la->lock);
   ret = la->sbuf.sb_ptr;
   sbuf_append_from_sbuf(&im->mm_iptv_buffer, &la->sbuf);
   sbuf_reset(&la->sbuf, WRITE_BUFFER_SIZE * 2);
   if (read(la->pipe.rd, buf, sizeof(buf))) {};
-  pthread_mutex_unlock(&la->lock);
+  tvh_mutex_unlock(&la->lock);
   return ret;
 }
 
index 2cf334eb60215eab8b7489129c8c15e919de70e6..a75cc4359293bef4f4ca88d4c002f16d9486c94b 100644 (file)
@@ -114,9 +114,9 @@ iptv_pipe_read ( iptv_input_t *mi, iptv_mux_t *im )
                  rd, r < 0 ? strerror(errno) : "No data");
       } else {
         /* avoid deadlock here */
-        pthread_mutex_unlock(&iptv_lock);
-        pthread_mutex_lock(&global_lock);
-        pthread_mutex_lock(&iptv_lock);
+        tvh_mutex_unlock(&iptv_lock);
+        tvh_mutex_lock(&global_lock);
+        tvh_mutex_lock(&iptv_lock);
         if (im->mm_active) {
           if (iptv_pipe_start(mi, im, im->mm_iptv_url_raw, NULL)) {
             tvherror(LS_IPTV, "unable to respawn %s", im->mm_iptv_url_raw);
@@ -125,9 +125,9 @@ iptv_pipe_read ( iptv_input_t *mi, iptv_mux_t *im )
             im->mm_iptv_respawn_last = mclk();
           }
         }
-        pthread_mutex_unlock(&iptv_lock);
-        pthread_mutex_unlock(&global_lock);
-        pthread_mutex_lock(&iptv_lock);
+        tvh_mutex_unlock(&iptv_lock);
+        tvh_mutex_unlock(&global_lock);
+        tvh_mutex_lock(&iptv_lock);
       }
       break;
     }
index 84109eb08de49d6eb1f67ef7949e82238f69f497..d73b0076be2641be4c28e45b77b6aa6a37d64fe1 100644 (file)
@@ -181,7 +181,7 @@ extern const idclass_t iptv_mux_class;
 
 extern iptv_network_t *iptv_network;
 
-extern pthread_mutex_t iptv_lock;
+extern tvh_mutex_t iptv_lock;
 
 int iptv_url_set ( char **url, char **sane_url, const char *str, int allow_file, int allow_pipe );
 
index e661cc0089bab52ce68194bae20c2d690cb23c3b..2e411c4717dd7505dea0be2df79926c2066bdb3c 100644 (file)
@@ -75,9 +75,9 @@ iptv_rtsp_header ( http_client_t *hc )
   if (im == NULL) {
     /* teardown (or teardown timeout) */
     if (hc->hc_cmd == RTSP_CMD_TEARDOWN) {
-      pthread_mutex_lock(&global_lock);
+      tvh_mutex_lock(&global_lock);
       mtimer_arm_rel(&hc->hc_close_timer, iptv_rtsp_close_cb, hc, 0);
-      pthread_mutex_unlock(&global_lock);
+      tvh_mutex_unlock(&global_lock);
     }
     return 0;
   }
@@ -111,12 +111,12 @@ iptv_rtsp_header ( http_client_t *hc )
         tvhwarn(LS_RTSP, "Can't connect to remote, RTCP receiver reports won't be sent");
     }
     hc->hc_cmd = HTTP_CMD_NONE;
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     if (im->mm_active)
       iptv_input_mux_started((iptv_input_t *)im->mm_active->mmi_input, im);
     mtimer_arm_rel(&rp->alive_timer, iptv_rtsp_alive_cb, im,
                    sec2mono(MAX(1, (hc->hc_rtp_timeout / 2) - 1)));
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
     break;
   default:
     break;
@@ -225,7 +225,7 @@ iptv_rtsp_stop
   rp->hc->hc_aux = NULL;
   if (play)
     rtsp_teardown(rp->hc, rp->path, "");
-  pthread_mutex_unlock(&iptv_lock);
+  tvh_mutex_unlock(&iptv_lock);
   mtimer_disarm(&rp->alive_timer);
   udp_multirecv_free(&rp->um);
   if (!play)
@@ -235,7 +235,7 @@ iptv_rtsp_stop
   rtcp_destroy(rp->rtcp_info);
   free(rp->rtcp_info);
   free(rp);
-  pthread_mutex_lock(&iptv_lock);
+  tvh_mutex_lock(&iptv_lock);
 }
 
 static void
index 28ce8ad407e1fa638a6983e4866cff83baad0a89..e086bda8396b397d2ecde067b93ebfc98263c937 100644 (file)
@@ -66,10 +66,10 @@ iptv_udp_stop
   udp_multirecv_t *um = im->im_data;
 
   im->im_data = NULL;
-  pthread_mutex_unlock(&iptv_lock);
+  tvh_mutex_unlock(&iptv_lock);
   udp_multirecv_free(um);
   free(um);
-  pthread_mutex_lock(&iptv_lock);
+  tvh_mutex_lock(&iptv_lock);
 }
 
 static ssize_t
index ad50987a2141867eab94eed0f88d5913db21709d..cc1e6c6ab2e8b06ab8af7b3afa1aa4e895f542b8 100644 (file)
@@ -384,7 +384,7 @@ linuxdvb_adapter_add ( const char *path )
   /* Note: some of the below can take a while, so we relinquish the lock
    *       to stop us blocking everyhing else
    */
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   /* Process each frontend */
   for (i = 0; i < 32; i++) {
@@ -438,7 +438,7 @@ linuxdvb_adapter_add ( const char *path )
     }
 
     /* Create/Find adapter */
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     if (!la) {
       la = linuxdvb_adapter_new(path, a, dfi.name, name, &conf, &save);
       if (la == NULL) {
@@ -481,7 +481,7 @@ linuxdvb_adapter_add ( const char *path )
 #else
     linuxdvb_frontend_create(feconf, la, i, fe_path, dmx_path, dvr_path, type, name);
 #endif
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
   }
 
   /* Process each CA device */
@@ -575,7 +575,7 @@ linuxdvb_adapter_add ( const char *path )
     }
 #endif /* ENABLE_DDCI */
 
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
 
     if (!la) {
       snprintf(name, sizeof(name), "CAM #%d", i);
@@ -594,7 +594,7 @@ linuxdvb_adapter_add ( const char *path )
       for (j = 0; j < cac.slot_num; j++)
         linuxdvb_ca_create(caconf, lcat, j);
     }
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
   }
 #endif /* ENABLE_LINUXDVB_CA */
 
@@ -603,7 +603,7 @@ linuxdvb_adapter_add ( const char *path )
     htsmsg_destroy(conf);
 
   /* Relock before exit */
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 
   /* Adapter couldn't be opened; there's nothing to work with  */
   if (!la)
@@ -792,7 +792,7 @@ linuxdvb_adapter_done ( void )
   linuxdvb_adapter_t *la;
   tvh_hardware_t *th, *n;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   fsmonitor_del("/dev/dvb", &devdvbmon);
   fsmonitor_del("/dev", &devmon);
   for (th = LIST_FIRST(&tvh_hardware); th != NULL; th = n) {
@@ -805,5 +805,5 @@ linuxdvb_adapter_done ( void )
 #if ENABLE_LINUXDVB_CA
   linuxdvb_ca_done();
 #endif
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
index 1a495bc40d184cc2e077323136b90c7b5c3c5c9a..60bc449b5e3e0013aecf9e6b00826142a37eae0e 100644 (file)
@@ -41,8 +41,8 @@
 
 #define TRANSPORT_RECOVERY 4 /* in seconds */
 
-static pthread_mutex_t linuxdvb_ca_mutex = PTHREAD_MUTEX_INITIALIZER;
-static pthread_mutex_t linuxdvb_capmt_mutex = PTHREAD_MUTEX_INITIALIZER;
+static tvh_mutex_t linuxdvb_ca_mutex = { .mutex = PTHREAD_MUTEX_INITIALIZER };
+static tvh_mutex_t linuxdvb_capmt_mutex = { .mutex = PTHREAD_MUTEX_INITIALIZER };
 static th_pipe_t linuxdvb_ca_pipe;
 static pthread_t linuxdvb_ca_threadid;
 static mtimer_t linuxdvb_ca_thread_join_timer;
@@ -201,14 +201,14 @@ linuxdvb_ca_close_fd( linuxdvb_transport_t *lcat, int reset )
   linuxdvb_ca_t *lca;
   linuxdvb_ca_write_t *lcw;
 
-  pthread_mutex_lock(&linuxdvb_capmt_mutex);
+  tvh_mutex_lock(&linuxdvb_capmt_mutex);
   LIST_FOREACH(lca, &lcat->lcat_slots, lca_link) {
     while ((lcw = TAILQ_FIRST(&lca->lca_write_queue)) != NULL) {
       TAILQ_REMOVE(&lca->lca_write_queue, lcw, lcw_link);
       free(lcw);
     }
   }
-  pthread_mutex_unlock(&linuxdvb_capmt_mutex);
+  tvh_mutex_unlock(&linuxdvb_capmt_mutex);
 
   if (fd < 0)
     return;
@@ -223,14 +223,14 @@ linuxdvb_ca_close_fd( linuxdvb_transport_t *lcat, int reset )
   tvhtrace(LS_EN50221, "%s: close %s (fd %d)",
            lcat->lcat_name, lcat->lcat_ca_path, fd);
   close(fd);
-  pthread_mutex_lock(&linuxdvb_capmt_mutex);
+  tvh_mutex_lock(&linuxdvb_capmt_mutex);
   LIST_FOREACH(lca, &lcat->lcat_slots, lca_link) {
     while ((lcw = TAILQ_FIRST(&lca->lca_write_queue)) != NULL) {
       TAILQ_REMOVE(&lca->lca_write_queue, lcw, lcw_link);
       free(lcw);
     }
   }
-  pthread_mutex_unlock(&linuxdvb_capmt_mutex);
+  tvh_mutex_unlock(&linuxdvb_capmt_mutex);
   if (reset)
     en50221_transport_reset(lcat->lcat_transport);
 }
@@ -301,7 +301,7 @@ linuxdvb_ca_thread ( void *aux )
     evp->ptr = &linuxdvb_ca_pipe;
     evp++;
     evcnt = 1;
-    pthread_mutex_lock(&linuxdvb_ca_mutex);
+    tvh_mutex_lock(&linuxdvb_ca_mutex);
     LIST_FOREACH(lcat, &linuxdvb_all_transports, lcat_all_link) {
       if (lcat->lcat_ca_fd < 0) {
         if (!lcat->lcat_enabled)
@@ -312,7 +312,7 @@ linuxdvb_ca_thread ( void *aux )
           continue;
       } else if (!lcat->lcat_enabled) {
         if (lcat->lcat_ca_fd >= 0 && lcat->lcat_close_time < mclk()) {
-          pthread_mutex_lock(&linuxdvb_capmt_mutex);
+          tvh_mutex_lock(&linuxdvb_capmt_mutex);
           busy = 0;
           LIST_FOREACH(lca, &lcat->lcat_slots, lca_link) {
             slot = en50221_transport_find_slot(lcat->lcat_transport,
@@ -321,7 +321,7 @@ linuxdvb_ca_thread ( void *aux )
               busy |= TAILQ_EMPTY(&slot->cil_write_queue) ? 0 : 2;
             busy |= TAILQ_EMPTY(&lca->lca_write_queue) ? 0 : 1;
           }
-          pthread_mutex_unlock(&linuxdvb_capmt_mutex);
+          tvh_mutex_unlock(&linuxdvb_capmt_mutex);
           tvhtrace(LS_EN50221, "%s: busy %x", lcat->lcat_name, busy);
           if (!busy)
             linuxdvb_ca_close_fd(lcat, 1);
@@ -344,14 +344,14 @@ linuxdvb_ca_thread ( void *aux )
       evp++;
       evcnt++;
     }
-    pthread_mutex_unlock(&linuxdvb_ca_mutex);
+    tvh_mutex_unlock(&linuxdvb_ca_mutex);
     tvhpoll_set(poll, ev, evcnt);
 
     r = tvhpoll_wait(poll, ev, evcnt, waitms);
     if (r < 0 && ERRNO_AGAIN(errno))
       continue;
 
-    pthread_mutex_lock(&linuxdvb_ca_mutex);
+    tvh_mutex_lock(&linuxdvb_ca_mutex);
     tm2 = mclk();
     monitor = (tm2 - tm) > (MONOCLOCK_RESOLUTION / 4); /* 250ms */
     if (monitor)
@@ -414,11 +414,11 @@ linuxdvb_ca_thread ( void *aux )
       LIST_FOREACH(lca, &lcat->lcat_slots, lca_link) {
         cquit = 0;
         while (!cquit) {
-          pthread_mutex_lock(&linuxdvb_capmt_mutex);
+          tvh_mutex_lock(&linuxdvb_capmt_mutex);
           lcw = TAILQ_FIRST(&lca->lca_write_queue);
           if (lcw)
             TAILQ_REMOVE(&lca->lca_write_queue, lcw, lcw_link);
-          pthread_mutex_unlock(&linuxdvb_capmt_mutex);
+          tvh_mutex_unlock(&linuxdvb_capmt_mutex);
           if (lcw == NULL) {
             lca->lca_capmt_blocked = 0;
             break;
@@ -431,9 +431,9 @@ linuxdvb_ca_thread ( void *aux )
               lcat->lcat_fatal_time = mclk();
               linuxdvb_ca_close_fd(lcat, 1);
             } else if (r > 0) {
-              pthread_mutex_lock(&linuxdvb_capmt_mutex);
+              tvh_mutex_lock(&linuxdvb_capmt_mutex);
               TAILQ_INSERT_HEAD(&lca->lca_write_queue, lcw, lcw_link);
-              pthread_mutex_unlock(&linuxdvb_capmt_mutex);
+              tvh_mutex_unlock(&linuxdvb_capmt_mutex);
               cquit = 1;
             } else {
               free(lcw);
@@ -450,7 +450,7 @@ linuxdvb_ca_thread ( void *aux )
           waitms = 1;
       }
     }
-    pthread_mutex_unlock(&linuxdvb_ca_mutex);
+    tvh_mutex_unlock(&linuxdvb_ca_mutex);
   }
 
   tvhpoll_destroy(poll);
@@ -463,8 +463,8 @@ static void linuxdvb_ca_thread_create(void)
 {
   if (linuxdvb_ca_threadid)
     return;
-  tvhthread_create(&linuxdvb_ca_threadid, NULL, linuxdvb_ca_thread,
-                   NULL, "lnxdvb-ca");
+  tvh_thread_create(&linuxdvb_ca_threadid, NULL, linuxdvb_ca_thread,
+                    NULL, "lnxdvb-ca");
   if (tvh_pipe(O_NONBLOCK, &linuxdvb_ca_pipe)) {
     tvherror(LS_EN50221, "unable to create thread pipe");
     pthread_join(linuxdvb_ca_threadid, NULL);
@@ -500,10 +500,10 @@ static int linuxdvb_ca_write_cmd
   lcw->cmd = cmd;
   memcpy(lcw->data, data, datalen);
 
-  pthread_mutex_lock(&linuxdvb_capmt_mutex);
+  tvh_mutex_lock(&linuxdvb_capmt_mutex);
   trigger = TAILQ_EMPTY(&lca->lca_write_queue);
   TAILQ_INSERT_TAIL(&lca->lca_write_queue, lcw, lcw_link);
-  pthread_mutex_unlock(&linuxdvb_capmt_mutex);
+  tvh_mutex_unlock(&linuxdvb_capmt_mutex);
 
   if (trigger)
     tvh_write(linuxdvb_ca_pipe.wr, "w", 1);
@@ -746,9 +746,9 @@ linuxdvb_ca_create
   /* Transport link */
   lca->lca_transport = lcat;
   LIST_INSERT_HEAD(&lcat->lcat_slots, lca, lca_link);
-  pthread_mutex_lock(&linuxdvb_ca_mutex);
+  tvh_mutex_lock(&linuxdvb_ca_mutex);
   LIST_INSERT_HEAD(&linuxdvb_all_cas, lca, lca_all_link);
-  pthread_mutex_unlock(&linuxdvb_ca_mutex);
+  tvh_mutex_unlock(&linuxdvb_ca_mutex);
 
   if (conf)
     idnode_load(&lca->lca_id, conf);
@@ -763,13 +763,13 @@ static void linuxdvb_ca_destroy( linuxdvb_ca_t *lca )
   if (lca == NULL)
     return;
   dvbcam_unregister_cam(lca);
-  pthread_mutex_lock(&linuxdvb_ca_mutex);
+  tvh_mutex_lock(&linuxdvb_ca_mutex);
   LIST_REMOVE(lca, lca_all_link);
   while ((lcw = TAILQ_FIRST(&lca->lca_write_queue)) != NULL) {
     TAILQ_REMOVE(&lca->lca_write_queue, lcw, lcw_link);
     free(lcw);
   }
-  pthread_mutex_unlock(&linuxdvb_ca_mutex);
+  tvh_mutex_unlock(&linuxdvb_ca_mutex);
   LIST_REMOVE(lca, lca_link);
   idnode_unlink(&lca->lca_id);
   free(lca->lca_pin_str);
@@ -1039,9 +1039,9 @@ linuxdvb_transport_t *linuxdvb_transport_create
 #endif
 
   LIST_INSERT_HEAD(&la->la_ca_transports, lcat, lcat_link);
-  pthread_mutex_lock(&linuxdvb_ca_mutex);
+  tvh_mutex_lock(&linuxdvb_ca_mutex);
   LIST_INSERT_HEAD(&linuxdvb_all_transports, lcat, lcat_all_link);
-  pthread_mutex_unlock(&linuxdvb_ca_mutex);
+  tvh_mutex_unlock(&linuxdvb_ca_mutex);
   return lcat;
 }
 
@@ -1051,9 +1051,9 @@ void linuxdvb_transport_destroy ( linuxdvb_transport_t *lcat )
 
   if (lcat == NULL)
     return;
-  pthread_mutex_lock(&linuxdvb_ca_mutex);
+  tvh_mutex_lock(&linuxdvb_ca_mutex);
   LIST_REMOVE(lcat, lcat_all_link);
-  pthread_mutex_unlock(&linuxdvb_ca_mutex);
+  tvh_mutex_unlock(&linuxdvb_ca_mutex);
   while ((ca = LIST_FIRST(&lcat->lcat_slots)) != NULL)
     linuxdvb_ca_destroy(ca);
   LIST_REMOVE(lcat, lcat_link);
index 9359f6c225f8e2f68da016b44c572180c87d3784..c9313b0b79b2ba110c7ba52b15b460c63f231115 100644 (file)
@@ -1,4 +1,4 @@
- /*
+/*
  *  Tvheadend - Linux DVB DDCI
  *
  *  Copyright (C) 2017 Jasmin Jessich
@@ -48,7 +48,7 @@ typedef struct linuxdvb_ddci_thread
   int                       lddci_thread_running;
   int                       lddci_thread_stop;
   pthread_t                 lddci_thread;
-  pthread_mutex_t           lddci_thread_lock;
+  tvh_mutex_t           lddci_thread_lock;
   tvh_cond_t                lddci_thread_cond;
 } linuxdvb_ddci_thread_t;
 
@@ -64,7 +64,7 @@ typedef struct linuxdvb_ddci_send_buffer
   TAILQ_HEAD(,linuxdvb_ddci_send_packet)  lddci_send_buf_queue;
   uint64_t                                lddci_send_buf_size_max;
   uint64_t                                lddci_send_buf_size;
-  pthread_mutex_t                         lddci_send_buf_lock;
+  tvh_mutex_t                         lddci_send_buf_lock;
   tvh_cond_t                              lddci_send_buf_cond;
   tvhlog_limit_t                          lddci_send_buf_loglimit;
   int                                     lddci_send_buf_pkgCntW;
@@ -125,10 +125,10 @@ linuxdvb_ddci_mtimer_disarm ( mtimer_t *mti )
 {
   int locked;
 
-  locked = ! pthread_mutex_trylock(&global_lock);
+  locked = ! tvh_mutex_trylock(&global_lock);
   mtimer_disarm(mti);
   if (locked)
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
 }
 
 /* When a DD CI is enabled on the WEB UI, the global lock is held when the
@@ -143,10 +143,10 @@ linuxdvb_ddci_mtimer_arm_rel
 {
   int locked;
 
-  locked = ! pthread_mutex_trylock(&global_lock);
+  locked = ! tvh_mutex_trylock(&global_lock);
   mtimer_arm_rel(mti, callback, opaque, delta);
   if (locked)
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
 }
 
 
@@ -163,8 +163,8 @@ linuxdvb_ddci_thread_init
   ddci_thread->lddci = lddci;
   ddci_thread->lddci_thread_running = 0;
   ddci_thread->lddci_thread_stop = 0;
-  pthread_mutex_init(&ddci_thread->lddci_thread_lock, NULL);
-  tvh_cond_init(&ddci_thread->lddci_thread_cond);
+  tvh_mutex_init(&ddci_thread->lddci_thread_lock, NULL);
+  tvh_cond_init(&ddci_thread->lddci_thread_cond, 1);
 }
 
 static inline int
@@ -187,9 +187,8 @@ linuxdvb_ddci_thread_start
   int e = -1;
 
   if (!linuxdvb_ddci_thread_running(ddci_thread)) {
-    pthread_mutex_lock(&ddci_thread->lddci_thread_lock);
-    tvhthread_create(&ddci_thread->lddci_thread, NULL, thread_routine, arg,
-                     name);
+    tvh_mutex_lock(&ddci_thread->lddci_thread_lock);
+    tvh_thread_create(&ddci_thread->lddci_thread, NULL, thread_routine, arg, name);
     do {
       e = tvh_cond_wait(&ddci_thread->lddci_thread_cond,
                         &ddci_thread->lddci_thread_lock);
@@ -198,7 +197,7 @@ linuxdvb_ddci_thread_start
         break;
       }
     } while (ERRNO_AGAIN(e));
-    pthread_mutex_unlock(&ddci_thread->lddci_thread_lock);
+    tvh_mutex_unlock(&ddci_thread->lddci_thread_lock);
   }
 
   return e;
@@ -227,8 +226,8 @@ linuxdvb_ddci_send_buffer_init
   TAILQ_INIT(&ddci_snd_buf->lddci_send_buf_queue);
   ddci_snd_buf->lddci_send_buf_size_max = ddci_snd_buf_max;
   ddci_snd_buf->lddci_send_buf_size = 0;
-  pthread_mutex_init(&ddci_snd_buf->lddci_send_buf_lock, NULL);
-  tvh_cond_init(&ddci_snd_buf->lddci_send_buf_cond);
+  tvh_mutex_init(&ddci_snd_buf->lddci_send_buf_lock, NULL);
+  tvh_cond_init(&ddci_snd_buf->lddci_send_buf_cond, 1);
   tvhlog_limit_reset(&ddci_snd_buf->lddci_send_buf_loglimit);
   ddci_snd_buf->lddci_send_buf_pkgCntW = 0;
   ddci_snd_buf->lddci_send_buf_pkgCntR = 0;
@@ -257,7 +256,7 @@ linuxdvb_ddci_send_buffer_get
 {
   linuxdvb_ddci_send_packet_t  *sp;
 
-  pthread_mutex_lock(&ddci_snd_buf->lddci_send_buf_lock);
+  tvh_mutex_lock(&ddci_snd_buf->lddci_send_buf_lock);
 
   /* packet present? */
   sp = TAILQ_FIRST(&ddci_snd_buf->lddci_send_buf_queue);
@@ -280,7 +279,7 @@ linuxdvb_ddci_send_buffer_get
 
   linuxdvb_ddci_send_buffer_remove(ddci_snd_buf, sp);
 
-  pthread_mutex_unlock(&ddci_snd_buf->lddci_send_buf_lock);
+  tvh_mutex_unlock(&ddci_snd_buf->lddci_send_buf_lock);
 
   return sp;
 }
@@ -289,7 +288,7 @@ static void
 linuxdvb_ddci_send_buffer_put
   ( linuxdvb_ddci_send_buffer_t *ddci_snd_buf, const uint8_t *tsb, int len )
 {
-  pthread_mutex_lock(&ddci_snd_buf->lddci_send_buf_lock);
+  tvh_mutex_lock(&ddci_snd_buf->lddci_send_buf_lock);
 
   if (ddci_snd_buf->lddci_send_buf_size < ddci_snd_buf->lddci_send_buf_size_max) {
     linuxdvb_ddci_send_packet_t  *sp;
@@ -324,7 +323,7 @@ linuxdvb_ddci_send_buffer_put
       tvhwarn(LS_DDCI, "too much queued output data in send buffer, discarding new");
   }
 
-  pthread_mutex_unlock(&ddci_snd_buf->lddci_send_buf_lock);
+  tvh_mutex_unlock(&ddci_snd_buf->lddci_send_buf_lock);
 }
 
 static void
@@ -332,7 +331,7 @@ linuxdvb_ddci_send_buffer_clear ( linuxdvb_ddci_send_buffer_t *ddci_snd_buf )
 {
   linuxdvb_ddci_send_packet_t  *sp;
 
-  pthread_mutex_lock(&ddci_snd_buf->lddci_send_buf_lock);
+  tvh_mutex_lock(&ddci_snd_buf->lddci_send_buf_lock);
 
   while ((sp = TAILQ_FIRST(&ddci_snd_buf->lddci_send_buf_queue)))
   {
@@ -344,7 +343,7 @@ linuxdvb_ddci_send_buffer_clear ( linuxdvb_ddci_send_buffer_t *ddci_snd_buf )
   ddci_snd_buf->lddci_send_buf_pkgCntWL = 0;
   ddci_snd_buf->lddci_send_buf_pkgCntRL = 0;
 
-  pthread_mutex_unlock(&ddci_snd_buf->lddci_send_buf_lock);
+  tvh_mutex_unlock(&ddci_snd_buf->lddci_send_buf_lock);
 }
 
 static void
@@ -462,10 +461,10 @@ linuxdvb_ddci_wr_thread_stop ( linuxdvb_ddci_wr_thread_t *ddci_wr_thread )
   /* See function linuxdvb_ddci_wr_thread_buffer_put why we lock here.
    */
 
-  pthread_mutex_lock(&ddci_wr_thread->lddci_thread_lock);
+  tvh_mutex_lock(&ddci_wr_thread->lddci_thread_lock);
   linuxdvb_ddci_thread_stop(LDDCI_TO_THREAD(ddci_wr_thread));
   linuxdvb_ddci_send_buffer_clear(&ddci_wr_thread->lddci_send_buffer);
-  pthread_mutex_unlock(&ddci_wr_thread->lddci_thread_lock);
+  tvh_mutex_unlock(&ddci_wr_thread->lddci_thread_lock);
 }
 
 static inline void
@@ -480,10 +479,10 @@ linuxdvb_ddci_wr_thread_buffer_put
    * linuxdvb_ddci_wr_thread_start will then re-init the queue and the wrongly
    * stored data is lost -> memory leak.
    */
-  pthread_mutex_lock(&ddci_wr_thread->lddci_thread_lock);
+  tvh_mutex_lock(&ddci_wr_thread->lddci_thread_lock);
   if (linuxdvb_ddci_thread_running(LDDCI_TO_THREAD(ddci_wr_thread)))
     linuxdvb_ddci_send_buffer_put(&ddci_wr_thread->lddci_send_buffer, tsb, len );
-  pthread_mutex_unlock(&ddci_wr_thread->lddci_thread_lock);
+  tvh_mutex_unlock(&ddci_wr_thread->lddci_thread_lock);
 }
 
 
index 6a7d26f8da74ef34a7c7dfc163e6a8389a67124f..b51f42de1cc9a2adaca326cfe47d435aef14cd99 100644 (file)
@@ -62,7 +62,7 @@
  * *************************************************************************/
 
 /* prevention of self raised DiSEqC collisions */
-static pthread_mutex_t linuxdvb_en50494_lock;
+static tvh_mutex_t linuxdvb_en50494_lock;
 
 static void
 linuxdvb_en50494_class_get_title
@@ -312,8 +312,8 @@ linuxdvb_en50494_tune
   /* wait until no other thread is setting up switch.
    * when an other thread was blocking, waiting 20ms.
    */
-  if (pthread_mutex_trylock(&linuxdvb_en50494_lock) != 0) {
-    if (pthread_mutex_lock(&linuxdvb_en50494_lock) != 0) {
+  if (tvh_mutex_trylock(&linuxdvb_en50494_lock) != 0) {
+    if (tvh_mutex_lock(&linuxdvb_en50494_lock) != 0) {
       tvherror(LS_EN50494,"failed to lock for tuning");
       return -1;
     }
@@ -380,7 +380,7 @@ linuxdvb_en50494_tune
       break;
     }
   }
-  pthread_mutex_unlock(&linuxdvb_en50494_lock);
+  tvh_mutex_unlock(&linuxdvb_en50494_lock);
 
   return ret == 0 ? 0 : -1;
 }
@@ -393,7 +393,7 @@ linuxdvb_en50494_tune
 void
 linuxdvb_en50494_init (void)
 {
-  if (pthread_mutex_init(&linuxdvb_en50494_lock, NULL) != 0) {
+  if (tvh_mutex_init(&linuxdvb_en50494_lock, NULL) != 0) {
     tvherror(LS_EN50494, "failed to init lock mutex");
   }
 }
index 64f88ff679e87144833ead4599884e16abecf02c..9f7278f53d578d097e4bc5b2b622c7dcd9253600 100644 (file)
@@ -732,9 +732,9 @@ linuxdvb_frontend_warm_mux ( mpegts_input_t *mi, mpegts_mux_instance_t *mmi )
   /* Stop other active frontend (should be only one) */
   LIST_FOREACH(lfe2, &lfe->lfe_adapter->la_frontends, lfe_link) {
     if (lfe2 == lfe || strcmp(lfe2->lfe_fe_path, lfe->lfe_fe_path)) continue;
-    pthread_mutex_lock(&lfe2->mi_output_lock);
+    tvh_mutex_lock(&lfe2->mi_output_lock);
     lmmi = LIST_FIRST(&lfe2->mi_mux_active);
-    pthread_mutex_unlock(&lfe2->mi_output_lock);
+    tvh_mutex_unlock(&lfe2->mi_output_lock);
     if (lmmi) {
       /* Stop */
       lmmi->mmi_mux->mm_stop(lmmi->mmi_mux, 1, SM_CODE_ABORTED);
@@ -801,7 +801,7 @@ linuxdvb_frontend_update_pids
   mpegts_pid_t *mp;
   mpegts_pid_sub_t *mps;
 
-  pthread_mutex_lock(&lfe->lfe_dvr_lock);
+  tvh_mutex_lock(&lfe->lfe_dvr_lock);
   mpegts_pid_done(&lfe->lfe_pids);
   RB_FOREACH(mp, &mm->mm_pids, mp_link) {
     if (mp->mp_pid == MPEGTS_FULLMUX_PID)
@@ -811,7 +811,7 @@ linuxdvb_frontend_update_pids
         mpegts_pid_add(&lfe->lfe_pids, mp->mp_pid, mps->mps_weight);
     }
   }
-  pthread_mutex_unlock(&lfe->lfe_dvr_lock);
+  tvh_mutex_unlock(&lfe->lfe_dvr_lock);
 
   if (lfe->lfe_dvr_pipe.wr > 0)
     tvh_write(lfe->lfe_dvr_pipe.wr, "c", 1);
@@ -955,15 +955,15 @@ linuxdvb_frontend_monitor ( void *aux )
   
       /* Start input */
       tvh_pipe(O_NONBLOCK, &lfe->lfe_dvr_pipe);
-      pthread_mutex_lock(&lfe->lfe_dvr_lock);
-      tvhthread_create(&lfe->lfe_dvr_thread, NULL,
-                       linuxdvb_frontend_input_thread, lfe, "lnxdvb-front");
+      tvh_mutex_lock(&lfe->lfe_dvr_lock);
+      tvh_thread_create(&lfe->lfe_dvr_thread, NULL,
+                        linuxdvb_frontend_input_thread, lfe, "lnxdvb-front");
       do {
         e = tvh_cond_wait(&lfe->lfe_dvr_cond, &lfe->lfe_dvr_lock);
         if (e == ETIMEDOUT)
           break;
       } while (ERRNO_AGAIN(e));
-      pthread_mutex_unlock(&lfe->lfe_dvr_lock);
+      tvh_mutex_unlock(&lfe->lfe_dvr_lock);
 
       /* Table handlers */
       psi_tables_install((mpegts_input_t *)lfe, mm,
@@ -986,7 +986,7 @@ linuxdvb_frontend_monitor ( void *aux )
   }
 
 
-  pthread_mutex_lock(&mmi->tii_stats_mutex);
+  tvh_mutex_lock(&mmi->tii_stats_mutex);
 
   /* Statistics - New API */
 #if DVB_VER_ATLEAST(5,10)
@@ -1232,12 +1232,12 @@ linuxdvb_frontend_monitor ( void *aux )
   sm.sm_type = SMT_SIGNAL_STATUS;
   sm.sm_data = &sigstat;
 
-  pthread_mutex_unlock(&mmi->tii_stats_mutex);
+  tvh_mutex_unlock(&mmi->tii_stats_mutex);
 
   LIST_FOREACH(s, &mmi->mmi_mux->mm_transports, s_active_link) {
-    pthread_mutex_lock(&s->s_stream_mutex);
+    tvh_mutex_lock(&s->s_stream_mutex);
     streaming_service_deliver(s, streaming_msg_clone(&sm));
-    pthread_mutex_unlock(&s->s_stream_mutex);
+    tvh_mutex_unlock(&s->s_stream_mutex);
   }
 }
 
@@ -1325,7 +1325,7 @@ linuxdvb_update_pids ( linuxdvb_frontend_t *lfe, const char *name,
   int all = lfe->lfe_pids.all;
   char buf[512];
 
-  pthread_mutex_lock(&lfe->lfe_dvr_lock);
+  tvh_mutex_lock(&lfe->lfe_dvr_lock);
 
   if (!all) {
     overlimit = mpegts_pid_weighted(&wpid, &lfe->lfe_pids, max, MPS_WEIGHT_ALLLIMIT);
@@ -1358,7 +1358,7 @@ linuxdvb_update_pids ( linuxdvb_frontend_t *lfe, const char *name,
 
   tuned->all = lfe->lfe_pids.all;
 
-  pthread_mutex_unlock(&lfe->lfe_dvr_lock);
+  tvh_mutex_unlock(&lfe->lfe_dvr_lock);
 }
 
 static void *
@@ -1384,11 +1384,11 @@ linuxdvb_frontend_input_thread ( void *aux )
   }
 
   /* Get MMI */
-  pthread_mutex_lock(&lfe->lfe_dvr_lock);
+  tvh_mutex_lock(&lfe->lfe_dvr_lock);
   lfe->mi_display_name((mpegts_input_t*)lfe, name, sizeof(name));
   mmi = LIST_FIRST(&lfe->mi_mux_active);
   tvh_cond_signal(&lfe->lfe_dvr_cond, 0);
-  pthread_mutex_unlock(&lfe->lfe_dvr_lock);
+  tvh_mutex_unlock(&lfe->lfe_dvr_lock);
   if (mmi == NULL) return NULL;
 
   /* Open DVR */
@@ -2210,8 +2210,8 @@ linuxdvb_frontend_create
   LIST_INSERT_HEAD(&la->la_frontends, lfe, lfe_link);
 
   /* DVR lock/cond */
-  pthread_mutex_init(&lfe->lfe_dvr_lock, NULL);
-  tvh_cond_init(&lfe->lfe_dvr_cond);
+  tvh_mutex_init(&lfe->lfe_dvr_lock, NULL);
+  tvh_cond_init(&lfe->lfe_dvr_cond, 1);
   mpegts_pid_init(&lfe->lfe_pids);
  
   /* Create satconf */
index 124b46c14a255cbec1c3d2b2986a00fa009ea59e..119a409334799af10ba66f5760ee180c8d70118c 100644 (file)
@@ -115,7 +115,7 @@ struct linuxdvb_frontend
   int                       lfe_fe_fd;
   pthread_t                 lfe_dvr_thread;
   th_pipe_t                 lfe_dvr_pipe;
-  pthread_mutex_t           lfe_dvr_lock;
+  tvh_mutex_t           lfe_dvr_lock;
   tvh_cond_t                lfe_dvr_cond;
   mpegts_apids_t            lfe_pids;
   int                       lfe_pids_max;
index 7fb5f46953f02b51df55b6d5657f9d6140ec8be3..268a5065fbcb11d6e37b007e37ca171ccf5a3d59 100644 (file)
@@ -410,14 +410,14 @@ mpegts_input_get_weight ( mpegts_input_t *mi, mpegts_mux_t *mm, int flags, int w
   int w = 0, count = 0;
 
   /* Service subs */
-  pthread_mutex_lock(&mi->mi_output_lock);
+  tvh_mutex_lock(&mi->mi_output_lock);
   LIST_FOREACH(mmi, &mi->mi_mux_active, mmi_active_link)
     LIST_FOREACH(s, &mmi->mmi_mux->mm_transports, s_active_link)
       LIST_FOREACH(ths, &s->s_subscriptions, ths_service_link) {
         w = MAX(w, ths->ths_weight);
         count++;
       }
-  pthread_mutex_unlock(&mi->mi_output_lock);
+  tvh_mutex_unlock(&mi->mi_output_lock);
   return w > 0 ? w + count - 1 : 0;
 }
 
@@ -771,8 +771,8 @@ mpegts_input_cat_pass_callback
   mi = mm->mm_active ? mm->mm_active->mmi_input : NULL;
   if (mi == NULL) goto fin;
 
-  pthread_mutex_lock(&mi->mi_output_lock);
-  pthread_mutex_lock(&s->s_stream_mutex);
+  tvh_mutex_lock(&mi->mi_output_lock);
+  tvh_mutex_lock(&s->s_stream_mutex);
 
   TAILQ_FOREACH(es, &s->s_components.set_all, es_link) {
     if (es->es_type != SCT_CAT) continue;
@@ -800,8 +800,8 @@ mpegts_input_cat_pass_callback
       elementary_set_stream_destroy(&s->s_components, es);
   }
 
-  pthread_mutex_unlock(&s->s_stream_mutex);
-  pthread_mutex_unlock(&mi->mi_output_lock);
+  tvh_mutex_unlock(&s->s_stream_mutex);
+  tvh_mutex_unlock(&mi->mi_output_lock);
 
   /* Finish */
 fin:
@@ -843,13 +843,13 @@ mpegts_input_open_service
   int i, reopen = !init;
 
   /* Add to list */
-  pthread_mutex_lock(&mi->mi_output_lock);
+  tvh_mutex_lock(&mi->mi_output_lock);
   if (!s->s_dvb_active_input) {
     LIST_INSERT_HEAD(&mm->mm_transports, ((service_t*)s), s_active_link);
     s->s_dvb_active_input = mi;
   }
   /* Register PIDs */
-  pthread_mutex_lock(&s->s_stream_mutex);
+  tvh_mutex_lock(&s->s_stream_mutex);
   if (s->s_type == STYPE_STD) {
 
     if (s->s_components.set_pmt_pid == SERVICE_PMT_AUTO)
@@ -893,8 +893,8 @@ mpegts_input_open_service
   }
 
 no_pids:
-  pthread_mutex_unlock(&s->s_stream_mutex);
-  pthread_mutex_unlock(&mi->mi_output_lock);
+  tvh_mutex_unlock(&s->s_stream_mutex);
+  tvh_mutex_unlock(&mi->mi_output_lock);
 
   /* Add PMT monitor */
   if (s->s_type == STYPE_STD) {
@@ -923,13 +923,13 @@ mpegts_input_close_service ( mpegts_input_t *mi, mpegts_service_t *s )
   s->s_cat_mon = NULL;
 
   /* Remove from list */
-  pthread_mutex_lock(&mi->mi_output_lock);
+  tvh_mutex_lock(&mi->mi_output_lock);
   if (s->s_dvb_active_input != NULL) {
     LIST_REMOVE(((service_t*)s), s_active_link);
     s->s_dvb_active_input = NULL;
   }
   /* Close PID */
-  pthread_mutex_lock(&s->s_stream_mutex);
+  tvh_mutex_lock(&s->s_stream_mutex);
   if (s->s_type == STYPE_STD) {
 
     if (s->s_components.set_pmt_pid == SERVICE_PMT_AUTO)
@@ -956,8 +956,8 @@ mpegts_input_close_service ( mpegts_input_t *mi, mpegts_service_t *s )
   }
 
 no_pids:
-  pthread_mutex_unlock(&s->s_stream_mutex);
-  pthread_mutex_unlock(&mi->mi_output_lock);
+  tvh_mutex_unlock(&s->s_stream_mutex);
+  tvh_mutex_unlock(&mi->mi_output_lock);
 
   mpegts_mux_update_pids(mm);
 
@@ -1005,11 +1005,11 @@ mpegts_input_stopping_mux
 {
   assert(mmi->mmi_mux->mm_active);
 
-  pthread_mutex_lock(&mi->mi_output_lock);
-  pthread_mutex_lock(&mi->mi_input_lock);
+  tvh_mutex_lock(&mi->mi_output_lock);
+  tvh_mutex_lock(&mi->mi_input_lock);
   mmi->mmi_mux->mm_active = NULL;
-  pthread_mutex_unlock(&mi->mi_input_lock);
-  pthread_mutex_unlock(&mi->mi_output_lock);
+  tvh_mutex_unlock(&mi->mi_input_lock);
+  tvh_mutex_unlock(&mi->mi_output_lock);
 }
 
 static void
@@ -1043,7 +1043,7 @@ mpegts_input_has_subscription ( mpegts_input_t *mi, mpegts_mux_t *mm )
   int ret = 0;
   const service_t *t;
   const th_subscription_t *ths;
-  pthread_mutex_lock(&mi->mi_output_lock);
+  tvh_mutex_lock(&mi->mi_output_lock);
   LIST_FOREACH(t, &mm->mm_transports, s_active_link) {
     if (t->s_type == STYPE_RAW) {
       LIST_FOREACH(ths, &t->s_subscriptions, ths_service_link)
@@ -1053,7 +1053,7 @@ mpegts_input_has_subscription ( mpegts_input_t *mi, mpegts_mux_t *mm )
     ret = 1;
     break;
   }
-  pthread_mutex_unlock(&mi->mi_output_lock);
+  tvh_mutex_unlock(&mi->mi_output_lock);
   return ret;
 }
 
@@ -1061,14 +1061,14 @@ static void
 mpegts_input_tuning_error ( mpegts_input_t *mi, mpegts_mux_t *mm )
 {
   service_t *t, *t_next;
-  pthread_mutex_lock(&mi->mi_output_lock);
+  tvh_mutex_lock(&mi->mi_output_lock);
   for (t = LIST_FIRST(&mm->mm_transports); t; t = t_next) {
     t_next = LIST_NEXT(t, s_active_link);
-    pthread_mutex_lock(&t->s_stream_mutex);
+    tvh_mutex_lock(&t->s_stream_mutex);
     service_set_streaming_status_flags(t, TSS_TUNING);
-    pthread_mutex_unlock(&t->s_stream_mutex);
+    tvh_mutex_unlock(&t->s_stream_mutex);
   }
-  pthread_mutex_unlock(&mi->mi_output_lock);
+  tvh_mutex_unlock(&mi->mi_output_lock);
 }
 
 /* **************************************************************************
@@ -1178,7 +1178,7 @@ mpegts_input_queue_packets
   const char *id = SRCLINEID();
   int len = mp->mp_len;
 
-  pthread_mutex_lock(&mi->mi_input_lock);
+  tvh_mutex_lock(&mi->mi_input_lock);
   if (mmi->mmi_mux->mm_active == mmi) {
     if (mi->mi_input_queue_size < 50*1024*1024) {
       mi->mi_input_queue_size += len;
@@ -1197,7 +1197,7 @@ mpegts_input_queue_packets
   } else {
     free(mp);
   }
-  pthread_mutex_unlock(&mi->mi_input_lock);
+  tvh_mutex_unlock(&mi->mi_input_lock);
 }
 
 void
@@ -1311,7 +1311,7 @@ mpegts_input_table_dispatch
   mpegts_table_t *mt, **vec;
 
   /* Collate - tables may be removed during callbacks */
-  pthread_mutex_lock(&mm->mm_tables_lock);
+  tvh_mutex_lock(&mm->mm_tables_lock);
   i = mm->mm_num_tables;
   vec = alloca(i * sizeof(mpegts_table_t *));
   LIST_FOREACH(mt, &mm->mm_tables, mt_link) {
@@ -1323,7 +1323,7 @@ mpegts_input_table_dispatch
     if (len < i)
       vec[len++] = mt;
   }
-  pthread_mutex_unlock(&mm->mm_tables_lock);
+  tvh_mutex_unlock(&mm->mm_tables_lock);
   if (i != c) {
     tvherror(LS_TBL, "tables count inconsistency (num %d, list %d)", i, c);
     assert(0);
@@ -1349,7 +1349,7 @@ mpegts_input_table_waiting ( mpegts_input_t *mi, mpegts_mux_t *mm )
 
   if (!mm || !mm->mm_active)
     return;
-  pthread_mutex_lock(&mm->mm_tables_lock);
+  tvh_mutex_lock(&mm->mm_tables_lock);
   while ((mt = TAILQ_FIRST(&mm->mm_defer_tables)) != NULL) {
     mpegts_table_consistency_check(mm);
     TAILQ_REMOVE(&mm->mm_defer_tables, mt, mt_defer_link);
@@ -1357,28 +1357,28 @@ mpegts_input_table_waiting ( mpegts_input_t *mi, mpegts_mux_t *mm )
       mt->mt_defer_cmd = 0;
       if (!mt->mt_subscribed) {
         mt->mt_subscribed = 1;
-        pthread_mutex_unlock(&mm->mm_tables_lock);
+        tvh_mutex_unlock(&mm->mm_tables_lock);
         mpegts_input_open_pid(mi, mm, mt->mt_pid, mpegts_table_type(mt), mt->mt_weight, mt, 0);
       } else {
-        pthread_mutex_unlock(&mm->mm_tables_lock);
+        tvh_mutex_unlock(&mm->mm_tables_lock);
       }
     } else if (mt->mt_defer_cmd == MT_DEFER_CLOSE_PID) {
       mt->mt_defer_cmd = 0;
       if (mt->mt_subscribed) {
         mt->mt_subscribed = 0;
-        pthread_mutex_unlock(&mm->mm_tables_lock);
+        tvh_mutex_unlock(&mm->mm_tables_lock);
         mpegts_input_close_pid(mi, mm, mt->mt_pid, mpegts_table_type(mt), mt);
       } else {
-        pthread_mutex_unlock(&mm->mm_tables_lock);
+        tvh_mutex_unlock(&mm->mm_tables_lock);
       }
     } else {
-      pthread_mutex_unlock(&mm->mm_tables_lock);
+      tvh_mutex_unlock(&mm->mm_tables_lock);
     }
     mpegts_table_release(mt);
-    pthread_mutex_lock(&mm->mm_tables_lock);
+    tvh_mutex_lock(&mm->mm_tables_lock);
   }
   mpegts_table_consistency_check(mm);
-  pthread_mutex_unlock(&mm->mm_tables_lock);
+  tvh_mutex_unlock(&mm->mm_tables_lock);
 }
 
 static int
@@ -1593,7 +1593,7 @@ mpegts_input_postdemux
   elementary_stream_t *st;
   mpegts_mux_instance_t *mmi;
 
-  pthread_mutex_lock(&mi->mi_output_lock);
+  tvh_mutex_lock(&mi->mi_output_lock);
   if (mm == NULL || (mmi = mm->mm_active) == NULL)
     goto unlock;
 
@@ -1634,19 +1634,19 @@ mpegts_input_postdemux
       if (type & MPS_SERVICE) {
         LIST_FOREACH(mps, &mp->mp_svc_subs, mps_svcraw_link) {
           s = mps->mps_owner;
-          pthread_mutex_lock(&s->s_stream_mutex);
+          tvh_mutex_lock(&s->s_stream_mutex);
           st = elementary_stream_find(&s->s_components, pid);
           ts_recv_packet0((mpegts_service_t*)s, st, tsb, llen);
-          pthread_mutex_unlock(&s->s_stream_mutex);
+          tvh_mutex_unlock(&s->s_stream_mutex);
         }
       } else
       /* Stream table data */
       if (type & MPS_STREAM) {
         LIST_FOREACH(s, &mm->mm_transports, s_active_link) {
           if (s->s_type != STYPE_STD) continue;
-          pthread_mutex_lock(&s->s_stream_mutex);
+          tvh_mutex_lock(&s->s_stream_mutex);
           ts_recv_packet0((mpegts_service_t*)s, NULL, tsb, llen);
-          pthread_mutex_unlock(&s->s_stream_mutex);
+          tvh_mutex_unlock(&s->s_stream_mutex);
         }
       }
 
@@ -1657,7 +1657,7 @@ done:
     len -= llen;
   }
 unlock:
-  pthread_mutex_unlock(&mi->mi_output_lock);
+  tvh_mutex_unlock(&mi->mi_output_lock);
 }
 
 static void *
@@ -1670,13 +1670,13 @@ mpegts_input_thread ( void * p )
   tprofile_t tprofile;
   char buf[256];
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   mi->mi_display_name(mi, buf, sizeof(buf));
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   tprofile_init(&tprofile, buf);
 
-  pthread_mutex_lock(&mi->mi_input_lock);
+  tvh_mutex_lock(&mi->mi_input_lock);
   while (atomic_get(&mi->mi_running)) {
 
     /* Wait for a packet */
@@ -1691,27 +1691,27 @@ mpegts_input_thread ( void * p )
     mi->mi_input_queue_size -= mp->mp_len;
     memoryinfo_free(&mpegts_input_queue_memoryinfo, sizeof(mpegts_packet_t) + mp->mp_len);
     TAILQ_REMOVE(&mi->mi_input_queue, mp, mp_link);
-    pthread_mutex_unlock(&mi->mi_input_lock);
+    tvh_mutex_unlock(&mi->mi_input_lock);
       
     /* Process */
-    pthread_mutex_lock(&mi->mi_output_lock);
+    tvh_mutex_lock(&mi->mi_output_lock);
     mpegts_input_table_waiting(mi, mp->mp_mux);
     if (mp->mp_mux && mp->mp_mux->mm_update_pids_flag) {
-      pthread_mutex_unlock(&mi->mi_output_lock);
-      pthread_mutex_lock(&global_lock);
+      tvh_mutex_unlock(&mi->mi_output_lock);
+      tvh_mutex_lock(&global_lock);
       mpegts_mux_update_pids(mp->mp_mux);
-      pthread_mutex_unlock(&global_lock);
-      pthread_mutex_lock(&mi->mi_output_lock);
+      tvh_mutex_unlock(&global_lock);
+      tvh_mutex_lock(&mi->mi_output_lock);
     }
     tprofile_start(&tprofile, "input");
     bytes += mpegts_input_process(mi, mp);
     tprofile_finish(&tprofile);
     update_pids = mp->mp_mux && mp->mp_mux->mm_update_pids_flag;
-    pthread_mutex_unlock(&mi->mi_output_lock);
+    tvh_mutex_unlock(&mi->mi_output_lock);
     if (update_pids) {
-      pthread_mutex_lock(&global_lock);
+      tvh_mutex_lock(&global_lock);
       mpegts_mux_update_pids(mp->mp_mux);
-      pthread_mutex_unlock(&global_lock);
+      tvh_mutex_unlock(&global_lock);
     }
 
     /* Cleanup */
@@ -1726,7 +1726,7 @@ mpegts_input_thread ( void * p )
     }
 #endif
 
-    pthread_mutex_lock(&mi->mi_input_lock);
+    tvh_mutex_lock(&mi->mi_input_lock);
   }
 
   tvhtrace(LS_MPEGTS, "input %s got %zu bytes (finish)", buf, bytes);
@@ -1740,7 +1740,7 @@ mpegts_input_thread ( void * p )
     free(mp);
   }
   mi->mi_input_queue_size = 0;
-  pthread_mutex_unlock(&mi->mi_input_lock);
+  tvh_mutex_unlock(&mi->mi_input_lock);
 
   tprofile_done(&tprofile);
 
@@ -1754,7 +1754,7 @@ mpegts_input_table_thread ( void *aux )
   mpegts_input_t *mi = aux;
   mpegts_mux_t *mm = NULL;
 
-  pthread_mutex_lock(&mi->mi_output_lock);
+  tvh_mutex_lock(&mi->mi_output_lock);
   while (atomic_get(&mi->mi_running)) {
 
     /* Wait for data */
@@ -1765,20 +1765,20 @@ mpegts_input_table_thread ( void *aux )
     mi->mi_table_queue_size -= mtf->mtf_len;
     memoryinfo_free(&mpegts_input_table_memoryinfo, sizeof(mpegts_table_feed_t) + mtf->mtf_len);
     TAILQ_REMOVE(&mi->mi_table_queue, mtf, mtf_link);
-    pthread_mutex_unlock(&mi->mi_output_lock);
+    tvh_mutex_unlock(&mi->mi_output_lock);
 
     /* Process */
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     if (atomic_get(&mi->mi_running)) {
       mm = mtf->mtf_mux;
       if (mm && mm->mm_active)
         mpegts_input_table_dispatch(mm, mm->mm_nicename, mtf->mtf_tsb, mtf->mtf_len);
     }
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
 
     /* Cleanup */
     free(mtf);
-    pthread_mutex_lock(&mi->mi_output_lock);
+    tvh_mutex_lock(&mi->mi_output_lock);
   }
 
   /* Flush */
@@ -1788,7 +1788,7 @@ mpegts_input_table_thread ( void *aux )
     free(mtf);
   }
   mi->mi_table_queue_size = 0;
-  pthread_mutex_unlock(&mi->mi_output_lock);
+  tvh_mutex_unlock(&mi->mi_output_lock);
 
   return NULL;
 }
@@ -1807,22 +1807,22 @@ mpegts_input_flush_mux
   //       the mux pointer and allow the threads to deal with the deletion
 
   /* Flush input Q */
-  pthread_mutex_lock(&mi->mi_input_lock);
+  tvh_mutex_lock(&mi->mi_input_lock);
   TAILQ_FOREACH(mp, &mi->mi_input_queue, mp_link) {
     if (mp->mp_mux == mm) {
       mpegts_mux_release(mm);
       mp->mp_mux = NULL;
     }
   }
-  pthread_mutex_unlock(&mi->mi_input_lock);
+  tvh_mutex_unlock(&mi->mi_input_lock);
 
   /* Flush table Q */
-  pthread_mutex_lock(&mi->mi_output_lock);
+  tvh_mutex_lock(&mi->mi_output_lock);
   TAILQ_FOREACH(mtf, &mi->mi_table_queue, mtf_link) {
     if (mtf->mtf_mux == mm)
       mtf->mtf_mux = NULL;
   }
-  pthread_mutex_unlock(&mi->mi_output_lock);
+  tvh_mutex_unlock(&mi->mi_output_lock);
   /* mux active must be NULL here */
   /* otherwise the picked mtf might be processed after mux deactivation */
   assert(mm->mm_active == NULL);
@@ -1865,7 +1865,7 @@ mpegts_input_stream_status
       mpegts_pid_add(st->pids, mp->mp_pid, 0);
   }
 
-  pthread_mutex_lock(&mmi->tii_stats_mutex);
+  tvh_mutex_lock(&mmi->tii_stats_mutex);
   st->stats.signal = mmi->tii_stats.signal;
   st->stats.snr    = mmi->tii_stats.snr;
   st->stats.ber    = mmi->tii_stats.ber;
@@ -1875,7 +1875,7 @@ mpegts_input_stream_status
   st->stats.tc_bit   = mmi->tii_stats.tc_bit;
   st->stats.ec_block = mmi->tii_stats.ec_block;
   st->stats.tc_block = mmi->tii_stats.tc_block;
-  pthread_mutex_unlock(&mmi->tii_stats_mutex);
+  tvh_mutex_unlock(&mmi->tii_stats_mutex);
   st->stats.unc   = atomic_get(&mmi->tii_stats.unc);
   st->stats.cc    = atomic_get(&mmi->tii_stats.cc);
   st->stats.te    = atomic_get(&mmi->tii_stats.te);
@@ -1897,11 +1897,11 @@ mpegts_input_empty_status
     mmi = (mpegts_mux_instance_t *)mmi_;
     st->stats.unc += atomic_get(&mmi->tii_stats.unc);
     st->stats.cc += atomic_get(&mmi->tii_stats.cc);
-    pthread_mutex_lock(&mmi->tii_stats_mutex);
+    tvh_mutex_lock(&mmi->tii_stats_mutex);
     st->stats.te += mmi->tii_stats.te;
     st->stats.ec_block += mmi->tii_stats.ec_block;
     st->stats.tc_block += mmi->tii_stats.tc_block;
-    pthread_mutex_unlock(&mmi->tii_stats_mutex);
+    tvh_mutex_unlock(&mmi->tii_stats_mutex);
   }
 }
 
@@ -1913,7 +1913,7 @@ mpegts_input_get_streams
   mpegts_input_t *mi = (mpegts_input_t*)i;
   mpegts_mux_instance_t *mmi;
 
-  pthread_mutex_lock(&mi->mi_output_lock);
+  tvh_mutex_lock(&mi->mi_output_lock);
   LIST_FOREACH(mmi, &mi->mi_mux_active, mmi_active_link) {
     st = calloc(1, sizeof(tvh_input_stream_t));
     mpegts_input_stream_status(mmi, st);
@@ -1924,7 +1924,7 @@ mpegts_input_get_streams
     mi->mi_empty_status(mi, st);
     LIST_INSERT_HEAD(isl, st, link);
   }
-  pthread_mutex_unlock(&mi->mi_output_lock);
+  tvh_mutex_unlock(&mi->mi_output_lock);
 }
 
 static void
@@ -1934,18 +1934,18 @@ mpegts_input_clear_stats ( tvh_input_t *i )
   tvh_input_instance_t *mmi_;
   mpegts_mux_instance_t *mmi;
 
-  pthread_mutex_lock(&mi->mi_output_lock);
+  tvh_mutex_lock(&mi->mi_output_lock);
   LIST_FOREACH(mmi_, &mi->mi_mux_instances, tii_input_link) {
     mmi = (mpegts_mux_instance_t *)mmi_;
     atomic_set(&mmi->tii_stats.unc, 0);
     atomic_set(&mmi->tii_stats.cc, 0);
-    pthread_mutex_lock(&mmi->tii_stats_mutex);
+    tvh_mutex_lock(&mmi->tii_stats_mutex);
     mmi->tii_stats.te = 0;
     mmi->tii_stats.ec_block = 0;
     mmi->tii_stats.tc_block = 0;
-    pthread_mutex_unlock(&mmi->tii_stats_mutex);
+    tvh_mutex_unlock(&mmi->tii_stats_mutex);
   }
-  pthread_mutex_unlock(&mi->mi_output_lock);
+  tvh_mutex_unlock(&mi->mi_output_lock);
   notify_reload("input_status");
 }
 
@@ -1955,10 +1955,10 @@ mpegts_input_thread_start ( void *aux )
   mpegts_input_t *mi = aux;
   atomic_set(&mi->mi_running, 1);
   
-  tvhthread_create(&mi->mi_table_tid, NULL,
-                   mpegts_input_table_thread, mi, "mi-table");
-  tvhthread_create(&mi->mi_input_tid, NULL,
-                   mpegts_input_thread, mi, "mi-main");
+  tvh_thread_create(&mi->mi_table_tid, NULL,
+                    mpegts_input_table_thread, mi, "mi-table");
+  tvh_thread_create(&mi->mi_input_tid, NULL,
+                    mpegts_input_thread, mi, "mi-main");
 }
 
 static void
@@ -1968,22 +1968,22 @@ mpegts_input_thread_stop ( mpegts_input_t *mi )
   mtimer_disarm(&mi->mi_input_thread_start);
 
   /* Stop input thread */
-  pthread_mutex_lock(&mi->mi_input_lock);
+  tvh_mutex_lock(&mi->mi_input_lock);
   tvh_cond_signal(&mi->mi_input_cond, 0);
-  pthread_mutex_unlock(&mi->mi_input_lock);
+  tvh_mutex_unlock(&mi->mi_input_lock);
 
   /* Stop table thread */
-  pthread_mutex_lock(&mi->mi_output_lock);
+  tvh_mutex_lock(&mi->mi_output_lock);
   tvh_cond_signal(&mi->mi_table_cond, 0);
-  pthread_mutex_unlock(&mi->mi_output_lock);
+  tvh_mutex_unlock(&mi->mi_output_lock);
 
   /* Join threads (relinquish lock due to potential deadlock) */
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   if (mi->mi_input_tid)
     pthread_join(mi->mi_input_tid, NULL);
   if (mi->mi_table_tid)
     pthread_join(mi->mi_table_tid, NULL);
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 }
 
 /* **************************************************************************
@@ -1999,7 +1999,7 @@ mpegts_input_status_timer ( void *p )
   htsmsg_t *e;
   int64_t subs = 0;
 
-  pthread_mutex_lock(&mi->mi_output_lock);
+  tvh_mutex_lock(&mi->mi_output_lock);
   LIST_FOREACH(mmi, &mi->mi_mux_active, mmi_active_link) {
     memset(&st, 0, sizeof(st));
     mpegts_input_stream_status(mmi, &st);
@@ -2009,7 +2009,7 @@ mpegts_input_status_timer ( void *p )
     subs += st.subs_count;
     tvh_input_stream_destroy(&st);
   }
-  pthread_mutex_unlock(&mi->mi_output_lock);
+  tvh_mutex_unlock(&mi->mi_output_lock);
   mtimer_arm_rel(&mi->mi_status_timer, mpegts_input_status_timer, mi, sec2mono(1));
   mpegts_input_dbus_notify(mi, subs);
 }
@@ -2062,12 +2062,12 @@ mpegts_input_create0
   mi->mi_instance             = ++mpegts_input_idx;
 
   /* Init input/output structures */
-  pthread_mutex_init(&mi->mi_input_lock, NULL);
-  tvh_cond_init(&mi->mi_input_cond);
+  tvh_mutex_init(&mi->mi_input_lock, NULL);
+  tvh_cond_init(&mi->mi_input_cond, 1);
   TAILQ_INIT(&mi->mi_input_queue);
 
-  pthread_mutex_init(&mi->mi_output_lock, NULL);
-  tvh_cond_init(&mi->mi_table_cond);
+  tvh_mutex_init(&mi->mi_output_lock, NULL);
+  tvh_cond_init(&mi->mi_table_cond, 1);
   TAILQ_INIT(&mi->mi_table_queue);
 
   /* Defaults */
@@ -2129,7 +2129,7 @@ mpegts_input_delete ( mpegts_input_t *mi, int delconf )
   mpegts_input_thread_stop(mi);
 
   tprofile_queue_done(&mi->mi_qprofile);
-  pthread_mutex_destroy(&mi->mi_output_lock);
+  tvh_mutex_destroy(&mi->mi_output_lock);
   tvh_cond_destroy(&mi->mi_table_cond);
   free(mi->mi_name);
   free(mi->mi_linked);
index 000891a00772202f49b6acba14f340b237846be5..58b132bb7a510d7027cdd11d5082c3ad9822747d 100644 (file)
@@ -55,7 +55,7 @@ mpegts_mux_instance_delete
   idnode_unlink(&tii->tii_id);
   LIST_REMOVE(mmi, mmi_mux_link);
   LIST_REMOVE(tii, tii_input_link);
-  pthread_mutex_destroy(&mmi->tii_stats_mutex);
+  tvh_mutex_destroy(&mmi->tii_stats_mutex);
   free(mmi);
 }
 
@@ -70,7 +70,7 @@ mpegts_mux_instance_create0
     return NULL;
   }
 
-  pthread_mutex_init(&mmi->tii_stats_mutex, NULL);
+  tvh_mutex_init(&mmi->tii_stats_mutex, NULL);
 
   /* Setup links */
   mmi->mmi_mux   = mm;
@@ -880,7 +880,7 @@ mpegts_mux_stop ( mpegts_mux_t *mm, int force, int reason )
   mpegts_input_flush_mux(mi, mm);
 
   /* Ensure PIDs are cleared */
-  pthread_mutex_lock(&mi->mi_output_lock);
+  tvh_mutex_lock(&mi->mi_output_lock);
   mm->mm_last_pid = -1;
   mm->mm_last_mp = NULL;
   while ((mp = RB_FIRST(&mm->mm_pids))) {
@@ -911,7 +911,7 @@ mpegts_mux_stop ( mpegts_mux_t *mm, int force, int reason )
     RB_REMOVE(&mm->mm_pids, mp, mp_link);
     free(mp);
   }
-  pthread_mutex_unlock(&mi->mi_output_lock);
+  tvh_mutex_unlock(&mi->mi_output_lock);
 
   /* Scanning */
   mpegts_network_scan_mux_cancel(mm, 1);
@@ -932,10 +932,10 @@ mpegts_mux_update_pids_cb ( void *aux )
   if (mm && mm->mm_active) {
     mi = mm->mm_active->mmi_input;
     if (mi) {
-      pthread_mutex_lock(&mi->mi_output_lock);
+      tvh_mutex_lock(&mi->mi_output_lock);
       mm->mm_update_pids_flag = 0;
       mi->mi_update_pids(mi, mm);
-      pthread_mutex_unlock(&mi->mi_output_lock);
+      tvh_mutex_unlock(&mi->mi_output_lock);
     }
   }
 }
@@ -978,11 +978,11 @@ mpegts_mux_open_table ( mpegts_mux_t *mm, mpegts_table_t *mt, int subscribe )
   if (subscribe && !mt->mt_subscribed) {
     mpegts_table_grab(mt);
     mt->mt_subscribed = 1;
-    pthread_mutex_unlock(&mm->mm_tables_lock);
-    pthread_mutex_lock(&mi->mi_output_lock);
+    tvh_mutex_unlock(&mm->mm_tables_lock);
+    tvh_mutex_lock(&mi->mi_output_lock);
     mpegts_input_open_pid(mi, mm, mt->mt_pid, mpegts_table_type(mt), mt->mt_weight, mt, 0);
-    pthread_mutex_unlock(&mi->mi_output_lock);
-    pthread_mutex_lock(&mm->mm_tables_lock);
+    tvh_mutex_unlock(&mi->mi_output_lock);
+    tvh_mutex_lock(&mm->mm_tables_lock);
     mpegts_table_release(mt);
   }
 }
@@ -998,11 +998,11 @@ mpegts_mux_unsubscribe_table ( mpegts_mux_t *mm, mpegts_table_t *mt )
   if (mt->mt_subscribed) {
     mpegts_table_grab(mt);
     mt->mt_subscribed = 0;
-    pthread_mutex_unlock(&mm->mm_tables_lock);
-    pthread_mutex_lock(&mi->mi_output_lock);
+    tvh_mutex_unlock(&mm->mm_tables_lock);
+    tvh_mutex_lock(&mi->mi_output_lock);
     mpegts_input_close_pid(mi, mm, mt->mt_pid, mpegts_table_type(mt), mt);
-    pthread_mutex_unlock(&mi->mi_output_lock);
-    pthread_mutex_lock(&mm->mm_tables_lock);
+    tvh_mutex_unlock(&mi->mi_output_lock);
+    tvh_mutex_lock(&mm->mm_tables_lock);
     mpegts_table_release(mt);
   }
   if ((mt->mt_flags & MT_DEFER) && mt->mt_defer_cmd == MT_DEFER_OPEN_PID) {
@@ -1093,7 +1093,7 @@ mpegts_mux_scan_done ( mpegts_mux_t *mm, const char *buf, int res )
   assert(mm->mm_scan_state == MM_SCAN_STATE_ACTIVE);
 
   /* Log */
-  pthread_mutex_lock(&mm->mm_tables_lock);
+  tvh_mutex_lock(&mm->mm_tables_lock);
   mpegts_table_consistency_check(mm);
   LIST_FOREACH(mt, &mm->mm_tables, mt_link) {
     if (mt->mt_flags & MT_QUICKREQ) {
@@ -1109,7 +1109,7 @@ mpegts_mux_scan_done ( mpegts_mux_t *mm, const char *buf, int res )
       tvhdebug(LS_MPEGTS, "%s - %04X (%d) %s %s", buf, mt->mt_pid, mt->mt_pid, mt->mt_name, s);
     }
   }
-  pthread_mutex_unlock(&mm->mm_tables_lock);
+  tvh_mutex_unlock(&mm->mm_tables_lock);
 
   /* override if all tables were found */
   if (res < 0 && incomplete <= 0 && total > 2)
@@ -1150,14 +1150,14 @@ mpegts_mux_scan_timeout ( void *aux )
   
   /* Check tables */
 again:
-  pthread_mutex_lock(&mm->mm_tables_lock);
+  tvh_mutex_lock(&mm->mm_tables_lock);
   mpegts_table_consistency_check(mm);
   c = q = w = 0;
   LIST_FOREACH(mt, &mm->mm_tables, mt_link) {
     if (!(mt->mt_flags & MT_QUICKREQ) && !mt->mt_working) continue;
     if (!mt->mt_count) {
       mpegts_table_grab(mt);
-      pthread_mutex_unlock(&mm->mm_tables_lock);
+      tvh_mutex_unlock(&mm->mm_tables_lock);
       mpegts_table_destroy(mt);
       mpegts_table_release(mt);
       goto again;
@@ -1169,7 +1169,7 @@ again:
       c++;
     }
   }
-  pthread_mutex_unlock(&mm->mm_tables_lock);
+  tvh_mutex_unlock(&mm->mm_tables_lock);
       
   /* No DATA - give up now */
   if (!c) {
@@ -1233,13 +1233,13 @@ mpegts_mux_create0
   mm->mm_open_table          = mpegts_mux_open_table;
   mm->mm_unsubscribe_table   = mpegts_mux_unsubscribe_table;
   mm->mm_close_table         = mpegts_mux_close_table;
-  pthread_mutex_init(&mm->mm_tables_lock, NULL);
+  tvh_mutex_init(&mm->mm_tables_lock, NULL);
   TAILQ_INIT(&mm->mm_table_queue);
   TAILQ_INIT(&mm->mm_defer_tables);
   LIST_INIT(&mm->mm_descrambler_caids);
   TAILQ_INIT(&mm->mm_descrambler_tables);
   TAILQ_INIT(&mm->mm_descrambler_emms);
-  pthread_mutex_init(&mm->mm_descrambler_lock, NULL);
+  tvh_mutex_init(&mm->mm_descrambler_lock, NULL);
 
   mm->mm_last_pid            = -1;
   mm->mm_created             = gclk();
@@ -1457,7 +1457,7 @@ mpegts_mux_tuning_error ( const char *mux_uuid, mpegts_mux_instance_t *mmi_match
         if (mmi->mmi_input)
           mmi->mmi_input->mi_tuning_error(mmi->mmi_input, mm);
     }
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
   }
 }
 
index 46ca4d18e3ee893dc88b8b846fca02567c5ad4ab..c7a1a4d4168a2b5404a7440e0df2525e57f2c376 100644 (file)
@@ -377,10 +377,10 @@ void
 mpegts_mux_sched_done ( void )
 {
   mpegts_mux_sched_t *mms;
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   while ((mms = LIST_FIRST(&mpegts_mux_sched_all)))
     mpegts_mux_sched_delete(mms, 0);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
 
 /******************************************************************************
index dd9a5ee1d4bda9283883394c482064bf37513961..ae1518518214581996178881d710ca58d6eb1283 100644 (file)
@@ -1007,13 +1007,13 @@ void dvb_network_done ( void )
 {
   int i;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   /* Unregister class builders */
   for (i = 0; i < ARRAY_SIZE(dvb_network_classes); i++) {
     mpegts_network_unregister_builder(dvb_network_classes[i]);
     mpegts_network_class_delete(dvb_network_classes[i], 0);
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   dvb_charset_done();
   scanfile_done();
index aa175395c59dfdb216c8ee416df4f2b5d3a42a92..76061714c4550168c0971ff0a7d6c9f1c62e276c 100644 (file)
@@ -778,7 +778,7 @@ mpegts_service_pid_list_ ( service_t *t, void *owner )
   mpegts_pid_t *mp;
 
   if (mi == NULL) return NULL;
-  pthread_mutex_lock(&mi->mi_output_lock);
+  tvh_mutex_lock(&mi->mi_output_lock);
   mm = ms->s_dvb_mux;
   RB_FOREACH(mp, &mm->mm_pids, mp_link) {
     RB_FOREACH(mps, &mp->mp_subs, mps_link) {
@@ -790,7 +790,7 @@ mpegts_service_pid_list_ ( service_t *t, void *owner )
       }
     }
   }
-  pthread_mutex_unlock(&mi->mi_output_lock);
+  tvh_mutex_unlock(&mi->mi_output_lock);
   return pids;
 }
 
@@ -880,9 +880,9 @@ mpegts_service_create0
   s->s_memoryinfo     = mpegts_service_memoryinfo;
   s->s_unseen         = mpegts_service_unseen;
 
-  pthread_mutex_lock(&s->s_stream_mutex);
+  tvh_mutex_lock(&s->s_stream_mutex);
   service_make_nicename((service_t*)s);
-  pthread_mutex_unlock(&s->s_stream_mutex);
+  tvh_mutex_unlock(&s->s_stream_mutex);
 
   tvhdebug(LS_MPEGTS, "%s - add service %04X %s",
            mm->mm_nicename, service_id16(s), s->s_dvb_svcname);
@@ -958,17 +958,17 @@ mpegts_service_find_by_pid ( mpegts_mux_t *mm, int pid )
 
   /* Find existing service */
   LIST_FOREACH(s, &mm->mm_services, s_dvb_mux_link) {
-    pthread_mutex_lock(&s->s_stream_mutex);
+    tvh_mutex_lock(&s->s_stream_mutex);
     if (pid == s->s_components.set_pmt_pid ||
         pid == s->s_components.set_pcr_pid)
       goto ok;
     if (elementary_stream_find(&s->s_components, pid))
       goto ok;
-    pthread_mutex_unlock(&s->s_stream_mutex);
+    tvh_mutex_unlock(&s->s_stream_mutex);
   }
   return NULL;
 ok:
-  pthread_mutex_unlock(&s->s_stream_mutex);
+  tvh_mutex_unlock(&s->s_stream_mutex);
   return s;
 }
 
@@ -1028,8 +1028,8 @@ mpegts_service_raw_update_pids(mpegts_service_t *t, mpegts_apids_t *pids)
   } else
     p = NULL;
   if (mi && mm) {
-    pthread_mutex_lock(&mi->mi_output_lock);
-    pthread_mutex_lock(&t->s_stream_mutex);
+    tvh_mutex_lock(&mi->mi_output_lock);
+    tvh_mutex_lock(&t->s_stream_mutex);
     x = t->s_pids;
     t->s_pids = p;
     if (pids && !pids->all && x && x->all) {
@@ -1063,14 +1063,14 @@ mpegts_service_raw_update_pids(mpegts_service_t *t, mpegts_apids_t *pids)
         mpegts_pid_done(&del);
       }
     }
-    pthread_mutex_unlock(&t->s_stream_mutex);
-    pthread_mutex_unlock(&mi->mi_output_lock);
+    tvh_mutex_unlock(&t->s_stream_mutex);
+    tvh_mutex_unlock(&mi->mi_output_lock);
     mpegts_mux_update_pids(mm);
   } else {
-    pthread_mutex_lock(&t->s_stream_mutex);
+    tvh_mutex_lock(&t->s_stream_mutex);
     x = t->s_pids;
     t->s_pids = p;
-    pthread_mutex_unlock(&t->s_stream_mutex);
+    tvh_mutex_unlock(&t->s_stream_mutex);
   }
   if (x) {
     mpegts_pid_done(x);
@@ -1108,12 +1108,12 @@ mpegts_service_update_slave_pids
   for (i = 0; i < s->s_masters.is_count; i++) {
     s2 = (mpegts_service_t *)s->s_masters.is_array[i];
     if (master && master != s2) continue;
-    pthread_mutex_lock(&s2->s_stream_mutex);
+    tvh_mutex_lock(&s2->s_stream_mutex);
     if (!del)
       mpegts_pid_add_group(s2->s_slaves_pids, pids);
     else
       mpegts_pid_del_group(s2->s_slaves_pids, pids);
-    pthread_mutex_unlock(&s2->s_stream_mutex);
+    tvh_mutex_unlock(&s2->s_stream_mutex);
   }
 
   mpegts_pid_destroy(&pids);
@@ -1122,33 +1122,33 @@ mpegts_service_update_slave_pids
 static int
 mpegts_service_link ( mpegts_service_t *master, mpegts_service_t *slave )
 {
-  pthread_mutex_lock(&slave->s_stream_mutex);
-  pthread_mutex_lock(&master->s_stream_mutex);
+  tvh_mutex_lock(&slave->s_stream_mutex);
+  tvh_mutex_lock(&master->s_stream_mutex);
   assert(!idnode_set_exists(&slave->s_masters, &master->s_id));
   idnode_set_alloc(&slave->s_masters, 16);
   idnode_set_add(&slave->s_masters, &master->s_id, NULL, NULL);
   idnode_set_alloc(&master->s_slaves, 16);
   idnode_set_add(&master->s_slaves, &slave->s_id, NULL, NULL);
-  pthread_mutex_unlock(&master->s_stream_mutex);
+  tvh_mutex_unlock(&master->s_stream_mutex);
   mpegts_service_update_slave_pids(slave, master, 0);
-  pthread_mutex_unlock(&slave->s_stream_mutex);
+  tvh_mutex_unlock(&slave->s_stream_mutex);
   return 0;
 }
 
 static int
 mpegts_service_unlink ( mpegts_service_t *master, mpegts_service_t *slave )
 {
-  pthread_mutex_lock(&slave->s_stream_mutex);
+  tvh_mutex_lock(&slave->s_stream_mutex);
   mpegts_service_update_slave_pids(slave, master, 1);
-  pthread_mutex_lock(&master->s_stream_mutex);
+  tvh_mutex_lock(&master->s_stream_mutex);
   idnode_set_remove(&slave->s_masters, &master->s_id);
   if (idnode_set_empty(&slave->s_masters))
     idnode_set_clear(&slave->s_masters);
   idnode_set_remove(&master->s_slaves, &slave->s_id);
   if (idnode_set_empty(&master->s_slaves))
     idnode_set_clear(&master->s_slaves);
-  pthread_mutex_unlock(&master->s_stream_mutex);
-  pthread_mutex_unlock(&slave->s_stream_mutex);
+  tvh_mutex_unlock(&master->s_stream_mutex);
+  tvh_mutex_unlock(&slave->s_stream_mutex);
   return 0;
 }
 
@@ -1196,10 +1196,10 @@ mpegts_service_create_raw ( mpegts_mux_t *mm )
   s->s_pid_list       = mpegts_service_raw_pid_list;
   s->s_memoryinfo     = mpegts_service_memoryinfo;
 
-  pthread_mutex_lock(&s->s_stream_mutex);
+  tvh_mutex_lock(&s->s_stream_mutex);
   free(s->s_nicename);
   s->s_nicename = strdup(mm->mm_nicename);
-  pthread_mutex_unlock(&s->s_stream_mutex);
+  tvh_mutex_unlock(&s->s_stream_mutex);
 
   tvhdebug(LS_MPEGTS, "%s - add raw service", mm->mm_nicename);
 
index 8049bd14eb306157a1376d8e20e4a03afd711020..dd88aaca0d4cd5c98d5bccf324ed611b321cacec 100644 (file)
@@ -51,13 +51,13 @@ mpegts_table_fastswitch ( mpegts_mux_t *mm, mpegts_table_t *mtm )
 
   assert(mm == mtm->mt_mux);
 
-  pthread_mutex_lock(&mm->mm_tables_lock);
+  tvh_mutex_lock(&mm->mm_tables_lock);
 
   if ((mtm->mt_flags & MT_ONESHOT) && (mtm->mt_complete && !mtm->mt_working))
     mm->mm_unsubscribe_table(mm, mtm);
 
   if (mm->mm_scan_state != MM_SCAN_STATE_ACTIVE) {
-    pthread_mutex_unlock(&mm->mm_tables_lock);
+    tvh_mutex_unlock(&mm->mm_tables_lock);
     return;
   }
 
@@ -68,12 +68,12 @@ mpegts_table_fastswitch ( mpegts_mux_t *mm, mpegts_table_t *mtm )
       tvhtrace(LS_MPEGTS, "table: mux %p no fastswitch %s %02X/%02X (%d) pid %04X (%d)",
                mm, mt->mt_name, mt->mt_table, mt->mt_mask, mt->mt_table,
                mt->mt_pid, mt->mt_pid);
-      pthread_mutex_unlock(&mm->mm_tables_lock);
+      tvh_mutex_unlock(&mm->mm_tables_lock);
       return;
     }
   }
 
-  pthread_mutex_unlock(&mm->mm_tables_lock);
+  tvh_mutex_unlock(&mm->mm_tables_lock);
 
   mpegts_mux_scan_done(mm, mm->mm_nicename, 1);
 }
@@ -154,10 +154,10 @@ mpegts_table_destroy ( mpegts_table_t *mt )
 {
   mpegts_mux_t *mm = mt->mt_mux;
 
-  pthread_mutex_lock(&mm->mm_tables_lock);
+  tvh_mutex_lock(&mm->mm_tables_lock);
   if (!mt->mt_destroyed)
     mpegts_table_destroy_(mt);
-  pthread_mutex_unlock(&mm->mm_tables_lock);
+  tvh_mutex_unlock(&mm->mm_tables_lock);
 }
 
 /**
@@ -182,7 +182,7 @@ mpegts_table_t *mpegts_table_find
 {
   mpegts_table_t *mt;
 
-  pthread_mutex_lock(&mm->mm_tables_lock);
+  tvh_mutex_lock(&mm->mm_tables_lock);
   mpegts_table_consistency_check(mm);
   LIST_FOREACH(mt, &mm->mm_tables, mt_link) {
     if (mt->mt_opaque != opaque)
@@ -192,7 +192,7 @@ mpegts_table_t *mpegts_table_find
     mpegts_table_consistency_check(mm);
     break;
   }
-  pthread_mutex_unlock(&mm->mm_tables_lock);
+  tvh_mutex_unlock(&mm->mm_tables_lock);
   return mt;
 }
 
@@ -211,7 +211,7 @@ mpegts_table_add
   char buf[64];
 
   /* Check for existing */
-  pthread_mutex_lock(&mm->mm_tables_lock);
+  tvh_mutex_lock(&mm->mm_tables_lock);
   mpegts_table_consistency_check(mm);
   LIST_FOREACH(mt, &mm->mm_tables, mt_link) {
     if (mt->mt_opaque != opaque)
@@ -238,7 +238,7 @@ mpegts_table_add
         mm->mm_open_table(mm, mt, 1);
     }
     mpegts_table_consistency_check(mm);
-    pthread_mutex_unlock(&mm->mm_tables_lock);
+    tvh_mutex_unlock(&mm->mm_tables_lock);
     return mt;
   }
   tvhtrace(LS_MPEGTS, "table: mux %p add %s %02X/%02X (%d) pid %04X (%d)",
@@ -274,7 +274,7 @@ mpegts_table_add
   }
   mm->mm_open_table(mm, mt, subscribe);
   mpegts_table_consistency_check(mm);
-  pthread_mutex_unlock(&mm->mm_tables_lock);
+  tvh_mutex_unlock(&mm->mm_tables_lock);
   return mt;
 }
 
@@ -287,7 +287,7 @@ mpegts_table_flush_all ( mpegts_mux_t *mm )
   mpegts_table_t        *mt;
 
   descrambler_flush_tables(mm);
-  pthread_mutex_lock(&mm->mm_tables_lock);
+  tvh_mutex_lock(&mm->mm_tables_lock);
   mpegts_table_consistency_check(mm);
   while ((mt = TAILQ_FIRST(&mm->mm_defer_tables))) {
     TAILQ_REMOVE(&mm->mm_defer_tables, mt, mt_defer_link);
@@ -303,7 +303,7 @@ mpegts_table_flush_all ( mpegts_mux_t *mm )
   assert(mm->mm_num_tables == 0);
   assert(TAILQ_FIRST(&mm->mm_defer_tables) == NULL);
   assert(LIST_FIRST(&mm->mm_tables) == NULL);
-  pthread_mutex_unlock(&mm->mm_tables_lock);
+  tvh_mutex_unlock(&mm->mm_tables_lock);
 }
 
 
index 000bec9d48c091e98a75814e05214d5d20b3c70d..84bb3118536995296ccd59958c55255c285b8ded 100644 (file)
@@ -66,7 +66,7 @@ satip_device_block( const char *addr, int block )
   satip_frontend_t *lfe;
   int val = block < 0 ? 0 : block;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   TVH_HARDWARE_FOREACH(th) {
     if (!idnode_is_instance(&th->th_id, &satip_device_class))
       continue;
@@ -81,7 +81,7 @@ satip_device_block( const char *addr, int block )
               block < 0 ? "stopped" : (block > 0 ? "allowed" : "disabled"));
     }
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
 
 static char *
@@ -621,7 +621,7 @@ satip_device_create( satip_device_info_t *info )
     return NULL;
   }
 
-  pthread_mutex_init(&sd->sd_tune_mutex, NULL);
+  tvh_mutex_init(&sd->sd_tune_mutex, NULL);
 
   TAILQ_INIT(&sd->sd_frontends);
   TAILQ_INIT(&sd->sd_serialize_queue);
@@ -1012,10 +1012,10 @@ satip_discovery_http_closed(http_client_t *hc, int errn)
   info.tunercfg = strdup(tunercfg);
   htsmsg_destroy(xml);
   xml = NULL;
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   if (!satip_device_find(info.uuid))
     satip_device_create(&info);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   free(info.myaddr);
   free(info.location);
   free(info.server);
@@ -1173,7 +1173,7 @@ satip_discovery_service_received
     return;
   }
 
-  pthread_mutex_lock(&global_lock);  
+  tvh_mutex_lock(&global_lock);  
   i = 1;
   if (!satip_discovery_find(d) && !satip_device_find(d->uuid)) {
     TAILQ_INSERT_TAIL(&satip_discoveries, d, disc_link);
@@ -1181,7 +1181,7 @@ satip_discovery_service_received
     mtimer_arm_rel(&satip_discovery_timerq, satip_discovery_timerq_cb, NULL, ms2mono(250));
     i = 0;
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   if (i) /* duplicate */
     satip_discovery_destroy(d, 0);
   return;
@@ -1190,10 +1190,10 @@ add_uuid:
   if (deviceid == NULL || uuid == NULL)
     return;
   /* if new uuid was discovered, retrigger MSEARCH */
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   if (!satip_device_find(uuid))
     mtimer_arm_rel(&satip_discovery_timer, satip_discovery_timer_cb, NULL, sec2mono(5));
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
 
 static void
@@ -1344,7 +1344,7 @@ void satip_done ( void )
   tvh_hardware_t *th, *n;
   satip_discovery_t *d, *nd;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   for (th = LIST_FIRST(&tvh_hardware); th != NULL; th = n) {
     n = LIST_NEXT(th, th_link);
     if (idnode_is_instance(&th->th_id, &satip_device_class)) {
@@ -1355,5 +1355,5 @@ void satip_done ( void )
     nd = TAILQ_NEXT(d, disc_link);
     satip_discovery_destroy(d, 1);
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
index 6ec620356947286dbfa726260bbf5995d06eedb6..c9ae7911cd6b73235449f652b9be8b98a7979629 100644 (file)
@@ -145,7 +145,7 @@ satip_frontend_signal_cb( void *aux )
                        ((dvb_mux_t *)mmi->mmi_mux)->lm_tuning.dmc_fe_delsys);
     lfe->sf_tables = 1;
   }
-  pthread_mutex_lock(&mmi->tii_stats_mutex);
+  tvh_mutex_lock(&mmi->tii_stats_mutex);
   sigstat.status_text  = signal2str(lfe->sf_status);
   sigstat.snr          = mmi->tii_stats.snr;
   sigstat.signal       = mmi->tii_stats.signal;
@@ -157,14 +157,14 @@ satip_frontend_signal_cb( void *aux )
   sigstat.tc_bit       = mmi->tii_stats.tc_bit;
   sigstat.ec_block     = mmi->tii_stats.ec_block;
   sigstat.tc_block     = mmi->tii_stats.tc_block;
-  pthread_mutex_unlock(&mmi->tii_stats_mutex);
+  tvh_mutex_unlock(&mmi->tii_stats_mutex);
   memset(&sm, 0, sizeof(sm));
   sm.sm_type = SMT_SIGNAL_STATUS;
   sm.sm_data = &sigstat;
   LIST_FOREACH(svc, &mmi->mmi_mux->mm_transports, s_active_link) {
-    pthread_mutex_lock(&svc->s_stream_mutex);
+    tvh_mutex_lock(&svc->s_stream_mutex);
     streaming_service_deliver(svc, streaming_msg_clone(&sm));
-    pthread_mutex_unlock(&svc->s_stream_mutex);
+    tvh_mutex_unlock(&svc->s_stream_mutex);
   }
   mtimer_arm_rel(&lfe->sf_monitor_timer, satip_frontend_signal_cb,
                  lfe, ms2mono(250));
@@ -781,7 +781,7 @@ satip_frontend_stop_mux
   /* Stop tune */
   tvh_write(lfe->sf_dvr_pipe.wr, "", 1);
 
-  pthread_mutex_lock(&lfe->sf_dvr_lock);
+  tvh_mutex_lock(&lfe->sf_dvr_lock);
   tr = lfe->sf_req;
   if (tr && tr != lfe->sf_req_thread) {
     mpegts_pid_done(&tr->sf_pids_tuned);
@@ -790,7 +790,7 @@ satip_frontend_stop_mux
   }
   lfe->sf_running = 0;
   lfe->sf_req = NULL;
-  pthread_mutex_unlock(&lfe->sf_dvr_lock);
+  tvh_mutex_unlock(&lfe->sf_dvr_lock);
 }
 
 static int
@@ -856,15 +856,15 @@ satip_frontend_start_mux
   tr->sf_netlimit   = lfe->sf_netlimit;
   tr->sf_netgroup   = lfe->sf_netgroup;
 
-  pthread_mutex_lock(&lfe->sf_dvr_lock);
+  tvh_mutex_lock(&lfe->sf_dvr_lock);
   lfe->sf_req       = tr;
   lfe->sf_running   = 1;
   lfe->sf_tables    = 0;
   lfe->sf_atsc_c    = lm->lm_tuning.dmc_fe_modulation != DVB_MOD_VSB_8;
-  pthread_mutex_unlock(&lfe->sf_dvr_lock);
-  pthread_mutex_lock(&mmi->tii_stats_mutex);
+  tvh_mutex_unlock(&lfe->sf_dvr_lock);
+  tvh_mutex_lock(&mmi->tii_stats_mutex);
   lfe->sf_status    = SIGNAL_NONE;
-  pthread_mutex_unlock(&mmi->tii_stats_mutex);
+  tvh_mutex_unlock(&mmi->tii_stats_mutex);
 
   /* notify thread that we are ready */
   tvh_write(lfe->sf_dvr_pipe.wr, "s", 1);
@@ -884,7 +884,7 @@ satip_frontend_update_pids
   mpegts_pid_t *mp;
   mpegts_pid_sub_t *mps;
 
-  pthread_mutex_lock(&lfe->sf_dvr_lock);
+  tvh_mutex_lock(&lfe->sf_dvr_lock);
   if ((tr = lfe->sf_req) != NULL) {
     mpegts_pid_done(&tr->sf_pids);
     RB_FOREACH(mp, &mm->mm_pids, mp_link) {
@@ -915,7 +915,7 @@ satip_frontend_update_pids
     if (lfe->sf_device->sd_pids21)
       mpegts_pid_add(&tr->sf_pids, 21, MPS_WEIGHT_PMT_SCAN);
   }
-  pthread_mutex_unlock(&lfe->sf_dvr_lock);
+  tvh_mutex_unlock(&lfe->sf_dvr_lock);
 
   tvh_write(lfe->sf_dvr_pipe.wr, "c", 1);
 }
@@ -933,14 +933,14 @@ satip_frontend_open_service
   if (!lfe->sf_device->sd_can_weight)
     return;
 
-  pthread_mutex_lock(&lfe->sf_dvr_lock);
+  tvh_mutex_lock(&lfe->sf_dvr_lock);
   if ((tr = lfe->sf_req) != NULL && tr->sf_mmi != NULL) {
-    pthread_mutex_lock(&mi->mi_output_lock);
+    tvh_mutex_lock(&mi->mi_output_lock);
     w = mpegts_mux_instance_weight(tr->sf_mmi);
     tr->sf_weight = MAX(w, weight);
-    pthread_mutex_unlock(&mi->mi_output_lock);
+    tvh_mutex_unlock(&mi->mi_output_lock);
   }
-  pthread_mutex_unlock(&lfe->sf_dvr_lock);
+  tvh_mutex_unlock(&lfe->sf_dvr_lock);
 
   tvh_write(lfe->sf_dvr_pipe.wr, "c", 1);
 }
@@ -1007,7 +1007,7 @@ satip_frontend_decode_rtcp( satip_frontend_t *lfe, const char *name,
    * -a BER lower than 2x10-4 after Viterbi for DVB-S
    * -a PER lower than 10-7 for DVB-S2
    */
-  pthread_mutex_lock(&mmi->tii_stats_mutex);
+  tvh_mutex_lock(&mmi->tii_stats_mutex);
   while (len >= 12) {
     if ((rtcp[0] & 0xc0) != 0x80)              /* protocol version: v2 */
       goto fail;
@@ -1097,7 +1097,7 @@ ok:
     status              = SIGNAL_FAINT;
   lfe->sf_status        = status;
 fail:
-  pthread_mutex_unlock(&mmi->tii_stats_mutex);
+  tvh_mutex_unlock(&mmi->tii_stats_mutex);
 }
 
 static int
@@ -1112,12 +1112,12 @@ satip_frontend_pid_changed( http_client_t *rtsp,
   int max_pids_count = sd->sd_pids_max;
   mpegts_apids_t wpid, padd, pdel;
 
-  pthread_mutex_lock(&lfe->sf_dvr_lock);
+  tvh_mutex_lock(&lfe->sf_dvr_lock);
 
   tr = lfe->sf_req_thread;
 
   if (!lfe->sf_running || !lfe->sf_req || !tr) {
-    pthread_mutex_unlock(&lfe->sf_dvr_lock);
+    tvh_mutex_unlock(&lfe->sf_dvr_lock);
     return 0;
   }
 
@@ -1127,7 +1127,7 @@ all:
     i = tr->sf_pids_tuned.all;
     mpegts_pid_done(&tr->sf_pids_tuned);
     tr->sf_pids_tuned.all = 1;
-    pthread_mutex_unlock(&lfe->sf_dvr_lock);
+    tvh_mutex_unlock(&lfe->sf_dvr_lock);
     if (i)
       goto skip;
     setup = (char *)"all";
@@ -1151,7 +1151,7 @@ all:
       sprintf(setup + strlen(setup), ",%i", wpid.pids[i].pid);
     mpegts_pid_copy(&tr->sf_pids_tuned, &wpid);
     tr->sf_pids_tuned.all = 0;
-    pthread_mutex_unlock(&lfe->sf_dvr_lock);
+    tvh_mutex_unlock(&lfe->sf_dvr_lock);
     mpegts_pid_done(&wpid);
 
     if (!j || setup[0] == '\0')
@@ -1188,7 +1188,7 @@ all:
 
     mpegts_pid_copy(&tr->sf_pids_tuned, &wpid);
     tr->sf_pids_tuned.all = 0;
-    pthread_mutex_unlock(&lfe->sf_dvr_lock);
+    tvh_mutex_unlock(&lfe->sf_dvr_lock);
 
     mpegts_pid_done(&wpid);
     mpegts_pid_done(&padd);
@@ -1224,7 +1224,7 @@ satip_frontend_other_is_waiting( satip_frontend_t *lfe )
   if (lfe->sf_type != DVB_TYPE_S)
     return 0;
 
-  pthread_mutex_lock(&lfe->sf_dvr_lock);
+  tvh_mutex_lock(&lfe->sf_dvr_lock);
   if (lfe->sf_req) {
     hash1 = lfe->sf_req->sf_netposhash;
     limit = (limit0 = lfe->sf_req->sf_netlimit) - 1;
@@ -1232,19 +1232,19 @@ satip_frontend_other_is_waiting( satip_frontend_t *lfe )
   } else {
     hash1 = limit0 = limit = group = 0;
   }
-  pthread_mutex_unlock(&lfe->sf_dvr_lock);
+  tvh_mutex_unlock(&lfe->sf_dvr_lock);
 
   if (hash1 == 0)
     return 0;
 
   r = count = 0;
-  pthread_mutex_lock(&sd->sd_tune_mutex);
+  tvh_mutex_lock(&sd->sd_tune_mutex);
   TAILQ_FOREACH(lfe2, &lfe->sf_device->sd_frontends, sf_link) count++;
   hashes = alloca(sizeof(int) * count);
   memset(hashes, 0, sizeof(int) * count);
   TAILQ_FOREACH(lfe2, &lfe->sf_device->sd_frontends, sf_link) {
     if (lfe2 == lfe) continue;
-    pthread_mutex_lock(&lfe2->sf_dvr_lock);
+    tvh_mutex_lock(&lfe2->sf_dvr_lock);
     cont = 0;
     if (limit0 > 0) {
       cont = group > 0 && lfe2->sf_req_thread && group != lfe2->sf_req_thread->sf_netgroup;
@@ -1253,7 +1253,7 @@ satip_frontend_other_is_waiting( satip_frontend_t *lfe )
              (lfe2->sf_master && lfe->sf_number != lfe2->sf_master);
     }
     hash2 = lfe2->sf_req_thread ? lfe2->sf_req_thread->sf_netposhash : 0;
-    pthread_mutex_unlock(&lfe2->sf_dvr_lock);
+    tvh_mutex_unlock(&lfe2->sf_dvr_lock);
     if (cont || hash2 == 0) continue;
     if (hash2 != hash1) {
       for (i = 0; i < count; i++) {
@@ -1266,7 +1266,7 @@ satip_frontend_other_is_waiting( satip_frontend_t *lfe )
       }
     }
   }
-  pthread_mutex_unlock(&sd->sd_tune_mutex);
+  tvh_mutex_unlock(&sd->sd_tune_mutex);
   return r > limit;
 }
 
@@ -1291,12 +1291,12 @@ satip_frontend_wake_other_waiting
     if ((lfe->sf_master && lfe2->sf_number != lfe->sf_master) ||
         (lfe2->sf_master && lfe->sf_number != lfe2->sf_master))
       continue;
-    while (pthread_mutex_trylock(&lfe2->sf_dvr_lock))
+    while (tvh_mutex_trylock(&lfe2->sf_dvr_lock))
       tvh_usleep(1000);
     hash2 = lfe2->sf_req ? lfe2->sf_req->sf_netposhash : 0;
     if (hash2 != 0 && hash1 != hash2 && lfe2->sf_running)
       tvh_write(lfe2->sf_dvr_pipe.wr, "o", 1);
-    pthread_mutex_unlock(&lfe2->sf_dvr_lock);
+    tvh_mutex_unlock(&lfe2->sf_dvr_lock);
   }
 
 end:
@@ -1409,10 +1409,10 @@ satip_frontend_shutdown
   sbuf_free(&lfe->sf_sbuf);
 
 wake:
-  pthread_mutex_lock(&lfe->sf_dvr_lock);
+  tvh_mutex_lock(&lfe->sf_dvr_lock);
   satip_frontend_wake_other_waiting(lfe, tr);
   satip_frontend_request_cleanup(lfe, tr);
-  pthread_mutex_unlock(&lfe->sf_dvr_lock);
+  tvh_mutex_unlock(&lfe->sf_dvr_lock);
 }
 
 static void
@@ -1422,15 +1422,15 @@ satip_frontend_tuning_error ( satip_frontend_t *lfe, satip_tune_req_t *tr )
   mpegts_mux_instance_t *mmi;
   char uuid[UUID_HEX_SIZE];
 
-  pthread_mutex_lock(&lfe->sf_dvr_lock);
+  tvh_mutex_lock(&lfe->sf_dvr_lock);
   if (lfe->sf_running && lfe->sf_req == tr &&
       (mmi = tr->sf_mmi) != NULL && (mm = mmi->mmi_mux) != NULL) {
     idnode_uuid_as_str(&mm->mm_id, uuid);
-    pthread_mutex_unlock(&lfe->sf_dvr_lock);
+    tvh_mutex_unlock(&lfe->sf_dvr_lock);
     mpegts_mux_tuning_error(uuid, mmi);
     return;
   }
-  pthread_mutex_unlock(&lfe->sf_dvr_lock);
+  tvh_mutex_unlock(&lfe->sf_dvr_lock);
 }
 
 static void
@@ -1532,13 +1532,14 @@ satip_frontend_rtp_data_received( http_client_t *hc, void *buf, size_t len )
 
     if (lfe->sf_sbuf.sb_ptr > 64 * 1024 ||
         lfe->sf_last_data_tstamp + sec2mono(1) <= mclk()) {
-      pthread_mutex_lock(&lfe->sf_dvr_lock);
+      tvh_mutex_lock(&lfe->sf_dvr_lock);
       if (lfe->sf_req == lfe->sf_req_thread) {
         mmi = lfe->sf_req->sf_mmi;
         atomic_add(&mmi->tii_stats.unc, unc);
         mpegts_input_recv_packets(mmi, &lfe->sf_sbuf, 0, NULL);
       }
-      pthread_mutex_unlock(&lfe->sf_dvr_lock);
+      tvh_mutex_unlock(&lfe->sf_dvr_lock);
+      lfe->sf_last_data_tstamp = mclk();
     }
     lfe->sf_last_data_tstamp = mclk();
 
@@ -1548,11 +1549,11 @@ satip_frontend_rtp_data_received( http_client_t *hc, void *buf, size_t len )
     len -= 4;
     memmove(b, b + 4, len);
 
-    pthread_mutex_lock(&lfe->sf_dvr_lock);
+    tvh_mutex_lock(&lfe->sf_dvr_lock);
     if (lfe->sf_req == lfe->sf_req_thread)
       satip_frontend_decode_rtcp(lfe, lfe->sf_display_name,
                                  lfe->sf_req->sf_mmi, b, len);
-    pthread_mutex_unlock(&lfe->sf_dvr_lock);
+    tvh_mutex_unlock(&lfe->sf_dvr_lock);
 
   }
 
@@ -1605,10 +1606,10 @@ satip_frontend_input_thread ( void *aux )
    * New tune
    */
 new_tune:
-  pthread_mutex_lock(&lfe->sf_dvr_lock);
+  tvh_mutex_lock(&lfe->sf_dvr_lock);
   if (lfe->sf_req)
     mpegts_pid_done(&lfe->sf_req->sf_pids_tuned);
-  pthread_mutex_unlock(&lfe->sf_dvr_lock);
+  tvh_mutex_unlock(&lfe->sf_dvr_lock);
 
   udp_rtp_packet_destroy_all(lfe);
   sbuf_free(sb);
@@ -1690,10 +1691,10 @@ new_tune:
 
   lfe->mi_display_name((mpegts_input_t*)lfe, buf, sizeof(buf));
 
-  pthread_mutex_lock(&lfe->sf_dvr_lock);
+  tvh_mutex_lock(&lfe->sf_dvr_lock);
   satip_frontend_request_cleanup(lfe, tr);
   lfe->sf_req_thread = tr = lfe->sf_req;
-  pthread_mutex_unlock(&lfe->sf_dvr_lock);
+  tvh_mutex_unlock(&lfe->sf_dvr_lock);
 
   if (!lfe->sf_req_thread)
     goto new_tune;
@@ -1745,10 +1746,10 @@ new_tune:
 
   i = 0;
   if (!rtsp) {
-    pthread_mutex_lock(&lfe->sf_device->sd_tune_mutex);
+    tvh_mutex_lock(&lfe->sf_device->sd_tune_mutex);
     u64 = lfe_master->sf_last_tune;
     i = lfe_master->sf_tdelay;
-    pthread_mutex_unlock(&lfe->sf_device->sd_tune_mutex);
+    tvh_mutex_unlock(&lfe->sf_device->sd_tune_mutex);
     if (i < 0)
       i = 0;
     if (i > 2000)
@@ -1808,9 +1809,9 @@ new_tune:
 
   }
 
-  pthread_mutex_lock(&lfe->sf_device->sd_tune_mutex);
+  tvh_mutex_lock(&lfe->sf_device->sd_tune_mutex);
   lfe_master->sf_last_tune = getfastmonoclock();
-  pthread_mutex_unlock(&lfe->sf_device->sd_tune_mutex);
+  tvh_mutex_unlock(&lfe->sf_device->sd_tune_mutex);
 
   i = 0;
   if (!rtsp) {
@@ -1863,7 +1864,7 @@ new_tune:
     rtsp_flags |= SATIP_SETUP_FE;
 
   r = -12345678;
-  pthread_mutex_lock(&lfe->sf_dvr_lock);
+  tvh_mutex_lock(&lfe->sf_dvr_lock);
   if (lfe->sf_req == lfe->sf_req_thread) {
     lfe->sf_req->sf_weight_tuned = lfe->sf_req->sf_weight;
     r = satip_rtsp_setup(rtsp,
@@ -1872,7 +1873,7 @@ new_tune:
                          rtsp_flags,
                          lfe->sf_req->sf_weight);
   }
-  pthread_mutex_unlock(&lfe->sf_dvr_lock);
+  tvh_mutex_unlock(&lfe->sf_dvr_lock);
   if (r < 0) {
     if (r != -12345678)
       tvherror(LS_SATIP, "%s - failed to tune (%i)", buf, r);
@@ -1995,7 +1996,7 @@ new_tune:
                         rtsp->hc_rtsp_session, rtsp->hc_rtsp_stream_id);
             if (lfe->sf_play2) {
               r = -12345678;
-              pthread_mutex_lock(&lfe->sf_dvr_lock);
+              tvh_mutex_lock(&lfe->sf_dvr_lock);
               if (lfe->sf_req == lfe->sf_req_thread) {
                 lfe->sf_req->sf_weight_tuned = lfe->sf_req->sf_weight;
                 r = satip_rtsp_setup(rtsp, position, lfe->sf_number,
@@ -2003,7 +2004,7 @@ new_tune:
                                      rtsp_flags | SATIP_SETUP_PLAY,
                                      lfe->sf_req->sf_weight);
               }
-              pthread_mutex_unlock(&lfe->sf_dvr_lock);
+              tvh_mutex_unlock(&lfe->sf_dvr_lock);
               if (r < 0) {
                 tvherror(LS_SATIP, "%s - failed to tune2 (%i)", buf, r);
                 satip_frontend_tuning_error(lfe, tr);
@@ -2059,10 +2060,10 @@ new_tune:
       c = recv(rtcp->fd, b, sizeof(b), MSG_DONTWAIT);
       if (c > 0) {
         lfe->sf_last_activity_tstamp = mclk();
-        pthread_mutex_lock(&lfe->sf_dvr_lock);
-        if (lfe->sf_req == lfe->sf_req_thread)
+        tvh_mutex_lock(&lfe->sf_dvr_lock);
+       if (lfe->sf_req == lfe->sf_req_thread)
           satip_frontend_decode_rtcp(lfe, buf, mmi, b, c);
-        pthread_mutex_unlock(&lfe->sf_dvr_lock);
+        tvh_mutex_unlock(&lfe->sf_dvr_lock);
       }
       continue;
     }
@@ -2090,13 +2091,13 @@ new_tune:
       if (satip_frontend_rtp_decode(lfe, &seq, &unc, iovec[i].iov_base, iovec[i].iov_len) == 0)
         continue;
     }
-    pthread_mutex_lock(&lfe->sf_dvr_lock);
+    tvh_mutex_lock(&lfe->sf_dvr_lock);
     if (lfe->sf_req == lfe->sf_req_thread) {
       atomic_add(&mmi->tii_stats.unc, unc);
       mpegts_input_recv_packets(mmi, sb, 0, NULL);
     } else
       fatal = 1;
-    pthread_mutex_unlock(&lfe->sf_dvr_lock);
+    tvh_mutex_unlock(&lfe->sf_dvr_lock);
   }
 
   sbuf_free(sb);
@@ -2126,17 +2127,17 @@ done:
   rtcp = rtp = NULL;
 
   if (lfe->sf_teardown_delay && lfe_master) {
-    pthread_mutex_lock(&lfe->sf_device->sd_tune_mutex);
+    tvh_mutex_lock(&lfe->sf_device->sd_tune_mutex);
     lfe->sf_last_tune = lfe_master->sf_last_tune = getfastmonoclock();
-    pthread_mutex_unlock(&lfe->sf_device->sd_tune_mutex);
+    tvh_mutex_unlock(&lfe->sf_device->sd_tune_mutex);
   }
 
   if (!exit_flag)
     goto new_tune;
 
-  pthread_mutex_lock(&lfe->sf_dvr_lock);
+  tvh_mutex_lock(&lfe->sf_dvr_lock);
   satip_frontend_request_cleanup(lfe, tr);
-  pthread_mutex_unlock(&lfe->sf_dvr_lock);
+  tvh_mutex_unlock(&lfe->sf_dvr_lock);
 
   if (rtsp)
     http_client_close(rtsp);
@@ -2305,7 +2306,7 @@ satip_frontend_create
   lfe->sf_pass_weight = 1;
   satip_frontend_hacks(lfe);
   TAILQ_INIT(&lfe->sf_satconf);
-  pthread_mutex_init(&lfe->sf_dvr_lock, NULL);
+  tvh_mutex_init(&lfe->sf_dvr_lock, NULL);
   lfe = (satip_frontend_t*)mpegts_input_create0((mpegts_input_t*)lfe, idc, uuid, conf);
   if (!lfe) return NULL;
 
@@ -2363,8 +2364,8 @@ satip_frontend_create
   }
 
   tvh_pipe(O_NONBLOCK, &lfe->sf_dvr_pipe);
-  tvhthread_create(&lfe->sf_dvr_thread, NULL,
-                   satip_frontend_input_thread, lfe, "satip-front");
+  tvh_thread_create(&lfe->sf_dvr_thread, NULL,
+                    satip_frontend_input_thread, lfe, "satip-front");
 
   return lfe;
 }
index 28239ea1ee469bbc780b0ec98089a87476a97a99..175004a07c61cdc2be9a7ef325dc9451164e4094 100644 (file)
@@ -97,7 +97,7 @@ struct satip_device
   int                        sd_skip_ts;
   int                        sd_disable_workarounds;
   int                        sd_wake_ref;
-  pthread_mutex_t            sd_tune_mutex;
+  tvh_mutex_t            sd_tune_mutex;
   TAILQ_HEAD(,satip_frontend)sd_serialize_queue;
 };
 
@@ -156,7 +156,7 @@ struct satip_frontend
    */
   pthread_t                  sf_dvr_thread;
   th_pipe_t                  sf_dvr_pipe;
-  pthread_mutex_t            sf_dvr_lock;
+  tvh_mutex_t            sf_dvr_lock;
   int                        sf_thread;
   int                        sf_running;
   int                        sf_tables;
index 9297958e728abfe7c8cb6cc64c43abb30d0c49d6..2215ac72d4d5f1f026f32004eb607f19c8f09c9f 100644 (file)
@@ -17,7 +17,6 @@
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <pthread.h>
 #include <signal.h>
 #include "tvheadend.h"
 #include "htsbuf.h"
index b586eca0c961a6f5a65b8fe4247ad601a3b5a63d..39a793dbb94f888f3e43e805c7237afe6693664c 100644 (file)
@@ -911,11 +911,11 @@ scanfile_init ( const char *muxconf_path, int lock )
 
   if (!initialized) {
     if (lock)
-      pthread_mutex_lock(&global_lock);
+      tvh_mutex_lock(&global_lock);
     memoryinfo_register(&scanfile_memoryinfo);
     initialized = 1;
     if (lock)
-      pthread_mutex_unlock(&global_lock);
+      tvh_mutex_unlock(&global_lock);
   }
 
   scanfile_total_load = 0;
@@ -946,12 +946,12 @@ scanfile_init ( const char *muxconf_path, int lock )
     scanfile_regions_load = NULL;
   } else {
     if (lock)
-      pthread_mutex_lock(&global_lock);
+      tvh_mutex_lock(&global_lock);
     scanfile_done();
     scanfile_regions = scanfile_regions_load;
     scanfile_regions_load = NULL;
     if (lock)
-      pthread_mutex_unlock(&global_lock);
+      tvh_mutex_unlock(&global_lock);
   }
 }
 
index a8ac3d86db9916a4df0da4952464107fa91a6463..c33b185a8e2fff3973e96c0e16f033f10fa29f57 100644 (file)
@@ -79,13 +79,13 @@ skip_cc:
 
   for(off = 0; off < t->s_masters.is_count; off++) {
     m = (mpegts_service_t *)t->s_masters.is_array[off];
-    pthread_mutex_lock(&m->s_stream_mutex);
+    tvh_mutex_lock(&m->s_stream_mutex);
     if(streaming_pad_probe_type(&m->s_streaming_pad, SMT_MPEGTS)) {
       pid = (tsb[1] & 0x1f) << 8 | tsb[2];
       if (mpegts_pid_rexists(m->s_slaves_pids, pid))
         ts_remux(m, tsb, len, errors);
     }
-    pthread_mutex_unlock(&m->s_stream_mutex);
+    tvh_mutex_unlock(&m->s_stream_mutex);
     /* mark service live even without real subscribers */
     service_set_streaming_status_flags((service_t*)t, TSS_PACKETS);
     t->s_streaming_live |= TSS_LIVE;
@@ -130,13 +130,13 @@ skip_cc:
 
   for(off = 0; off < t->s_masters.is_count; off++) {
     m = (mpegts_service_t *)t->s_masters.is_array[off];
-    pthread_mutex_lock(&m->s_stream_mutex);
+    tvh_mutex_lock(&m->s_stream_mutex);
     if(streaming_pad_probe_type(&m->s_streaming_pad, SMT_MPEGTS)) {
       pid = (tsb[1] & 0x1f) << 8 | tsb[2];
       if (mpegts_pid_rexists(t->s_slaves_pids, pid))
         ts_skip(m, tsb, len);
     }
-    pthread_mutex_unlock(&m->s_stream_mutex);
+    tvh_mutex_unlock(&m->s_stream_mutex);
   }
 }
 
@@ -161,11 +161,11 @@ ts_recv_packet1
          tsb[0], tsb[1], tsb[2], tsb[3], tsb[4], tsb[5]);
 #endif
 
-  pthread_mutex_lock(&t->s_stream_mutex);
+  tvh_mutex_lock(&t->s_stream_mutex);
 
   /* Service inactive - ignore */
   if(t->s_status != SERVICE_RUNNING) {
-    pthread_mutex_unlock(&t->s_stream_mutex);
+    tvh_mutex_unlock(&t->s_stream_mutex);
     return 0;
   }
 
@@ -181,7 +181,7 @@ ts_recv_packet1
   st = elementary_stream_find(&t->s_components, pid);
 
   if((st == NULL) && (pid != t->s_components.set_pcr_pid) && !table) {
-    pthread_mutex_unlock(&t->s_stream_mutex);
+    tvh_mutex_unlock(&t->s_stream_mutex);
     return 0;
   }
 
@@ -200,7 +200,7 @@ ts_recv_packet1
     /* scrambled stream */
     r = descrambler_descramble((service_t *)t, st, tsb, len);
     if(r > 0) {
-      pthread_mutex_unlock(&t->s_stream_mutex);
+      tvh_mutex_unlock(&t->s_stream_mutex);
       return 1;
     }
 
@@ -215,7 +215,7 @@ ts_recv_packet1
   } else {
     ts_recv_packet0(t, st, tsb, len);
   }
-  pthread_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
   return 1;
 }
 
@@ -262,7 +262,7 @@ ts_recv_raw(mpegts_service_t *t, uint64_t tspos, const uint8_t *tsb, int len)
 {
   int pid, parent = 0;
 
-  pthread_mutex_lock(&t->s_stream_mutex);
+  tvh_mutex_lock(&t->s_stream_mutex);
   service_set_streaming_status_flags((service_t*)t, TSS_MUX_PACKETS);
   if (!idnode_set_empty(&t->s_slaves)) {
     /* If PID is owned by a slave service, let parent service to
@@ -282,7 +282,7 @@ ts_recv_raw(mpegts_service_t *t, uint64_t tspos, const uint8_t *tsb, int len)
       t->s_streaming_live |= TSS_LIVE;
     }
   }
-  pthread_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
 }
 
 /**
index c7540ef3a49e47aa5a075e1278ddc251e0db2bfc..407e0619726ddbc983d52ff7f3361d838a1a4583 100644 (file)
@@ -26,7 +26,7 @@
 /*
  * Globals
  */
-pthread_mutex_t          tsfile_lock;
+tvh_mutex_t          tsfile_lock;
 mpegts_network_t         *tsfile_network;
 tsfile_input_list_t      tsfile_inputs;
 
@@ -52,14 +52,14 @@ static mpegts_service_t *
 tsfile_network_create_service
   ( mpegts_mux_t *mm, uint16_t sid, uint16_t pmt_pid )
 {
-  pthread_mutex_lock(&tsfile_lock);
+  tvh_mutex_lock(&tsfile_lock);
   mpegts_service_t *s = mpegts_service_create1(NULL, mm, sid, pmt_pid, NULL);
 
   // TODO: HACK: REMOVE ME
   if (s) {
     s->s_config_save = tsfile_service_config_save;
     s->s_delete = tsfile_service_delete;
-    pthread_mutex_unlock(&tsfile_lock);
+    tvh_mutex_unlock(&tsfile_lock);
     channel_t *c = channel_create(NULL, NULL, NULL);
     if (c) {
       c->ch_dont_save = 1;
@@ -67,7 +67,7 @@ tsfile_network_create_service
     }
   }
   else
-    pthread_mutex_unlock(&tsfile_lock);
+    tvh_mutex_unlock(&tsfile_lock);
 
   return s;
 }
@@ -81,7 +81,7 @@ void tsfile_init ( int tuners )
   tsfile_input_t *mi;
 
   /* Mutex - used for minor efficiency in service processing */
-  pthread_mutex_init(&tsfile_lock, NULL);
+  tvh_mutex_init(&tsfile_lock, NULL);
 
   /* Shared network */
   tsfile_network = calloc(1, sizeof(*tsfile_network));
@@ -108,7 +108,7 @@ void
 tsfile_done ( void )
 {
   tsfile_input_t *mi;
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   while ((mi = LIST_FIRST(&tsfile_inputs))) {
     LIST_REMOVE(mi, tsi_link);
     mpegts_input_stop_all((mpegts_input_t*)mi);
@@ -116,7 +116,7 @@ tsfile_done ( void )
     // doesn't close the pipe!
   }
   mpegts_network_class_delete(&mpegts_network_class, 1);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
 
 /*
index b7cc980e08b42aa710b96b87118e0d39b0123200..3615fef92dcf56fb303b44bb3c65f7ea9d5a6f15 100644 (file)
@@ -52,7 +52,7 @@ tsfile_input_thread ( void *aux )
   tsfile_mux_instance_t *tmi;
 
   /* Open file */
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 
   if ((mmi = LIST_FIRST(&mi->mi_mux_active))) {
     tmi = (tsfile_mux_instance_t*)mmi;
@@ -63,7 +63,7 @@ tsfile_input_thread ( void *aux )
     else
       tvhtrace(LS_TSFILE, "adapter %d opened %s", mi->mi_instance, tmi->mmi_tsfile_path);
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   if (fd == -1) return NULL;
   
   /* Polling */
@@ -94,12 +94,12 @@ tsfile_input_thread ( void *aux )
     /* Find PCR PID */
     if (tmi->mmi_tsfile_pcr_pid == MPEGTS_PID_NONE) { 
       mpegts_service_t *s;
-      pthread_mutex_lock(&tsfile_lock);
+      tvh_mutex_lock(&tsfile_lock);
       LIST_FOREACH(s, &tmi->mmi_mux->mm_services, s_dvb_mux_link) {
         if (s->s_components.set_pcr_pid)
           tmi->mmi_tsfile_pcr_pid = s->s_components.set_pcr_pid;
       }
-      pthread_mutex_unlock(&tsfile_lock);
+      tvh_mutex_unlock(&tsfile_lock);
     }
     
     /* Check for terminate */
@@ -219,7 +219,7 @@ tsfile_input_start_mux ( mpegts_input_t *mi, mpegts_mux_instance_t *t, int weigh
       return SM_CODE_TUNING_FAILED;
     }
     tvhtrace(LS_TSFILE, "adapter %d starting thread", mi->mi_instance);
-    tvhthread_create(&ti->ti_thread_id, NULL, tsfile_input_thread, mi, "tsfile");
+    tvh_thread_create(&ti->ti_thread_id, NULL, tsfile_input_thread, mi, "tsfile");
   }
 
   /* Current */
index 57003fb18ea7c7ad0ac5fa548b1ecf2af00cde13..cbf903a6bfea61b5dec6f92561ab40172e13d514 100644 (file)
@@ -34,7 +34,7 @@ typedef LIST_HEAD(,tsfile_input)   tsfile_input_list_t;
  */
 extern mpegts_network_t    *tsfile_network;
 extern tsfile_input_list_t tsfile_inputs;
-extern pthread_mutex_t     tsfile_lock;
+extern tvh_mutex_t     tsfile_lock;
 
 
 /*
index edce2150353aa03e262f3ecbfe9b9c9bdf4966a7..d079aa780c518b1d2ecfce6e52c539ac7367349f 100644 (file)
@@ -17,6 +17,8 @@
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "libhdhomerun/hdhomerun.h"
+
 #include "tvheadend.h"
 #include "input.h"
 #include "htsbuf.h"
@@ -80,7 +82,7 @@ static int tvhdhomerun_discoveries_count;
 static struct tvhdhomerun_discovery_queue tvhdhomerun_discoveries;
 
 static pthread_t tvhdhomerun_discovery_tid;
-static pthread_mutex_t tvhdhomerun_discovery_lock;
+static tvh_mutex_t tvhdhomerun_discovery_lock;
 static tvh_cond_t tvhdhomerun_discovery_cond;
 
 static void
@@ -398,7 +400,7 @@ tvhdhomerun_device_discovery_thread( void *aux )
         numDevices--;
         struct hdhomerun_discover_device_t* cDev = &result_list[numDevices];
         if ( cDev->device_type == HDHOMERUN_DEVICE_TYPE_TUNER ) {
-          pthread_mutex_lock(&global_lock);
+          tvh_mutex_lock(&global_lock);
           tvhdhomerun_device_t *existing = tvhdhomerun_device_find(cDev->device_id);
           if ( tvheadend_is_running() ) {
             if ( !existing ) {
@@ -424,12 +426,12 @@ tvhdhomerun_device_discovery_thread( void *aux )
               tvhdhomerun_device_create(cDev);
             }
           }
-          pthread_mutex_unlock(&global_lock);
+          tvh_mutex_unlock(&global_lock);
         }
       }
     }
 
-    pthread_mutex_lock(&tvhdhomerun_discovery_lock);
+    tvh_mutex_lock(&tvhdhomerun_discovery_lock);
     brk = 0;
     if (tvheadend_is_running()) {
       brk = tvh_cond_timedwait(&tvhdhomerun_discovery_cond,
@@ -437,7 +439,7 @@ tvhdhomerun_device_discovery_thread( void *aux )
                                mclk() + sec2mono(15));
       brk = !ERRNO_AGAIN(brk) && brk != ETIMEDOUT;
     }
-    pthread_mutex_unlock(&tvhdhomerun_discovery_lock);
+    tvh_mutex_unlock(&tvhdhomerun_discovery_lock);
     if (brk)
       break;
   }
@@ -461,11 +463,11 @@ void tvhdhomerun_init ( void )
   idclass_register(&tvhdhomerun_frontend_atsc_c_class);
   idclass_register(&tvhdhomerun_frontend_cablecard_class);
   TAILQ_INIT(&tvhdhomerun_discoveries);
-  pthread_mutex_init(&tvhdhomerun_discovery_lock, NULL);
-  tvh_cond_init(&tvhdhomerun_discovery_cond);
-  tvhthread_create(&tvhdhomerun_discovery_tid, NULL,
-                   tvhdhomerun_device_discovery_thread,
-                   NULL, "hdhm-disc");
+  tvh_mutex_init(&tvhdhomerun_discovery_lock, NULL);
+  tvh_cond_init(&tvhdhomerun_discovery_cond, 1);
+  tvh_thread_create(&tvhdhomerun_discovery_tid, NULL,
+                    tvhdhomerun_device_discovery_thread,
+                    NULL, "hdhm-disc");
 }
 
 void tvhdhomerun_done ( void )
@@ -473,12 +475,12 @@ void tvhdhomerun_done ( void )
   tvh_hardware_t *th, *n;
   tvhdhomerun_discovery_t *d, *nd;
 
-  pthread_mutex_lock(&tvhdhomerun_discovery_lock);
+  tvh_mutex_lock(&tvhdhomerun_discovery_lock);
   tvh_cond_signal(&tvhdhomerun_discovery_cond, 0);
-  pthread_mutex_unlock(&tvhdhomerun_discovery_lock);
+  tvh_mutex_unlock(&tvhdhomerun_discovery_lock);
   pthread_join(tvhdhomerun_discovery_tid, NULL);
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   for (th = LIST_FIRST(&tvh_hardware); th != NULL; th = n) {
     n = LIST_NEXT(th, th_link);
     if (idnode_is_instance(&th->th_id, &tvhdhomerun_device_class)) {
@@ -489,7 +491,7 @@ void tvhdhomerun_done ( void )
     nd = TAILQ_NEXT(d, disc_link);
     tvhdhomerun_discovery_destroy(d, 1);
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   hdhomerun_debug_destroy(hdhomerun_debug_obj);
 }
 
index 6277e81cb1a2b8e15c33b9784dabc88555fa9727..b993a5b0d6ad3a781a61f29fdd83f74cc8a3f4fd 100644 (file)
@@ -17,6 +17,8 @@
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "libhdhomerun/hdhomerun.h"
+
 #include <fcntl.h>
 #include "tvheadend.h"
 #include "tvhpoll.h"
@@ -70,11 +72,11 @@ tvhdhomerun_frontend_input_thread ( void *aux )
   tvhdebug(LS_TVHDHOMERUN, "starting input thread");
 
   /* Get MMI */
-  pthread_mutex_lock(&hfe->hf_input_thread_mutex);
+  tvh_mutex_lock(&hfe->hf_input_thread_mutex);
   hfe->mi_display_name((mpegts_input_t*)hfe, buf, sizeof(buf));
   mmi = LIST_FIRST(&hfe->mi_mux_active);
   tvh_cond_signal(&hfe->hf_input_thread_cond, 0);
-  pthread_mutex_unlock(&hfe->hf_input_thread_mutex);
+  tvh_mutex_unlock(&hfe->hf_input_thread_mutex);
   if (mmi == NULL) return NULL;
 
   tvhdebug(LS_TVHDHOMERUN, "opening client socket");
@@ -150,9 +152,9 @@ tvhdhomerun_frontend_input_thread ( void *aux )
     (unsigned int)(local_ip >>  0) & 0xFF,
     ntohs(sock_addr.sin_port));
   tvhdebug(LS_TVHDHOMERUN, "setting target to: %s", target);
-  pthread_mutex_lock(&hfe->hf_hdhomerun_device_mutex);
+  tvh_mutex_lock(&hfe->hf_hdhomerun_device_mutex);
   r = hdhomerun_device_set_tuner_target(hfe->hf_hdhomerun_tuner, target);
-  pthread_mutex_unlock(&hfe->hf_hdhomerun_device_mutex);
+  tvh_mutex_unlock(&hfe->hf_hdhomerun_device_mutex);
   if(r < 1) {
     tvherror(LS_TVHDHOMERUN, "failed to set target: %d", r);
     close(sockfd);
@@ -205,9 +207,9 @@ tvhdhomerun_frontend_input_thread ( void *aux )
   }
 
   tvhdebug(LS_TVHDHOMERUN, "setting target to none");
-  pthread_mutex_lock(&hfe->hf_hdhomerun_device_mutex);
+  tvh_mutex_lock(&hfe->hf_hdhomerun_device_mutex);
   hdhomerun_device_set_tuner_target(hfe->hf_hdhomerun_tuner, "none");
-  pthread_mutex_unlock(&hfe->hf_hdhomerun_device_mutex);
+  tvh_mutex_unlock(&hfe->hf_hdhomerun_device_mutex);
 
   sbuf_free(&sb);
   tvhpoll_destroy(efd);
@@ -237,9 +239,9 @@ tvhdhomerun_frontend_monitor_cb( void *aux )
                  hfe, sec2mono(1));
 
   /* Get current status */
-  pthread_mutex_lock(&hfe->hf_hdhomerun_device_mutex);
+  tvh_mutex_lock(&hfe->hf_hdhomerun_device_mutex);
   res = hdhomerun_device_get_tuner_status(hfe->hf_hdhomerun_tuner, &tuner_status_str, &tuner_status);
-  pthread_mutex_unlock(&hfe->hf_hdhomerun_device_mutex);
+  tvh_mutex_unlock(&hfe->hf_hdhomerun_device_mutex);
   if(res < 1)
     tvhwarn(LS_TVHDHOMERUN, "tuner_status (%d)", res);
 
@@ -261,10 +263,10 @@ tvhdhomerun_frontend_monitor_cb( void *aux )
       dvb_mux_t *lm = (dvb_mux_t *)mm;
       struct hdhomerun_tuner_vstatus_t tuner_vstatus;
       char *tuner_vstatus_str;
-      pthread_mutex_lock(&hfe->hf_hdhomerun_device_mutex);
+      tvh_mutex_lock(&hfe->hf_hdhomerun_device_mutex);
       res = hdhomerun_device_get_tuner_vstatus(hfe->hf_hdhomerun_tuner,
         &tuner_vstatus_str, &tuner_vstatus);
-      pthread_mutex_unlock(&hfe->hf_hdhomerun_device_mutex);
+      tvh_mutex_unlock(&hfe->hf_hdhomerun_device_mutex);
       if (res < 1)
         tvhwarn(LS_TVHDHOMERUN, "tuner_vstatus (%d)", res);
       lm->lm_tuning.u.dmc_fe_cablecard.name = strdup(tuner_vstatus.name);
@@ -272,14 +274,14 @@ tvhdhomerun_frontend_monitor_cb( void *aux )
 
       /* start input thread */
       tvh_pipe(O_NONBLOCK, &hfe->hf_input_thread_pipe);
-      pthread_mutex_lock(&hfe->hf_input_thread_mutex);
-      tvhthread_create(&hfe->hf_input_thread, NULL, tvhdhomerun_frontend_input_thread, hfe, "hdhm-front");
+      tvh_mutex_lock(&hfe->hf_input_thread_mutex);
+      tvh_thread_create(&hfe->hf_input_thread, NULL, tvhdhomerun_frontend_input_thread, hfe, "hdhm-front");
       do {
         e = tvh_cond_wait(&hfe->hf_input_thread_cond, &hfe->hf_input_thread_mutex);
         if (e == ETIMEDOUT)
           break;
       } while (ERRNO_AGAIN(e));
-      pthread_mutex_unlock(&hfe->hf_input_thread_mutex);
+      tvh_mutex_unlock(&hfe->hf_input_thread_mutex);
 
       /* install table handlers */
       psi_tables_install(mmi->mmi_input, mm,
@@ -290,7 +292,7 @@ tvhdhomerun_frontend_monitor_cb( void *aux )
     }
   }
 
-  pthread_mutex_lock(&mmi->tii_stats_mutex);
+  tvh_mutex_lock(&mmi->tii_stats_mutex);
 
   if(tuner_status.signal_present) {
     /* TODO: totaly stupid conversion from 0-100 scale to 0-655.35 */
@@ -311,12 +313,12 @@ tvhdhomerun_frontend_monitor_cb( void *aux )
   sm.sm_type = SMT_SIGNAL_STATUS;
   sm.sm_data = &sigstat;
 
-  pthread_mutex_unlock(&mmi->tii_stats_mutex);
+  tvh_mutex_unlock(&mmi->tii_stats_mutex);
 
   LIST_FOREACH(svc, &mmi->mmi_mux->mm_transports, s_active_link) {
-    pthread_mutex_lock(&svc->s_stream_mutex);
+    tvh_mutex_lock(&svc->s_stream_mutex);
     streaming_service_deliver(svc, streaming_msg_clone(&sm));
-    pthread_mutex_unlock(&svc->s_stream_mutex);
+    tvh_mutex_unlock(&svc->s_stream_mutex);
   }
 }
 
@@ -331,18 +333,18 @@ static void tvhdhomerun_device_open_pid(tvhdhomerun_frontend_t *hfe, int pid) {
   /* a full mux subscription should specificly set the filter */
   if (pid == MPEGTS_FULLMUX_PID) {
     tvhdebug(LS_TVHDHOMERUN, "setting PID filter full mux");
-    pthread_mutex_lock(&hfe->hf_hdhomerun_device_mutex);
+    tvh_mutex_lock(&hfe->hf_hdhomerun_device_mutex);
     res = hdhomerun_device_set_tuner_filter(hfe->hf_hdhomerun_tuner, "0x0000-0x1FFF");
-    pthread_mutex_unlock(&hfe->hf_hdhomerun_device_mutex);
+    tvh_mutex_unlock(&hfe->hf_hdhomerun_device_mutex);
     if(res < 1)
       tvherror(LS_TVHDHOMERUN, "failed to set_tuner_filter to 0x0000 - 0x1FFF");
     return;
   }
 
   /* get the current filter */
-  pthread_mutex_lock(&hfe->hf_hdhomerun_device_mutex);
+  tvh_mutex_lock(&hfe->hf_hdhomerun_device_mutex);
   res = hdhomerun_device_get_tuner_filter(hfe->hf_hdhomerun_tuner, &pfilter);
-  pthread_mutex_unlock(&hfe->hf_hdhomerun_device_mutex);
+  tvh_mutex_unlock(&hfe->hf_hdhomerun_device_mutex);
   if(res < 1) {
       tvherror(LS_TVHDHOMERUN, "failed to get_tuner_filter: %d", res);
       return;
@@ -364,9 +366,9 @@ static void tvhdhomerun_device_open_pid(tvhdhomerun_frontend_t *hfe, int pid) {
     snprintf(buf, sizeof(buf), "%s 0x%04x", pfilter, pid);
     tvhdebug(LS_TVHDHOMERUN, "setting pfilter to: %s", buf);
 
-    pthread_mutex_lock(&hfe->hf_hdhomerun_device_mutex);
+    tvh_mutex_lock(&hfe->hf_hdhomerun_device_mutex);
     res = hdhomerun_device_set_tuner_filter(hfe->hf_hdhomerun_tuner, buf);
-    pthread_mutex_unlock(&hfe->hf_hdhomerun_device_mutex);
+    tvh_mutex_unlock(&hfe->hf_hdhomerun_device_mutex);
     if(res < 1)
       tvherror(LS_TVHDHOMERUN, "failed to set_tuner_filter: %d", res);
   } else {
@@ -443,10 +445,10 @@ static int tvhdhomerun_frontend_tune(tvhdhomerun_frontend_t *hfe, mpegts_mux_ins
 
   tvhinfo(LS_TVHDHOMERUN, "tuning to %s", channel_buf);
 
-  pthread_mutex_lock(&hfe->hf_hdhomerun_device_mutex);
+  tvh_mutex_lock(&hfe->hf_hdhomerun_device_mutex);
   res = hdhomerun_device_tuner_lockkey_request(hfe->hf_hdhomerun_tuner, &perror);
   if(res < 1) {
-    pthread_mutex_unlock(&hfe->hf_hdhomerun_device_mutex);
+    tvh_mutex_unlock(&hfe->hf_hdhomerun_device_mutex);
     tvherror(LS_TVHDHOMERUN, "failed to acquire lockkey: %s", perror);
     return SM_CODE_TUNING_FAILED;
   }
@@ -454,7 +456,7 @@ static int tvhdhomerun_frontend_tune(tvhdhomerun_frontend_t *hfe, mpegts_mux_ins
     res = hdhomerun_device_set_tuner_vchannel(hfe->hf_hdhomerun_tuner, channel_buf);
   else
     res = hdhomerun_device_set_tuner_channel(hfe->hf_hdhomerun_tuner, channel_buf);
-  pthread_mutex_unlock(&hfe->hf_hdhomerun_device_mutex);
+  tvh_mutex_unlock(&hfe->hf_hdhomerun_device_mutex);
   if(res < 1) {
     tvherror(LS_TVHDHOMERUN, "failed to tune to %s", channel_buf);
     return SM_CODE_TUNING_FAILED;
@@ -486,9 +488,9 @@ tvhdhomerun_frontend_start_mux
 
   /* reset the pfilters */
   if (hfe->hf_type != DVB_TYPE_CABLECARD) {
-    pthread_mutex_lock(&hfe->hf_hdhomerun_device_mutex);
+    tvh_mutex_lock(&hfe->hf_hdhomerun_device_mutex);
     r = hdhomerun_device_set_tuner_filter(hfe->hf_hdhomerun_tuner, "0x0000");
-    pthread_mutex_unlock(&hfe->hf_hdhomerun_device_mutex);
+    tvh_mutex_unlock(&hfe->hf_hdhomerun_device_mutex);
     if(r < 1)
       tvherror(LS_TVHDHOMERUN, "failed to reset pfilter: %d", r);
   }
@@ -711,8 +713,8 @@ tvhdhomerun_frontend_delete ( tvhdhomerun_frontend_t *hfe )
   /* Remove from adapter */
   TAILQ_REMOVE(&hfe->hf_device->hd_frontends, hfe, hf_link);
 
-  pthread_mutex_destroy(&hfe->hf_input_thread_mutex);
-  pthread_mutex_destroy(&hfe->hf_hdhomerun_device_mutex);
+  tvh_mutex_destroy(&hfe->hf_input_thread_mutex);
+  tvh_mutex_destroy(&hfe->hf_hdhomerun_device_mutex);
 
   /* Finish */
   mpegts_input_delete((mpegts_input_t*)hfe, 0);
@@ -804,9 +806,9 @@ tvhdhomerun_frontend_create(tvhdhomerun_device_t *hd, struct hdhomerun_discover_
   TAILQ_INSERT_TAIL(&hd->hd_frontends, hfe, hf_link);
 
   /* mutex init */
-  pthread_mutex_init(&hfe->hf_hdhomerun_device_mutex, NULL);
-  pthread_mutex_init(&hfe->hf_input_thread_mutex, NULL);
-  tvh_cond_init(&hfe->hf_input_thread_cond);
+  tvh_mutex_init(&hfe->hf_hdhomerun_device_mutex, NULL);
+  tvh_mutex_init(&hfe->hf_input_thread_mutex, NULL);
+  tvh_cond_init(&hfe->hf_input_thread_cond, 1);
 
   return hfe;
 }
index 93235f7e965bb7c2ddaa7560020d268588628387..eaf14f81d4f7f64d1fbe5f013168eedf2d136bfd 100644 (file)
@@ -24,8 +24,6 @@
 #include "htsbuf.h"
 #include "tvhdhomerun.h"
 
-#include "libhdhomerun/hdhomerun.h"
-
 typedef struct tvhdhomerun_device_info tvhdhomerun_device_info_t;
 typedef struct tvhdhomerun_device      tvhdhomerun_device_t;
 typedef struct tvhdhomerun_frontend    tvhdhomerun_frontend_t;
@@ -100,14 +98,14 @@ struct tvhdhomerun_frontend
 
   // input thread..
   pthread_t                      hf_input_thread;
-  pthread_mutex_t                hf_input_thread_mutex;        /* used in condition signaling */
+  tvh_mutex_t                    hf_input_thread_mutex;        /* used in condition signaling */
   tvh_cond_t                     hf_input_thread_cond;         /* used in condition signaling */
   th_pipe_t                      hf_input_thread_pipe;         /* IPC with input thread */
   uint8_t                        hf_input_thread_running;      // Indicates if input_thread is running.
   uint8_t                        hf_input_thread_terminating;  // Used for terminating the input_thread.
 
   // Global lock for the libhdhomerun library since it seems to have some threading-issues.
-  pthread_mutex_t                hf_hdhomerun_device_mutex;
+  tvh_mutex_t                    hf_hdhomerun_device_mutex;
 
   /*
    * Reception
index 6e9b92013ae70ef18f4ef16ae9070f3571a47814..48a11ec8106d60130fd0ce7e5e4f127624bce8f5 100644 (file)
@@ -10,11 +10,11 @@ typedef struct intlconv_cache {
 
 static RB_HEAD(,intlconv_cache) intlconv_all;
 static intlconv_cache_t        *intlconv_last_ic;
-pthread_mutex_t                 intlconv_lock;
+tvh_mutex_t                 intlconv_lock;
 
 static RB_HEAD(,intlconv_cache) intlconv_src_all;
 static intlconv_cache_t        *intlconv_last_src_ic;
-pthread_mutex_t                 intlconv_lock_src;
+tvh_mutex_t                 intlconv_lock_src;
 
 static inline size_t
 tvh_iconv(iconv_t cd, char **inbuf, size_t *inbytesleft,
@@ -43,8 +43,8 @@ intlconv_test( void )
 void
 intlconv_init( void )
 {
-  pthread_mutex_init(&intlconv_lock, NULL);
-  pthread_mutex_init(&intlconv_lock_src, NULL);
+  tvh_mutex_init(&intlconv_lock, NULL);
+  tvh_mutex_init(&intlconv_lock_src, NULL);
   intlconv_test();
 }
 
@@ -53,7 +53,7 @@ intlconv_done( void )
 {
   intlconv_cache_t *ic;
 
-  pthread_mutex_lock(&intlconv_lock);
+  tvh_mutex_lock(&intlconv_lock);
   intlconv_last_ic = NULL;
   while ((ic = RB_FIRST(&intlconv_all)) != NULL) {
     iconv_close(ic->ic_handle);
@@ -68,7 +68,7 @@ intlconv_done( void )
     RB_REMOVE(&intlconv_src_all, ic, ic_link);
     free(ic);
   }
-  pthread_mutex_unlock(&intlconv_lock);
+  tvh_mutex_unlock(&intlconv_lock);
 }
 
 const char *
@@ -127,7 +127,7 @@ intlconv_utf8( char *dst, size_t dst_size,
     return strlen(dst);
   }
   templ.ic_charset_id = (char *)dst_charset_id;
-  pthread_mutex_lock(&intlconv_lock);
+  tvh_mutex_lock(&intlconv_lock);
   if (intlconv_last_ic &&
       strcmp(intlconv_last_ic->ic_charset_id, dst_charset_id) == 0) {
     ic = intlconv_last_ic;
@@ -137,18 +137,18 @@ intlconv_utf8( char *dst, size_t dst_size,
   if (!ic) {
     iconv_t c = iconv_open(dst_charset_id, "UTF-8");
     if ((iconv_t)-1 == c) {
-      pthread_mutex_unlock(&intlconv_lock);
+      tvh_mutex_unlock(&intlconv_lock);
       return -EIO;
     }
     ic = malloc(sizeof(*ic));
     if (ic == NULL) {
-      pthread_mutex_unlock(&intlconv_lock);
+      tvh_mutex_unlock(&intlconv_lock);
       iconv_close(c);
       return -ENOMEM;
     }
     ic->ic_charset_id = strdup(dst_charset_id);
     if (ic->ic_charset_id == NULL) {
-      pthread_mutex_unlock(&intlconv_lock);
+      tvh_mutex_unlock(&intlconv_lock);
       free(ic);
       iconv_close(c);
       return -ENOMEM;
@@ -158,7 +158,7 @@ intlconv_utf8( char *dst, size_t dst_size,
   }
   intlconv_last_ic = ic;
 found:
-  pthread_mutex_unlock(&intlconv_lock);
+  tvh_mutex_unlock(&intlconv_lock);
   inbuf       = (char **)&src_utf8;
   inbuf_left  = strlen(src_utf8);
   outbuf      = &dst;
@@ -215,7 +215,7 @@ intlconv_to_utf8( char *dst, size_t dst_size,
     return strlen(dst);
   }
   templ.ic_charset_id = (char *)src_charset_id;
-  pthread_mutex_lock(&intlconv_lock_src);
+  tvh_mutex_lock(&intlconv_lock_src);
   if (intlconv_last_src_ic &&
       strcmp(intlconv_last_src_ic->ic_charset_id, src_charset_id) == 0) {
     ic = intlconv_last_src_ic;
@@ -225,18 +225,18 @@ intlconv_to_utf8( char *dst, size_t dst_size,
   if (!ic) {
     iconv_t c = iconv_open("UTF-8", src_charset_id);
     if ((iconv_t)-1 == c) {
-      pthread_mutex_unlock(&intlconv_lock_src);
+      tvh_mutex_unlock(&intlconv_lock_src);
       return -EIO;
     }
     ic = malloc(sizeof(*ic));
     if (ic == NULL) {
-      pthread_mutex_unlock(&intlconv_lock_src);
+      tvh_mutex_unlock(&intlconv_lock_src);
       iconv_close(c);
       return -ENOMEM;
     }
     ic->ic_charset_id = strdup(src_charset_id);
     if (ic->ic_charset_id == NULL) {
-      pthread_mutex_unlock(&intlconv_lock_src);
+      tvh_mutex_unlock(&intlconv_lock_src);
       free(ic);
       iconv_close(c);
       return -ENOMEM;
@@ -246,7 +246,7 @@ intlconv_to_utf8( char *dst, size_t dst_size,
   }
   intlconv_last_src_ic = ic;
 found:
-  pthread_mutex_unlock(&intlconv_lock_src);
+  tvh_mutex_unlock(&intlconv_lock_src);
   inbuf       = (char **)&src;
   inbuf_left  = src_size;
   outbuf      = &dst;
index f51666e712bdc7c12a5dcf8d583994b4a56c9ef7..9eeed12ee71626c20809683eaf204a6488cce48d 100644 (file)
@@ -500,7 +500,7 @@ lang_code_lookup_t* lang_codes_code2b = NULL;
 lang_code_lookup_t* lang_codes_code1 = NULL;
 lang_code_lookup_t* lang_codes_code2t = NULL;
 
-pthread_mutex_t lang_code_split_mutex = PTHREAD_MUTEX_INITIALIZER;
+tvh_mutex_t lang_code_split_mutex = { .mutex = PTHREAD_MUTEX_INITIALIZER };
 RB_HEAD(,lang_code_list) lang_code_split_tree = { NULL, NULL, NULL, 0 };
 
 /* **************************************************************************
@@ -632,7 +632,7 @@ const lang_code_list_t *lang_code_split ( const char *codes )
   /* No config */
   if (!codes) return NULL;
 
-  pthread_mutex_lock(&lang_code_split_mutex);
+  tvh_mutex_lock(&lang_code_split_mutex);
 
   skel.langs = (char *)codes;
   ret = RB_FIND(&lang_code_split_tree, &skel, link, _split_cmp);
@@ -663,7 +663,7 @@ const lang_code_list_t *lang_code_split ( const char *codes )
   }
 
 unlock:
-  pthread_mutex_unlock(&lang_code_split_mutex);
+  tvh_mutex_unlock(&lang_code_split_mutex);
   return ret;
 }
 
@@ -722,13 +722,13 @@ char *lang_code_user( const char *ucode )
 void lang_code_done( void )
 {
   lang_code_list_t *lcs;
-  pthread_mutex_lock(&lang_code_split_mutex);
+  tvh_mutex_lock(&lang_code_split_mutex);
   while ((lcs = RB_FIRST(&lang_code_split_tree)) != NULL) {
     RB_REMOVE(&lang_code_split_tree, lcs, link);
     free((char *)lcs->langs);
     free(lcs);
   }
-  pthread_mutex_unlock(&lang_code_split_mutex);
+  tvh_mutex_unlock(&lang_code_split_mutex);
   lang_code_free(lang_codes_code2b);
   lang_code_free(lang_codes_code1);
   lang_code_free(lang_codes_code2t);
index 1ed301ac814336e5d81da112cc265c0dfdb98165..94140ae2fcdda2b011e94751a990220b8a6e2f2e 100644 (file)
@@ -16,7 +16,7 @@
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <pthread.h>
+#include <tvh_thread.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <stdio.h>
@@ -180,10 +180,10 @@ const tvh_caps_t tvheadend_capabilities[] = {
   { NULL, NULL }
 };
 
-pthread_mutex_t global_lock;
-pthread_mutex_t tasklet_lock;
-pthread_mutex_t fork_lock;
-pthread_mutex_t atomic_lock;
+tvh_mutex_t global_lock;
+tvh_mutex_t tasklet_lock;
+tvh_mutex_t fork_lock;
+tvh_mutex_t atomic_lock;
 
 /*
  * Locals
@@ -195,7 +195,7 @@ static pthread_t mtimer_tid;
 static pthread_t mtimer_tick_tid;
 static tprofile_t mtimer_profile;
 static LIST_HEAD(, gtimer) gtimers;
-static pthread_cond_t gtimer_cond;
+static tvh_cond_t gtimer_cond;
 static tprofile_t gtimer_profile;
 static TAILQ_HEAD(, tasklet) tasklets;
 static tvh_cond_t tasklet_cond;
@@ -222,8 +222,8 @@ void
 doexit(int x)
 {
   if (pthread_self() != main_tid)
-    pthread_kill(main_tid, SIGTERM);
-  pthread_cond_signal(&gtimer_cond);
+    tvh_thread_kill(main_tid, SIGTERM);
+  tvh_cond_signal(&gtimer_cond, 0);
   tvh_cond_signal(&mtimer_cond, 1);
   atomic_set(&tvheadend_running, 0);
   signal(x, doexit);
@@ -341,7 +341,7 @@ GTIMER_FCN(gtimer_arm_absn)
   LIST_INSERT_SORTED(&gtimers, gti, gti_link, gtimercmp);
 
   if (LIST_FIRST(&gtimers) == gti)
-    pthread_cond_signal(&gtimer_cond); // force timer re-check
+    tvh_cond_signal(&gtimer_cond, 0); // force timer re-check
 }
 
 /**
@@ -391,7 +391,7 @@ tasklet_arm_alloc(tsk_callback_t *callback, void *opaque)
 void
 tasklet_arm(tasklet_t *tsk, tsk_callback_t *callback, void *opaque)
 {
-  pthread_mutex_lock(&tasklet_lock);
+  tvh_mutex_lock(&tasklet_lock);
 
   if (tsk->tsk_callback != NULL)
     TAILQ_REMOVE(&tasklets, tsk, tsk_link);
@@ -404,7 +404,7 @@ tasklet_arm(tasklet_t *tsk, tsk_callback_t *callback, void *opaque)
   if (TAILQ_FIRST(&tasklets) == tsk)
     tvh_cond_signal(&tasklet_cond, 0);
 
-  pthread_mutex_unlock(&tasklet_lock);
+  tvh_mutex_unlock(&tasklet_lock);
 }
 
 /**
@@ -413,7 +413,7 @@ tasklet_arm(tasklet_t *tsk, tsk_callback_t *callback, void *opaque)
 void
 tasklet_disarm(tasklet_t *tsk)
 {
-  pthread_mutex_lock(&tasklet_lock);
+  tvh_mutex_lock(&tasklet_lock);
 
   if(tsk->tsk_callback) {
     TAILQ_REMOVE(&tasklets, tsk, tsk_link);
@@ -422,7 +422,7 @@ tasklet_disarm(tasklet_t *tsk)
     if (tsk->tsk_free) tsk->tsk_free(tsk);
   }
 
-  pthread_mutex_unlock(&tasklet_lock);
+  tvh_mutex_unlock(&tasklet_lock);
 }
 
 static void
@@ -430,7 +430,7 @@ tasklet_flush()
 {
   tasklet_t *tsk;
 
-  pthread_mutex_lock(&tasklet_lock);
+  tvh_mutex_lock(&tasklet_lock);
 
   while ((tsk = TAILQ_FIRST(&tasklets)) != NULL) {
     TAILQ_REMOVE(&tasklets, tsk, tsk_link);
@@ -442,7 +442,7 @@ tasklet_flush()
     }
   }
 
-  pthread_mutex_unlock(&tasklet_lock);
+  tvh_mutex_unlock(&tasklet_lock);
 }
 
 /**
@@ -455,9 +455,9 @@ tasklet_thread ( void *aux )
   tsk_callback_t *tsk_cb;
   void *opaque;
 
-  tvhthread_renice(20);
+  tvh_thread_renice(20);
 
-  pthread_mutex_lock(&tasklet_lock);
+  tvh_mutex_lock(&tasklet_lock);
   while (tvheadend_is_running()) {
     tsk = TAILQ_FIRST(&tasklets);
     if (tsk == NULL) {
@@ -475,12 +475,12 @@ tasklet_thread ( void *aux )
     }
     /* now, the callback can be safely called */
     if (tsk_cb) {
-      pthread_mutex_unlock(&tasklet_lock);
+      tvh_mutex_unlock(&tasklet_lock);
       tsk_cb(opaque, 0);
-      pthread_mutex_lock(&tasklet_lock);
+      tvh_mutex_lock(&tasklet_lock);
     }
   }
-  pthread_mutex_unlock(&tasklet_lock);
+  tvh_mutex_unlock(&tasklet_lock);
 
   return NULL;
 }
@@ -611,16 +611,16 @@ mtimer_thread(void *aux)
   int64_t now, next;
   const char *id;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   while (tvheadend_is_running() && atomic_get(&tvheadend_mainloop) == 0)
     tvh_cond_wait(&mtimer_cond, &global_lock);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   while (tvheadend_is_running()) {
     now = mdispatch_clock_update();
 
     /* Global monoclock timers */
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
 
     next = now + sec2mono(3600);
 
@@ -654,7 +654,7 @@ mtimer_thread(void *aux)
 
     /* Wait */
     tvh_cond_timedwait(&mtimer_cond, &global_lock, next);
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
   }
 
   return NULL;
@@ -678,7 +678,7 @@ mainloop(void)
     ts.tv_nsec = 0;
 
     /* Global timers */
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
 
     // TODO: there is a risk that if timers re-insert themselves to
     //       the top of the list with a 0 offset we could loop indefinitely
@@ -714,8 +714,8 @@ mainloop(void)
     }
 
     /* Wait */
-    pthread_cond_timedwait(&gtimer_cond, &global_lock, &ts);
-    pthread_mutex_unlock(&global_lock);
+    tvh_cond_timedwait(&gtimer_cond, &global_lock, (intptr_t )&ts);
+    tvh_mutex_unlock(&global_lock);
   }
 }
 
@@ -749,13 +749,13 @@ main(int argc, char **argv)
   main_tid = pthread_self();
 
   /* Setup global mutexes */
-  pthread_mutex_init(&fork_lock, NULL);
-  pthread_mutex_init(&global_lock, NULL);
-  pthread_mutex_init(&tasklet_lock, NULL);
-  pthread_mutex_init(&atomic_lock, NULL);
-  tvh_cond_init(&mtimer_cond);
-  pthread_cond_init(&gtimer_cond, NULL);
-  tvh_cond_init(&tasklet_cond);
+  tvh_mutex_init(&fork_lock, NULL);
+  tvh_mutex_init(&global_lock, NULL);
+  tvh_mutex_init(&tasklet_lock, NULL);
+  tvh_mutex_init(&atomic_lock, NULL);
+  tvh_cond_init(&mtimer_cond, 1);
+  tvh_cond_init(&gtimer_cond, 0);
+  tvh_cond_init(&tasklet_cond, 1);
   TAILQ_INIT(&tasklets);
 
   /* Defaults */
@@ -1155,7 +1155,7 @@ main(int argc, char **argv)
     tvhlog_options &= ~TVHLOG_OPT_DECORATE;
 
   /* Initialise clock */
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   __mdispatch_clock = getmonoclock();
   __gdispatch_clock = time(NULL);
 
@@ -1205,9 +1205,9 @@ main(int argc, char **argv)
 
   epg_in_load = 1;
 
-  tvhthread_create(&mtimer_tick_tid, NULL, mtimer_tick_thread, NULL, "mtick");
-  tvhthread_create(&mtimer_tid, NULL, mtimer_thread, NULL, "mtimer");
-  tvhthread_create(&tasklet_tid, NULL, tasklet_thread, NULL, "tasklet");
+  tvh_thread_create(&mtimer_tick_tid, NULL, mtimer_tick_thread, NULL, "mtick");
+  tvh_thread_create(&mtimer_tid, NULL, mtimer_thread, NULL, "mtimer");
+  tvh_thread_create(&tasklet_tid, NULL, tasklet_thread, NULL, "tasklet");
 
 #if CONFIG_LINUXDVB_CA
   en50221_register_apps();
@@ -1265,7 +1265,7 @@ main(int argc, char **argv)
   tvhftrace(LS_MAIN, epg_updated); // cleanup now all prev ref's should have been created
   epg_in_load = 0;
 
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   tvhftrace(LS_MAIN, watchdog_init);
 
@@ -1291,14 +1291,14 @@ main(int argc, char **argv)
   if(opt_abort)
     abort();
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   tvheadend_mainloop = 1;
   tvh_cond_signal(&mtimer_cond, 0);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   mainloop();
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   tvh_cond_signal(&mtimer_cond, 0);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   pthread_join(mtimer_tid, NULL);
 
 #if ENABLE_DBUS_1
@@ -1317,13 +1317,13 @@ main(int argc, char **argv)
 
   // Note: the locking is obviously a bit redundant, but without
   //       we need to disable the gtimer_arm call in epg_save()
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   tvhftrace(LS_MAIN, epg_save);
 
 #if ENABLE_TIMESHIFT
   tvhftrace(LS_MAIN, timeshift_term);
 #endif
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   tvhftrace(LS_MAIN, epggrab_done);
 #if ENABLE_MPEGTS
@@ -1434,16 +1434,6 @@ tvh_str_update(char **strp, const char *src)
 }
 
 
-/**
- *
- */
-void
-scopedunlock(pthread_mutex_t **mtxp)
-{
-  pthread_mutex_unlock(*mtxp);
-}
-
-
 /**
  *
  */
index aee6312c07505b3bf7a78f6822642afb0a1ae7ff..23d02ad1d18be5e5db753fc7b18f452870f4493e 100644 (file)
@@ -27,7 +27,7 @@
 #include "webui/webui.h"
 
 static tvh_cond_t             notify_cond;
-static pthread_mutex_t        notify_mutex;
+static tvh_mutex_t        notify_mutex;
 static htsmsg_t              *notify_queue;
 static pthread_t              notify_tid;
 static void*                  notify_thread(void* p);
@@ -58,7 +58,7 @@ notify_delayed(const char *id, const char *event, const char *action)
   if (!tvheadend_is_running())
     return;
 
-  pthread_mutex_lock(&notify_mutex);
+  tvh_mutex_lock(&notify_mutex);
   if (notify_queue == NULL) {
     notify_queue = htsmsg_create_map();
   } else {
@@ -77,7 +77,7 @@ notify_delayed(const char *id, const char *event, const char *action)
   htsmsg_add_str(e, NULL, id);
   tvh_cond_signal(&notify_cond, 0);
 skip:
-  pthread_mutex_unlock(&notify_mutex);
+  tvh_mutex_unlock(&notify_mutex);
 }
 
 void *
@@ -86,7 +86,7 @@ notify_thread ( void *p )
   htsmsg_t *q = NULL;
   htsmsg_field_t *f;
 
-  pthread_mutex_lock(&notify_mutex);
+  tvh_mutex_lock(&notify_mutex);
 
   while (tvheadend_is_running()) {
 
@@ -97,23 +97,23 @@ notify_thread ( void *p )
     }
     q            = notify_queue;
     notify_queue = NULL;
-    pthread_mutex_unlock(&notify_mutex);
+    tvh_mutex_unlock(&notify_mutex);
 
     /* Process */
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
 
     HTSMSG_FOREACH(f, q)
       notify_by_msg(htsmsg_field_name(f), htsmsg_detach_submsg(f), 0);
 
     /* Finished */
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
     htsmsg_destroy(q);
 
     /* Wait */
     tvh_safe_usleep(500000);
-    pthread_mutex_lock(&notify_mutex);
+    tvh_mutex_lock(&notify_mutex);
   }
-  pthread_mutex_unlock(&notify_mutex);
+  tvh_mutex_unlock(&notify_mutex);
 
   return NULL;
 }
@@ -125,19 +125,19 @@ notify_thread ( void *p )
 void notify_init( void )
 {
   notify_queue = NULL;
-  pthread_mutex_init(&notify_mutex, NULL);
-  tvh_cond_init(&notify_cond);
-  tvhthread_create(&notify_tid, NULL, notify_thread, NULL, "notify");
+  tvh_mutex_init(&notify_mutex, NULL);
+  tvh_cond_init(&notify_cond, 1);
+  tvh_thread_create(&notify_tid, NULL, notify_thread, NULL, "notify");
 }
 
 void notify_done( void )
 {
-  pthread_mutex_lock(&notify_mutex);
+  tvh_mutex_lock(&notify_mutex);
   tvh_cond_signal(&notify_cond, 0);
-  pthread_mutex_unlock(&notify_mutex);
+  tvh_mutex_unlock(&notify_mutex);
   pthread_join(notify_tid, NULL);
-  pthread_mutex_lock(&notify_mutex);
+  tvh_mutex_lock(&notify_mutex);
   htsmsg_destroy(notify_queue);
   notify_queue = NULL;
-  pthread_mutex_unlock(&notify_mutex);
+  tvh_mutex_unlock(&notify_mutex);
 }
index 06eea53e03e11cc96f45c927d799e435647002b4..74c92401df184e9699e1d6c46b2067a44d9b49cb 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <pthread.h>
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-
 #include "parsers.h"
 #include "../input/mpegts/dvb_psi_hbbtv.h"
 #include "packet.h"
index dbf2aa366aec82f460e024bb89318b029a96ff02..eb567c15335bf6a261ca3b176c4133977fa121c9 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <pthread.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
 #include <ctype.h>
-#include <stdint.h>
-#include <assert.h>
 
 #include "tvheadend.h"
 #include "packet.h"
index beb20039ff32908962b86c5ca338b5d308d46711..9d2328e37cfe52fb41302cf22722d2a260aa25b5 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <pthread.h>
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-
 #include "parsers.h"
 #include "parser_h264.h"
 #include "parser_avc.h"
index f439447749ee56e0f0af278c79ed93240060392e..59477305df5bdd2f7a4f438370e6b28a9b28bcb4 100644 (file)
@@ -726,7 +726,7 @@ profile_input_queue(void *opaque, streaming_message_t *sm)
   profile_sharer_message_t *psm = malloc(sizeof(*psm));
   psm->psm_prch = prch;
   psm->psm_sm = sm;
-  pthread_mutex_lock(&prsh->prsh_queue_mutex);
+  tvh_mutex_lock(&prsh->prsh_queue_mutex);
   if (prsh->prsh_queue_run) {
     TAILQ_INSERT_TAIL(&prsh->prsh_queue, psm, psm_link);
     tvh_cond_signal(&prsh->prsh_queue_cond, 0);
@@ -734,7 +734,7 @@ profile_input_queue(void *opaque, streaming_message_t *sm)
     streaming_msg_free(sm);
     free(psm);
   }
-  pthread_mutex_unlock(&prsh->prsh_queue_mutex);
+  tvh_mutex_unlock(&prsh->prsh_queue_mutex);
 }
 
 static htsmsg_t *
@@ -865,8 +865,8 @@ profile_sharer_find(profile_chain_t *prch)
     prsh = calloc(1, sizeof(*prsh));
     prsh->prsh_do_queue = do_queue;
     if (do_queue) {
-      pthread_mutex_init(&prsh->prsh_queue_mutex, NULL);
-      tvh_cond_init(&prsh->prsh_queue_cond);
+      tvh_mutex_init(&prsh->prsh_queue_mutex, NULL);
+      tvh_cond_init(&prsh->prsh_queue_cond, 1);
       TAILQ_INIT(&prsh->prsh_queue);
     }
     streaming_target_init(&prsh->prsh_input, &profile_sharer_input_ops, prsh, 0);
@@ -886,7 +886,7 @@ profile_sharer_thread(void *aux)
   int run = 1;
 
   while (run) {
-    pthread_mutex_lock(&prsh->prsh_queue_mutex);
+    tvh_mutex_lock(&prsh->prsh_queue_mutex);
     run = prsh->prsh_queue_run;
     psm = TAILQ_FIRST(&prsh->prsh_queue);
     if (run && psm == NULL) {
@@ -901,7 +901,7 @@ profile_sharer_thread(void *aux)
         free(psm);
       }
     }
-    pthread_mutex_unlock(&prsh->prsh_queue_mutex);
+    tvh_mutex_unlock(&prsh->prsh_queue_mutex);
   }
   return NULL;
 }
@@ -919,8 +919,8 @@ profile_sharer_postinit(profile_sharer_t *prsh)
   if (prsh->prsh_queue_run)
     return 0;
   prsh->prsh_queue_run = 1;
-  r = tvhthread_create(&prsh->prsh_queue_thread, NULL,
-                       profile_sharer_thread, prsh, "sharer");
+  r = tvh_thread_create(&prsh->prsh_queue_thread, NULL,
+                        profile_sharer_thread, prsh, "sharer");
   if (r) {
     prsh->prsh_queue_run = 0;
     tvherror(LS_PROFILE, "unable to create sharer thread");
@@ -937,13 +937,13 @@ profile_sharer_create(profile_sharer_t *prsh,
                       streaming_target_t *dst)
 {
   prch->prch_post_share = dst;
-  pthread_mutex_lock(&prsh->prsh_queue_mutex);
+  tvh_mutex_lock(&prsh->prsh_queue_mutex);
   prch->prch_ts_delta = LIST_EMPTY(&prsh->prsh_chains) ? 0 : PTS_UNSET;
   LIST_INSERT_HEAD(&prsh->prsh_chains, prch, prch_sharer_link);
   prch->prch_sharer = prsh;
   if (!prsh->prsh_master)
     prsh->prsh_master = prch;
-  pthread_mutex_unlock(&prsh->prsh_queue_mutex);
+  tvh_mutex_unlock(&prsh->prsh_queue_mutex);
   return 0;
 }
 
@@ -959,7 +959,7 @@ profile_sharer_destroy(profile_chain_t *prch)
 
   if (prsh == NULL)
     return;
-  pthread_mutex_lock(&prsh->prsh_queue_mutex);
+  tvh_mutex_lock(&prsh->prsh_queue_mutex);
   LIST_REMOVE(prch, prch_sharer_link);
   if (LIST_EMPTY(&prsh->prsh_chains)) {
     if ((run = prsh->prsh_queue_run) != 0) {
@@ -969,7 +969,7 @@ profile_sharer_destroy(profile_chain_t *prch)
     prch->prch_sharer = NULL;
     prch->prch_post_share = NULL;
   }
-  pthread_mutex_unlock(&prsh->prsh_queue_mutex);
+  tvh_mutex_unlock(&prsh->prsh_queue_mutex);
   if (run) {
     pthread_join(prsh->prsh_queue_thread, NULL);
     while ((psm = TAILQ_FIRST(&prsh->prsh_queue)) != NULL) {
@@ -988,7 +988,7 @@ profile_sharer_destroy(profile_chain_t *prch)
     free(prsh);
   } else {
     if (prsh->prsh_queue_run) {
-      pthread_mutex_lock(&prsh->prsh_queue_mutex);
+      tvh_mutex_lock(&prsh->prsh_queue_mutex);
       for (psm = TAILQ_FIRST(&prsh->prsh_queue); psm; psm = psm2) {
         psm2 = TAILQ_NEXT(psm, psm_link);
         if (psm->psm_prch != prch) continue;
@@ -1004,14 +1004,14 @@ profile_sharer_destroy(profile_chain_t *prch)
       prch->prch_post_share = NULL;
       if (prsh->prsh_master == prch)
         prsh->prsh_master = NULL;
-      pthread_mutex_unlock(&prsh->prsh_queue_mutex);
+      tvh_mutex_unlock(&prsh->prsh_queue_mutex);
     } else {
-      pthread_mutex_lock(&prsh->prsh_queue_mutex);
+      tvh_mutex_lock(&prsh->prsh_queue_mutex);
       prch->prch_sharer = NULL;
       prch->prch_post_share = NULL;
       if (prsh->prsh_master == prch)
         prsh->prsh_master = NULL;
-      pthread_mutex_unlock(&prsh->prsh_queue_mutex);
+      tvh_mutex_unlock(&prsh->prsh_queue_mutex);
     }
   }
 }
@@ -2632,7 +2632,7 @@ profile_done(void)
   profile_t *pro;
   profile_build_t *pb;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   profile_default = NULL;
   while ((pro = TAILQ_FIRST(&profiles)) != NULL)
     profile_delete(pro, 0);
@@ -2640,5 +2640,5 @@ profile_done(void)
     LIST_REMOVE(pb, link);
     free(pb);
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
index 196c612db92c114d74dd461f7484bf0636f859fe..fa7ffbe91a0fd53eaecd518125acdd4074aafd6e 100644 (file)
@@ -145,7 +145,7 @@ typedef struct profile_sharer {
   uint32_t                  prsh_do_queue: 1;
   uint32_t                  prsh_queue_run: 1;
   pthread_t                 prsh_queue_thread;
-  pthread_mutex_t           prsh_queue_mutex;
+  tvh_mutex_t               prsh_queue_mutex;
   tvh_cond_t                prsh_queue_cond;
   TAILQ_HEAD(,profile_sharer_message) prsh_queue;
   streaming_target_t        prsh_input;
index 98b0ac8b4dcf0db544e0e68bedbee3720a763188..9cf0b8751da9d5ab6131ff52c8783a5ba8cf9ba1 100644 (file)
@@ -17,7 +17,6 @@
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <pthread.h>
 #include <signal.h>
 #include "tvheadend.h"
 #include "htsbuf.h"
index a15cf240b9250d8f0a7c3a69717ea3831d6ef6cd..3f98a91d8ea9ed6601f1f5de9244335c8fdd6064 100644 (file)
@@ -73,14 +73,14 @@ typedef struct satip_rtp_session {
   uint16_t seq;
   signal_status_t sig;
   int sig_lock;
-  pthread_mutex_t lock;
+  tvh_mutex_t lock;
   http_connection_t *hc;
   sbuf_t table_data;
   void (*no_data_cb)(void *opaque);
   void *no_data_opaque;
 } satip_rtp_session_t;
 
-static pthread_mutex_t satip_rtp_lock;
+static tvh_mutex_t satip_rtp_lock;
 static pthread_t satip_rtcp_tid;
 static int satip_rtcp_run;
 static TAILQ_HEAD(, satip_rtp_session) satip_rtp_sessions;
@@ -365,9 +365,9 @@ found:
 static void
 satip_rtp_signal_status(satip_rtp_session_t *rtp, signal_status_t *sig)
 {
-  pthread_mutex_lock(&rtp->lock);
+  tvh_mutex_lock(&rtp->lock);
   rtp->sig = *sig;
-  pthread_mutex_unlock(&rtp->lock);
+  tvh_mutex_unlock(&rtp->lock);
 }
 
 static void *
@@ -386,7 +386,7 @@ satip_rtp_thread(void *aux)
   tvhdebug(LS_SATIPS, "RTP streaming to %s:%d open", peername,
            tcp ? ntohs(IP_PORT(rtp->peer)) : rtp->port);
 
-  pthread_mutex_lock(&sq->sq_mutex);
+  tvh_mutex_lock(&sq->sq_mutex);
   while (rtp->sq && !fatal) {
     sm = TAILQ_FIRST(&sq->sq_queue);
     if (sm == NULL) {
@@ -403,7 +403,7 @@ satip_rtp_thread(void *aux)
       continue;
     }
     streaming_queue_remove(sq, sm);
-    pthread_mutex_unlock(&sq->sq_mutex);
+    tvh_mutex_unlock(&sq->sq_mutex);
 
     switch (sm->sm_type) {
     case SMT_MPEGTS:
@@ -413,12 +413,12 @@ satip_rtp_thread(void *aux)
       if (r > 0)
         atomic_set(&rtp->sig_lock, 1);
       if (atomic_get(&rtp->allow_data)) {
-        pthread_mutex_lock(&rtp->lock);
+        tvh_mutex_lock(&rtp->lock);
         if (tcp)
           r = satip_rtp_tcp_loop(rtp, pktbuf_ptr(pb), r);
         else
           r = satip_rtp_loop(rtp, pktbuf_ptr(pb), r);
-        pthread_mutex_unlock(&rtp->lock);
+        tvh_mutex_unlock(&rtp->lock);
         if (r) fatal = 1;
       }
       break;
@@ -446,9 +446,9 @@ satip_rtp_thread(void *aux)
     }
 
     streaming_msg_free(sm);
-    pthread_mutex_lock(&sq->sq_mutex);
+    tvh_mutex_lock(&sq->sq_mutex);
   }
-  pthread_mutex_unlock(&sq->sq_mutex);
+  tvh_mutex_unlock(&sq->sq_mutex);
 
   tvhdebug(LS_SATIPS, "RTP streaming to %s:%d closed (%s request)%s",
            peername,
@@ -522,7 +522,7 @@ void *satip_rtp_queue(th_subscription_t *subs,
   rtp->frontend = frontend;
   rtp->dmc = *dmc;
   rtp->source = source;
-  pthread_mutex_init(&rtp->lock, NULL);
+  tvh_mutex_init(&rtp->lock, NULL);
 
   dscp = config.dscp >= 0 ? config.dscp : IPTOS_DSCP_EF;
   socket_set_dscp(rtp->fd_rtp, dscp, NULL, 0);
@@ -539,10 +539,10 @@ void *satip_rtp_queue(th_subscription_t *subs,
 
   tvhtrace(LS_SATIPS, "rtp queue %p", rtp);
 
-  pthread_mutex_lock(&satip_rtp_lock);
+  tvh_mutex_lock(&satip_rtp_lock);
   TAILQ_INSERT_TAIL(&satip_rtp_sessions, rtp, link);
-  tvhthread_create(&rtp->tid, NULL, satip_rtp_thread, rtp, "satip-rtp");
-  pthread_mutex_unlock(&satip_rtp_lock);
+  tvh_thread_create(&rtp->tid, NULL, satip_rtp_thread, rtp, "satip-rtp");
+  tvh_mutex_unlock(&satip_rtp_lock);
   return rtp;
 }
 
@@ -552,9 +552,9 @@ void satip_rtp_allow_data(void *_rtp)
 
   if (rtp == NULL)
     return;
-  pthread_mutex_lock(&satip_rtp_lock);
+  tvh_mutex_lock(&satip_rtp_lock);
   atomic_set(&rtp->allow_data, 1);
-  pthread_mutex_unlock(&satip_rtp_lock);
+  tvh_mutex_unlock(&satip_rtp_lock);
 }
 
 void satip_rtp_update_pids(void *_rtp, mpegts_apids_t *pids)
@@ -563,11 +563,11 @@ void satip_rtp_update_pids(void *_rtp, mpegts_apids_t *pids)
 
   if (rtp == NULL)
     return;
-  pthread_mutex_lock(&satip_rtp_lock);
-  pthread_mutex_lock(&rtp->lock);
+  tvh_mutex_lock(&satip_rtp_lock);
+  tvh_mutex_lock(&rtp->lock);
   mpegts_pid_copy(&rtp->pids, pids);
-  pthread_mutex_unlock(&rtp->lock);
-  pthread_mutex_unlock(&satip_rtp_lock);
+  tvh_mutex_unlock(&rtp->lock);
+  tvh_mutex_unlock(&satip_rtp_lock);
 }
 
 void satip_rtp_update_pmt_pids(void *_rtp, mpegts_apids_t *pmt_pids)
@@ -578,8 +578,8 @@ void satip_rtp_update_pmt_pids(void *_rtp, mpegts_apids_t *pmt_pids)
 
   if (rtp == NULL)
     return;
-  pthread_mutex_lock(&satip_rtp_lock);
-  pthread_mutex_lock(&rtp->lock);
+  tvh_mutex_lock(&satip_rtp_lock);
+  tvh_mutex_lock(&rtp->lock);
   TAILQ_FOREACH(tbl, &rtp->pmt_tables, link)
     if (!mpegts_pid_rexists(pmt_pids, tbl->pid))
       tbl->remove_mark = 1;
@@ -603,8 +603,8 @@ void satip_rtp_update_pmt_pids(void *_rtp, mpegts_apids_t *pmt_pids)
       free(tbl);
     }
   }
-  pthread_mutex_unlock(&rtp->lock);
-  pthread_mutex_unlock(&satip_rtp_lock);
+  tvh_mutex_unlock(&rtp->lock);
+  tvh_mutex_unlock(&satip_rtp_lock);
 }
 
 void satip_rtp_close(void *_rtp)
@@ -615,15 +615,15 @@ void satip_rtp_close(void *_rtp)
 
   if (rtp == NULL)
     return;
-  pthread_mutex_lock(&satip_rtp_lock);
+  tvh_mutex_lock(&satip_rtp_lock);
   tvhtrace(LS_SATIPS, "rtp close %p", rtp);
   TAILQ_REMOVE(&satip_rtp_sessions, rtp, link);
   sq = rtp->sq;
-  pthread_mutex_lock(&sq->sq_mutex);
+  tvh_mutex_lock(&sq->sq_mutex);
   rtp->sq = NULL;
   tvh_cond_signal(&sq->sq_cond, 0);
-  pthread_mutex_unlock(&sq->sq_mutex);
-  pthread_mutex_unlock(&satip_rtp_lock);
+  tvh_mutex_unlock(&sq->sq_mutex);
+  tvh_mutex_unlock(&satip_rtp_lock);
   pthread_join(rtp->tid, NULL);
   if (rtp->port == RTSP_TCP_DATA) {
     http_extra_destroy(rtp->hc);
@@ -637,7 +637,7 @@ void satip_rtp_close(void *_rtp)
     TAILQ_REMOVE(&rtp->pmt_tables, tbl, link);
     free(tbl);
   }
-  pthread_mutex_destroy(&rtp->lock);
+  tvh_mutex_destroy(&rtp->lock);
   free(rtp);
 }
 
@@ -860,11 +860,11 @@ int satip_rtp_status(void *_rtp, char *buf, int len)
   buf[0] = '\0';
   if (rtp == NULL)
     return 0;
-  pthread_mutex_lock(&satip_rtp_lock);
-  pthread_mutex_lock(&rtp->lock);
+  tvh_mutex_lock(&satip_rtp_lock);
+  tvh_mutex_lock(&rtp->lock);
   r = satip_status_build(rtp, buf, len);
-  pthread_mutex_unlock(&rtp->lock);
-  pthread_mutex_unlock(&satip_rtp_lock);
+  tvh_mutex_unlock(&rtp->lock);
+  tvh_mutex_unlock(&satip_rtp_lock);
   return r;
 }
 
@@ -877,9 +877,9 @@ satip_rtcp_build(satip_rtp_session_t *rtp, uint8_t *msg)
   char buf[1500];
   int len, len2;
 
-  pthread_mutex_lock(&rtp->lock);
+  tvh_mutex_lock(&rtp->lock);
   len = satip_status_build(rtp, buf, sizeof(buf));
-  pthread_mutex_unlock(&rtp->lock);
+  tvh_mutex_unlock(&rtp->lock);
 
   len = len2 = MIN(len, RTCP_PAYLOAD - 16);
   if (len == 0)
@@ -931,7 +931,7 @@ satip_rtcp_thread(void *aux)
       if (!atomic_get(&satip_rtcp_run))
         goto end;
     } while (us > 0);
-    pthread_mutex_lock(&satip_rtp_lock);
+    tvh_mutex_lock(&satip_rtp_lock);
     TAILQ_FOREACH(rtp, &satip_rtp_sessions, link) {
       if (rtp->sq == NULL || rtp->disable_rtcp) continue;
       len = satip_rtcp_build(rtp, msg);
@@ -968,7 +968,7 @@ satip_rtcp_thread(void *aux)
         }
       }
     }
-    pthread_mutex_unlock(&satip_rtp_lock);
+    tvh_mutex_unlock(&satip_rtp_lock);
   }
 end:
   return NULL;
@@ -980,14 +980,14 @@ end:
 void satip_rtp_init(int boot)
 {
   TAILQ_INIT(&satip_rtp_sessions);
-  pthread_mutex_init(&satip_rtp_lock, NULL);
+  tvh_mutex_init(&satip_rtp_lock, NULL);
 
   if (boot)
     atomic_set(&satip_rtcp_run, 0);
 
   if (!boot && !atomic_get(&satip_rtcp_run)) {
     atomic_set(&satip_rtcp_run, 1);
-    tvhthread_create(&satip_rtcp_tid, NULL, satip_rtcp_thread, NULL, "satip-rtcp");
+    tvh_thread_create(&satip_rtcp_tid, NULL, satip_rtcp_thread, NULL, "satip-rtcp");
   }
 }
 
@@ -999,7 +999,7 @@ void satip_rtp_done(void)
   assert(TAILQ_EMPTY(&satip_rtp_sessions));
   if (atomic_get(&satip_rtcp_run)) {
     atomic_set(&satip_rtcp_run, 0);
-    pthread_kill(satip_rtcp_tid, SIGTERM);
+    tvh_thread_kill(satip_rtcp_tid, SIGTERM);
     pthread_join(satip_rtcp_tid, NULL);
   }
 }
index 75cee0375cc0f9103841bfc5c84b0fe0287f4ec3..483263d41ec19ff35b11a17260d048e7c784571f 100644 (file)
@@ -88,7 +88,7 @@ static int rtsp_rewrite_pmt = 0;
 static int rtsp_muxcnf = MUXCNF_AUTO;
 static void *rtsp_server = NULL;
 static TAILQ_HEAD(,session) rtsp_sessions;
-static pthread_mutex_t rtsp_lock;
+static tvh_mutex_t rtsp_lock;
 
 static void rtsp_close_session(session_t *rs);
 static void rtsp_free_session(session_t *rs);
@@ -112,7 +112,7 @@ satip_rtsp_delsys(int fe, int *findex, const char **ftype)
 
   if (fe < 1)
     return DVB_SYS_NONE;
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   i = satip_server_conf.satip_dvbs;
   if (fe <= i) {
     res = DVB_SYS_DVBS;
@@ -168,10 +168,10 @@ satip_rtsp_delsys(int fe, int *findex, const char **ftype)
     t = "ATSC-C";
     goto result;
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   return DVB_SYS_NONE;
 result:
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   *findex = i;
   if (ftype)
     *ftype = t;
@@ -253,21 +253,21 @@ rtsp_session_timer_cb(void *aux)
   session_t *rs = aux;
 
   tvhwarn(LS_SATIPS, "-/%s/%i: session closed (timeout)", rs->session, rs->stream);
-  pthread_mutex_unlock(&global_lock);
-  pthread_mutex_lock(&rtsp_lock);
+  tvh_mutex_unlock(&global_lock);
+  tvh_mutex_lock(&rtsp_lock);
   rtsp_close_session(rs);
   rtsp_free_session(rs);
-  pthread_mutex_unlock(&rtsp_lock);
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_unlock(&rtsp_lock);
+  tvh_mutex_lock(&global_lock);
 }
 
 static inline void
 rtsp_rearm_session_timer(session_t *rs)
 {
   if (!rs->shutdown_on_close || (rs->rtp_peer_port == RTSP_TCP_DATA)) {
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     mtimer_arm_rel(&rs->timer, rtsp_session_timer_cb, rs, sec2mono(RTSP_TIMEOUT));
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
   }
 }
 
@@ -385,10 +385,10 @@ rtsp_slave_add
   char buf[128];
   slave_subscription_t *sub = calloc(1, sizeof(*sub));
 
-  pthread_mutex_lock(&master->s_stream_mutex);
+  tvh_mutex_lock(&master->s_stream_mutex);
   if (master->s_slaves_pids == NULL)
     master->s_slaves_pids = mpegts_pid_alloc();
-  pthread_mutex_unlock(&master->s_stream_mutex);
+  tvh_mutex_unlock(&master->s_stream_mutex);
   master->s_link(master, slave);
   sub->service = slave;
   profile_chain_init(&sub->prch, NULL, slave, 0);
@@ -485,9 +485,9 @@ rtsp_validate_service(mpegts_service_t *s, mpegts_apids_t *pids)
   int av = 0, enc = 0;
   elementary_stream_t *st;
 
-  pthread_mutex_lock(&s->s_stream_mutex);
+  tvh_mutex_lock(&s->s_stream_mutex);
   if (s->s_components.set_pmt_pid <= 0 || s->s_components.set_pcr_pid <= 0) {
-    pthread_mutex_unlock(&s->s_stream_mutex);
+    tvh_mutex_unlock(&s->s_stream_mutex);
     return 0;
   }
   TAILQ_FOREACH(st, &s->s_components.set_all, es_link) {
@@ -498,7 +498,7 @@ rtsp_validate_service(mpegts_service_t *s, mpegts_apids_t *pids)
         if ((SCT_ISVIDEO(st->es_type) || SCT_ISAUDIO(st->es_type)))
           av = 1;
   }
-  pthread_mutex_unlock(&s->s_stream_mutex);
+  tvh_mutex_unlock(&s->s_stream_mutex);
   if (enc == 0 || av == 0)
     return 0;
   return pids == NULL ||
@@ -597,7 +597,7 @@ rtsp_start
   char buf[384];
   int res = HTTP_STATUS_NOT_ALLOWED, qsize = 3000000, created = 0, weight;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   weight = satip_server_conf.satip_weight;
   if (satip_server_conf.satip_allow_remote_weight && rs->weight)
     weight = rs->weight;
@@ -737,12 +737,12 @@ pids:
     satip_rtp_allow_data(rs->rtp_handle);
   }
   rtsp_manage_descramble(rs);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   return 0;
 
 endclean:
   rtsp_clean(rs, 0);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   return res;
 }
 
@@ -1296,13 +1296,13 @@ rtsp_process_options(http_connection_t *hc)
 
   if (hc->hc_session) {
     found = 0;
-    pthread_mutex_lock(&rtsp_lock);
+    tvh_mutex_lock(&rtsp_lock);
     TAILQ_FOREACH(rs, &rtsp_sessions, link)
       if (!strcmp(rs->session, hc->hc_session)) {
         rtsp_rearm_session_timer(rs);
         found = 1;
       }
-    pthread_mutex_unlock(&rtsp_lock);
+    tvh_mutex_unlock(&rtsp_lock);
     if (!found) {
       http_error(hc, HTTP_STATUS_BAD_SESSION);
       return 0;
@@ -1339,7 +1339,7 @@ rtsp_describe_header(session_t *rs, htsbuf_queue_t *q)
                  strchr(rtsp_ip, ':') ? "IP6" : "IP4",
                  rtsp_ip);
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   htsbuf_qprintf(q, "s=SatIPServer:1 %d",
                  satip_server_conf.satip_dvbs +
                  satip_server_conf.satip_dvbs2);
@@ -1353,7 +1353,7 @@ rtsp_describe_header(session_t *rs, htsbuf_queue_t *q)
     htsbuf_qprintf(q, " %d\r\n", dvbt);
   else
     htsbuf_append(q, "\r\n", 1);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   htsbuf_append_str(q, "t=0 0\r\n");
 }
@@ -1408,16 +1408,16 @@ rtsp_process_describe(http_connection_t *hc)
 
   stream = rtsp_parse_args(hc, u);
 
-  pthread_mutex_lock(&rtsp_lock);
+  tvh_mutex_lock(&rtsp_lock);
 
   if (TAILQ_FIRST(&hc->hc_req_args)) {
     if (stream < 0) {
-      pthread_mutex_unlock(&rtsp_lock);
+      tvh_mutex_unlock(&rtsp_lock);
       goto error;
     }
     r = rtsp_parse_cmd(hc, stream, RTSP_CMD_DESCRIBE, &rs, &valid);
     if (r) {
-      pthread_mutex_unlock(&rtsp_lock);
+      tvh_mutex_unlock(&rtsp_lock);
       goto error;
     }
   }
@@ -1439,7 +1439,7 @@ rtsp_process_describe(http_connection_t *hc)
     }
     rtsp_describe_session(rs, &q);
   }
-  pthread_mutex_unlock(&rtsp_lock);
+  tvh_mutex_unlock(&rtsp_lock);
 
   if (first) {
     if (hc->hc_session) {
@@ -1497,7 +1497,7 @@ rtsp_process_play(http_connection_t *hc, int cmd)
   if ((stream = rtsp_parse_args(hc, u)) < 0)
     goto error2;
 
-  pthread_mutex_lock(&rtsp_lock);
+  tvh_mutex_lock(&rtsp_lock);
 
   errcode = rtsp_parse_cmd(hc, stream, cmd, &rs, &valid);
 
@@ -1552,7 +1552,7 @@ rtsp_process_play(http_connection_t *hc, int cmd)
     http_arg_set(&args, "RTP-Info", buf);
   }
 
-  pthread_mutex_unlock(&rtsp_lock);
+  tvh_mutex_unlock(&rtsp_lock);
 
   http_send_begin(hc);
   http_send_header(hc, HTTP_STATUS_OK, NULL, 0, NULL, NULL, 0, NULL, NULL, &args);
@@ -1561,7 +1561,7 @@ rtsp_process_play(http_connection_t *hc, int cmd)
   goto end;
 
 error:
-  pthread_mutex_unlock(&rtsp_lock);
+  tvh_mutex_unlock(&rtsp_lock);
 error2:
   http_error(hc, errcode);
 
@@ -1591,16 +1591,16 @@ rtsp_process_teardown(http_connection_t *hc)
   tvhdebug(LS_SATIPS, "-/%s/%i: teardown from %s:%d",
            hc->hc_session, stream, hc->hc_peer_ipstr, ntohs(IP_PORT(*hc->hc_peer)));
 
-  pthread_mutex_lock(&rtsp_lock);
+  tvh_mutex_lock(&rtsp_lock);
   rs = rtsp_find_session(hc, stream);
   if (!rs || stream != rs->stream) {
-    pthread_mutex_unlock(&rtsp_lock);
+    tvh_mutex_unlock(&rtsp_lock);
     http_error(hc, !rs ? HTTP_STATUS_BAD_SESSION : HTTP_STATUS_NOT_FOUND);
   } else {
     strlcpy(session, rs->session, sizeof(session));
     rtsp_close_session(rs);
     rtsp_free_session(rs);
-    pthread_mutex_unlock(&rtsp_lock);
+    tvh_mutex_unlock(&rtsp_lock);
     http_arg_init(&args);
     http_arg_set(&args, "Session", session);
     http_send_begin(hc);
@@ -1641,7 +1641,7 @@ rtsp_flush_requests(http_connection_t *hc)
 {
   struct session *rs, *rs_next;
 
-  pthread_mutex_lock(&rtsp_lock);
+  tvh_mutex_lock(&rtsp_lock);
   for (rs = TAILQ_FIRST(&rtsp_sessions); rs; rs = rs_next) {
     rs_next = TAILQ_NEXT(rs, link);
     if (rs->shutdown_on_close == hc) {
@@ -1654,7 +1654,7 @@ rtsp_flush_requests(http_connection_t *hc)
       rs->state = STATE_SETUP;
     }
   }
-  pthread_mutex_unlock(&rtsp_lock);
+  tvh_mutex_unlock(&rtsp_lock);
 }
 
 /*
@@ -1728,7 +1728,7 @@ rtsp_serve(int fd, void **opaque, struct sockaddr_storage *peer,
   tcp = tcp_connection_launch(fd, 1, rtsp_stream_status, &aa);
 
   /* Note: global_lock held on entry */
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   hc.hc_subsys  = LS_SATIPS;
   hc.hc_fd      = fd;
@@ -1744,7 +1744,7 @@ rtsp_serve(int fd, void **opaque, struct sockaddr_storage *peer,
   close(fd);
 
   /* Note: leave global_lock held for parent */
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   *opaque = NULL;
 
   tcp_connection_land(tcp);
@@ -1767,11 +1767,11 @@ rtsp_close_session(session_t *rs)
   rs->rtp_udp_bound = 0;
   rs->shutdown_on_close = NULL;
   rs->tcp_data = NULL;
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   mpegts_pid_reset(&rs->pids);
   rtsp_clean(rs, 1);
   mtimer_disarm(&rs->timer);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
 
 /*
@@ -1781,9 +1781,9 @@ static void
 rtsp_free_session(session_t *rs)
 {
   TAILQ_REMOVE(&rtsp_sessions, rs, link);
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   mtimer_disarm(&rs->timer);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   mpegts_pid_done(&rs->pids);
   free(rs->peer_ipstr);
   free(rs);
@@ -1797,13 +1797,13 @@ rtsp_close_sessions(void)
 {
   session_t *rs;
   do {
-    pthread_mutex_lock(&rtsp_lock);
+    tvh_mutex_lock(&rtsp_lock);
     rs = TAILQ_FIRST(&rtsp_sessions);
     if (rs) {
       rtsp_close_session(rs);
       rtsp_free_session(rs);
     }
-    pthread_mutex_unlock(&rtsp_lock);
+    tvh_mutex_unlock(&rtsp_lock);
   } while (rs != NULL);
 }
 
@@ -1826,7 +1826,7 @@ void satip_server_rtsp_init
     uuid_random(rnd, sizeof(rnd));
     session_number = *(uint32_t *)rnd;
     TAILQ_INIT(&rtsp_sessions);
-    pthread_mutex_init(&rtsp_lock, NULL);
+    tvh_mutex_init(&rtsp_lock, NULL);
     satip_rtp_init(1);
   }
   if (rtsp_port != port && rtsp_server) {
@@ -1863,12 +1863,12 @@ void satip_server_rtsp_register(void)
 
 void satip_server_rtsp_done(void)
 {
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   if (rtsp_server)
     tcp_server_delete(rtsp_server);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   rtsp_close_sessions();
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   rtsp_server = NULL;
   rtsp_port = -1;
   rtsp_nat_port = -1;
@@ -1877,5 +1877,5 @@ void satip_server_rtsp_done(void)
   free(rtsp_nat_ip);
   rtsp_ip = rtp_src_ip = rtsp_nat_ip = NULL;
   satip_rtp_done();
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
index c5003df4c32ee958bba7ebff1e79643dfe86c52d..6168279ec274065dae94f0855c9ae445ae682b23 100644 (file)
@@ -35,7 +35,7 @@ static char *satip_server_bindaddr;
 static int satip_server_rtsp_port;
 static int satip_server_rtsp_port_locked;
 static upnp_service_t *satips_upnp_discovery;
-static pthread_mutex_t satip_server_reinit;
+static tvh_mutex_t satip_server_reinit;
 
 static void satip_server_save(void);
 
@@ -138,7 +138,7 @@ satip_server_http_xml(http_connection_t *hc)
 
   htsbuf_queue_init(&q, 0);
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   LIST_FOREACH(mn, &mpegts_network_all, mn_global_link) {
     if (mn->mn_satip_source == 0)
       continue;
@@ -184,7 +184,7 @@ satip_server_http_xml(http_connection_t *hc)
       }
     }
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   if (!dvbs)
     srcs = 0;
 
@@ -997,9 +997,9 @@ static void satip_server_init_common(const char *prefix, int announce)
   rtp_src_ip = strdup(satip_server_conf.satip_rtp_src_ip ?: "");
 
   if (announce)
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
 
-  pthread_mutex_lock(&satip_server_reinit);
+  tvh_mutex_lock(&satip_server_reinit);
 
   satip_server_rtsp_init(http_server_ip, satip_server_rtsp_port, descramble, rewrite_pmt, muxcnf, rtp_src_ip, nat_ip, nat_port);
   satip_server_info(prefix, descramble, muxcnf);
@@ -1007,10 +1007,10 @@ static void satip_server_init_common(const char *prefix, int announce)
   if (announce)
     satips_upnp_send_announce();
 
-  pthread_mutex_unlock(&satip_server_reinit);
+  tvh_mutex_unlock(&satip_server_reinit);
 
   if (announce)
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
 
   free(nat_ip);
   free(rtp_src_ip);
@@ -1026,11 +1026,11 @@ static void satip_server_save(void)
     if (satip_server_rtsp_port > 0) {
       satip_server_init_common("re", 1);
     } else {
-      pthread_mutex_unlock(&global_lock);
+      tvh_mutex_unlock(&global_lock);
       tvhinfo(LS_SATIPS, "SAT>IP Server shutdown");
       satip_server_rtsp_done();
       satips_upnp_send_byebye();
-      pthread_mutex_lock(&global_lock);
+      tvh_mutex_lock(&global_lock);
     }
   }
 }
@@ -1050,7 +1050,7 @@ void satip_server_boot(void)
 
 void satip_server_init(const char *bindaddr, int rtsp_port)
 {
-  pthread_mutex_init(&satip_server_reinit, NULL);
+  tvh_mutex_init(&satip_server_reinit, NULL);
 
   http_server_ip = NULL;
 
index 7738e9b31d8d631c2b48ed55d6edea295d590224..a53c85f5c73d39af1c2bdf9676bc1fb8efe43b09 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <pthread.h>
-#include <assert.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <ctype.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-
 #include "tvheadend.h"
 #include "service.h"
 #include "subscriptions.h"
@@ -111,9 +96,9 @@ service_class_encrypted_get ( void *p )
 {
   static int t;
   service_t *s = p;
-  pthread_mutex_lock(&s->s_stream_mutex);
+  tvh_mutex_lock(&s->s_stream_mutex);
   t = service_is_encrypted(s);
-  pthread_mutex_unlock(&s->s_stream_mutex);
+  tvh_mutex_unlock(&s->s_stream_mutex);
   return &t;
 }
 
@@ -275,7 +260,7 @@ service_stop(service_t *t)
 
   descrambler_service_stop(t);
 
-  pthread_mutex_lock(&t->s_stream_mutex);
+  tvh_mutex_lock(&t->s_stream_mutex);
 
   t->s_tt_commercial_advice = COMMERCIAL_UNKNOWN;
 
@@ -287,7 +272,7 @@ service_stop(service_t *t)
   t->s_status = SERVICE_IDLE;
   tvhlog_limit_reset(&t->s_tei_log);
 
-  pthread_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
 }
 
 
@@ -337,9 +322,9 @@ service_start(service_t *t, int instance, int weight, int flags,
   t->s_scrambled_pass   = !!(flags & SUBSCRIPTION_NODESCR);
   t->s_start_time       = mclk();
 
-  pthread_mutex_lock(&t->s_stream_mutex);
+  tvh_mutex_lock(&t->s_stream_mutex);
   elementary_set_filter_build(&t->s_components);
-  pthread_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
 
   descrambler_caid_changed(t);
 
@@ -348,7 +333,7 @@ service_start(service_t *t, int instance, int weight, int flags,
 
   descrambler_service_start(t);
 
-  pthread_mutex_lock(&t->s_stream_mutex);
+  tvh_mutex_lock(&t->s_stream_mutex);
 
   t->s_status = SERVICE_RUNNING;
 
@@ -357,7 +342,7 @@ service_start(service_t *t, int instance, int weight, int flags,
    */
   elementary_set_init_filter_streams(&t->s_components);
 
-  pthread_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
 
   if(t->s_grace_period != NULL)
     stimeout = t->s_grace_period(t);
@@ -712,7 +697,7 @@ service_create0
   else
     TAILQ_INSERT_TAIL(&service_all, t, s_all_link);
 
-  pthread_mutex_init(&t->s_stream_mutex, NULL);
+  tvh_mutex_init(&t->s_stream_mutex, NULL);
   t->s_type = service_type;
   t->s_type_user = ST_UNSET;
   t->s_source_type = source_type;
@@ -801,7 +786,7 @@ service_data_timeout(void *aux)
   service_t *t = aux;
   int flags = 0;
 
-  pthread_mutex_lock(&t->s_stream_mutex);
+  tvh_mutex_lock(&t->s_stream_mutex);
 
   if(!(t->s_streaming_status & TSS_PACKETS))
     flags |= TSS_GRACEPERIOD;
@@ -811,7 +796,7 @@ service_data_timeout(void *aux)
     service_set_streaming_status_flags(t, flags);
   t->s_streaming_live &= ~TSS_LIVE;
 
-  pthread_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
 
   if (t->s_timeout > 0)
     mtimer_arm_rel(&t->s_receive_timer, service_data_timeout, t,
@@ -1032,9 +1017,9 @@ service_restart(service_t *t)
   tvhtrace(LS_SERVICE, "restarting service '%s'", t->s_nicename);
 
   if (t->s_type == STYPE_STD) {
-    pthread_mutex_lock(&t->s_stream_mutex);
+    tvh_mutex_lock(&t->s_stream_mutex);
     service_restart_streams(t);
-    pthread_mutex_unlock(&t->s_stream_mutex);
+    tvh_mutex_unlock(&t->s_stream_mutex);
 
     descrambler_caid_changed(t);
   }
@@ -1087,7 +1072,7 @@ service_update_elementary_stream(service_t *t, elementary_stream_t *src)
  *
  */
 
-static pthread_mutex_t pending_save_mutex;
+static tvh_mutex_t pending_save_mutex;
 static tvh_cond_t pending_save_cond;
 static struct service_queue pending_save_queue;
 
@@ -1100,7 +1085,7 @@ service_request_save(service_t *t)
   if (t->s_type != STYPE_STD)
     return;
 
-  pthread_mutex_lock(&pending_save_mutex);
+  tvh_mutex_lock(&pending_save_mutex);
 
   if(!t->s_ps_onqueue) {
     t->s_ps_onqueue = 1;
@@ -1109,7 +1094,7 @@ service_request_save(service_t *t)
     tvh_cond_signal(&pending_save_cond, 0);
   }
 
-  pthread_mutex_unlock(&pending_save_mutex);
+  tvh_mutex_unlock(&pending_save_mutex);
 }
 
 
@@ -1151,7 +1136,7 @@ service_saver(void *aux)
 {
   service_t *t;
 
-  pthread_mutex_lock(&pending_save_mutex);
+  tvh_mutex_lock(&pending_save_mutex);
 
   while(tvheadend_is_running()) {
 
@@ -1164,18 +1149,18 @@ service_saver(void *aux)
     TAILQ_REMOVE(&pending_save_queue, t, s_ps_link);
     t->s_ps_onqueue = 0;
 
-    pthread_mutex_unlock(&pending_save_mutex);
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_unlock(&pending_save_mutex);
+    tvh_mutex_lock(&global_lock);
 
     if(t->s_status != SERVICE_ZOMBIE && t->s_config_save)
       idnode_changed(&t->s_id);
     service_unref(t);
 
-    pthread_mutex_unlock(&global_lock);
-    pthread_mutex_lock(&pending_save_mutex);
+    tvh_mutex_unlock(&global_lock);
+    tvh_mutex_lock(&pending_save_mutex);
   }
 
-  pthread_mutex_unlock(&pending_save_mutex);
+  tvh_mutex_unlock(&pending_save_mutex);
   return NULL;
 }
 
@@ -1221,9 +1206,9 @@ service_init(void)
   TAILQ_INIT(&service_raw_remove);
   idclass_register(&service_class);
   idclass_register(&service_raw_class);
-  pthread_mutex_init(&pending_save_mutex, NULL);
-  tvh_cond_init(&pending_save_cond);
-  tvhthread_create(&service_saver_tid, NULL, service_saver, NULL, "service");
+  tvh_mutex_init(&pending_save_mutex, NULL);
+  tvh_cond_init(&pending_save_cond, 1);
+  tvh_thread_create(&service_saver_tid, NULL, service_saver, NULL, "service");
 }
 
 void
@@ -1231,16 +1216,16 @@ service_done(void)
 {
   service_t *t;
 
-  pthread_mutex_lock(&pending_save_mutex);
+  tvh_mutex_lock(&pending_save_mutex);
   tvh_cond_signal(&pending_save_cond, 0);
-  pthread_mutex_unlock(&pending_save_mutex);
+  tvh_mutex_unlock(&pending_save_mutex);
   pthread_join(service_saver_tid, NULL);
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   while ((t = TAILQ_FIRST(&service_raw_remove)) != NULL)
     service_destroy(t, 0);
   memoryinfo_unregister(&services_memoryinfo);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
 
 /**
@@ -1287,9 +1272,9 @@ service_nicename(service_t *t)
 const char *
 service_adapter_nicename(service_t *t, char *buf, size_t len)
 {
-  pthread_mutex_lock(&t->s_stream_mutex);
+  tvh_mutex_lock(&t->s_stream_mutex);
   service_make_nicename0(t, buf, len, 1);
-  pthread_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
   return buf;
 }
 
@@ -1555,7 +1540,7 @@ void service_save ( service_t *t, htsmsg_t *m )
   htsmsg_add_u32(m, "pcr", t->s_components.set_pcr_pid);
   htsmsg_add_u32(m, "pmt", t->s_components.set_pmt_pid);
 
-  pthread_mutex_lock(&t->s_stream_mutex);
+  tvh_mutex_lock(&t->s_stream_mutex);
 
   list = htsmsg_create_list();
   TAILQ_FOREACH(st, &t->s_components.set_all, es_link) {
@@ -1615,7 +1600,7 @@ void service_save ( service_t *t, htsmsg_t *m )
 
   hbbtv = htsmsg_copy(t->s_hbbtv);
 
-  pthread_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
 
   htsmsg_add_msg(m, "stream", list);
   if (hbbtv)
@@ -1718,7 +1703,7 @@ void service_load ( service_t *t, htsmsg_t *c )
 
   idnode_load(&t->s_id, c);
 
-  pthread_mutex_lock(&t->s_stream_mutex);
+  tvh_mutex_lock(&t->s_stream_mutex);
   if(!htsmsg_get_s32(c, "verified", &s32))
     t->s_verified = s32;
   else
@@ -1807,5 +1792,5 @@ void service_load ( service_t *t, htsmsg_t *c )
   else
     elementary_stream_type_destroy(&t->s_components, SCT_PCR);
   elementary_set_sort_streams(&t->s_components);
-  pthread_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
 }
index 1791b48997a2b02de194750057b63fbfb03d01af..b8359daa553bf20bb8e8fc6bd9c6e731b3641511 100644 (file)
@@ -311,7 +311,7 @@ typedef struct service {
    * This mutex also protects all elementary_stream_t instances for this
    * transport.
    */
-  pthread_mutex_t s_stream_mutex;
+  tvh_mutex_t s_stream_mutex;
 
   /**
    *
index 84e77873136ba535e8a68fcebf1f1cf787ea32d6..52c735f1575dbadfe684b36b780a917b62d7f653 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <assert.h>
 #include <ctype.h>
-#include <pthread.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
 
 #include "tvheadend.h"
 #include "channels.h"
@@ -99,10 +92,10 @@ service_mapper_start ( const service_mapper_conf_t *conf, htsmsg_t *uuids )
     tvhtrace(LS_SERVICE_MAPPER, "  enabled");
 
     /* Get service info */
-    pthread_mutex_lock(&s->s_stream_mutex);
+    tvh_mutex_lock(&s->s_stream_mutex);
     e  = service_is_encrypted(s);
     tr = service_is_tv(s) || service_is_radio(s);
-    pthread_mutex_unlock(&s->s_stream_mutex);
+    tvh_mutex_unlock(&s->s_stream_mutex);
 
     /* Skip non-TV / Radio */
     if (!tr) continue;
@@ -373,7 +366,7 @@ service_mapper_thread ( void *aux )
   prch.prch_st = &prch.prch_sq.sq_st;
   sq = &prch.prch_sq;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 
   while (tvheadend_is_running()) {
     
@@ -416,7 +409,7 @@ service_mapper_thread ( void *aux )
     service_ref(s);
     service_mapper_stat.active = s;
     api_service_mapper_notify();
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
 
     /* Wait */
     run = 1;
@@ -431,9 +424,9 @@ service_mapper_thread ( void *aux )
       }
 
       if (timeout_other < mclk()) {
-        pthread_mutex_lock(&global_lock);
+        tvh_mutex_lock(&global_lock);
         r = service_is_other(s);
-        pthread_mutex_unlock(&global_lock);
+        tvh_mutex_unlock(&global_lock);
         if (r) {
           run = 0;
           err = streaming_code2txt(SM_CODE_OTHER_SERVICE);
@@ -442,7 +435,7 @@ service_mapper_thread ( void *aux )
       }
 
       /* Wait for message */
-      pthread_mutex_lock(&sq->sq_mutex);
+      tvh_mutex_lock(&sq->sq_mutex);
       while((sm = TAILQ_FIRST(&sq->sq_queue)) == NULL) {
         tvh_cond_wait(&sq->sq_cond, &sq->sq_mutex);
         if (!tvheadend_is_running())
@@ -450,7 +443,7 @@ service_mapper_thread ( void *aux )
       }
       if (sm)
         streaming_queue_remove(sq, sm);
-      pthread_mutex_unlock(&sq->sq_mutex);
+      tvh_mutex_unlock(&sq->sq_mutex);
       if (!tvheadend_is_running())
         break;
 
@@ -482,11 +475,11 @@ service_mapper_thread ( void *aux )
     if (!tvheadend_is_running())
       break;
 
-    pthread_mutex_lock(&sq->sq_mutex);
+    tvh_mutex_lock(&sq->sq_mutex);
     streaming_queue_clear(&sq->sq_queue);
-    pthread_mutex_unlock(&sq->sq_mutex);
+    tvh_mutex_unlock(&sq->sq_mutex);
  
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
     subscription_unsubscribe(sub, UNSUBSCRIBE_FINAL);
 
     if(err) {
@@ -500,7 +493,7 @@ service_mapper_thread ( void *aux )
     api_service_mapper_notify();
   }
 
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   profile_chain_close(&prch);
   return NULL;
 }
@@ -686,8 +679,8 @@ void service_mapper_init ( void )
 
   TAILQ_INIT(&service_mapper_queue);
   idclass_register(&service_mapper_conf_class);
-  tvh_cond_init(&service_mapper_cond);
-  tvhthread_create(&service_mapper_tid, NULL, service_mapper_thread, NULL, "svcmap");
+  tvh_cond_init(&service_mapper_cond, 1);
+  tvh_thread_create(&service_mapper_tid, NULL, service_mapper_thread, NULL, "svcmap");
 
   /* Defaults */
   memset(&service_mapper_conf, 0, sizeof(service_mapper_conf));
index 0e25c4634a4a12f96f2539919c9ecb0abc014997..ca54ca4b12abdb2aa3a98f18096a7c48738ce4e8 100644 (file)
@@ -41,7 +41,7 @@
 
 extern char **environ;
 
-pthread_mutex_t spawn_mutex = PTHREAD_MUTEX_INITIALIZER;
+tvh_mutex_t spawn_mutex = { .mutex = PTHREAD_MUTEX_INITIALIZER };
 
 static LIST_HEAD(, spawn) spawns;
 
@@ -247,7 +247,7 @@ spawn_reap(pid_t wpid, char *stxt, size_t stxtlen)
     return 0;
   }
 
-  pthread_mutex_lock(&spawn_mutex);
+  tvh_mutex_lock(&spawn_mutex);
   LIST_FOREACH(s, &spawns, link)
     if(s->pid == pid)
       break;
@@ -276,7 +276,7 @@ spawn_reap(pid_t wpid, char *stxt, size_t stxtlen)
     free((void *)s->name);
     free(s);
   }
-  pthread_mutex_unlock(&spawn_mutex);
+  tvh_mutex_unlock(&spawn_mutex);
   return res;
 }
 
@@ -298,7 +298,7 @@ spawn_reaper(void)
   } while (1);
 
   /* forced kill for expired PIDs */
-  pthread_mutex_lock(&spawn_mutex);
+  tvh_mutex_lock(&spawn_mutex);
   LIST_FOREACH(s, &spawns, link)
     if (s->killed && s->killed < mclk()) {
       /* kill the whole process group */
@@ -306,7 +306,7 @@ spawn_reaper(void)
       if (r && errno == EPERM)
         tvherror(LS_SPAWN, "Unable to kill task pid %d (not enough permissions)", s->pid);
     }
-  pthread_mutex_unlock(&spawn_mutex);
+  tvh_mutex_unlock(&spawn_mutex);
 }
 
 /**
@@ -321,7 +321,7 @@ spawn_kill(pid_t pid, int sig, int timeout)
   if (pid > 0) {
     spawn_reaper();
 
-    pthread_mutex_lock(&spawn_mutex);
+    tvh_mutex_lock(&spawn_mutex);
     LIST_FOREACH(s, &spawns, link)
       if(s->pid == pid)
         break;
@@ -336,7 +336,7 @@ spawn_kill(pid_t pid, int sig, int timeout)
         r = -errno;
       }
     }
-    pthread_mutex_unlock(&spawn_mutex);
+    tvh_mutex_unlock(&spawn_mutex);
   }
   return r;
 }
@@ -350,9 +350,9 @@ spawn_enq(const char *name, int pid)
   spawn_t *s = calloc(1, sizeof(spawn_t));
   s->name = strdup(name);
   s->pid = pid;
-  pthread_mutex_lock(&spawn_mutex);
+  tvh_mutex_lock(&spawn_mutex);
   LIST_INSERT_HEAD(&spawns, s, link);
-  pthread_mutex_unlock(&spawn_mutex);
+  tvh_mutex_unlock(&spawn_mutex);
   return s;
 }
 
@@ -514,17 +514,17 @@ spawn_and_give_stdout(const char *prog, char *argv[], char *envp[],
 
   maxfd = sysconf(_SC_OPEN_MAX);
 
-  pthread_mutex_lock(&fork_lock);
+  tvh_mutex_lock(&fork_lock);
 
   if(pipe(fd) == -1) {
-    pthread_mutex_unlock(&fork_lock);
+    tvh_mutex_unlock(&fork_lock);
     return -1;
   }
 
   p = fork();
 
   if(p == -1) {
-    pthread_mutex_unlock(&fork_lock);
+    tvh_mutex_unlock(&fork_lock);
     close(fd[0]);
     close(fd[1]);
     tvherror(LS_SPAWN, "Unable to fork() for \"%s\" -- %s",
@@ -563,7 +563,7 @@ spawn_and_give_stdout(const char *prog, char *argv[], char *envp[],
     exit(1);
   }
 
-  pthread_mutex_unlock(&fork_lock);
+  tvh_mutex_unlock(&fork_lock);
 
   spawn_enq(prog, p);
 
@@ -640,10 +640,10 @@ spawn_with_passthrough(const char *prog, char *argv[], char *envp[],
 
   maxfd = sysconf(_SC_OPEN_MAX);
 
-  pthread_mutex_lock(&fork_lock);
+  tvh_mutex_lock(&fork_lock);
 
   if(pipe(fd) == -1) {
-    pthread_mutex_unlock(&fork_lock);
+    tvh_mutex_unlock(&fork_lock);
     // do not pass the local variable outside
     if (argv[0] == bin)
       argv[0] = NULL;
@@ -653,7 +653,7 @@ spawn_with_passthrough(const char *prog, char *argv[], char *envp[],
   p = fork();
 
   if(p == -1) {
-    pthread_mutex_unlock(&fork_lock);
+    tvh_mutex_unlock(&fork_lock);
     close(fd[0]);
     close(fd[1]);
     tvherror(LS_SPAWN, "Unable to fork() for \"%s\" -- %s",
@@ -699,7 +699,7 @@ spawn_with_passthrough(const char *prog, char *argv[], char *envp[],
     exit(1);
   }
 
-  pthread_mutex_unlock(&fork_lock);
+  tvh_mutex_unlock(&fork_lock);
 
   spawn_enq(prog, p);
 
@@ -742,12 +742,12 @@ spawnv(const char *prog, char *argv[], pid_t *pid, int redir_stdout, int redir_s
 
   maxfd = sysconf(_SC_OPEN_MAX);
 
-  pthread_mutex_lock(&fork_lock);
+  tvh_mutex_lock(&fork_lock);
 
   p = fork();
 
   if(p == -1) {
-    pthread_mutex_unlock(&fork_lock);
+    tvh_mutex_unlock(&fork_lock);
     tvherror(LS_SPAWN, "Unable to fork() for \"%s\" -- %s",
             prog, strerror(errno));
     // do not pass the local variable outside
@@ -786,7 +786,7 @@ spawnv(const char *prog, char *argv[], pid_t *pid, int redir_stdout, int redir_s
     exit(1);
   }
 
-  pthread_mutex_unlock(&fork_lock);
+  tvh_mutex_unlock(&fork_lock);
 
   spawn_enq(prog, p);
 
@@ -821,7 +821,7 @@ void spawn_done(void)
   spawn_t *s;
 
   atomic_set(&spawn_pipe_running, 0);
-  pthread_kill(spawn_pipe_tid, SIGTERM);
+  tvh_thread_kill(spawn_pipe_tid, SIGTERM);
   pthread_join(spawn_pipe_tid, NULL);
   tvh_pipe_close(&spawn_pipe_error);
   tvh_pipe_close(&spawn_pipe_info);
index a2456c0457ff4309e1127656c8e0b0e377837ca3..bcd504412649c7188bd9f1ba4832b85d203c8f29 100644 (file)
@@ -74,7 +74,7 @@ streaming_queue_deliver(void *opauqe, streaming_message_t *sm)
 {
   streaming_queue_t *sq = opauqe;
 
-  pthread_mutex_lock(&sq->sq_mutex);
+  tvh_mutex_lock(&sq->sq_mutex);
 
   /* queue size protection */
   if (sq->sq_maxsize && sq->sq_maxsize < sq->sq_size) {
@@ -85,7 +85,7 @@ streaming_queue_deliver(void *opauqe, streaming_message_t *sm)
   }
 
   tvh_cond_signal(&sq->sq_cond, 0);
-  pthread_mutex_unlock(&sq->sq_mutex);
+  tvh_mutex_unlock(&sq->sq_mutex);
 }
 
 /**
@@ -97,9 +97,9 @@ streaming_queue_info(void *opaque, htsmsg_t *list)
   streaming_queue_t *sq = opaque;
   size_t size;
   char buf[256];
-  pthread_mutex_lock(&sq->sq_mutex);
+  tvh_mutex_lock(&sq->sq_mutex);
   size = sq->sq_size;
-  pthread_mutex_unlock(&sq->sq_mutex);
+  tvh_mutex_unlock(&sq->sq_mutex);
   snprintf(buf, sizeof(buf), "streaming queue %p size %zd", sq, size);
   htsmsg_add_str(list, NULL, buf);
   return list;
@@ -128,8 +128,8 @@ streaming_queue_init(streaming_queue_t *sq, int reject_filter, size_t maxsize)
 
   streaming_target_init(&sq->sq_st, &ops, sq, reject_filter);
 
-  pthread_mutex_init(&sq->sq_mutex, NULL);
-  tvh_cond_init(&sq->sq_cond);
+  tvh_mutex_init(&sq->sq_mutex, NULL);
+  tvh_cond_init(&sq->sq_cond, 1);
   TAILQ_INIT(&sq->sq_queue);
 
   sq->sq_maxsize = maxsize;
@@ -144,7 +144,7 @@ streaming_queue_deinit(streaming_queue_t *sq)
 {
   sq->sq_size = 0;
   streaming_queue_clear(&sq->sq_queue);
-  pthread_mutex_destroy(&sq->sq_mutex);
+  tvh_mutex_destroy(&sq->sq_mutex);
   tvh_cond_destroy(&sq->sq_cond);
 }
 
@@ -640,7 +640,7 @@ void streaming_init(void)
 
 void streaming_done(void)
 {
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   memoryinfo_unregister(&streaming_msg_memoryinfo);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
\ No newline at end of file
index 9e16791406310969753dfd9e3479e4b1d95f6377..3ea3514d9dc745d348de3bb65c8f3c1743e2c4f6 100644 (file)
@@ -354,11 +354,11 @@ struct streaming_queue {
 
   streaming_target_t sq_st;
 
-  pthread_mutex_t sq_mutex;    /* Protects sp_queue */
-  tvh_cond_t  sq_cond;         /* Condvar for signalling new packets */
+  tvh_mutex_t sq_mutex;    /* Protects sp_queue */
+  tvh_cond_t  sq_cond;     /* Condvar for signalling new packets */
 
-  size_t          sq_maxsize;  /* Max queue size (bytes) */
-  size_t          sq_size;     /* Actual queue size (bytes) - only data */
+  size_t      sq_maxsize;  /* Max queue size (bytes) */
+  size_t      sq_size;     /* Actual queue size (bytes) - only data */
 
   struct streaming_message_queue sq_queue;
 
index 032f484a2b8c7da777c9c2f1ea99ea6caa76cc7d..54daa2714531321558f6dd9d359cb1d0fdea055b 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <assert.h>
-#include <pthread.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-#include <errno.h>
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-
 #include "tvheadend.h"
 #include "subscriptions.h"
 #include "streaming.h"
@@ -103,7 +88,7 @@ subscription_link_service(th_subscription_t *s, service_t *t)
   tvhtrace(LS_SUBSCRIPTION, "%04X: linking sub %p to svc %p type %i",
            shortid(s), s, t, t->s_type);
 
-  pthread_mutex_lock(&t->s_stream_mutex);
+  tvh_mutex_lock(&t->s_stream_mutex);
 
   if(elementary_set_has_streams(&t->s_components, 1) || t->s_type != STYPE_STD) {
     streaming_msg_free(s->ths_start_message);
@@ -132,7 +117,7 @@ subscription_link_service(th_subscription_t *s, service_t *t)
     streaming_target_deliver(s->ths_output, sm);
   }
 
-  pthread_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
 }
 
 /**
@@ -148,7 +133,7 @@ subscription_unlink_service0(th_subscription_t *s, int reason, int resched)
   if (!s->ths_current_instance) goto stop;
   s->ths_current_instance = NULL;
 
-  pthread_mutex_lock(&t->s_stream_mutex);
+  tvh_mutex_lock(&t->s_stream_mutex);
 
   streaming_target_disconnect(&t->s_streaming_pad, &s->ths_input);
 
@@ -162,7 +147,7 @@ subscription_unlink_service0(th_subscription_t *s, int reason, int resched)
   if (s->ths_parser)
     s->ths_output = parser_output(s->ths_parser);
 
-  pthread_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
 
   LIST_REMOVE(s, ths_service_link);
 
@@ -316,11 +301,11 @@ subscription_ca_check_cb(void *aux)
   if (t == NULL)
     return;
 
-  pthread_mutex_lock(&t->s_stream_mutex);
+  tvh_mutex_lock(&t->s_stream_mutex);
 
   service_set_streaming_status_flags(t, TSS_CA_CHECK);
 
-  pthread_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
 }
 
 /**
@@ -401,10 +386,10 @@ subscription_reschedule(void)
       tvhwarn(LS_SUBSCRIPTION, "%04X: service instance is bad, reason: %s",
               shortid(s), streaming_code2txt(s->ths_testing_error));
 
-      pthread_mutex_lock(&t->s_stream_mutex);
+      tvh_mutex_lock(&t->s_stream_mutex);
       t->s_streaming_status = 0;
       t->s_status = SERVICE_IDLE;
-      pthread_mutex_unlock(&t->s_stream_mutex);
+      tvh_mutex_unlock(&t->s_stream_mutex);
 
       si = s->ths_current_instance;
       assert(si != NULL);
@@ -493,7 +478,7 @@ subscription_set_postpone(void *aux, const char *path, int64_t postpone)
   /* some limits that make sense */
   postpone = MINMAX(postpone, 0, 120);
   postpone2 = sec2mono(postpone);
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   if (subscription_postpone != postpone) {
     subscription_postpone = postpone;
     tvhinfo(LS_SUBSCRIPTION, "postpone set to %"PRId64" seconds", postpone);
@@ -504,7 +489,7 @@ subscription_set_postpone(void *aux, const char *path, int64_t postpone)
     }
     subscription_delayed_reschedule(0);
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   return postpone;
 }
 
@@ -1064,7 +1049,7 @@ subscription_create_msg(th_subscription_t *s, const char *lang)
   if ((t = s->ths_service) != NULL) {
     htsmsg_add_str(m, "service", service_adapter_nicename(t, buf, sizeof(buf)));
 
-    pthread_mutex_lock(&t->s_stream_mutex);
+    tvh_mutex_lock(&t->s_stream_mutex);
     if ((di = t->s_descramble_info) != NULL) {
       if (di->caid == 0 && di->ecmtime == 0) {
         snprintf(buf, sizeof(buf), N_("Failed"));
@@ -1075,7 +1060,7 @@ subscription_create_msg(th_subscription_t *s, const char *lang)
       }
       htsmsg_add_str(m, "descramble", buf);
     }
-    pthread_mutex_unlock(&t->s_stream_mutex);
+    tvh_mutex_unlock(&t->s_stream_mutex);
 
     if (t->s_pid_list) {
       pids = t->s_pid_list(t);
@@ -1163,11 +1148,11 @@ subscription_init(void)
 void
 subscription_done(void)
 {
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   mtimer_disarm(&subscription_status_timer);
   /* clear remaining subscriptions */
   subscription_reschedule();
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   assert(LIST_FIRST(&subscriptions) == NULL);
 }
 
@@ -1223,13 +1208,13 @@ subscription_set_speed ( th_subscription_t *s, int speed )
 
   if (!t) return;
 
-  pthread_mutex_lock(&t->s_stream_mutex);
+  tvh_mutex_lock(&t->s_stream_mutex);
 
   sm = streaming_msg_create_code(SMT_SPEED, speed);
 
   streaming_target_deliver(s->ths_output, sm);
 
-  pthread_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
 }
 
 /**
@@ -1243,7 +1228,7 @@ subscription_set_skip ( th_subscription_t *s, const streaming_skip_t *skip )
 
   if (!t) return;
 
-  pthread_mutex_lock(&t->s_stream_mutex);
+  tvh_mutex_lock(&t->s_stream_mutex);
 
   sm = streaming_msg_create(SMT_SKIP);
   sm->sm_data = malloc(sizeof(streaming_skip_t));
@@ -1251,7 +1236,7 @@ subscription_set_skip ( th_subscription_t *s, const streaming_skip_t *skip )
 
   streaming_target_deliver(s->ths_output, sm);
 
-  pthread_mutex_unlock(&t->s_stream_mutex);
+  tvh_mutex_unlock(&t->s_stream_mutex);
 }
 
 /* **************************************************************************
index 62256c6137e86d773324c6b4040ddc4c9d8e02a0..a79a886a7421e628a7d31c8f8dc6e5fd05381746 100644 (file)
--- a/src/tcp.c
+++ b/src/tcp.c
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <pthread.h>
-#include <netdb.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <poll.h>
-#include <assert.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
 #include <fcntl.h>
-#include <errno.h>
+#include <poll.h>
 #include <signal.h>
 #include <netinet/in.h>
 #include <netinet/ip.h>
 #include <netinet/tcp.h>
 #include <arpa/inet.h>
 #include <sys/types.h>
+#include <sys/socket.h>
 #include <ifaddrs.h>
+#include <netdb.h>
 
 #include "tvheadend.h"
 #include "tcp.h"
@@ -619,9 +610,9 @@ try_again:
                  sused, used2);
         return NULL;
       }
-      pthread_mutex_unlock(&global_lock);
+      tvh_mutex_unlock(&global_lock);
       tvh_safe_usleep(250000);
-      pthread_mutex_lock(&global_lock);
+      tvh_mutex_lock(&global_lock);
       if (!tcp_socket_dead(fd) && tvheadend_is_running())
         goto try_again;
       return NULL;
@@ -712,7 +703,7 @@ tcp_server_start(void *aux)
 
   /* Start */
   time(&tsl->started);
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   tsl->id = ++tcp_server_launch_id;
   if (!tsl->id) tsl->id = ++tcp_server_launch_id;
   tsl->ops.start(tsl->fd, &tsl->opaque, &tsl->peer, &tsl->self);
@@ -721,7 +712,7 @@ tcp_server_start(void *aux)
   if (tsl->ops.stop) tsl->ops.stop(tsl->opaque);
   LIST_REMOVE(tsl, alink);
   LIST_INSERT_HEAD(&tcp_server_join, tsl, jlink);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   if (atomic_get(&tcp_server_running))
     tvh_write(tcp_server_pipe.wr, &c, 1);
   return NULL;
@@ -756,10 +747,10 @@ tcp_server_loop(void *aux)
       r = read(tcp_server_pipe.rd, &c, 1);
       if (r > 0) {
 next:
-        pthread_mutex_lock(&global_lock);
+        tvh_mutex_lock(&global_lock);
         while ((tsl = LIST_FIRST(&tcp_server_join)) != NULL) {
           LIST_REMOVE(tsl, jlink);
-          pthread_mutex_unlock(&global_lock);
+          tvh_mutex_unlock(&global_lock);
           pthread_join(tsl->tid, NULL);
           free(tsl);
           goto next;
@@ -768,7 +759,7 @@ next:
           LIST_REMOVE(ts, link);
           free(ts);
         }
-        pthread_mutex_unlock(&global_lock);
+        tvh_mutex_unlock(&global_lock);
       }
       continue;
     }
@@ -805,10 +796,10 @@ next:
         continue;
       }
 
-      pthread_mutex_lock(&global_lock);
+      tvh_mutex_lock(&global_lock);
       LIST_INSERT_HEAD(&tcp_server_active, tsl, alink);
-      pthread_mutex_unlock(&global_lock);
-      tvhthread_create(&tsl->tid, NULL, tcp_server_start, tsl, "tcp-start");
+      tvh_mutex_unlock(&global_lock);
+      tvh_thread_create(&tsl->tid, NULL, tcp_server_start, tsl, "tcp-start");
     }
   }
   tvhtrace(LS_TCP, "server thread finished");
@@ -1171,7 +1162,7 @@ tcp_server_init(void)
   tvhpoll_add1(tcp_server_poll, tcp_server_pipe.rd, TVHPOLL_IN, &tcp_server_pipe);
 
   atomic_set(&tcp_server_running, 1);
-  tvhthread_create(&tcp_server_tid, NULL, tcp_server_loop, NULL, "tcp-loop");
+  tvh_thread_create(&tcp_server_tid, NULL, tcp_server_loop, NULL, "tcp-loop");
 }
 
 void
@@ -1185,39 +1176,39 @@ tcp_server_done(void)
   atomic_set(&tcp_server_running, 0);
   tvh_write(tcp_server_pipe.wr, &c, 1);
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   LIST_FOREACH(tsl, &tcp_server_active, alink) {
     if (tsl->ops.cancel)
       tsl->ops.cancel(tsl->opaque);
     if (tsl->fd >= 0)
       shutdown(tsl->fd, SHUT_RDWR);
-    pthread_kill(tsl->tid, SIGTERM);
+    tvh_thread_kill(tsl->tid, SIGTERM);
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   pthread_join(tcp_server_tid, NULL);
   tvh_pipe_close(&tcp_server_pipe);
   tvhpoll_destroy(tcp_server_poll);
   
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   t = mclk();
   while (LIST_FIRST(&tcp_server_active) != NULL) {
     if (t + sec2mono(5) < mclk())
       tvhtrace(LS_TCP, "tcp server %p active too long", LIST_FIRST(&tcp_server_active));
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
     tvh_safe_usleep(20000);
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
   }
   while ((tsl = LIST_FIRST(&tcp_server_join)) != NULL) {
     LIST_REMOVE(tsl, jlink);
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
     pthread_join(tsl->tid, NULL);
     free(tsl);
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
   }
   while ((ts = LIST_FIRST(&tcp_server_delete_list)) != NULL) {
     LIST_REMOVE(ts, link);
     free(ts);
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
index e2a0e1a01bd3255892faf0f6ff91db8cb7ff74b6..be5655318c0bc6afebf04247e76eef177030f619 100644 (file)
@@ -417,12 +417,12 @@ timeshift_destroy(streaming_target_t *pad)
   /* Ensure the threads exits */
   // Note: this is a workaround for the fact the Q might have been flushed
   //       in reader thread (VERY unlikely)
-  pthread_mutex_lock(&ts->state_mutex);
+  tvh_mutex_lock(&ts->state_mutex);
   sm = streaming_msg_create(SMT_EXIT);
   streaming_target_deliver2(&ts->wr_queue.sq_st, sm);
   if (!ts->exit)
     timeshift_write_exit(ts->rd_pipe.wr);
-  pthread_mutex_unlock(&ts->state_mutex);
+  tvh_mutex_unlock(&ts->state_mutex);
 
   /* Wait for all threads */
   pthread_join(ts->rd_thread, NULL);
@@ -484,7 +484,7 @@ streaming_target_t *timeshift_create
   ts->seek.frame = NULL;
   ts->ram_segments = 0;
   ts->file_segments = 0;
-  pthread_mutex_init(&ts->state_mutex, NULL);
+  tvh_mutex_init(&ts->state_mutex, NULL);
 
   /* Initialise output */
   tvh_pipe(O_NONBLOCK, &ts->rd_pipe);
@@ -492,8 +492,8 @@ streaming_target_t *timeshift_create
   /* Initialise input */
   streaming_queue_init(&ts->wr_queue, 0, 0);
   streaming_target_init(&ts->input, &timeshift_input_ops, ts, 0);
-  tvhthread_create(&ts->wr_thread, NULL, timeshift_writer, ts, "tshift-wr");
-  tvhthread_create(&ts->rd_thread, NULL, timeshift_reader, ts, "tshift-rd");
+  tvh_thread_create(&ts->wr_thread, NULL, timeshift_writer, ts, "tshift-wr");
+  tvh_thread_create(&ts->rd_thread, NULL, timeshift_reader, ts, "tshift-rd");
 
   /* Update index */
   timeshift_index++;
index fe496df926a7f894fe17f016fba1dab4bc1fe947..5c6000e2ae8e2089bd614f664a07683c2efcbfa8 100644 (file)
@@ -74,7 +74,7 @@ typedef struct timeshift_file
 
   TAILQ_ENTRY(timeshift_file) link;     ///< List entry
 
-  pthread_mutex_t               ram_lock; ///< Mutex for the ram array access
+  tvh_mutex_t               ram_lock; ///< Mutex for the ram array access
 } timeshift_file_t;
 
 typedef TAILQ_HEAD(timeshift_file_list,timeshift_file) timeshift_file_list_t;
@@ -113,7 +113,7 @@ typedef struct timeshift {
     TS_PAUSE,
     TS_PLAY,
   }                           state;       ///< Play state
-  pthread_mutex_t             state_mutex; ///< Protect state changes
+  tvh_mutex_t             state_mutex; ///< Protect state changes
   uint8_t                     exit;        ///< Exit from the main input thread
   uint8_t                     full;        ///< Buffer is full
 
index 06e3e846fe32de8bdfe8f4637f37ee01787694ac..e82e2cf3311b7b10a4b8c9acc68fae1fec5d315f 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
 #include <fcntl.h>
-#include <string.h>
-#include <assert.h>
-#include <pthread.h>
 
 #include "tvheadend.h"
 #include "streaming.h"
@@ -35,7 +29,7 @@
 static int                   timeshift_reaper_run;
 static timeshift_file_list_t timeshift_reaper_list;
 static pthread_t             timeshift_reaper_thread;
-static pthread_mutex_t       timeshift_reaper_lock;
+static tvh_mutex_t       timeshift_reaper_lock;
 static tvh_cond_t            timeshift_reaper_cond;
 
 uint64_t                     timeshift_total_size;
@@ -52,7 +46,7 @@ static void* timeshift_reaper_callback ( void *p )
   timeshift_index_iframe_t *ti;
   timeshift_index_data_t *tid;
   streaming_message_t *sm;
-  pthread_mutex_lock(&timeshift_reaper_lock);
+  tvh_mutex_lock(&timeshift_reaper_lock);
   while (timeshift_reaper_run) {
 
     /* Get next */
@@ -62,7 +56,7 @@ static void* timeshift_reaper_callback ( void *p )
       continue;
     }
     TAILQ_REMOVE(&timeshift_reaper_list, tsf, link);
-    pthread_mutex_unlock(&timeshift_reaper_lock);
+    tvh_mutex_unlock(&timeshift_reaper_lock);
 
     if (tsf->path) {
       tvhtrace(LS_TIMESHIFT, "remove file %s", tsf->path);
@@ -97,9 +91,9 @@ static void* timeshift_reaper_callback ( void *p )
     memoryinfo_free(&timeshift_memoryinfo, sizeof(*tsf));
     free(tsf);
 
-    pthread_mutex_lock(&timeshift_reaper_lock);
+    tvh_mutex_lock(&timeshift_reaper_lock);
   }
-  pthread_mutex_unlock(&timeshift_reaper_lock);
+  tvh_mutex_unlock(&timeshift_reaper_lock);
   tvhtrace(LS_TIMESHIFT, "reaper thread exit");
   return NULL;
 }
@@ -112,10 +106,10 @@ static void timeshift_reaper_remove ( timeshift_file_t *tsf )
     else
       tvhtrace(LS_TIMESHIFT, "queue file for removal - RAM segment time %li", (long)tsf->time);
   }
-  pthread_mutex_lock(&timeshift_reaper_lock);
+  tvh_mutex_lock(&timeshift_reaper_lock);
   TAILQ_INSERT_TAIL(&timeshift_reaper_list, tsf, link);
   tvh_cond_signal(&timeshift_reaper_cond, 0);
-  pthread_mutex_unlock(&timeshift_reaper_lock);
+  tvh_mutex_unlock(&timeshift_reaper_lock);
 }
 
 /* **************************************************************************
@@ -251,7 +245,7 @@ static timeshift_file_t * timeshift_filemgr_file_init
   TAILQ_INIT(&tsf->iframes);
   TAILQ_INIT(&tsf->sstart);
   TAILQ_INSERT_TAIL(&ts->files, tsf, link);
-  pthread_mutex_init(&tsf->ram_lock, NULL);
+  tvh_mutex_init(&tsf->ram_lock, NULL);
   return tsf;
 }
 
@@ -456,11 +450,11 @@ void timeshift_filemgr_init ( void )
 
   /* Start the reaper thread */
   timeshift_reaper_run = 1;
-  pthread_mutex_init(&timeshift_reaper_lock, NULL);
-  tvh_cond_init(&timeshift_reaper_cond);
+  tvh_mutex_init(&timeshift_reaper_lock, NULL);
+  tvh_cond_init(&timeshift_reaper_cond, 1);
   TAILQ_INIT(&timeshift_reaper_list);
-  tvhthread_create(&timeshift_reaper_thread, NULL,
-                   timeshift_reaper_callback, NULL, "tshift-reap");
+  tvh_thread_create(&timeshift_reaper_thread, NULL,
+                    timeshift_reaper_callback, NULL, "tshift-reap");
 }
 
 /*
@@ -471,10 +465,10 @@ void timeshift_filemgr_term ( void )
   char path[512];
 
   /* Wait for thread */
-  pthread_mutex_lock(&timeshift_reaper_lock);
+  tvh_mutex_lock(&timeshift_reaper_lock);
   timeshift_reaper_run = 0;
   tvh_cond_signal(&timeshift_reaper_cond, 0);
-  pthread_mutex_unlock(&timeshift_reaper_lock);
+  tvh_mutex_unlock(&timeshift_reaper_lock);
   pthread_join(timeshift_reaper_thread, NULL);
 
   /* Remove the lot */
index 7feff7d52e78758573088b24e8c7de69a9be1029..6867cff713238651391452c5b33ee365b044905f 100644 (file)
@@ -81,10 +81,10 @@ static ssize_t _read_buf ( timeshift_file_t *tsf, int fd, void *buf, size_t size
   if (tsf && tsf->ram) {
     if (tsf->roff == tsf->woff) return 0;
     if (tsf->roff + size > tsf->woff) return -1;
-    pthread_mutex_lock(&tsf->ram_lock);
+    tvh_mutex_lock(&tsf->ram_lock);
     memcpy(buf, tsf->ram + tsf->roff, size);
     tsf->roff += size;
-    pthread_mutex_unlock(&tsf->ram_lock);
+    tvh_mutex_unlock(&tsf->ram_lock);
     return size;
   } else {
     ret = 0;
@@ -564,7 +564,7 @@ void *timeshift_reader ( void *p )
     mono_now  = getfastmonoclock();
 
     /* Control */
-    pthread_mutex_lock(&ts->state_mutex);
+    tvh_mutex_lock(&ts->state_mutex);
     if (nfds == 1) {
       if (_read_msg(NULL, ts->rd_pipe.rd, &ctrl) > 0) {
 
@@ -774,7 +774,7 @@ void *timeshift_reader ( void *p )
         timeshift_status(ts, last_time);
         mono_last_status = mono_now;
       }
-      pthread_mutex_unlock(&ts->state_mutex);
+      tvh_mutex_unlock(&ts->state_mutex);
       continue;
     }
 
@@ -809,7 +809,7 @@ void *timeshift_reader ( void *p )
 
       /* Find packet */
       if (_timeshift_read(ts, seek, &sm, &wait) == -1) {
-        pthread_mutex_unlock(&ts->state_mutex);
+        tvh_mutex_unlock(&ts->state_mutex);
         break;
       }
     }
@@ -881,7 +881,7 @@ void *timeshift_reader ( void *p )
 
         /* Flush timeshift buffer to live */
         if (_timeshift_flush_to_live(ts, seek, &wait) == -1) {
-          pthread_mutex_unlock(&ts->state_mutex);
+          tvh_mutex_unlock(&ts->state_mutex);
           break;
         }
 
@@ -916,7 +916,7 @@ void *timeshift_reader ( void *p )
 
     }
 
-    pthread_mutex_unlock(&ts->state_mutex);
+    tvh_mutex_unlock(&ts->state_mutex);
   }
 
   /* Cleanup */
index 092c1eca007cdefde7b233c307199525ce75ca22..8eb22a167e647a9ed1c592094944b61d5600635d 100644 (file)
@@ -61,7 +61,7 @@ static ssize_t _write
   size_t alloc;
   ssize_t ret;
   if (tsf->ram) {
-    pthread_mutex_lock(&tsf->ram_lock);
+    tvh_mutex_lock(&tsf->ram_lock);
     if (tsf->ram_size < tsf->woff + count) {
       if (tsf->ram_size >= timeshift_conf.ram_segment_size)
         alloc = MAX(count, 64*1024);
@@ -70,7 +70,7 @@ static ssize_t _write
       ram = realloc(tsf->ram, tsf->ram_size + alloc);
       if (ram == NULL) {
         tvhwarn(LS_TIMESHIFT, "RAM timeshift memalloc failed");
-        pthread_mutex_unlock(&tsf->ram_lock);
+        tvh_mutex_unlock(&tsf->ram_lock);
         return -1;
       }
       memoryinfo_append(&timeshift_memoryinfo_ram, alloc);
@@ -79,7 +79,7 @@ static ssize_t _write
     }
     memcpy(tsf->ram + tsf->woff, buf, count);
     tsf->woff += count;
-    pthread_mutex_unlock(&tsf->ram_lock);
+    tvh_mutex_unlock(&tsf->ram_lock);
     return count;
   }
   ret = _write_fd(tsf->wfd, buf, count);
@@ -353,7 +353,7 @@ static void _process_msg
     case SMT_SIGNAL_STATUS:
     case SMT_START:
     case SMT_MPEGTS:
-      pthread_mutex_lock(&ts->state_mutex);
+      tvh_mutex_lock(&ts->state_mutex);
       if (!teletext) /* do not use time from teletext packets */
         ts->buf_time = sm->sm_time;
       if (ts->state == TS_LIVE) {
@@ -378,7 +378,7 @@ static void _process_msg
           timeshift_file_put(tsf);
         }
       }
-      pthread_mutex_unlock(&ts->state_mutex);
+      tvh_mutex_unlock(&ts->state_mutex);
       break;
   }
 
@@ -387,12 +387,12 @@ static void _process_msg
   return;
 
 live:
-  pthread_mutex_lock(&ts->state_mutex);
+  tvh_mutex_lock(&ts->state_mutex);
   if (ts->state == TS_LIVE)
     streaming_target_deliver2(ts->output, sm);
   else
     streaming_msg_free(sm);
-  pthread_mutex_unlock(&ts->state_mutex);
+  tvh_mutex_unlock(&ts->state_mutex);
 }
 
 void *timeshift_writer ( void *aux )
@@ -402,7 +402,7 @@ void *timeshift_writer ( void *aux )
   streaming_queue_t *sq = &ts->wr_queue;
   streaming_message_t *sm;
 
-  pthread_mutex_lock(&sq->sq_mutex);
+  tvh_mutex_lock(&sq->sq_mutex);
 
   while (run) {
 
@@ -413,13 +413,13 @@ void *timeshift_writer ( void *aux )
       continue;
     }
     streaming_queue_remove(sq, sm);
-    pthread_mutex_unlock(&sq->sq_mutex);
+    tvh_mutex_unlock(&sq->sq_mutex);
 
     _process_msg(ts, sm, &run);
 
-    pthread_mutex_lock(&sq->sq_mutex);
+    tvh_mutex_lock(&sq->sq_mutex);
   }
 
-  pthread_mutex_unlock(&sq->sq_mutex);
+  tvh_mutex_unlock(&sq->sq_mutex);
   return NULL;
 }
index ad2b7099bcd42445b63c876293938fb080dec4ac..dc8b40156c5a7aefb145e2072e64f0e4aa6d0370 100644 (file)
@@ -23,8 +23,8 @@
 #include "tprofile.h"
 
 int tprofile_running;
-static pthread_mutex_t tprofile_mutex;
-static pthread_mutex_t qprofile_mutex;
+static tvh_mutex_t tprofile_mutex;
+static tvh_mutex_t qprofile_mutex;
 static LIST_HEAD(, tprofile) tprofile_all;
 static LIST_HEAD(, qprofile) qprofile_all;
 
@@ -32,9 +32,9 @@ void tprofile_init1(tprofile_t *tprof, const char *name)
 {
   memset(tprof, 0, sizeof(*tprof));
   tprof->name = strdup(name);
-  pthread_mutex_lock(&tprofile_mutex);
+  tvh_mutex_lock(&tprofile_mutex);
   LIST_INSERT_HEAD(&tprofile_all, tprof, link);
-  pthread_mutex_unlock(&tprofile_mutex);
+  tvh_mutex_unlock(&tprofile_mutex);
 }
 
 static void tprofile_time_done(tprofile_time_t *tpt)
@@ -57,20 +57,20 @@ static void tprofile_destroy(tprofile_t *tprof)
 void tprofile_done1(tprofile_t *tprof)
 {
   tprofile_t *fin = malloc(sizeof(*fin));
-  pthread_mutex_lock(&tprofile_mutex);
+  tvh_mutex_lock(&tprofile_mutex);
   LIST_REMOVE(tprof, link);
   if (fin) {
     *fin = *tprof;
     fin->changed = fin->finish = 1;
     LIST_INSERT_HEAD(&tprofile_all, fin, link);
   }
-  pthread_mutex_unlock(&tprofile_mutex);
+  tvh_mutex_unlock(&tprofile_mutex);
   if (!fin) tprofile_destroy(tprof);
 }
 
 void tprofile_start1(tprofile_t *tprof, const char *id)
 {
-  pthread_mutex_lock(&tprofile_mutex);
+  tvh_mutex_lock(&tprofile_mutex);
   assert(tprof->start == 0);
   tprof->start = getfastmonoclock();
   if (id) {
@@ -80,7 +80,7 @@ void tprofile_start1(tprofile_t *tprof, const char *id)
     snprintf(buf, sizeof(buf), "[%p]", tprof);
     tprof->start_id = strdup(buf);
   }
-  pthread_mutex_unlock(&tprofile_mutex);
+  tvh_mutex_unlock(&tprofile_mutex);
 }
 
 static void
@@ -102,7 +102,7 @@ void tprofile_finish1(tprofile_t *tprof)
 {
   if (tprof->start) {
     uint64_t mono, diff;
-    pthread_mutex_lock(&tprofile_mutex);
+    tvh_mutex_lock(&tprofile_mutex);
     mono = getfastmonoclock();
     diff = mono - tprof->start;
     if (diff > tprof->tmax.t)
@@ -112,7 +112,7 @@ void tprofile_finish1(tprofile_t *tprof)
     tprof->start_id = NULL;
     tprof->start = 0;
     tprof->changed = 1;
-    pthread_mutex_unlock(&tprofile_mutex);
+    tvh_mutex_unlock(&tprofile_mutex);
   }
 }
 
@@ -120,9 +120,9 @@ void tprofile_queue_init1(qprofile_t *qprof, const char *name)
 {
   memset(qprof, 0, sizeof(*qprof));
   qprof->name = strdup(name);
-  pthread_mutex_lock(&qprofile_mutex);
+  tvh_mutex_lock(&qprofile_mutex);
   LIST_INSERT_HEAD(&qprofile_all, qprof, link);
-  pthread_mutex_unlock(&qprofile_mutex);
+  tvh_mutex_unlock(&qprofile_mutex);
 }
 
 static void qprofile_time_done(qprofile_time_t *qpt)
@@ -144,14 +144,14 @@ static void qprofile_destroy(qprofile_t *qprof)
 void tprofile_queue_done1(qprofile_t *qprof)
 {
   qprofile_t *fin = malloc(sizeof(*fin));
-  pthread_mutex_lock(&qprofile_mutex);
+  tvh_mutex_lock(&qprofile_mutex);
   LIST_REMOVE(qprof, link);
   if (fin) {
     *fin = *qprof;
     fin->changed = fin->finish = 1;
     LIST_INSERT_HEAD(&qprofile_all, fin, link);
   }
-  pthread_mutex_unlock(&qprofile_mutex);
+  tvh_mutex_unlock(&qprofile_mutex);
   if (!fin) qprofile_destroy(qprof);
 }
 
@@ -175,35 +175,35 @@ qprofile_avg_update(qprofile_avg_t *tpa, uint64_t val)
 void tprofile_queue_set1(qprofile_t *qprof, const char *id, uint64_t pos)
 {
   uint64_t mono;
-  pthread_mutex_lock(&qprofile_mutex);
+  tvh_mutex_lock(&qprofile_mutex);
   mono = getfastmonoclock();
   if (pos > qprof->qmax.pos)
     qprofile_time_replace(&qprof->qmax, id, mono, pos);
   qprofile_avg_update(&qprof->qavg, pos);
   qprof->changed = 1;
-  pthread_mutex_unlock(&qprofile_mutex);
+  tvh_mutex_unlock(&qprofile_mutex);
 }
 
 void tprofile_queue_add1(qprofile_t *qprof, const char *id, uint64_t count)
 {
-  pthread_mutex_lock(&qprofile_mutex);
+  tvh_mutex_lock(&qprofile_mutex);
   qprof->qsum += count;
-  pthread_mutex_unlock(&qprofile_mutex);
+  tvh_mutex_unlock(&qprofile_mutex);
 }
 
 void tprofile_queue_drop1(qprofile_t *qprof, const char *id, uint64_t count)
 {
-  pthread_mutex_lock(&qprofile_mutex);
+  tvh_mutex_lock(&qprofile_mutex);
   qprof->qdrop += count;
   qprof->qdropcnt++;
-  pthread_mutex_unlock(&qprofile_mutex);
+  tvh_mutex_unlock(&qprofile_mutex);
 }
 
 static void tprofile_log_tstats(void)
 {
   tprofile_t *tprof, *tprof_next;
 
-  pthread_mutex_lock(&tprofile_mutex);
+  tvh_mutex_lock(&tprofile_mutex);
   for (tprof = LIST_FIRST(&tprofile_all); tprof; tprof = tprof_next) {
     tprof_next = LIST_NEXT(tprof, link);
     if (tprof->changed == 0) continue;
@@ -221,7 +221,7 @@ static void tprofile_log_tstats(void)
     }
     tprof->changed = 0;
   }
-  pthread_mutex_unlock(&tprofile_mutex);
+  tvh_mutex_unlock(&tprofile_mutex);
 }
 
 static void qprofile_log_qstats(void)
@@ -229,7 +229,7 @@ static void qprofile_log_qstats(void)
   qprofile_t *qprof, *qprof_next;
   uint64_t mono, diff;
 
-  pthread_mutex_lock(&qprofile_mutex);
+  tvh_mutex_lock(&qprofile_mutex);
   mono = getfastmonoclock();
   for (qprof = LIST_FIRST(&qprofile_all); qprof; qprof = qprof_next) {
     qprof_next = LIST_NEXT(qprof, link);
@@ -255,7 +255,7 @@ static void qprofile_log_qstats(void)
     qprof->qsum = 0;
     qprof->tstamp = mono;
   }
-  pthread_mutex_unlock(&qprofile_mutex);
+  tvh_mutex_unlock(&qprofile_mutex);
 }
 
 void tprofile_log_stats1(void)
@@ -272,8 +272,8 @@ char *tprofile_get_json_stats(void)
 void tprofile_module_init(int enable)
 {
   tprofile_running = enable;
-  pthread_mutex_init(&tprofile_mutex, NULL);
-  pthread_mutex_init(&qprofile_mutex, NULL);
+  tvh_mutex_init(&tprofile_mutex, NULL);
+  tvh_mutex_init(&qprofile_mutex, NULL);
 }
 
 void tprofile_module_done(void)
index 11c3e8f81021c3f74a094be600106fcb39767d88..8c78eda5fca3438c2b99c71c3b1dda0c1b27ccaa 100644 (file)
@@ -70,12 +70,12 @@ codec_init(void)
 void
 codec_done(void)
 {
-    pthread_mutex_lock(&global_lock);
+    tvh_mutex_lock(&global_lock);
 
     // codec profiles
     tvh_codec_profiles_remove();
     // codecs
     tvh_codecs_forget();
 
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
 }
index 70599ccf1eeb8abe2a8dac3f076d1ef5f98056ee..9ad31ad8c7340563c3566b444eb41086b3a2672d 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <pthread.h>
-#include "pthread.h"
+#include "tvh_thread.h"
 #include "tvh_locale.h"
 #include "tvh_string.h"
 #include "redblack.h"
@@ -34,7 +30,7 @@ struct tvh_locale {
 
 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
 
-pthread_mutex_t tvh_gettext_mutex = PTHREAD_MUTEX_INITIALIZER;
+tvh_mutex_t tvh_gettext_mutex = { .mutex = PTHREAD_MUTEX_INITIALIZER };
 
 /*
  *
@@ -169,10 +165,10 @@ int tvh_gettext_langcode_valid(const char *code)
   struct lng ls;
   int ret;
 
-  pthread_mutex_lock(&tvh_gettext_mutex);
+  tvh_mutex_lock(&tvh_gettext_mutex);
   ls.tvh_lang = code;
   ret = RB_FIND(&lngs, &ls, link, lng_cmp) != NULL;
-  pthread_mutex_unlock(&tvh_gettext_mutex);
+  tvh_mutex_unlock(&tvh_gettext_mutex);
   return ret;
 }
 
@@ -219,7 +215,7 @@ static void tvh_gettext_default_init(void)
 
 const char *tvh_gettext_lang(const char *lang, const char *s)
 {
-  pthread_mutex_lock(&tvh_gettext_mutex);
+  tvh_mutex_lock(&tvh_gettext_mutex);
   if (lang == NULL) {
     s = msg_find(lng_default, s);
   } else {
@@ -232,7 +228,7 @@ const char *tvh_gettext_lang(const char *lang, const char *s)
         s = msg_find(lng_last, s);
     }
   }
-  pthread_mutex_unlock(&tvh_gettext_mutex);
+  tvh_mutex_unlock(&tvh_gettext_mutex);
   return s;
 }
 
index d5ce71f92c4238bf2316b09237d924eb73fd5837..05564a4000ee2b70587379e9aaaf18ac951b6f80 100644 (file)
@@ -18,6 +18,8 @@
 #ifndef __TVH_LOCALE_H__
 #define __TVH_LOCALE_H__
 
+#include <stdio.h>
+
 const char *tvh_gettext_get_lang(const char *lang);
 const char *tvh_gettext_lang(const char *lang, const char *s);
 static inline const char *tvh_gettext(const char *s)
index ecf09fdbf46aaa2403d36c705fc1532e4cee608b..62e25320071f356b33a4a36f70772e488ce853a0 100644 (file)
@@ -19,6 +19,9 @@
 #ifndef TVHEADEND_STRING_H
 #define TVHEADEND_STRING_H
 
+#include <string.h>
+#include <stdlib.h>
+
 #include "build.h"
 
 static inline int strempty(const char *c)
diff --git a/src/tvh_thread.c b/src/tvh_thread.c
new file mode 100644 (file)
index 0000000..3849ec5
--- /dev/null
@@ -0,0 +1,251 @@
+#define __USE_GNU
+#include "tvheadend.h"
+#include <assert.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/resource.h>
+#include <unistd.h>
+#include <signal.h>
+#define TVH_THREAD_C 1
+#include "tvh_thread.h"
+
+#ifdef PLATFORM_LINUX
+#include <sys/prctl.h>
+#include <sys/syscall.h>
+#endif
+
+#ifdef PLATFORM_FREEBSD
+#include <pthread_np.h>
+#endif
+
+/*
+ * thread routines
+ */
+
+static void doquit(int sig)
+{
+}
+
+struct
+thread_state {
+  void *(*run)(void*);
+  void *arg;
+  char name[17];
+};
+
+static void *
+thread_wrapper ( void *p )
+{
+  struct thread_state *ts = p;
+  sigset_t set;
+
+#if defined(PLATFORM_LINUX)
+  /* Set name */
+  prctl(PR_SET_NAME, ts->name);
+#elif defined(PLATFORM_FREEBSD)
+  /* Set name of thread */
+  pthread_set_name_np(pthread_self(), ts->name);
+#elif defined(PLATFORM_DARWIN)
+  pthread_setname_np(ts->name);
+#endif
+
+  sigemptyset(&set);
+  sigaddset(&set, SIGTERM);
+  sigaddset(&set, SIGQUIT);
+  pthread_sigmask(SIG_UNBLOCK, &set, NULL);
+
+  signal(SIGTERM, doexit);
+  signal(SIGQUIT, doquit);
+
+  /* Run */
+  tvhtrace(LS_THREAD, "created thread %ld [%s / %p(%p)]",
+           (long)pthread_self(), ts->name, ts->run, ts->arg);
+  void *r = ts->run(ts->arg);
+  free(ts);
+
+  return r;
+}
+
+int
+tvh_thread_create
+  (pthread_t *thread, const pthread_attr_t *attr,
+   void *(*start_routine) (void *), void *arg, const char *name)
+{
+  int r;
+  struct thread_state *ts = calloc(1, sizeof(struct thread_state));
+  pthread_attr_t _attr;
+  if (attr == NULL) {
+    pthread_attr_init(&_attr);
+    pthread_attr_setstacksize(&_attr, 2*1024*1024);
+    attr = &_attr;
+  }
+  strlcpy(ts->name, "tvh:", 5);
+  strlcpy(ts->name+4, name, sizeof(ts->name)-4);
+  ts->run  = start_routine;
+  ts->arg  = arg;
+  r = pthread_create(thread, attr, thread_wrapper, ts);
+  return r;
+}
+
+int tvh_thread_kill(pthread_t thread, int sig)
+{
+  return pthread_kill(thread, sig);
+}
+
+/* linux style: -19 .. 20 */
+int
+tvh_thread_renice(int value)
+{
+  int ret = 0;
+#ifdef SYS_gettid
+  pid_t tid;
+  tid = syscall(SYS_gettid);
+  ret = setpriority(PRIO_PROCESS, tid, value);
+#elif ENABLE_ANDROID
+  pid_t tid;
+  tid = gettid();
+  ret = setpriority(PRIO_PROCESS, tid, value);
+#elif defined(PLATFORM_DARWIN)
+  /* Currently not possible */
+#elif defined(PLATFORM_FREEBSD)
+  /* Currently not possible */
+#else
+#warning "Implement renice for your platform!"
+#endif
+  return ret;
+}
+
+int tvh_mutex_init(tvh_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr)
+{
+  return pthread_mutex_init(&mutex->mutex, attr);
+}
+
+int tvh_mutex_destroy(tvh_mutex_t *mutex)
+{
+  return pthread_mutex_destroy(&mutex->mutex);
+}
+
+int tvh_mutex_lock(tvh_mutex_t *mutex)
+{
+  return pthread_mutex_lock(&mutex->mutex);
+}
+
+int tvh_mutex_trylock(tvh_mutex_t *mutex)
+{
+  return pthread_mutex_trylock(&mutex->mutex);
+}
+
+int tvh_mutex_unlock(tvh_mutex_t *mutex)
+{
+  return pthread_mutex_unlock(&mutex->mutex);
+}
+
+
+int
+tvh_mutex_timedlock
+  ( tvh_mutex_t *mutex, int64_t usec )
+{
+  int64_t finish = getfastmonoclock() + usec;
+  int retcode;
+
+  while ((retcode = pthread_mutex_trylock (&mutex->mutex)) == EBUSY) {
+    if (getfastmonoclock() >= finish)
+      return ETIMEDOUT;
+
+    tvh_safe_usleep(10000);
+  }
+
+  return retcode;
+}
+
+/*
+ * thread condition variables - monotonic clocks
+ */
+
+int
+tvh_cond_init
+  ( tvh_cond_t *cond, int monotonic )
+{
+  int r;
+
+  pthread_condattr_t attr;
+  pthread_condattr_init(&attr);
+#if defined(PLATFORM_DARWIN)
+  /*
+   * pthread_condattr_setclock() not supported on platform Darwin.
+   * We use pthread_cond_timedwait_relative_np() which doesn't
+   * need it.
+   */
+  r = 0;
+#else
+  r = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
+  if (r) {
+    fprintf(stderr, "Unable to set monotonic clocks for conditions! (%d)", r);
+    abort();
+  }
+#endif
+  return pthread_cond_init(&cond->cond, &attr);
+}
+
+int
+tvh_cond_destroy
+  ( tvh_cond_t *cond )
+{
+  return pthread_cond_destroy(&cond->cond);
+}
+
+int
+tvh_cond_signal
+  ( tvh_cond_t *cond, int broadcast )
+{
+  if (broadcast)
+    return pthread_cond_broadcast(&cond->cond);
+  else
+    return pthread_cond_signal(&cond->cond);
+}
+
+int
+tvh_cond_wait
+  ( tvh_cond_t *cond, tvh_mutex_t *mutex)
+{
+  return pthread_cond_wait(&cond->cond, &mutex->mutex);
+}
+
+int
+tvh_cond_timedwait
+  ( tvh_cond_t *cond, tvh_mutex_t *mutex, int64_t monoclock )
+{
+#if defined(PLATFORM_DARWIN)
+  /* Use a relative timedwait implementation */
+  int64_t now = getmonoclock();
+  int64_t relative = monoclock - now;
+  struct timespec ts;
+
+  if (relative < 0)
+    return 0;
+
+  ts.tv_sec  = relative / MONOCLOCK_RESOLUTION;
+  ts.tv_nsec = (relative % MONOCLOCK_RESOLUTION) *
+               (1000000000ULL/MONOCLOCK_RESOLUTION);
+
+  return pthread_cond_timedwait_relative_np(&cond->cond, &mutex->mutex, &ts);
+#else
+  struct timespec ts;
+  ts.tv_sec = monoclock / MONOCLOCK_RESOLUTION;
+  ts.tv_nsec = (monoclock % MONOCLOCK_RESOLUTION) *
+               (1000000000ULL/MONOCLOCK_RESOLUTION);
+  return pthread_cond_timedwait(&cond->cond, &mutex->mutex, &ts);
+#endif
+}
+
+int tvh_cond_timedwait_ts(tvh_cond_t *cond, tvh_mutex_t *mutex, struct timespec *ts)
+{
+  return pthread_cond_timedwait(&cond->cond, &mutex->mutex, ts);
+}
+
+void
+tvh_mutex_not_held(const char *file, int line)
+{
+  fprintf(stderr, "Mutex not held at %s:%d\n", file, line);
+  abort();
+}
diff --git a/src/tvh_thread.h b/src/tvh_thread.h
new file mode 100644 (file)
index 0000000..2fbf435
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ *  Tvheadend - mutex functions
+ *  Copyright (C) 2018 Jaroslav Kysela
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef TVHEADEND_THREAD_H
+#define TVHEADEND_THREAD_H
+
+#include <errno.h>
+#include <stdint.h>
+#include "pthread.h"
+
+typedef struct {
+  pthread_cond_t cond;
+} tvh_cond_t;
+
+typedef struct {
+  pthread_mutex_t mutex;
+} tvh_mutex_t;
+
+/*
+ *
+ */
+
+void tvh_mutex_not_held(const char *file, int line);
+
+static inline void
+lock_assert0(tvh_mutex_t *l, const char *file, int line)
+{
+#if 0 && ENABLE_LOCKOWNER
+  assert(l->mutex.__data.__owner == syscall(SYS_gettid));
+#else
+  if(pthread_mutex_trylock(&l->mutex) == EBUSY)
+    return;
+  tvh_mutex_not_held(file, line);
+#endif
+}
+
+#define lock_assert(l) lock_assert0(l, __FILE__, __LINE__)
+
+/*
+ *
+ */
+
+int tvh_thread_create
+  (pthread_t *thread, const pthread_attr_t *attr,
+   void *(*start_routine) (void *), void *arg,
+   const char *name);
+
+int tvh_thread_kill(pthread_t thread, int sig);
+int tvh_thread_renice(int value);
+
+int tvh_mutex_init(tvh_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr);
+int tvh_mutex_destroy(tvh_mutex_t *mutex);
+int tvh_mutex_lock(tvh_mutex_t *mutex);
+int tvh_mutex_trylock(tvh_mutex_t *mutex);
+int tvh_mutex_unlock(tvh_mutex_t *mutex);
+int tvh_mutex_timedlock(tvh_mutex_t *mutex, int64_t usec);
+
+int tvh_cond_init(tvh_cond_t *cond, int monotonic);
+int tvh_cond_destroy(tvh_cond_t *cond);
+int tvh_cond_signal(tvh_cond_t *cond, int broadcast);
+int tvh_cond_wait(tvh_cond_t *cond, tvh_mutex_t *mutex);
+int tvh_cond_timedwait(tvh_cond_t *cond, tvh_mutex_t *mutex, int64_t clock);
+int tvh_cond_timedwait_ts(tvh_cond_t *cond, tvh_mutex_t *mutex, struct timespec *ts);
+
+#ifndef TVH_THREAD_C
+#define pthread_cond    __do_not_use_pthread_cond
+#define pthread_cond_t  __do_not_use_pthread_cond_t
+#define pthread_mutex   __do_not_use_pthread_mutex
+#define pthread_mutex_t __do_not_use_pthread_mutex_t
+#endif
+
+#endif /* TVHEADEND_THREAD_H */
index 3ff3decc0844e451279e68a8a51925c96b466f42..0d926b5bb7b004cbbaeb0c920f831dada28e9a7c 100644 (file)
@@ -20,8 +20,6 @@
 
 #include "build.h"
 
-#define _GNU_SOURCE
-#include <pthread.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <errno.h>
 #include <assert.h>
 #include <unistd.h>
 #include <limits.h>
-#if ENABLE_LOCKOWNER || ENABLE_ANDROID
-#include <sys/syscall.h>
-#endif
 #include "queue.h"
+#include "tvh_thread.h"
 #include "tvh_string.h"
 #include "hts_strtab.h"
 #include "htsmsg.h"
@@ -78,45 +74,20 @@ typedef struct str_list
 #define PTS_UNSET INT64_C(0x8000000000000000)
 #define PTS_MASK  INT64_C(0x00000001ffffffff)
 
-extern pthread_mutex_t global_lock;
-extern pthread_mutex_t tasklet_lock;
-extern pthread_mutex_t fork_lock;
+extern tvh_mutex_t global_lock;
+extern tvh_mutex_t tasklet_lock;
+extern tvh_mutex_t fork_lock;
 
 extern int tvheadend_webui_port;
 extern int tvheadend_webui_debug;
 extern int tvheadend_htsp_port;
 
-static inline void
-lock_assert0(pthread_mutex_t *l, const char *file, int line)
-{
-#if 0 && ENABLE_LOCKOWNER
-  assert(l->__data.__owner == syscall(SYS_gettid));
-#else
-  if(pthread_mutex_trylock(l) == EBUSY)
-    return;
-
-  fprintf(stderr, "Mutex not held at %s:%d\n", file, line);
-  abort();
-#endif
-}
-
-#define lock_assert(l) lock_assert0(l, __FILE__, __LINE__)
-
 #if defined(__has_feature)
 #if __has_feature(address_sanitizer) || __has_feature(thread_sanitizer)
 #define CLANG_SANITIZER 1
 #endif
 #endif
 
-/*
- *
- */
-
-typedef struct {
-  pthread_cond_t cond;
-} tvh_cond_t;
-
-
 /*
  *
  */
@@ -246,15 +217,6 @@ int tvh_kill_to_sig(int tvh_kill);
 int sri_to_rate(int sri);
 int rate_to_sri(int rate);
 
-extern void scopedunlock(pthread_mutex_t **mtxp);
-
-#define scopedlock(mtx) \
- pthread_mutex_t *scopedlock ## __LINE__ \
- __attribute__((cleanup(scopedunlock))) = mtx; \
- pthread_mutex_lock(scopedlock ## __LINE__);
-
-#define scopedgloballock() scopedlock(&global_lock)
-
 typedef struct th_pipe
 {
   int rd;
@@ -263,25 +225,6 @@ typedef struct th_pipe
 
 void doexit(int x);
 
-int tvhthread_create
-  (pthread_t *thread, const pthread_attr_t *attr,
-   void *(*start_routine) (void *), void *arg,
-   const char *name);
-
-int tvhthread_renice(int value);
-
-int tvh_mutex_timedlock(pthread_mutex_t *mutex, int64_t usec);
-
-int tvh_cond_init(tvh_cond_t *cond);
-
-int tvh_cond_destroy(tvh_cond_t *cond);
-
-int tvh_cond_signal(tvh_cond_t *cond, int broadcast);
-
-int tvh_cond_wait(tvh_cond_t *cond, pthread_mutex_t *mutex);
-
-int tvh_cond_timedwait(tvh_cond_t *cond, pthread_mutex_t *mutex, int64_t monoclock);
-
 int tvh_open(const char *pathname, int flags, mode_t mode);
 
 int tvh_socket(int domain, int type, int protocol);
index 80b2a3111e6468017e40807417b97f6887bb963d..ef41aaf82c2a9f2981f2b44116aebbd2f0d6f43c 100644 (file)
@@ -17,7 +17,6 @@
  */
 
 #include "tvhlog.h"
-#include <pthread.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -40,7 +39,7 @@ char                    *tvhlog_path;
 bitops_ulong_t           tvhlog_debug[TVHLOG_BITARRAY];
 bitops_ulong_t           tvhlog_trace[TVHLOG_BITARRAY];
 pthread_t                tvhlog_tid;
-pthread_mutex_t          tvhlog_mutex;
+tvh_mutex_t              tvhlog_mutex;
 tvh_cond_t               tvhlog_cond;
 TAILQ_HEAD(,tvhlog_msg)  tvhlog_queue;
 int                      tvhlog_queue_size;
@@ -335,7 +334,7 @@ tvhlog_thread ( void *p )
   FILE *fp = NULL;
   tvhlog_msg_t *msg;
 
-  pthread_mutex_lock(&tvhlog_mutex);
+  tvh_mutex_lock(&tvhlog_mutex);
   while (tvhlog_run) {
 
     /* Wait */
@@ -363,13 +362,13 @@ tvhlog_thread ( void *p )
       }
     }
     options  = tvhlog_options;
-    pthread_mutex_unlock(&tvhlog_mutex);
+    tvh_mutex_unlock(&tvhlog_mutex);
     tvhlog_process(msg, options, &fp, path);
-    pthread_mutex_lock(&tvhlog_mutex);
+    tvh_mutex_lock(&tvhlog_mutex);
   }
   if (fp)
     fclose(fp);
-  pthread_mutex_unlock(&tvhlog_mutex);
+  tvh_mutex_unlock(&tvhlog_mutex);
   return NULL;
 }
 
@@ -398,11 +397,11 @@ void tvhlogv ( const char *file, int line, int severity,
   if (!ok)
     return;
 
-  pthread_mutex_lock(&tvhlog_mutex);
+  tvh_mutex_lock(&tvhlog_mutex);
 
   /* Check for full */
   if (tvhlog_queue_full) {
-    pthread_mutex_unlock(&tvhlog_mutex);
+    tvh_mutex_unlock(&tvhlog_mutex);
     return;
   }
 
@@ -447,7 +446,7 @@ void tvhlogv ( const char *file, int line, int severity,
 #if TVHLOG_THREAD
   }
 #endif
-  pthread_mutex_unlock(&tvhlog_mutex);
+  tvh_mutex_unlock(&tvhlog_mutex);
 }
 
 
@@ -536,8 +535,8 @@ tvhlog_init ( int level, int options, const char *path )
   memset(tvhlog_debug, 0, sizeof(tvhlog_debug));
   tvhlog_run     = 1;
   openlog("tvheadend", LOG_PID, LOG_DAEMON);
-  pthread_mutex_init(&tvhlog_mutex, NULL);
-  tvh_cond_init(&tvhlog_cond);
+  tvh_mutex_init(&tvhlog_mutex, NULL);
+  tvh_cond_init(&tvhlog_cond, 1);
   TAILQ_INIT(&tvhlog_queue);
 }
 
@@ -545,7 +544,7 @@ void
 tvhlog_start ( void )
 {
   idclass_register(&tvhlog_conf_class);
-  tvhthread_create(&tvhlog_tid, NULL, tvhlog_thread, NULL, "log");
+  tvh_thread_create(&tvhlog_tid, NULL, tvhlog_thread, NULL, "log");
 }
 
 void
@@ -553,18 +552,18 @@ tvhlog_end ( void )
 {
   FILE *fp = NULL;
   tvhlog_msg_t *msg;
-  pthread_mutex_lock(&tvhlog_mutex);
+  tvh_mutex_lock(&tvhlog_mutex);
   tvhlog_run = 0;
   tvh_cond_signal(&tvhlog_cond, 0);
-  pthread_mutex_unlock(&tvhlog_mutex);
+  tvh_mutex_unlock(&tvhlog_mutex);
   pthread_join(tvhlog_tid, NULL);
-  pthread_mutex_lock(&tvhlog_mutex);
+  tvh_mutex_lock(&tvhlog_mutex);
   while ((msg = TAILQ_FIRST(&tvhlog_queue)) != NULL) {
     TAILQ_REMOVE(&tvhlog_queue, msg, link);
     tvhlog_process(msg, tvhlog_options, &fp, tvhlog_path);
   }
   tvhlog_queue_full = 1;
-  pthread_mutex_unlock(&tvhlog_mutex);
+  tvh_mutex_unlock(&tvhlog_mutex);
   if (fp)
     fclose(fp);
   free(tvhlog_path);
@@ -586,14 +585,14 @@ tvhlog_class_path_set ( void *o, const void *v )
 {
   const char *s = v;
   if (strcmp(s ?: "", tvhlog_path ?: "")) {
-    pthread_mutex_lock(&tvhlog_mutex);
+    tvh_mutex_lock(&tvhlog_mutex);
     free(tvhlog_path);
     tvhlog_path = strdup(s ?: "");
     if (tvhlog_path && tvhlog_path[0])
       tvhlog_options |= TVHLOG_OPT_DBG_FILE;
     else
       tvhlog_options &= ~TVHLOG_OPT_DBG_FILE;
-    pthread_mutex_unlock(&tvhlog_mutex);
+    tvh_mutex_unlock(&tvhlog_mutex);
     return 1;
   }
   return 0;
@@ -640,12 +639,12 @@ tvhlog_class_enable_syslog_get ( void *o )
 static int
 tvhlog_class_enable_syslog_set ( void *o, const void *v )
 {
-  pthread_mutex_lock(&tvhlog_mutex);
+  tvh_mutex_lock(&tvhlog_mutex);
   if (*(int *)v)
     tvhlog_options |= TVHLOG_OPT_SYSLOG;
   else
     tvhlog_options &= ~TVHLOG_OPT_SYSLOG;
-  pthread_mutex_unlock(&tvhlog_mutex);
+  tvh_mutex_unlock(&tvhlog_mutex);
   return 1;
 }
 
@@ -660,12 +659,12 @@ tvhlog_class_debug_syslog_get ( void *o )
 static int
 tvhlog_class_debug_syslog_set ( void *o, const void *v )
 {
-  pthread_mutex_lock(&tvhlog_mutex);
+  tvh_mutex_lock(&tvhlog_mutex);
   if (*(int *)v)
     tvhlog_options |= TVHLOG_OPT_DBG_SYSLOG;
   else
     tvhlog_options &= ~TVHLOG_OPT_DBG_SYSLOG;
-  pthread_mutex_unlock(&tvhlog_mutex);
+  tvh_mutex_unlock(&tvhlog_mutex);
   return 1;
 }
 
@@ -695,13 +694,13 @@ tvhlog_class_libav_get ( void *o )
 static int
 tvhlog_class_libav_set ( void *o, const void *v )
 {
-  pthread_mutex_lock(&tvhlog_mutex);
+  tvh_mutex_lock(&tvhlog_mutex);
   if (*(int *)v)
     tvhlog_options |= TVHLOG_OPT_LIBAV;
   else
     tvhlog_options &= ~TVHLOG_OPT_LIBAV;
   libav_set_loglevel();
-  pthread_mutex_unlock(&tvhlog_mutex);
+  tvh_mutex_unlock(&tvhlog_mutex);
   return 1;
 }
 
index f6b20b32922bebb01fdaf3fd92d0f922dc5b7a15..54ba771dd323ee161a4c75e7997397ebc15a172c 100644 (file)
 #define __TVH_LOGGING_H__
 
 #include <sys/types.h>
+#include <stdarg.h>
 #include "build.h"
 #if ENABLE_ANDROID
 #include <syslog.h>
 #else
 #include <sys/syslog.h>
 #endif
-#include <pthread.h>
-#include <stdarg.h>
-#include <time.h>
 
+#include "tvh_thread.h"
 #include "atomic.h"
 #include "clock.h"
 #include "htsmsg.h"
@@ -47,7 +46,7 @@ typedef struct {
 extern int              tvhlog_level;
 extern char            *tvhlog_path;
 extern int              tvhlog_options;
-extern pthread_mutex_t  tvhlog_mutex;
+extern tvh_mutex_t      tvhlog_mutex;
 extern tvhlog_subsys_t  tvhlog_subsystems[];
 
 /* Initialise */
index b3292b348c5314bfe9433dd31da9ea706cb4a935..1803346552f7c52806bb5d34a7d3c43d22ba268c 100644 (file)
@@ -41,7 +41,7 @@
 
 struct tvhpoll
 {
-  pthread_mutex_t lock;
+  tvh_mutex_t lock;
   uint8_t *events;
   uint32_t events_off;
   uint32_t nevents;
@@ -142,7 +142,7 @@ tvhpoll_create ( size_t n )
   fd = -1;
 #endif
   tvhpoll_t *tp = calloc(1, sizeof(tvhpoll_t));
-  pthread_mutex_init(&tp->lock, NULL);
+  tvh_mutex_init(&tp->lock, NULL);
   tp->fd = fd;
   tvhpoll_alloc(tp, n);
   return tp;
@@ -157,7 +157,7 @@ void tvhpoll_destroy ( tvhpoll_t *tp )
   close(tp->fd);
 #endif
   free(tp->events);
-  pthread_mutex_destroy(&tp->lock);
+  tvh_mutex_destroy(&tp->lock);
   free(tp);
 }
 
@@ -229,9 +229,9 @@ int tvhpoll_add
 {
   int r;
 
-  pthread_mutex_lock(&tp->lock);
+  tvh_mutex_lock(&tp->lock);
   r = tvhpoll_add0(tp, evs, num);
-  pthread_mutex_unlock(&tp->lock);
+  tvh_mutex_unlock(&tp->lock);
   return r;
 }
 
@@ -286,9 +286,9 @@ int tvhpoll_rem
 {
   int r;
 
-  pthread_mutex_lock(&tp->lock);
+  tvh_mutex_lock(&tp->lock);
   r = tvhpoll_rem0(tp, evs, num);
-  pthread_mutex_unlock(&tp->lock);
+  tvh_mutex_unlock(&tp->lock);
   return r;
 }
 
@@ -305,7 +305,7 @@ int tvhpoll_set
 {
   tvhpoll_event_t *lev, *ev;
   int i, j, k, r;
-  pthread_mutex_lock(&tp->lock);
+  tvh_mutex_lock(&tp->lock);
   lev = alloca(tp->nevents * sizeof(*lev));
   for (i = k = 0; i < tp->nevents; i++)
     if (tp->events[i]) {
@@ -323,7 +323,7 @@ int tvhpoll_set
   r = tvhpoll_rem0(tp, lev, k);
   if (r == 0)
     r = tvhpoll_add0(tp, evs, num);
-  pthread_mutex_unlock(&tp->lock);
+  tvh_mutex_unlock(&tp->lock);
   return r;
 }
 
index e1bbbaf3ccd0f2c76753f5e507ac5bec21ab9d6c..8623da1e6251b181454ef94746d9d181679e2538 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <pthread.h>
-#include <assert.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <fcntl.h>
-#include <errno.h>
+#include "tvheadend.h"
+#include "tvhpoll.h"
+#include "upnp.h"
+
 #include <signal.h>
 #include <netinet/in.h>
 #include <netinet/tcp.h>
 #include <arpa/inet.h>
 
-#include "tvheadend.h"
-#include "tvhpoll.h"
-#include "upnp.h"
-
 #if defined(PLATFORM_FREEBSD) || ENABLE_ANDROID
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -41,7 +32,7 @@
 
 int              upnp_running;
 static pthread_t upnp_tid;
-pthread_mutex_t  upnp_lock;
+tvh_mutex_t      upnp_lock;
 
 TAILQ_HEAD(upnp_active_services, upnp_service);
 
@@ -64,18 +55,18 @@ static struct sockaddr_storage upnp_ipv4_multicast;
  */
 upnp_service_t *upnp_service_create0( upnp_service_t *us )
 {
-  pthread_mutex_lock(&upnp_lock);
+  tvh_mutex_lock(&upnp_lock);
   TAILQ_INSERT_TAIL(&upnp_services, us, us_link);
-  pthread_mutex_unlock(&upnp_lock);
+  tvh_mutex_unlock(&upnp_lock);
   return us;
 }
 
 void upnp_service_destroy( upnp_service_t *us )
 {
-  pthread_mutex_lock(&upnp_lock);
+  tvh_mutex_lock(&upnp_lock);
   TAILQ_REMOVE(&upnp_services, us, us_link);
   us->us_destroy(us);
-  pthread_mutex_unlock(&upnp_lock);
+  tvh_mutex_unlock(&upnp_lock);
   free(us);
 }
 
@@ -99,9 +90,9 @@ upnp_send( htsbuf_queue_t *q, struct sockaddr_storage *storage,
     data->storage = *storage;
   data->delay_ms = delay_ms;
   data->from_multicast = from_multicast;
-  pthread_mutex_lock(&upnp_lock);
+  tvh_mutex_lock(&upnp_lock);
   TAILQ_INSERT_TAIL(&upnp_data_write, data, data_link);
-  pthread_mutex_unlock(&upnp_lock);
+  tvh_mutex_unlock(&upnp_lock);
 }
 
 /*
@@ -184,7 +175,7 @@ upnp_thread( void *aux )
     }
 
     while (delay_ms == 0) {
-      pthread_mutex_lock(&upnp_lock);
+      tvh_mutex_lock(&upnp_lock);
       data = TAILQ_FIRST(&upnp_data_write);
       if (data) {
         delay_ms = data->delay_ms;
@@ -195,7 +186,7 @@ upnp_thread( void *aux )
           data = NULL;
         }
       }
-      pthread_mutex_unlock(&upnp_lock);
+      tvh_mutex_unlock(&upnp_lock);
       if (data == NULL)
         break;
       upnp_dump_data(data);
@@ -209,11 +200,11 @@ upnp_thread( void *aux )
 
   /* flush the write queue (byebye messages) */
   while (1) {
-    pthread_mutex_lock(&upnp_lock);
+    tvh_mutex_lock(&upnp_lock);
     data = TAILQ_FIRST(&upnp_data_write);
     if (data)
       TAILQ_REMOVE(&upnp_data_write, data, data_link);
-    pthread_mutex_unlock(&upnp_lock);
+    tvh_mutex_unlock(&upnp_lock);
     if (data == NULL)
       break;
     tvh_safe_usleep((long)data->delay_ms * 1000);
@@ -245,11 +236,11 @@ upnp_server_init(const char *bindaddr)
   r = inet_pton(AF_INET, "239.255.255.250", &IP_AS_V4(upnp_ipv4_multicast, addr));
   assert(r);
 
-  pthread_mutex_init(&upnp_lock, NULL);
+  tvh_mutex_init(&upnp_lock, NULL);
   TAILQ_INIT(&upnp_data_write);
   TAILQ_INIT(&upnp_services);
   atomic_set(&upnp_running, 1);
-  tvhthread_create(&upnp_tid, NULL, upnp_thread, (char *)bindaddr, "upnp");
+  tvh_thread_create(&upnp_tid, NULL, upnp_thread, (char *)bindaddr, "upnp");
 }
 
 void
@@ -259,7 +250,7 @@ upnp_server_done(void)
   upnp_service_t *us;
 
   atomic_set(&upnp_running, 0);
-  pthread_kill(upnp_tid, SIGTERM);
+  tvh_thread_kill(upnp_tid, SIGTERM);
   pthread_join(upnp_tid, NULL);
   while ((us = TAILQ_FIRST(&upnp_services)) != NULL)
     upnp_service_destroy(us);
index f51ad46f20728666472067464a08df32112a0abf..62c8a8222b0b1c49185122d83e393e6c3c62a4c6 100644 (file)
@@ -22,7 +22,7 @@
 #include <systemd/sd-daemon.h>
 
 static pthread_t watchdog_tid;
-static pthread_mutex_t watchdog_exiting_mutex;
+static tvh_mutex_t watchdog_exiting_mutex;
 static tvh_cond_t watchdog_exiting_cond;
 static int watchdog_exiting;    /* 1 if exit has been requested */
 static int watchdog_enabled;    /* 1 if watchdog was enabled for the systemd unit */
@@ -33,7 +33,7 @@ static void* watchdog_thread(void* aux)
   int exiting = 0;
   (void) aux; /* ignore */
   sd_notify(0, "READY=1");
-  pthread_mutex_lock(&watchdog_exiting_mutex);
+  tvh_mutex_lock(&watchdog_exiting_mutex);
   while (!exiting) {
     if (!watchdog_exiting) {
       /*
@@ -42,14 +42,14 @@ static void* watchdog_thread(void* aux)
        */
       tvh_cond_timedwait(&watchdog_exiting_cond, &watchdog_exiting_mutex, mclk() + watchdog_interval_usec);
       if (!watchdog_exiting) {
-        pthread_mutex_lock(&global_lock);
-        pthread_mutex_unlock(&global_lock);
+        tvh_mutex_lock(&global_lock);
+        tvh_mutex_unlock(&global_lock);
         sd_notify(0, "WATCHDOG=1");
       }
     }
     exiting = watchdog_exiting;
   }
-  pthread_mutex_unlock(&watchdog_exiting_mutex);
+  tvh_mutex_unlock(&watchdog_exiting_mutex);
 
   return NULL;
 }
@@ -70,20 +70,20 @@ void watchdog_init(void)
     watchdog_interval_usec /= 2;
 
     watchdog_exiting = 0;
-    tvh_cond_init(&watchdog_exiting_cond);
+    tvh_cond_init(&watchdog_exiting_cond, 1);
     pthread_mutex_init(&watchdog_exiting_mutex, NULL);
 
-    tvhthread_create(&watchdog_tid, NULL, watchdog_thread, NULL, "systemd watchdog");
+    tvh_thread_create(&watchdog_tid, NULL, watchdog_thread, NULL, "systemd watchdog");
   }
 }
 
 void watchdog_done(void)
 {
   if (watchdog_enabled) {
-    pthread_mutex_lock(&watchdog_exiting_mutex);
+    tvh_mutex_lock(&watchdog_exiting_mutex);
     watchdog_exiting = 1;
     tvh_cond_signal(&watchdog_exiting_cond, 0);
-    pthread_mutex_unlock(&watchdog_exiting_mutex);
+    tvh_mutex_unlock(&watchdog_exiting_mutex);
 
     pthread_join(watchdog_tid, NULL);
 
index 5f5b6d0430e36998d13c869f3a644f4e8bb7aaab..4dd7e2db50d781a760a8adf5c9bdbfcfd2d69392 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <pthread.h>
-#include <assert.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <arpa/inet.h>
-#include <sys/socket.h>
 #include <openssl/sha.h>
 
 #include "htsmsg.h"
@@ -39,7 +31,7 @@
 #include "tcp.h"
 #include "memoryinfo.h"
 
-static pthread_mutex_t comet_mutex = PTHREAD_MUTEX_INITIALIZER;
+static tvh_mutex_t comet_mutex = { .mutex = PTHREAD_MUTEX_INITIALIZER };
 static tvh_cond_t comet_cond;
 static int comet_waiting;
 
@@ -102,7 +94,7 @@ comet_flush(void)
 {
   comet_mailbox_t *cmb, *next;
 
-  pthread_mutex_lock(&comet_mutex);
+  tvh_mutex_lock(&comet_mutex);
 
   for(cmb = LIST_FIRST(&mailboxes); cmb != NULL; cmb = next) {
     next = LIST_NEXT(cmb, cmb_link);
@@ -111,7 +103,7 @@ comet_flush(void)
        cmb->cmb_last_used && cmb->cmb_last_used + sec2mono(60) < mclk())
       cmb_destroy(cmb);
   }
-  pthread_mutex_unlock(&comet_mutex);
+  tvh_mutex_unlock(&comet_mutex);
 }
 
 /**
@@ -302,9 +294,9 @@ comet_find_mailbox(http_connection_t *hc, const char *cometid, const char *lang,
   if (http_access_verify(hc, ACCESS_ADMIN)) {
     if (!cmb->cmb_restricted) {
       cmb->cmb_restricted = 1;
-      pthread_mutex_unlock(&comet_mutex);
+      tvh_mutex_unlock(&comet_mutex);
       comet_mailbox_add_logmsg(tvh_gettext_lang(lang, N_("Restricted log mode (no administrator)")), 0, 0);
-      pthread_mutex_lock(&comet_mutex);
+      tvh_mutex_lock(&comet_mutex);
     }
   }
 
@@ -328,10 +320,10 @@ comet_mailbox_poll(http_connection_t *hc, const char *remain, void *opaque)
   if(!im)
     tvh_safe_usleep(100000); /* Always sleep 0.1 sec to avoid comet storms */
 
-  pthread_mutex_lock(&comet_mutex);
+  tvh_mutex_lock(&comet_mutex);
   cmb = comet_find_mailbox(hc, cometid, lang, 1);
   if (cmb == NULL) {
-    pthread_mutex_unlock(&comet_mutex);
+    tvh_mutex_unlock(&comet_mutex);
     return HTTP_STATUS_BAD_REQUEST;
   }
 
@@ -345,13 +337,13 @@ comet_mailbox_poll(http_connection_t *hc, const char *remain, void *opaque)
     } while (ERRNO_AGAIN(e));
     atomic_dec(&comet_waiting, 1);
     if (!atomic_get(&comet_running)) {
-      pthread_mutex_unlock(&comet_mutex);
+      tvh_mutex_unlock(&comet_mutex);
       return HTTP_STATUS_BAD_REQUEST;
     }
   }
 
   m = comet_message(cmb, 1, 0);
-  pthread_mutex_unlock(&comet_mutex);
+  tvh_mutex_unlock(&comet_mutex);
 
   htsmsg_json_serialize(m, &hc->hc_reply, 0);
   htsmsg_destroy(m);
@@ -373,7 +365,7 @@ comet_mailbox_dbg(http_connection_t *hc, const char *remain, void *opaque)
   if(cometid == NULL)
     return HTTP_STATUS_BAD_REQUEST;
 
-  pthread_mutex_lock(&comet_mutex);
+  tvh_mutex_lock(&comet_mutex);
   cmb = comet_find_mailbox(hc, cometid, lang, 0);
   if (cmb) {
     char buf[64];
@@ -397,7 +389,7 @@ comet_mailbox_dbg(http_connection_t *hc, const char *remain, void *opaque)
 
     tvh_cond_signal(&comet_cond, 1);
   }
-  pthread_mutex_unlock(&comet_mutex);
+  tvh_mutex_unlock(&comet_mutex);
 
   http_output_content(hc, "text/plain; charset=UTF-8");
   return 0;
@@ -410,14 +402,14 @@ static void
 comet_mailbox_ws_msg(http_connection_t *hc, comet_mailbox_t *cmb, int first, htsmsg_t *msg)
 {
   htsmsg_t *m = NULL;
-  pthread_mutex_lock(&comet_mutex);
+  tvh_mutex_lock(&comet_mutex);
   if (!atomic_get(&comet_running)) {
-    pthread_mutex_unlock(&comet_mutex);
+    tvh_mutex_unlock(&comet_mutex);
     return;
   }
   m = comet_message(cmb, first, 1);
   cmb->cmb_last_used = 0;
-  pthread_mutex_unlock(&comet_mutex);
+  tvh_mutex_unlock(&comet_mutex);
   if (m) {
     http_websocket_send_json(hc, m);
     htsmsg_destroy(m);
@@ -438,12 +430,12 @@ comet_mailbox_ws(http_connection_t *hc, const char *remain, void *opaque)
 
   res = http_send_header_websocket(hc, "tvheadend-comet");
 
-  pthread_mutex_lock(&comet_mutex);
+  tvh_mutex_lock(&comet_mutex);
   cmb = comet_find_mailbox(hc, cometid, lang, 1);
   if (cmb)
     cmb->cmb_refcount++;
   atomic_add(&comet_waiting, 1);
-  pthread_mutex_unlock(&comet_mutex);
+  tvh_mutex_unlock(&comet_mutex);
   if (!cmb)
     return -1;
 
@@ -461,12 +453,12 @@ comet_mailbox_ws(http_connection_t *hc, const char *remain, void *opaque)
     }
   }
 
-  pthread_mutex_lock(&comet_mutex);
+  tvh_mutex_lock(&comet_mutex);
   assert(cmb->cmb_refcount > 0);
   cmb->cmb_refcount--;
   cmb->cmb_last_used = mclk();
   atomic_dec(&comet_waiting, 1);
-  pthread_mutex_unlock(&comet_mutex);
+  tvh_mutex_unlock(&comet_mutex);
 
   return res;
 }
@@ -480,11 +472,11 @@ comet_init(void)
   http_path_t *hp;
 
   memoryinfo_register(&comet_memoryinfo);
-  pthread_mutex_lock(&comet_mutex);
-  tvh_cond_init(&comet_cond);
+  tvh_mutex_lock(&comet_mutex);
+  tvh_cond_init(&comet_cond, 1);
   atomic_set(&comet_running, 1);
   atomic_set(&comet_waiting, 0);
-  pthread_mutex_unlock(&comet_mutex);
+  tvh_mutex_unlock(&comet_mutex);
   hp = http_path_add("/comet/ws", NULL, comet_mailbox_ws, ACCESS_WEB_INTERFACE);
   hp->hp_flags = HTTP_PATH_WEBSOCKET;
   http_path_add("/comet/poll",  NULL, comet_mailbox_poll, ACCESS_WEB_INTERFACE);
@@ -496,10 +488,10 @@ comet_done(void)
 {
   comet_mailbox_t *cmb;
 
-  pthread_mutex_lock(&comet_mutex);
+  tvh_mutex_lock(&comet_mutex);
   atomic_set(&comet_running, 0);
   tvh_cond_signal(&comet_cond, 1);
-  pthread_mutex_unlock(&comet_mutex);
+  tvh_mutex_unlock(&comet_mutex);
 
   while (atomic_get(&comet_waiting))
     tvh_usleep(10000);
@@ -509,9 +501,9 @@ comet_done(void)
   while ((cmb = LIST_FIRST(&mailboxes)) != NULL)
     cmb_destroy(cmb);
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   memoryinfo_unregister(&comet_memoryinfo);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 }
 
 /**
@@ -568,7 +560,7 @@ comet_mailbox_add_message(htsmsg_t *m, int isdebug, int rewrite)
   if (!atomic_get(&comet_running))
     return;
 
-  pthread_mutex_lock(&comet_mutex);
+  tvh_mutex_lock(&comet_mutex);
 
   if (atomic_get(&comet_running)) {
     LIST_FOREACH(cmb, &mailboxes, cmb_link) {
@@ -589,7 +581,7 @@ comet_mailbox_add_message(htsmsg_t *m, int isdebug, int rewrite)
     tvh_cond_signal(&comet_cond, 1);
   }
 
-  pthread_mutex_unlock(&comet_mutex);
+  tvh_mutex_unlock(&comet_mutex);
 }
 
 /**
index da14e68a97fa45be84c36e9acdee3e596864ac94..e4f776cfef4433f0152b72f666f7f31c3c45f275 100644 (file)
@@ -216,15 +216,15 @@ md_class(htsbuf_queue_t *hq, const char *clazz, const char *lang,
   const char *s, **doc;
   int nl = 0;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   ic = idclass_find(clazz);
   if (ic == NULL) {
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
     return HTTP_STATUS_NOT_FOUND;
   }
   doc = idclass_get_doc(ic);
   m = idclass_serializedoc(ic, lang);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   if (hdr) {
     s = htsmsg_get_str(m, "caption");
     if (s) {
@@ -250,10 +250,10 @@ http_markdown_classes(http_connection_t *hc)
   const idclass_t *ic;
   htsbuf_queue_t *hq = &hc->hc_reply;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   all = idclass_find_all();
   if (all == NULL) {
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
     return HTTP_STATUS_NOT_FOUND;
   }
   for (all2 = all; *all2; all2++) {
@@ -263,7 +263,7 @@ http_markdown_classes(http_connection_t *hc)
       htsbuf_append(hq, "\n", 1);
     }
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   free(all);
   return 0;
index 434ae5d9ad398e37443e7dfa03dadadc2f51ba20..1d1f412828709c0e8ae46b4f1a82dff3e7a066ca 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <pthread.h>
-#include <assert.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <sys/socket.h>
-
-#include <arpa/inet.h>
-
 #include "htsmsg.h"
 #include "htsmsg_json.h"
 
index 64399e7d41fc4817de4fc07ed676ed7eede17123..3443029cfe7fb6782757b8ea8d98f4e248b7c49a 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <pthread.h>
-#include <assert.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-
 #include "tvheadend.h"
 #include "http.h"
 #include "webui.h"
@@ -197,7 +189,7 @@ page_simple(http_connection_t *hc,
   
   htsbuf_qprintf(hq, "</form><hr>");
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 
 
   if(s != NULL) {
@@ -303,7 +295,7 @@ page_simple(http_connection_t *hc,
 
   dvr_query_free(&dqr);
 
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   htsbuf_qprintf(hq, "</body></html>");
   http_output_html(hc);
@@ -326,10 +318,10 @@ page_einfo(http_connection_t *hc, const char *remain, void *opaque)
   const char *s;
   htsmsg_t *conf;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 
   if(remain == NULL || (e = epg_broadcast_find_by_id(strtoll(remain, NULL, 10))) == NULL) {
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
     return 404;
   }
 
@@ -398,7 +390,7 @@ page_einfo(http_connection_t *hc, const char *remain, void *opaque)
     htsbuf_qprintf(hq, "%s", s);
   
 
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   htsbuf_qprintf(hq, "<hr><a href=\"/simple.html\">To main page</a><br>");
   htsbuf_qprintf(hq, "</body></html>");
@@ -418,10 +410,10 @@ page_pvrinfo(http_connection_t *hc, const char *remain, void *opaque)
   const char *rstatus;
   char ubuf[UUID_HEX_SIZE];
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 
   if(remain == NULL || (de = dvr_entry_find_by_id(atoi(remain))) == NULL) {
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
     return 404;
   }
   if((http_arg_get(&hc->hc_req_args, "clear")) != NULL) {
@@ -431,7 +423,7 @@ page_pvrinfo(http_connection_t *hc, const char *remain, void *opaque)
   }
 
   if(de == NULL) {
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
     http_redirect(hc, "/simple.html", &hc->hc_req_args, 0);
     return 0;
   }
@@ -476,7 +468,7 @@ page_pvrinfo(http_connection_t *hc, const char *remain, void *opaque)
   htsbuf_qprintf(hq, "</form>");
   htsbuf_qprintf(hq, "%s", lang_str_get(de->de_desc, NULL));
 
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   htsbuf_qprintf(hq, "<hr><a href=\"/simple.html\">To main page</a><br>");
   htsbuf_qprintf(hq, "</body></html>");
@@ -521,7 +513,7 @@ page_status(http_connection_t *hc,
 #endif
   htsbuf_qprintf(hq,"<recordings>\n");
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 
   dvr_query(&dqr);
   dvr_query_sort(&dqr);
@@ -589,7 +581,7 @@ page_status(http_connection_t *hc,
   htsbuf_qprintf(hq, "</recordings>\n<subscriptions>");
   htsbuf_qprintf(hq, "%d</subscriptions>\n",subscriptions_active());
 
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   htsbuf_qprintf(hq, "</currentload>");
   http_output_content(hc, "text/xml");
@@ -609,9 +601,9 @@ page_epgsave(http_connection_t *hc,
   htsbuf_qprintf(hq, "<?xml version=\"1.0\"?>\n"
                  "<epgflush>1</epgflush>\n");
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   epg_save();
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   http_output_content(hc, "text/xml");
 
index 1397df095d682eebb8e70a6fb1e210f49d622bd9..0be3f6ac49f17faf95dbcb5ca11493191d381ce9 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <pthread.h>
-#include <assert.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-
 #include "tvheadend.h"
 #include "http.h"
 #include "webui.h"
@@ -144,9 +137,6 @@ page_statedump(http_connection_t *hc, const char *remain, void *opaque)
 {
   htsbuf_queue_t *hq = &hc->hc_reply;
 
-  scopedgloballock();
-
   htsbuf_qprintf(hq, "Tvheadend %s  Binary SHA1: "
                 "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
                 "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n",
index 8cb985002b8549b94ec3fc144c69fc7c52646238..5732a3ce0492a24f466289e77b208859a08fdfa3 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#define _GNU_SOURCE /* for splice() */
-#include <fcntl.h>
-
-#include <pthread.h>
-#include <assert.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <arpa/inet.h>
-
 #include <sys/stat.h>
+#include <fcntl.h>
 
 #include "tvheadend.h"
 #include "config.h"
@@ -366,13 +355,13 @@ http_stream_run(http_connection_t *hc, profile_chain_t *prch,
   ptimeout = prch->prch_pro ? prch->prch_pro->pro_timeout : 5;
 
   if (hc->hc_no_output) {
-    pthread_mutex_lock(&sq->sq_mutex);
+    tvh_mutex_lock(&sq->sq_mutex);
     sq->sq_maxsize = 100000;
-    pthread_mutex_unlock(&sq->sq_mutex);
+    tvh_mutex_unlock(&sq->sq_mutex);
   }
 
   while(!hc->hc_shutdown && run && tvheadend_is_running()) {
-    pthread_mutex_lock(&sq->sq_mutex);
+    tvh_mutex_lock(&sq->sq_mutex);
     sm = TAILQ_FIRST(&sq->sq_queue);
     if(sm == NULL) {
       mono = mclk() + sec2mono(1);
@@ -391,12 +380,12 @@ http_stream_run(http_connection_t *hc, profile_chain_t *prch,
           break;
         }
       } while (ERRNO_AGAIN(r));
-      pthread_mutex_unlock(&sq->sq_mutex);
+      tvh_mutex_unlock(&sq->sq_mutex);
       continue;
     }
 
     streaming_queue_remove(sq, sm);
-    pthread_mutex_unlock(&sq->sq_mutex);
+    tvh_mutex_unlock(&sq->sq_mutex);
 
     switch(sm->sm_type) {
     case SMT_MPEGTS:
@@ -1044,7 +1033,7 @@ page_http_playlist_
   if(nc == 2)
     http_deescape(components[1]);
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 
   if(nc == 2 && !strcmp(components[0], "channelid"))
     ch = channel_find_by_id(atoi(components[1]));
@@ -1097,7 +1086,7 @@ page_http_playlist_
     }
   }
 
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   if (r == 0)
     http_output_content(hc, pltype == PLAYLIST_E2 ? MIME_E2 : MIME_M3U);
@@ -1186,9 +1175,9 @@ http_stream_service(http_connection_t *hc, service_t *service, int weight)
                                         NULL);
     if(s) {
       name = tvh_strdupa(service->s_nicename);
-      pthread_mutex_unlock(&global_lock);
+      tvh_mutex_unlock(&global_lock);
       http_stream_run(hc, &prch, name, s);
-      pthread_mutex_lock(&global_lock);
+      tvh_mutex_lock(&global_lock);
       subscription_unsubscribe(s, UNSUBSCRIBE_FINAL);
       res = 0;
     }
@@ -1265,9 +1254,9 @@ http_stream_mux(http_connection_t *hc, mpegts_mux_t *mm, int weight)
       name = tvh_strdupa(s->ths_title);
       ms = (mpegts_service_t *)s->ths_service;
       if (ms->s_update_pids(ms, &pids) == 0) {
-        pthread_mutex_unlock(&global_lock);
+        tvh_mutex_unlock(&global_lock);
         http_stream_run(hc, &prch, name, s);
-        pthread_mutex_lock(&global_lock);
+        tvh_mutex_lock(&global_lock);
       }
       subscription_unsubscribe(s, UNSUBSCRIBE_FINAL);
       res = 0;
@@ -1328,9 +1317,9 @@ http_stream_channel(http_connection_t *hc, channel_t *ch, int weight)
 
     if(s) {
       name = tvh_strdupa(channel_get_name(ch, channel_blank_name));
-      pthread_mutex_unlock(&global_lock);
+      tvh_mutex_unlock(&global_lock);
       http_stream_run(hc, &prch, name, s);
-      pthread_mutex_lock(&global_lock);
+      tvh_mutex_lock(&global_lock);
       subscription_unsubscribe(s, UNSUBSCRIBE_FINAL);
       res = 0;
     }
@@ -1376,8 +1365,6 @@ http_stream(http_connection_t *hc, const char *remain, void *opaque)
   if ((str = http_arg_get(&hc->hc_req_args, "weight")))
     weight = atoi(str);
 
-  scopedgloballock();
-
   if(!strcmp(components[0], "channelid")) {
     ch = channel_find_by_id(atoi(components[1]));
   } else if(!strcmp(components[0], "channelnumber")) {
@@ -1391,7 +1378,7 @@ http_stream(http_connection_t *hc, const char *remain, void *opaque)
 #if ENABLE_MPEGTS
   } else if(!strcmp(components[0], "mux")) {
     // TODO: do we want to be able to force starting a particular instance
-    mm      = mpegts_mux_find(components[1]);
+    mm = mpegts_mux_find(components[1]);
 #endif
   }
 
@@ -1440,9 +1427,9 @@ page_xspf(http_connection_t *hc, const char *remain, void *opaque, int urlauth)
     ticket = http_arg_get(&hc->hc_req_args, "ticket");
     if (strempty(ticket)) {
       snprintf(buf, sizeof(buf), "/%s", remain);
-      pthread_mutex_lock(&global_lock);
+      tvh_mutex_lock(&global_lock);
       ticket = access_ticket_create(buf, hc->hc_access);
-      pthread_mutex_unlock(&global_lock);
+      tvh_mutex_unlock(&global_lock);
     }
     htsbuf_qprintf(hq, "%sticket=%s", delim, ticket);
     break;
@@ -1498,9 +1485,9 @@ page_m3u(http_connection_t *hc, const char *remain, void *opaque, int urlauth)
     ticket = http_arg_get(&hc->hc_req_args, "ticket");
     if (strempty(ticket)) {
       snprintf(buf, sizeof(buf), "/%s", remain);
-      pthread_mutex_lock(&global_lock);
+      tvh_mutex_lock(&global_lock);
       ticket = access_ticket_create(buf, hc->hc_access);
-      pthread_mutex_unlock(&global_lock);
+      tvh_mutex_unlock(&global_lock);
     }
     htsbuf_qprintf(hq, "%sticket=%s", delim, ticket);
     break;
@@ -1791,7 +1778,7 @@ page_dvrfile_preop(http_connection_t *hc, off_t file_start,
 {
   page_dvrfile_priv_t *priv = opaque;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   priv->tcp_id = http_stream_preop(hc);
   priv->sub = NULL;
   if (priv->tcp_id && !hc->hc_no_output && content_len > 64*1024) {
@@ -1804,7 +1791,7 @@ page_dvrfile_preop(http_connection_t *hc, off_t file_start,
       priv->tcp_id = NULL;
     }
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   if (priv->tcp_id == NULL)
     return HTTP_STATUS_NOT_ALLOWED;
   return 0;
@@ -1827,7 +1814,7 @@ page_dvrfile_postop(http_connection_t *hc,
   if (!is_fully_played)
     return 0;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   /* Play count + 1 when not doing HEAD */
   if (!hc->hc_no_output) {
     de = dvr_entry_find_by_uuid(priv->uuid);
@@ -1838,7 +1825,7 @@ page_dvrfile_postop(http_connection_t *hc,
       dvr_entry_changed(de);
     }
   }
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   return 0;
 }
 
@@ -1870,16 +1857,16 @@ page_dvrfile(http_connection_t *hc, const char *remain, void *opaque)
                                     ACCESS_RECORDER)))
     return HTTP_STATUS_UNAUTHORIZED;
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   de = dvr_entry_find_by_uuid(remain);
   if (de == NULL)
     de = dvr_entry_find_by_id(atoi(remain));
   if(de == NULL || (filename = dvr_get_filename(de)) == NULL) {
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
     return HTTP_STATUS_NOT_FOUND;
   }
   if(dvr_entry_verify(de, hc->hc_access, 1)) {
-    pthread_mutex_unlock(&global_lock);
+    tvh_mutex_unlock(&global_lock);
     return HTTP_STATUS_UNAUTHORIZED;
   }
 
@@ -1890,16 +1877,16 @@ page_dvrfile(http_connection_t *hc, const char *remain, void *opaque)
   priv.tcp_id = NULL;
   priv.sub = NULL;
 
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   ret = http_serve_file(hc, priv.fname, 1, priv.content,
                         page_dvrfile_preop, page_dvrfile_postop, page_dvrfile_stats, &priv);
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   if (priv.sub)
     subscription_unsubscribe(priv.sub, UNSUBSCRIBE_FINAL);
   http_stream_postop(priv.tcp_id);
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
   return ret;
 }
 
@@ -1933,9 +1920,9 @@ page_imagecache(http_connection_t *hc, const char *remain, void *opaque)
     return HTTP_STATUS_BAD_REQUEST;
 
   /* Fetch details */
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
   r = imagecache_filename(id, fname, sizeof(fname));
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   if (r)
     return HTTP_STATUS_NOT_FOUND;
index 6ab540965d9f2ea592b45f8b7520549c574dbce6..90668b6914b369bf6f306393f6c4418d154ebbeb 100644 (file)
@@ -318,7 +318,7 @@ page_xmltv(http_connection_t *hc, const char *remain, void *opaque)
   if (nc == 2)
     http_deescape(components[1]);
 
-  pthread_mutex_lock(&global_lock);
+  tvh_mutex_lock(&global_lock);
 
   if (nc == 2 && !strcmp(components[0], "channelid"))
     ch = channel_find_by_id(atoi(components[1]));
@@ -347,7 +347,7 @@ page_xmltv(http_connection_t *hc, const char *remain, void *opaque)
     }
   }
 
-  pthread_mutex_unlock(&global_lock);
+  tvh_mutex_unlock(&global_lock);
 
   if (r == 0)
     http_output_content(hc, "text/xml");
index 3fa9ba2cba72972cabc91f95c6a73c298174b1f5..60554dc5f1f6f599b0ea034d05cbe8dfa7b256fa 100644 (file)
@@ -1,24 +1,7 @@
-#define __USE_GNU
-#include "tvheadend.h"
-#include <assert.h>
-#include <fcntl.h>
-#include <sys/types.h>          /* See NOTES */
-#include <sys/socket.h>
+#define _GNU_SOURCE
 #include <sys/stat.h>
-#include <sys/resource.h>
-#include <unistd.h>
-#include <signal.h>
-#include <pthread.h>
-
-#ifdef PLATFORM_LINUX
-#include <sys/prctl.h>
-#include <sys/syscall.h>
-#endif
-
-#ifdef PLATFORM_FREEBSD
-#include <pthread_np.h>
-#endif
-
+#include <fcntl.h>
+#include "tvheadend.h"
 #include "tvhregex.h"
 
 /*
@@ -30,11 +13,11 @@ tvh_open(const char *pathname, int flags, mode_t mode)
 {
   int fd;
 
-  pthread_mutex_lock(&fork_lock);
+  tvh_mutex_lock(&fork_lock);
   fd = open(pathname, flags, mode);
   if (fd != -1)
     fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
-  pthread_mutex_unlock(&fork_lock);
+  tvh_mutex_unlock(&fork_lock);
   return fd;
 }
 
@@ -43,11 +26,11 @@ tvh_socket(int domain, int type, int protocol)
 {
   int fd;
 
-  pthread_mutex_lock(&fork_lock);
+  tvh_mutex_lock(&fork_lock);
   fd = socket(domain, type, protocol);
   if (fd != -1)
     fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
-  pthread_mutex_unlock(&fork_lock);
+  tvh_mutex_unlock(&fork_lock);
   return fd;
 }
 
@@ -55,7 +38,7 @@ int
 tvh_pipe(int flags, th_pipe_t *p)
 {
   int fd[2], err;
-  pthread_mutex_lock(&fork_lock);
+  tvh_mutex_lock(&fork_lock);
   err = pipe(fd);
   if (err != -1) {
     fcntl(fd[0], F_SETFD, fcntl(fd[0], F_GETFD) | FD_CLOEXEC);
@@ -65,7 +48,7 @@ tvh_pipe(int flags, th_pipe_t *p)
     p->rd = fd[0];
     p->wr = fd[1];
   }
-  pthread_mutex_unlock(&fork_lock);
+  tvh_mutex_unlock(&fork_lock);
   return err;
 }
 
@@ -126,202 +109,16 @@ tvh_fopen(const char *filename, const char *mode)
 {
   FILE *f;
   int fd;
-  pthread_mutex_lock(&fork_lock);
+  tvh_mutex_lock(&fork_lock);
   f = fopen(filename, mode);
   if (f) {
     fd = fileno(f);
     fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
   }
-  pthread_mutex_unlock(&fork_lock);
+  tvh_mutex_unlock(&fork_lock);
   return f;
 }
 
-/*
- * thread routines
- */
-
-static void doquit(int sig)
-{
-}
-
-struct
-thread_state {
-  void *(*run)(void*);
-  void *arg;
-  char name[17];
-};
-
-static void *
-thread_wrapper ( void *p )
-{
-  struct thread_state *ts = p;
-  sigset_t set;
-
-#if defined(PLATFORM_LINUX)
-  /* Set name */
-  prctl(PR_SET_NAME, ts->name);
-#elif defined(PLATFORM_FREEBSD)
-  /* Set name of thread */
-  pthread_set_name_np(pthread_self(), ts->name);
-#elif defined(PLATFORM_DARWIN)
-  pthread_setname_np(ts->name);
-#endif
-
-  sigemptyset(&set);
-  sigaddset(&set, SIGTERM);
-  sigaddset(&set, SIGQUIT);
-  pthread_sigmask(SIG_UNBLOCK, &set, NULL);
-
-  signal(SIGTERM, doexit);
-  signal(SIGQUIT, doquit);
-
-  /* Run */
-  tvhtrace(LS_THREAD, "created thread %ld [%s / %p(%p)]",
-           (long)pthread_self(), ts->name, ts->run, ts->arg);
-  void *r = ts->run(ts->arg);
-  free(ts);
-
-  return r;
-}
-
-int
-tvhthread_create
-  (pthread_t *thread, const pthread_attr_t *attr,
-   void *(*start_routine) (void *), void *arg, const char *name)
-{
-  int r;
-  struct thread_state *ts = calloc(1, sizeof(struct thread_state));
-  pthread_attr_t _attr;
-  if (attr == NULL) {
-    pthread_attr_init(&_attr);
-    pthread_attr_setstacksize(&_attr, 2*1024*1024);
-    attr = &_attr;
-  }
-  strlcpy(ts->name, "tvh:", 5);
-  strlcpy(ts->name+4, name, sizeof(ts->name)-4);
-  ts->run  = start_routine;
-  ts->arg  = arg;
-  r = pthread_create(thread, attr, thread_wrapper, ts);
-  return r;
-}
-
-/* linux style: -19 .. 20 */
-int
-tvhthread_renice(int value)
-{
-  int ret = 0;
-#ifdef SYS_gettid
-  pid_t tid;
-  tid = syscall(SYS_gettid);
-  ret = setpriority(PRIO_PROCESS, tid, value);
-#elif ENABLE_ANDROID
-  pid_t tid;
-  tid = gettid();
-  ret = setpriority(PRIO_PROCESS, tid, value);
-#elif defined(PLATFORM_DARWIN)
-  /* Currently not possible */
-#elif defined(PLATFORM_FREEBSD)
-  /* Currently not possible */
-#else
-#warning "Implement renice for your platform!"
-#endif
-  return ret;
-}
-
-int
-tvh_mutex_timedlock
-  ( pthread_mutex_t *mutex, int64_t usec )
-{
-  int64_t finish = getfastmonoclock() + usec;
-  int retcode;
-
-  while ((retcode = pthread_mutex_trylock (mutex)) == EBUSY) {
-    if (getfastmonoclock() >= finish)
-      return ETIMEDOUT;
-
-    tvh_safe_usleep(10000);
-  }
-
-  return retcode;
-}
-
-/*
- * thread condition variables - monotonic clocks
- */
-
-int
-tvh_cond_init
-  ( tvh_cond_t *cond )
-{
-  int r;
-
-  pthread_condattr_t attr;
-  pthread_condattr_init(&attr);
-#if defined(PLATFORM_DARWIN)
-  /*
-   * pthread_condattr_setclock() not supported on platform Darwin.
-   * We use pthread_cond_timedwait_relative_np() which doesn't
-   * need it.
-   */
-   r = 0;
-#else
-  r = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
-  if (r) {
-    fprintf(stderr, "Unable to set monotonic clocks for conditions! (%d)", r);
-    abort();
-  }
-#endif
-  return pthread_cond_init(&cond->cond, &attr);
-}
-
-int
-tvh_cond_destroy
-  ( tvh_cond_t *cond )
-{
-  return pthread_cond_destroy(&cond->cond);
-}
-
-int
-tvh_cond_signal
-  ( tvh_cond_t *cond, int broadcast )
-{
-  if (broadcast)
-    return pthread_cond_broadcast(&cond->cond);
-  else
-    return pthread_cond_signal(&cond->cond);
-}
-
-int
-tvh_cond_wait
-  ( tvh_cond_t *cond, pthread_mutex_t *mutex)
-{
-  return pthread_cond_wait(&cond->cond, mutex);
-}
-
-int
-tvh_cond_timedwait
-  ( tvh_cond_t *cond, pthread_mutex_t *mutex, int64_t monoclock )
-{
-#if defined(PLATFORM_DARWIN)
-  /* Use a relative timedwait implementation */
-  int64_t now = getmonoclock();
-  int64_t relative = monoclock - now;
-
-  struct timespec ts;
-  ts.tv_sec  = relative / MONOCLOCK_RESOLUTION;
-  ts.tv_nsec = (relative % MONOCLOCK_RESOLUTION) *
-               (1000000000ULL/MONOCLOCK_RESOLUTION);
-
-  return pthread_cond_timedwait_relative_np(&cond->cond, mutex, &ts);
-#else
-  struct timespec ts;
-  ts.tv_sec = monoclock / MONOCLOCK_RESOLUTION;
-  ts.tv_nsec = (monoclock % MONOCLOCK_RESOLUTION) *
-               (1000000000ULL/MONOCLOCK_RESOLUTION);
-  return pthread_cond_timedwait(&cond->cond, mutex, &ts);
-#endif
-}
-
 /*
  * clocks
  */