src/proplib.c \
src/utils.c \
src/wrappers.c \
+ src/tvh_thread.c \
src/tvhvfs.c \
src/access.c \
src/tcp.c \
* 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"
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)
superuser_username = NULL;
free((void *)superuser_password);
superuser_password = NULL;
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
}
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;
}
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;
}
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;
}
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);
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;
}
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;
}
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);
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;
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;
}
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];
}
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);
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;
}
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;
}
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) {
}
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;
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;
}
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.
*/
}
}
}
- 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) {
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))) {
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);
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);
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);
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;
}
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;
}
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) {
res = 0;
free(lang);
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
return res;
}
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) {
idnode_changed(&de->de_id);
}
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
htsmsg_destroy(conf);
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);
dvr_autorec_completed(dae, 0);
}
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
return 0;
}
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) {
}
}
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
count++;
}
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;
}
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 */
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);
/* 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 */
/* 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 */
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) {
entries++;
}
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
free(lang);
/* Build response */
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);
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;
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;
}
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;
}
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;
}
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 */
if (conf.limit > 0) conf.limit--;
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
/* Output */
*resp = htsmsg_create_map();
( 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;
}
/* 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;
}
flist = api_idnode_flist_conf(args, "list");
- pthread_mutex_lock(&global_lock);
+ tvh_mutex_lock(&global_lock);
/* Multiple */
if (uuids) {
htsmsg_destroy(l);
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
htsmsg_destroy(flist);
/* 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;
}
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();
err = EPERM;
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
if (l) {
*resp = htsmsg_create_map();
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) {
// TODO: return updated UUIDs?
exit:
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
return err;
}
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)) {
err = EPERM;
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
return err;
}
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;
}
}
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);
idnode_set_free(v);
}
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
return 0;
}
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) {
*resp = idclass_serialize0(idc, flist, 0, perm->aa_lang_ui);
exit:
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
htsmsg_destroy(flist);
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;
}
idnode_perm_unset(in);
cnt++;
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
if (destroyed)
sched_yield(); /* delete penalty */
}
/* 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 {
}
htsmsg_destroy(msg);
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
}
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;
}
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;
}
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;
}
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)
htsmsg_add_msg(*resp, "entries", l);
exit:
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
return err;
}
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;
} else {
err = EINVAL;
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
return err;
}
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 {
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;
err = 0;
exit:
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
return err;
}
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;
err = 0;
exit:
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
return err;
}
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;
} else {
err = EINVAL;
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
return err;
}
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;
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();
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;
}
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;
/* 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;
}
if (!(uuid = htsmsg_field_get_str(f)))
return EINVAL;
- pthread_mutex_lock(&global_lock);
+ tvh_mutex_lock(&global_lock);
l = htsmsg_create_list();
/* Multiple */
htsmsg_destroy(l);
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
return err;
}
return EINVAL;
htsmsg_print(msg);
- pthread_mutex_lock(&global_lock);
+ tvh_mutex_lock(&global_lock);
/* Single or Foreach */
if (!msg->hm_islist) {
// TODO: return updated UUIDs?
exit:
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
return err;
}
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;
}
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;
}
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) {
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);
htsmsg_add_msg(*resp, "hbbtv", hbbtv);
/* Done */
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
return 0;
}
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;
}
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))) {
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);
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;
}
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;
}
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
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;
}
typedef void * volatile * atomic_refptr_t;
-extern pthread_mutex_t atomic_lock;
+extern tvh_mutex_t atomic_lock;
/*
* Atomic FETCH and ADD operation
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
{
if (!avahi_required())
return;
- tvhthread_create(&avahi_tid, NULL, avahi_thread, NULL, "avahi");
+ tvh_thread_create(&avahi_tid, NULL, avahi_thread, NULL, "avahi");
}
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);
}
{
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);
}
* 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"
{
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();
}
{
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
#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__)
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;
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() */
}
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);
}
/**
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);
}
/**
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;
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);
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) {
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
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);
};
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)
}
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);
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);
{
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
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
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
{
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);
}
/*
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
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");
{
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);
}
* 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"
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 */
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);
}
}
}
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;
}
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;
}
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);
}
/**
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;
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)
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);
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;
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
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)
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
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);
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
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;
descrambler_change_keystate((th_descrambler_t *)ct, keystate, 1);
}
}
- pthread_mutex_unlock(&capmt->capmt_mutex);
+ tvh_mutex_unlock(&capmt->capmt_mutex);
}
#endif
#endif
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;
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
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;
cardsystem, pid, ecmtime, hops, reader, from,
protocol);
}
- pthread_mutex_unlock(&capmt->capmt_mutex);
+ tvh_mutex_unlock(&capmt->capmt_mutex);
}
static int
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;
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) &&
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;
#endif
}
- pthread_mutex_lock(&capmt->capmt_mutex);
+ tvh_mutex_lock(&capmt->capmt_mutex);
caclient_set_status((caclient_t *)capmt, CACLIENT_STATUS_DISCONNECTED);
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;
}
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));
/* 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];
}
}
- pthread_mutex_unlock(&capmt->capmt_mutex);
+ tvh_mutex_unlock(&capmt->capmt_mutex);
}
static void
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;
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);
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 */
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;
}
}
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);
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);
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);
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;
#include <fcntl.h>
#include <signal.h>
-#include <pthread.h>
+
#include "tvheadend.h"
#include "tcp.h"
#include "cclient.h"
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) {
es->es_data_len = 0;
}
ct->ecm_state = ECM_RESET;
- pthread_mutex_unlock(&cc->cc_mutex);
+ tvh_mutex_unlock(&cc->cc_mutex);
return 0;
}
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;
es->es_data_len = 0;
}
ct->ecm_state = ECM_RESET;
- pthread_mutex_unlock(&cc->cc_mutex);
+ tvh_mutex_unlock(&cc->cc_mutex);
}
/**
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,
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);
}
}
{
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)",
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))
int attempts = 0;
int64_t mono;
- pthread_mutex_lock(&cc->cc_mutex);
+ tvh_mutex_lock(&cc->cc_mutex);
while(cc->cc_running) {
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++;
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;
}
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) {
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);
}
/**
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;
}
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);
}
/**
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);
}
/**
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;
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);
}
/**
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) {
}
}
}
- pthread_mutex_unlock(&cc->cc_mutex);
+ tvh_mutex_unlock(&cc->cc_mutex);
}
/**
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);
/* 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 */
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 &&
}
if (c) break;
}
- pthread_mutex_unlock(&t->s_stream_mutex);
+ tvh_mutex_unlock(&t->s_stream_mutex);
if (st == NULL)
return;
}
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);
}
}
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;
}
- 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));
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);
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++) {
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
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++;
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[] = {
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;
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;
}
}
end:
- pthread_mutex_unlock(&t->s_stream_mutex);
+ tvh_mutex_unlock(&t->s_stream_mutex);
}
void
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;
free(des);
}
}
- pthread_mutex_unlock(&mux->mm_descrambler_lock);
+ tvh_mutex_unlock(&mux->mm_descrambler_lock);
}
static inline void
((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;
return 0;
clk = mclk();
LIST_INIT(§ions);
- 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)
des->opaque = ds->opaque;
LIST_INSERT_HEAD(§ions, des, active_link);
}
- pthread_mutex_unlock(&mt->mt_mux->mm_descrambler_lock);
+ tvh_mutex_unlock(&mt->mt_mux->mm_descrambler_lock);
LIST_FOREACH(des, §ions, 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) {
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);
}
} 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];
}
}
}
- pthread_mutex_unlock(&t->s_stream_mutex);
+ tvh_mutex_unlock(&t->s_stream_mutex);
}
}
}
{
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;
}
{
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;
}
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) {
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
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;
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 )
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) {
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);
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);
}
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;
}
}
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;
}
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);
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;
}
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;
/*
*
{
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);
}
/*
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) {
call_update = ac_first == NULL;
reterr:
- pthread_mutex_unlock(&dvbcam_mutex);
+ tvh_mutex_unlock(&dvbcam_mutex);
if (call_update)
dvbcam_status_update();
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) {
call_update = TAILQ_EMPTY(&dvbcam_active_cams);
- pthread_mutex_unlock(&dvbcam_mutex);
+ tvh_mutex_unlock(&dvbcam_mutex);
if (call_update)
dvbcam_status_update();
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)
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
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) {
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);
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) {
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;
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);
}
}
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);
}
/*
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;
} 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);
}
}
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);
}
tsdebugcw_service_t *ct;
} tsdebugcw_request_t;
-pthread_mutex_t tsdebugcw_mutex;
+tvh_mutex_t tsdebugcw_mutex;
TAILQ_HEAD(,tsdebugcw_request) tsdebugcw_requests;
/*
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) {
free(ctr);
}
}
- pthread_mutex_unlock(&tsdebugcw_mutex);
+ tvh_mutex_unlock(&tsdebugcw_mutex);
LIST_REMOVE(td, td_service_link);
free(ct->td_nicename);
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);
}
/*
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);
}
/*
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,
void
tsdebugcw_init(void)
{
- pthread_mutex_init(&tsdebugcw_mutex, NULL);
+ tvh_mutex_init(&tsdebugcw_mutex, NULL);
TAILQ_INIT(&tsdebugcw_requests);
}
last_url++;
}
- pthread_mutex_lock(&global_lock);
+ tvh_mutex_lock(&global_lock);
if (dn->http_client == NULL)
goto out;
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;
* 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"
{
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
* 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"
#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();
* 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"
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;
if (chg)
idnode_changed(&de->de_id);
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
return r;
}
* 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"
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");
}
/**
{
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);
}
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);
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;
* 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"
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);
*run = 0;
return 0;
}
- pthread_mutex_lock(&global_lock);
+ tvh_mutex_lock(&global_lock);
return 1;
}
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);
}
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) {
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) {
}
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);
* 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"
{
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
* 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"
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;
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)
dvr_disk_space_config_size = idx;
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
}
/**
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);
}
/**
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));
}
{
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;
} else {
res = -EINVAL;
}
- pthread_mutex_unlock(&dvr_disk_space_mutex);
+ tvh_mutex_unlock(&dvr_disk_space_mutex);
return res;
}
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
-#include <pthread.h>
#include <signal.h>
#include <setjmp.h>
{
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);
}
/* **************************************************************************
/* 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;
/* 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;
}
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;
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 */
epggrab_rerun_internal(void)
{
epggrab_confver++;
- pthread_cond_signal(&epggrab_cond);
+ tvh_cond_signal(&epggrab_cond, 0);
}
/*
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);
}
}
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);
}
TAILQ_REMOVE(&epggrab_data_modules, mod, qlink);
}
- pthread_mutex_unlock(&epggrab_data_mutex);
+ tvh_mutex_unlock(&epggrab_data_mutex);
return NULL;
}
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);
}
/* **************************************************************************
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
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);
/* 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");
}
/*
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);
epggrab_conf.ota_cron = NULL;
epggrab_channel_done();
memoryinfo_unregister(&epggrab_data_memoryinfo);
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
}
#include "idnode.h"
-#include <pthread.h>
-
/* **************************************************************************
* Typedefs/Forward decls
* *************************************************************************/
* 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;
* 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>
#include "epg.h"
#include "epggrab.h"
#include "epggrab/private.h"
+
extern gtimer_t epggrab_save_timer;
/* **************************************************************************
/* 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
*/
gtimer_arm_rel(&epggrab_save_timer, epg_save_callback, NULL,
60 * 2);
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
}
}
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;
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;
}
_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) {
}
}
if (lock)
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
#if TODO_ADD_EXTRA
if (ev.extra) htsmsg_destroy(ev.extra);
}
if (save) {
- pthread_mutex_lock(&global_lock);
+ tvh_mutex_lock(&global_lock);
epg_updated();
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
}
}
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);
}
/* ************************************************************************
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;
}
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);
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
{
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 */
tvhwarn(LS_EPGGRAB, "ota cron config invalid or unset");
}
- pthread_mutex_unlock(&epggrab_ota_mutex);
+ tvh_mutex_unlock(&epggrab_ota_mutex);
}
/*
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 = {
{
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);
}
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;
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);
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);
}
break;
/* Process */
- pthread_mutex_lock(&global_lock);
+ tvh_mutex_lock(&global_lock);
i = 0;
while ( i < c ) {
ev = (struct inotify_event*)&buf[i];
fsm->fsm_delete(fsm, path);
}
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
}
return NULL;
}
{
/* 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");
}
/*
{
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);
}
} bin;
htsmsg_t *msg;
double dbl;
- int bool;
+ int boolean;
} u;
#if ENABLE_SLOW_MEMORYINFO
#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)
* 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"
/* **************************************************************************
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;
{
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);
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);
}
/**
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);
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);
}
/**
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"));
}
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);
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");
htsmsg_destroy(args2);
- pthread_mutex_lock(&global_lock);
+ tvh_mutex_lock(&global_lock);
return ret;
}
fd = hf->hf_fd;
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
/* Seek (optional) */
if (!htsmsg_get_s64(in, "offset", &off))
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;
}
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();
}
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;
}
}
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;
}
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;
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;
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,
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);
}
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);
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;
}
size_t dlen;
int r;
- pthread_mutex_lock(&htsp->htsp_out_mutex);
+ tvh_mutex_lock(&htsp->htsp_out_mutex);
while(htsp->htsp_writer_run) {
}
}
- 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;
}
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",
// 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;
}
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
* 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)
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);
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);
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);
}
/* **************************************************************************
* 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;
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]);
* 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"
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[] = {
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 ||
*_hp = *hp;
hp = _hp;
}
- pthread_mutex_unlock(hc->hc_paths_mutex);
+ tvh_mutex_unlock(hc->hc_paths_mutex);
if(hp == NULL)
return 0;
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;
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;
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;
}
{
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) {
atomic_dec(&hc->hc_extra_chunks, 1);
}
}
- pthread_mutex_unlock(&hc->hc_extra_lock);
+ tvh_mutex_unlock(&hc->hc_extra_lock);
}
/**
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);
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))
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;
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);
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);
}
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;
}
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);
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;
close(fd);
// Note: leave global_lock held for parent
- pthread_mutex_lock(&global_lock);
+ tvh_mutex_lock(&global_lock);
*opaque = NULL;
}
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);
}
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);
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;
TAILQ_ENTRY(http_client) hc_link;
- pthread_mutex_t hc_mutex;
+ tvh_mutex_t hc_mutex;
int hc_id;
int hc_fd;
#include "tcp.h"
#include "config.h"
-#include <pthread.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
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;
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;
}
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)
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);
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;
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);
}
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;
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;
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;
}
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;
}
}
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);
}
}
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;
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;
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);
}
/*
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);
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);
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);
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
}
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 */
/* 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
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);
}
/*
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;
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;
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)
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);
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);
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;
}
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);
}
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);
}
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
{
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);
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)
* 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"
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 */
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;
}
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);
/* Process */
error_lock:
- pthread_mutex_lock(&global_lock);
+ tvh_mutex_lock(&global_lock);
error:
if (NULL != hc) http_client_close(hc);
urlreset(&url);
{
imagecache_image_t *img;
- pthread_mutex_lock(&global_lock);
+ tvh_mutex_lock(&global_lock);
while (tvheadend_is_running()) {
/* Check we're enabled */
/* Fetch */
(void)imagecache_image_fetch(img);
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
return NULL;
}
/* Create threads */
#if ENABLE_IMAGECACHE
- tvh_cond_init(&imagecache_cond);
+ tvh_cond_init(&imagecache_cond, 1);
TAILQ_INIT(&imagecache_queue);
#endif
/* 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
#ifndef __IMAGE_CACHE_H__
#define __IMAGE_CACHE_H__
-#include <pthread.h>
+#include "tvh_thread.h"
#include "idnode.h"
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 );
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);
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;
/*
// 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;
/* 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;
/* 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;
}
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);
/* 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) {
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|
* 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;
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);
}
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);
}
/* 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) {
im->mm_active = NULL;
}
}
- pthread_mutex_unlock(&iptv_lock);
+ tvh_mutex_unlock(&iptv_lock);
urlreset(&url);
free(s);
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);
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);
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;
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));
}
im = ev.ptr;
r = 0;
- pthread_mutex_lock(&iptv_lock);
+ tvh_mutex_lock(&iptv_lock);
/* Only when active */
if (im->mm_active) {
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;
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);
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();
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);
}
/******************************************************************************
#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);
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) {
#endif
off += r;
}
- pthread_mutex_unlock(&iptv_lock);
+ tvh_mutex_unlock(&iptv_lock);
return NULL;
}
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;
}
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;
}
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)
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)
} else {
iptv_input_recv_flush(hp->im);
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
hp->started = 1;
}
return 0;
return 0;
}
- pthread_mutex_lock(&iptv_lock);
+ tvh_mutex_lock(&iptv_lock);
if (hp->hls_encrypted) {
off = im->mm_iptv_buffer.sb_ptr;
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;
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;
}
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 {
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);
int running;
int pause;
pthread_t thread;
- pthread_mutex_t lock;
+ tvh_mutex_t lock;
th_pipe_t pipe;
AVFormatContext *ictx;
AVFormatContext *octx;
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;
}
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;
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;
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);
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;
}
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);
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;
}
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 );
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;
}
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;
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)
rtcp_destroy(rp->rtcp_info);
free(rp->rtcp_info);
free(rp);
- pthread_mutex_lock(&iptv_lock);
+ tvh_mutex_lock(&iptv_lock);
}
static void
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
/* 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++) {
}
/* 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) {
#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 */
}
#endif /* ENABLE_DDCI */
- pthread_mutex_lock(&global_lock);
+ tvh_mutex_lock(&global_lock);
if (!la) {
snprintf(name, sizeof(name), "CAM #%d", i);
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 */
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)
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) {
#if ENABLE_LINUXDVB_CA
linuxdvb_ca_done();
#endif
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
}
#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;
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;
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);
}
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)
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,
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);
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)
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;
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);
waitms = 1;
}
}
- pthread_mutex_unlock(&linuxdvb_ca_mutex);
+ tvh_mutex_unlock(&linuxdvb_ca_mutex);
}
tvhpoll_destroy(poll);
{
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);
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);
/* 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);
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);
#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;
}
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);
- /*
+/*
* Tvheadend - Linux DVB DDCI
*
* Copyright (C) 2017 Jasmin Jessich
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;
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;
{
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
{
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);
}
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
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);
break;
}
} while (ERRNO_AGAIN(e));
- pthread_mutex_unlock(&ddci_thread->lddci_thread_lock);
+ tvh_mutex_unlock(&ddci_thread->lddci_thread_lock);
}
return e;
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;
{
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);
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;
}
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;
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
{
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)))
{
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
/* 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
* 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);
}
* *************************************************************************/
/* 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
/* 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;
}
break;
}
}
- pthread_mutex_unlock(&linuxdvb_en50494_lock);
+ tvh_mutex_unlock(&linuxdvb_en50494_lock);
return ret == 0 ? 0 : -1;
}
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");
}
}
/* 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);
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)
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);
/* 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,
}
- pthread_mutex_lock(&mmi->tii_stats_mutex);
+ tvh_mutex_lock(&mmi->tii_stats_mutex);
/* Statistics - New API */
#if DVB_VER_ATLEAST(5,10)
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);
}
}
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);
tuned->all = lfe->lfe_pids.all;
- pthread_mutex_unlock(&lfe->lfe_dvr_lock);
+ tvh_mutex_unlock(&lfe->lfe_dvr_lock);
}
static void *
}
/* 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 */
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 */
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;
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;
}
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;
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:
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)
}
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) {
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)
}
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);
{
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
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)
ret = 1;
break;
}
- pthread_mutex_unlock(&mi->mi_output_lock);
+ tvh_mutex_unlock(&mi->mi_output_lock);
return ret;
}
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);
}
/* **************************************************************************
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;
} else {
free(mp);
}
- pthread_mutex_unlock(&mi->mi_input_lock);
+ tvh_mutex_unlock(&mi->mi_input_lock);
}
void
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) {
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);
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);
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
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;
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);
}
}
len -= llen;
}
unlock:
- pthread_mutex_unlock(&mi->mi_output_lock);
+ tvh_mutex_unlock(&mi->mi_output_lock);
}
static void *
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 */
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 */
}
#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);
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);
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 */
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 */
free(mtf);
}
mi->mi_table_queue_size = 0;
- pthread_mutex_unlock(&mi->mi_output_lock);
+ tvh_mutex_unlock(&mi->mi_output_lock);
return NULL;
}
// 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);
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;
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);
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);
}
}
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);
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
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");
}
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
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);
}
/* **************************************************************************
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);
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);
}
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 */
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);
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);
}
return NULL;
}
- pthread_mutex_init(&mmi->tii_stats_mutex, NULL);
+ tvh_mutex_init(&mmi->tii_stats_mutex, NULL);
/* Setup links */
mmi->mmi_mux = mm;
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))) {
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);
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);
}
}
}
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);
}
}
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) {
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) {
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)
/* 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;
c++;
}
}
- pthread_mutex_unlock(&mm->mm_tables_lock);
+ tvh_mutex_unlock(&mm->mm_tables_lock);
/* No DATA - give up now */
if (!c) {
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();
if (mmi->mmi_input)
mmi->mmi_input->mi_tuning_error(mmi->mmi_input, mm);
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
}
}
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);
}
/******************************************************************************
{
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();
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) {
}
}
}
- pthread_mutex_unlock(&mi->mi_output_lock);
+ tvh_mutex_unlock(&mi->mi_output_lock);
return pids;
}
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);
/* 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;
}
} 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) {
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);
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);
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;
}
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);
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;
}
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);
}
{
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);
}
/**
{
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)
mpegts_table_consistency_check(mm);
break;
}
- pthread_mutex_unlock(&mm->mm_tables_lock);
+ tvh_mutex_unlock(&mm->mm_tables_lock);
return mt;
}
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)
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)",
}
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;
}
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);
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);
}
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;
block < 0 ? "stopped" : (block > 0 ? "allowed" : "disabled"));
}
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
}
static char *
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);
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);
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);
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;
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
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)) {
nd = TAILQ_NEXT(d, disc_link);
satip_discovery_destroy(d, 1);
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
}
((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;
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));
/* 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);
}
lfe->sf_running = 0;
lfe->sf_req = NULL;
- pthread_mutex_unlock(&lfe->sf_dvr_lock);
+ tvh_mutex_unlock(&lfe->sf_dvr_lock);
}
static int
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);
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) {
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);
}
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);
}
* -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;
status = SIGNAL_FAINT;
lfe->sf_status = status;
fail:
- pthread_mutex_unlock(&mmi->tii_stats_mutex);
+ tvh_mutex_unlock(&mmi->tii_stats_mutex);
}
static int
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;
}
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";
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')
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);
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;
} 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;
(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++) {
}
}
}
- pthread_mutex_unlock(&sd->sd_tune_mutex);
+ tvh_mutex_unlock(&sd->sd_tune_mutex);
return r > limit;
}
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:
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
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
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();
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);
}
* 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);
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;
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)
}
- 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) {
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,
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);
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,
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);
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;
}
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);
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);
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;
}
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;
}
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;
};
*/
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;
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <pthread.h>
#include <signal.h>
#include "tvheadend.h"
#include "htsbuf.h"
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;
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);
}
}
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;
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);
}
}
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;
}
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;
}
/* 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;
}
} else {
ts_recv_packet0(t, st, tsb, len);
}
- pthread_mutex_unlock(&t->s_stream_mutex);
+ tvh_mutex_unlock(&t->s_stream_mutex);
return 1;
}
{
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
t->s_streaming_live |= TSS_LIVE;
}
}
- pthread_mutex_unlock(&t->s_stream_mutex);
+ tvh_mutex_unlock(&t->s_stream_mutex);
}
/**
/*
* Globals
*/
-pthread_mutex_t tsfile_lock;
+tvh_mutex_t tsfile_lock;
mpegts_network_t *tsfile_network;
tsfile_input_list_t tsfile_inputs;
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;
}
}
else
- pthread_mutex_unlock(&tsfile_lock);
+ tvh_mutex_unlock(&tsfile_lock);
return s;
}
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));
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);
// doesn't close the pipe!
}
mpegts_network_class_delete(&mpegts_network_class, 1);
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
}
/*
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;
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 */
/* 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 */
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 */
*/
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;
/*
* 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"
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
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 ) {
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,
mclk() + sec2mono(15));
brk = !ERRNO_AGAIN(brk) && brk != ETIMEDOUT;
}
- pthread_mutex_unlock(&tvhdhomerun_discovery_lock);
+ tvh_mutex_unlock(&tvhdhomerun_discovery_lock);
if (brk)
break;
}
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 )
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)) {
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);
}
* 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"
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");
(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);
}
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);
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);
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);
/* 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,
}
}
- 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 */
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);
}
}
/* 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;
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 {
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;
}
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;
/* 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);
}
/* 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);
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;
}
#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;
// 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
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,
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();
}
{
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);
RB_REMOVE(&intlconv_src_all, ic, ic_link);
free(ic);
}
- pthread_mutex_unlock(&intlconv_lock);
+ tvh_mutex_unlock(&intlconv_lock);
}
const char *
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;
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;
}
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;
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;
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;
}
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;
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 };
/* **************************************************************************
/* 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);
}
unlock:
- pthread_mutex_unlock(&lang_code_split_mutex);
+ tvh_mutex_unlock(&lang_code_split_mutex);
return ret;
}
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);
* 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>
{ 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
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;
doexit(int x)
{
if (pthread_self() != main_tid)
- pthread_kill(main_tid, SIGTERM);
- pthread_cond_signal(>imer_cond);
+ tvh_thread_kill(main_tid, SIGTERM);
+ tvh_cond_signal(>imer_cond, 0);
tvh_cond_signal(&mtimer_cond, 1);
atomic_set(&tvheadend_running, 0);
signal(x, doexit);
LIST_INSERT_SORTED(>imers, gti, gti_link, gtimercmp);
if (LIST_FIRST(>imers) == gti)
- pthread_cond_signal(>imer_cond); // force timer re-check
+ tvh_cond_signal(>imer_cond, 0); // force timer re-check
}
/**
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);
if (TAILQ_FIRST(&tasklets) == tsk)
tvh_cond_signal(&tasklet_cond, 0);
- pthread_mutex_unlock(&tasklet_lock);
+ tvh_mutex_unlock(&tasklet_lock);
}
/**
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);
if (tsk->tsk_free) tsk->tsk_free(tsk);
}
- pthread_mutex_unlock(&tasklet_lock);
+ tvh_mutex_unlock(&tasklet_lock);
}
static void
{
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);
}
}
- pthread_mutex_unlock(&tasklet_lock);
+ tvh_mutex_unlock(&tasklet_lock);
}
/**
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) {
}
/* 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;
}
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);
/* Wait */
tvh_cond_timedwait(&mtimer_cond, &global_lock, next);
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
}
return NULL;
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
}
/* Wait */
- pthread_cond_timedwait(>imer_cond, &global_lock, &ts);
- pthread_mutex_unlock(&global_lock);
+ tvh_cond_timedwait(>imer_cond, &global_lock, (intptr_t )&ts);
+ tvh_mutex_unlock(&global_lock);
}
}
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(>imer_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(>imer_cond, 0);
+ tvh_cond_init(&tasklet_cond, 1);
TAILQ_INIT(&tasklets);
/* Defaults */
tvhlog_options &= ~TVHLOG_OPT_DECORATE;
/* Initialise clock */
- pthread_mutex_lock(&global_lock);
+ tvh_mutex_lock(&global_lock);
__mdispatch_clock = getmonoclock();
__gdispatch_clock = time(NULL);
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();
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);
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
// 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
}
-/**
- *
- */
-void
-scopedunlock(pthread_mutex_t **mtxp)
-{
- pthread_mutex_unlock(*mtxp);
-}
-
-
/**
*
*/
#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);
if (!tvheadend_is_running())
return;
- pthread_mutex_lock(¬ify_mutex);
+ tvh_mutex_lock(¬ify_mutex);
if (notify_queue == NULL) {
notify_queue = htsmsg_create_map();
} else {
htsmsg_add_str(e, NULL, id);
tvh_cond_signal(¬ify_cond, 0);
skip:
- pthread_mutex_unlock(¬ify_mutex);
+ tvh_mutex_unlock(¬ify_mutex);
}
void *
htsmsg_t *q = NULL;
htsmsg_field_t *f;
- pthread_mutex_lock(¬ify_mutex);
+ tvh_mutex_lock(¬ify_mutex);
while (tvheadend_is_running()) {
}
q = notify_queue;
notify_queue = NULL;
- pthread_mutex_unlock(¬ify_mutex);
+ tvh_mutex_unlock(¬ify_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(¬ify_mutex);
+ tvh_mutex_lock(¬ify_mutex);
}
- pthread_mutex_unlock(¬ify_mutex);
+ tvh_mutex_unlock(¬ify_mutex);
return NULL;
}
void notify_init( void )
{
notify_queue = NULL;
- pthread_mutex_init(¬ify_mutex, NULL);
- tvh_cond_init(¬ify_cond);
- tvhthread_create(¬ify_tid, NULL, notify_thread, NULL, "notify");
+ tvh_mutex_init(¬ify_mutex, NULL);
+ tvh_cond_init(¬ify_cond, 1);
+ tvh_thread_create(¬ify_tid, NULL, notify_thread, NULL, "notify");
}
void notify_done( void )
{
- pthread_mutex_lock(¬ify_mutex);
+ tvh_mutex_lock(¬ify_mutex);
tvh_cond_signal(¬ify_cond, 0);
- pthread_mutex_unlock(¬ify_mutex);
+ tvh_mutex_unlock(¬ify_mutex);
pthread_join(notify_tid, NULL);
- pthread_mutex_lock(¬ify_mutex);
+ tvh_mutex_lock(¬ify_mutex);
htsmsg_destroy(notify_queue);
notify_queue = NULL;
- pthread_mutex_unlock(¬ify_mutex);
+ tvh_mutex_unlock(¬ify_mutex);
}
* 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"
* 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"
* 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"
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);
streaming_msg_free(sm);
free(psm);
}
- pthread_mutex_unlock(&prsh->prsh_queue_mutex);
+ tvh_mutex_unlock(&prsh->prsh_queue_mutex);
}
static htsmsg_t *
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);
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) {
free(psm);
}
}
- pthread_mutex_unlock(&prsh->prsh_queue_mutex);
+ tvh_mutex_unlock(&prsh->prsh_queue_mutex);
}
return NULL;
}
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");
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;
}
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) {
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) {
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;
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);
}
}
}
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);
LIST_REMOVE(pb, link);
free(pb);
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
}
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;
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <pthread.h>
#include <signal.h>
#include "tvheadend.h"
#include "htsbuf.h"
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;
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 *
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) {
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:
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;
}
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,
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);
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;
}
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)
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)
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;
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)
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);
TAILQ_REMOVE(&rtp->pmt_tables, tbl, link);
free(tbl);
}
- pthread_mutex_destroy(&rtp->lock);
+ tvh_mutex_destroy(&rtp->lock);
free(rtp);
}
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;
}
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)
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);
}
}
}
- pthread_mutex_unlock(&satip_rtp_lock);
+ tvh_mutex_unlock(&satip_rtp_lock);
}
end:
return NULL;
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");
}
}
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);
}
}
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);
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;
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;
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);
}
}
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);
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) {
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 ||
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;
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;
}
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;
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);
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");
}
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;
}
}
}
rtsp_describe_session(rs, &q);
}
- pthread_mutex_unlock(&rtsp_lock);
+ tvh_mutex_unlock(&rtsp_lock);
if (first) {
if (hc->hc_session) {
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);
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);
goto end;
error:
- pthread_mutex_unlock(&rtsp_lock);
+ tvh_mutex_unlock(&rtsp_lock);
error2:
http_error(hc, errcode);
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);
{
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) {
rs->state = STATE_SETUP;
}
}
- pthread_mutex_unlock(&rtsp_lock);
+ tvh_mutex_unlock(&rtsp_lock);
}
/*
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;
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);
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);
}
/*
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);
{
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);
}
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) {
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;
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);
}
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);
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;
}
}
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
if (!dvbs)
srcs = 0;
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);
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);
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);
}
}
}
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;
* 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"
{
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;
}
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;
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);
}
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);
descrambler_service_start(t);
- pthread_mutex_lock(&t->s_stream_mutex);
+ tvh_mutex_lock(&t->s_stream_mutex);
t->s_status = SERVICE_RUNNING;
*/
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);
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;
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;
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,
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);
}
*
*/
-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;
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;
tvh_cond_signal(&pending_save_cond, 0);
}
- pthread_mutex_unlock(&pending_save_mutex);
+ tvh_mutex_unlock(&pending_save_mutex);
}
{
service_t *t;
- pthread_mutex_lock(&pending_save_mutex);
+ tvh_mutex_lock(&pending_save_mutex);
while(tvheadend_is_running()) {
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;
}
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
{
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);
}
/**
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;
}
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) {
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)
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
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);
}
* This mutex also protects all elementary_stream_t instances for this
* transport.
*/
- pthread_mutex_t s_stream_mutex;
+ tvh_mutex_t s_stream_mutex;
/**
*
* 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"
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;
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()) {
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;
}
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);
}
/* 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())
}
if (sm)
streaming_queue_remove(sq, sm);
- pthread_mutex_unlock(&sq->sq_mutex);
+ tvh_mutex_unlock(&sq->sq_mutex);
if (!tvheadend_is_running())
break;
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) {
api_service_mapper_notify();
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
profile_chain_close(&prch);
return NULL;
}
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));
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;
return 0;
}
- pthread_mutex_lock(&spawn_mutex);
+ tvh_mutex_lock(&spawn_mutex);
LIST_FOREACH(s, &spawns, link)
if(s->pid == pid)
break;
free((void *)s->name);
free(s);
}
- pthread_mutex_unlock(&spawn_mutex);
+ tvh_mutex_unlock(&spawn_mutex);
return res;
}
} 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 */
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);
}
/**
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;
r = -errno;
}
}
- pthread_mutex_unlock(&spawn_mutex);
+ tvh_mutex_unlock(&spawn_mutex);
}
return r;
}
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;
}
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",
exit(1);
}
- pthread_mutex_unlock(&fork_lock);
+ tvh_mutex_unlock(&fork_lock);
spawn_enq(prog, p);
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;
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",
exit(1);
}
- pthread_mutex_unlock(&fork_lock);
+ tvh_mutex_unlock(&fork_lock);
spawn_enq(prog, p);
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
exit(1);
}
- pthread_mutex_unlock(&fork_lock);
+ tvh_mutex_unlock(&fork_lock);
spawn_enq(prog, p);
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);
{
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) {
}
tvh_cond_signal(&sq->sq_cond, 0);
- pthread_mutex_unlock(&sq->sq_mutex);
+ tvh_mutex_unlock(&sq->sq_mutex);
}
/**
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;
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;
{
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);
}
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
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;
* 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"
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);
streaming_target_deliver(s->ths_output, sm);
}
- pthread_mutex_unlock(&t->s_stream_mutex);
+ tvh_mutex_unlock(&t->s_stream_mutex);
}
/**
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);
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);
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);
}
/**
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);
/* 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);
}
subscription_delayed_reschedule(0);
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
return postpone;
}
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"));
}
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);
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);
}
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);
}
/**
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));
streaming_target_deliver(s->ths_output, sm);
- pthread_mutex_unlock(&t->s_stream_mutex);
+ tvh_mutex_unlock(&t->s_stream_mutex);
}
/* **************************************************************************
* 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"
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;
/* 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);
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;
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;
LIST_REMOVE(ts, link);
free(ts);
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
}
continue;
}
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");
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
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);
}
/* 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);
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);
/* Initialise input */
streaming_queue_init(&ts->wr_queue, 0, 0);
streaming_target_init(&ts->input, ×hift_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++;
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;
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
* 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"
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;
timeshift_index_iframe_t *ti;
timeshift_index_data_t *tid;
streaming_message_t *sm;
- pthread_mutex_lock(×hift_reaper_lock);
+ tvh_mutex_lock(×hift_reaper_lock);
while (timeshift_reaper_run) {
/* Get next */
continue;
}
TAILQ_REMOVE(×hift_reaper_list, tsf, link);
- pthread_mutex_unlock(×hift_reaper_lock);
+ tvh_mutex_unlock(×hift_reaper_lock);
if (tsf->path) {
tvhtrace(LS_TIMESHIFT, "remove file %s", tsf->path);
memoryinfo_free(×hift_memoryinfo, sizeof(*tsf));
free(tsf);
- pthread_mutex_lock(×hift_reaper_lock);
+ tvh_mutex_lock(×hift_reaper_lock);
}
- pthread_mutex_unlock(×hift_reaper_lock);
+ tvh_mutex_unlock(×hift_reaper_lock);
tvhtrace(LS_TIMESHIFT, "reaper thread exit");
return NULL;
}
else
tvhtrace(LS_TIMESHIFT, "queue file for removal - RAM segment time %li", (long)tsf->time);
}
- pthread_mutex_lock(×hift_reaper_lock);
+ tvh_mutex_lock(×hift_reaper_lock);
TAILQ_INSERT_TAIL(×hift_reaper_list, tsf, link);
tvh_cond_signal(×hift_reaper_cond, 0);
- pthread_mutex_unlock(×hift_reaper_lock);
+ tvh_mutex_unlock(×hift_reaper_lock);
}
/* **************************************************************************
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;
}
/* Start the reaper thread */
timeshift_reaper_run = 1;
- pthread_mutex_init(×hift_reaper_lock, NULL);
- tvh_cond_init(×hift_reaper_cond);
+ tvh_mutex_init(×hift_reaper_lock, NULL);
+ tvh_cond_init(×hift_reaper_cond, 1);
TAILQ_INIT(×hift_reaper_list);
- tvhthread_create(×hift_reaper_thread, NULL,
- timeshift_reaper_callback, NULL, "tshift-reap");
+ tvh_thread_create(×hift_reaper_thread, NULL,
+ timeshift_reaper_callback, NULL, "tshift-reap");
}
/*
char path[512];
/* Wait for thread */
- pthread_mutex_lock(×hift_reaper_lock);
+ tvh_mutex_lock(×hift_reaper_lock);
timeshift_reaper_run = 0;
tvh_cond_signal(×hift_reaper_cond, 0);
- pthread_mutex_unlock(×hift_reaper_lock);
+ tvh_mutex_unlock(×hift_reaper_lock);
pthread_join(timeshift_reaper_thread, NULL);
/* Remove the lot */
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;
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) {
timeshift_status(ts, last_time);
mono_last_status = mono_now;
}
- pthread_mutex_unlock(&ts->state_mutex);
+ tvh_mutex_unlock(&ts->state_mutex);
continue;
}
/* Find packet */
if (_timeshift_read(ts, seek, &sm, &wait) == -1) {
- pthread_mutex_unlock(&ts->state_mutex);
+ tvh_mutex_unlock(&ts->state_mutex);
break;
}
}
/* 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;
}
}
- pthread_mutex_unlock(&ts->state_mutex);
+ tvh_mutex_unlock(&ts->state_mutex);
}
/* Cleanup */
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);
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(×hift_memoryinfo_ram, alloc);
}
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);
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) {
timeshift_file_put(tsf);
}
}
- pthread_mutex_unlock(&ts->state_mutex);
+ tvh_mutex_unlock(&ts->state_mutex);
break;
}
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 )
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) {
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;
}
#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;
{
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)
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) {
snprintf(buf, sizeof(buf), "[%p]", tprof);
tprof->start_id = strdup(buf);
}
- pthread_mutex_unlock(&tprofile_mutex);
+ tvh_mutex_unlock(&tprofile_mutex);
}
static void
{
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)
tprof->start_id = NULL;
tprof->start = 0;
tprof->changed = 1;
- pthread_mutex_unlock(&tprofile_mutex);
+ tvh_mutex_unlock(&tprofile_mutex);
}
}
{
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)
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);
}
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;
}
tprof->changed = 0;
}
- pthread_mutex_unlock(&tprofile_mutex);
+ tvh_mutex_unlock(&tprofile_mutex);
}
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);
qprof->qsum = 0;
qprof->tstamp = mono;
}
- pthread_mutex_unlock(&qprofile_mutex);
+ tvh_mutex_unlock(&qprofile_mutex);
}
void tprofile_log_stats1(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)
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);
}
* 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"
#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 };
/*
*
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;
}
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 {
s = msg_find(lng_last, s);
}
}
- pthread_mutex_unlock(&tvh_gettext_mutex);
+ tvh_mutex_unlock(&tvh_gettext_mutex);
return s;
}
#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)
#ifndef TVHEADEND_STRING_H
#define TVHEADEND_STRING_H
+#include <string.h>
+#include <stdlib.h>
+
#include "build.h"
static inline int strempty(const char *c)
--- /dev/null
+#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();
+}
--- /dev/null
+/*
+ * 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 */
#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"
#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;
-
-
/*
*
*/
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;
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);
*/
#include "tvhlog.h"
-#include <pthread.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
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;
FILE *fp = NULL;
tvhlog_msg_t *msg;
- pthread_mutex_lock(&tvhlog_mutex);
+ tvh_mutex_lock(&tvhlog_mutex);
while (tvhlog_run) {
/* Wait */
}
}
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;
}
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;
}
#if TVHLOG_THREAD
}
#endif
- pthread_mutex_unlock(&tvhlog_mutex);
+ tvh_mutex_unlock(&tvhlog_mutex);
}
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);
}
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
{
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);
{
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;
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;
}
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;
}
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;
}
#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"
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 */
struct tvhpoll
{
- pthread_mutex_t lock;
+ tvh_mutex_t lock;
uint8_t *events;
uint32_t events_off;
uint32_t nevents;
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;
close(tp->fd);
#endif
free(tp->events);
- pthread_mutex_destroy(&tp->lock);
+ tvh_mutex_destroy(&tp->lock);
free(tp);
}
{
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;
}
{
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;
}
{
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]) {
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;
}
* 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>
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);
*/
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);
}
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);
}
/*
}
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;
data = NULL;
}
}
- pthread_mutex_unlock(&upnp_lock);
+ tvh_mutex_unlock(&upnp_lock);
if (data == NULL)
break;
upnp_dump_data(data);
/* 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);
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
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);
#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 */
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) {
/*
*/
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;
}
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);
* 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"
#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;
{
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);
cmb->cmb_last_used && cmb->cmb_last_used + sec2mono(60) < mclk())
cmb_destroy(cmb);
}
- pthread_mutex_unlock(&comet_mutex);
+ tvh_mutex_unlock(&comet_mutex);
}
/**
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);
}
}
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;
}
} 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);
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];
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;
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);
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;
}
}
- 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;
}
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);
{
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);
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);
}
/**
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) {
tvh_cond_signal(&comet_cond, 1);
}
- pthread_mutex_unlock(&comet_mutex);
+ tvh_mutex_unlock(&comet_mutex);
}
/**
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) {
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++) {
htsbuf_append(hq, "\n", 1);
}
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
free(all);
return 0;
* 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"
* 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"
htsbuf_qprintf(hq, "</form><hr>");
- pthread_mutex_lock(&global_lock);
+ tvh_mutex_lock(&global_lock);
if(s != NULL) {
dvr_query_free(&dqr);
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
htsbuf_qprintf(hq, "</body></html>");
http_output_html(hc);
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;
}
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>");
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) {
}
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;
}
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>");
#endif
htsbuf_qprintf(hq,"<recordings>\n");
- pthread_mutex_lock(&global_lock);
+ tvh_mutex_lock(&global_lock);
dvr_query(&dqr);
dvr_query_sort(&dqr);
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");
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");
* 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"
{
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",
* 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"
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);
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:
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]));
}
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
if (r == 0)
http_output_content(hc, pltype == PLAYLIST_E2 ? MIME_E2 : MIME_M3U);
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;
}
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;
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;
}
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")) {
#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
}
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;
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;
{
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) {
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;
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);
dvr_entry_changed(de);
}
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
return 0;
}
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;
}
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;
}
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;
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]));
}
}
- pthread_mutex_unlock(&global_lock);
+ tvh_mutex_unlock(&global_lock);
if (r == 0)
http_output_content(hc, "text/xml");
-#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"
/*
{
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;
}
{
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;
}
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);
p->rd = fd[0];
p->wr = fd[1];
}
- pthread_mutex_unlock(&fork_lock);
+ tvh_mutex_unlock(&fork_lock);
return err;
}
{
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
*/