Skip to content

Commit

Permalink
Use pthread instead of upnp ithread which seems to be deprecated.
Browse files Browse the repository at this point in the history
Fixes #254
  • Loading branch information
hzeller committed Sep 23, 2022
1 parent dd00115 commit 8871dfd
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#endif

#include <upnp.h>
#include <ithread.h>
#include <pthread.h>

// For version strings of upnp and gstreamer
#include <upnpconfig.h>
Expand Down
4 changes: 2 additions & 2 deletions src/upnp_connmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <string.h>

#include <upnp.h>
#include <ithread.h>
#include <pthread.h>

// Can't include above upnp.h breaks stdbool?
#include <stdbool.h>
Expand Down Expand Up @@ -141,7 +141,7 @@ static const char *direction_values[] = {
NULL
};

static ithread_mutex_t connmgr_mutex;
static pthread_mutex_t connmgr_mutex;

static GSList* supported_types_list;

Expand Down
8 changes: 4 additions & 4 deletions src/upnp_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <string.h>

#include <upnp.h>
#include <ithread.h>
#include <pthread.h>

#include "logging.h"
#include "webserver.h"
Expand Down Expand Up @@ -178,11 +178,11 @@ typedef enum {

static variable_container_t *state_variables_ = NULL;

static ithread_mutex_t control_mutex;
static pthread_mutex_t control_mutex;

static void service_lock(void)
{
ithread_mutex_lock(&control_mutex);
pthread_mutex_lock(&control_mutex);
struct upnp_last_change_collector*
collector = upnp_control_get_service()->last_change;
if (collector) {
Expand All @@ -197,7 +197,7 @@ static void service_unlock(void)
if (collector) {
UPnPLastChangeCollector_finish(collector);
}
ithread_mutex_unlock(&control_mutex);
pthread_mutex_unlock(&control_mutex);
}

static struct argument arguments_list_presets[] = {
Expand Down
30 changes: 15 additions & 15 deletions src/upnp_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include <arpa/inet.h>

#include <upnp.h>
#include <ithread.h>
#include <pthread.h>
#include <upnptools.h>

#include "logging.h"
Expand All @@ -56,7 +56,7 @@

struct upnp_device {
struct upnp_device_descriptor *upnp_device_descriptor;
ithread_mutex_t device_mutex;
pthread_mutex_t device_mutex;
UpnpDevice_Handle device_handle;
};

Expand Down Expand Up @@ -98,13 +98,13 @@ void upnp_append_variable(struct action_event *event,
assert(event != NULL);
assert(paramname != NULL);

ithread_mutex_lock(service->service_mutex);
pthread_mutex_lock(service->service_mutex);

value = VariableContainer_get(service->variable_container, varnum, NULL);
assert(value != NULL); // triggers on invalid variable.
upnp_add_response(event, paramname, value);

ithread_mutex_unlock(service->service_mutex);
pthread_mutex_unlock(service->service_mutex);
}

void upnp_set_error(struct action_event *event, int error_code,
Expand Down Expand Up @@ -180,7 +180,7 @@ static int handle_subscription_request(struct upnp_device *priv,
}

int result = -1;
ithread_mutex_lock(&(priv->device_mutex));
pthread_mutex_lock(&(priv->device_mutex));

// There is really only one variable evented: LastChange
const char *eventvar_names[] = {
Expand All @@ -193,7 +193,7 @@ static int handle_subscription_request(struct upnp_device *priv,

// Build the current state of the variables as one gigantic initial
// LastChange update.
ithread_mutex_lock(srv->service_mutex);
pthread_mutex_lock(srv->service_mutex);
const int var_count =
VariableContainer_get_num_vars(srv->variable_container);
// TODO(hzeller): maybe use srv->last_change directly ?
Expand All @@ -209,7 +209,7 @@ static int handle_subscription_request(struct upnp_device *priv,
UPnPLastChangeBuilder_add(builder, name, value);
}
}
ithread_mutex_unlock(srv->service_mutex);
pthread_mutex_unlock(srv->service_mutex);
char *xml_value = UPnPLastChangeBuilder_to_xml(builder);
Log_info("upnp", "Initial variable sync: %s", xml_value);
eventvar_values[0] = xmlescape(xml_value, 0);
Expand All @@ -227,7 +227,7 @@ static int handle_subscription_request(struct upnp_device *priv,
UpnpGetErrorMessage(rc), rc);
}

ithread_mutex_unlock(&(priv->device_mutex));
pthread_mutex_unlock(&(priv->device_mutex));

free((char*)eventvar_values[0]);

Expand Down Expand Up @@ -258,7 +258,7 @@ static int handle_var_request(struct upnp_device *priv,
return -1;
}

ithread_mutex_lock(srv->service_mutex);
pthread_mutex_lock(srv->service_mutex);

char *result = NULL;
const int var_count =
Expand All @@ -273,7 +273,7 @@ static int handle_var_request(struct upnp_device *priv,
}
}

ithread_mutex_unlock(srv->service_mutex);
pthread_mutex_unlock(srv->service_mutex);

UpnpStateVarRequest_set_CurrentVal(event, result);
int errCode = (result == NULL) ? UPNP_SOAP_E_INVALID_VAR : UPNP_E_SUCCESS;
Expand Down Expand Up @@ -314,9 +314,9 @@ static int handle_action_request(struct upnp_device *priv,
// It would be good to enqueue the upnp_device_notify() after
// the action event is finished.
if (event_service->last_change) {
ithread_mutex_lock(event_service->service_mutex);
pthread_mutex_lock(event_service->service_mutex);
UPnPLastChangeCollector_start(event_service->last_change);
ithread_mutex_unlock(event_service->service_mutex);
pthread_mutex_unlock(event_service->service_mutex);
}

#ifdef ENABLE_ACTION_LOGGING
Expand Down Expand Up @@ -383,9 +383,9 @@ static int handle_action_request(struct upnp_device *priv,
}

if (event_service->last_change) { // See comment above.
ithread_mutex_lock(event_service->service_mutex);
pthread_mutex_lock(event_service->service_mutex);
UPnPLastChangeCollector_finish(event_service->last_change);
ithread_mutex_unlock(event_service->service_mutex);
pthread_mutex_unlock(event_service->service_mutex);
}
return 0;
}
Expand Down Expand Up @@ -502,7 +502,7 @@ struct upnp_device *upnp_device_init(struct upnp_device_descriptor *device_def,

struct upnp_device *result_device = (struct upnp_device*)malloc(sizeof(*result_device));
result_device->upnp_device_descriptor = device_def;
ithread_mutex_init(&(result_device->device_mutex), NULL);
pthread_mutex_init(&(result_device->device_mutex), NULL);

/* register icons in web server */
for (int i = 0; (icon_entry = device_def->icons[i]); i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/upnp_renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include <arpa/inet.h>

#include <upnp.h>
#include <ithread.h>
#include <pthread.h>

#include "webserver.h"
#include "upnp_service.h"
Expand Down
2 changes: 1 addition & 1 deletion src/upnp_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <assert.h>
#include <string.h>

#include <ithread.h>
#include <pthread.h>

#include "xmldoc.h"
#include "upnp_service.h"
Expand Down
4 changes: 2 additions & 2 deletions src/upnp_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#define _UPNP_SERVICE_H

#include <upnp.h>
#include <ithread.h>
#include <pthread.h>
#include "upnp_compat.h"

struct action;
Expand Down Expand Up @@ -91,7 +91,7 @@ struct icon {
};

struct service {
ithread_mutex_t *service_mutex;
pthread_mutex_t *service_mutex;
const char *service_id;
const char *service_type;
const char *scpd_url;
Expand Down
8 changes: 4 additions & 4 deletions src/upnp_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include <glib.h>

#include <upnp.h>
#include <ithread.h>
#include <pthread.h>

#include "output.h"
#include "upnp_service.h"
Expand Down Expand Up @@ -406,11 +406,11 @@ static variable_container_t *state_variables_ = NULL;

/* protects transport_values, and service-specific state */

static ithread_mutex_t transport_mutex;
static pthread_mutex_t transport_mutex;

static void service_lock(void)
{
ithread_mutex_lock(&transport_mutex);
pthread_mutex_lock(&transport_mutex);

struct upnp_last_change_collector *
collector = upnp_transport_get_service()->last_change;
Expand All @@ -426,7 +426,7 @@ static void service_unlock(void)
if (collector) {
UPnPLastChangeCollector_finish(collector);
}
ithread_mutex_unlock(&transport_mutex);
pthread_mutex_unlock(&transport_mutex);
}

static char has_instance_id(struct action_event *event)
Expand Down
2 changes: 1 addition & 1 deletion src/webserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

#include <upnp.h>
#include <upnptools.h> // UpnpGetErrorMessage
#include <ithread.h>
#include <pthread.h>

#include "logging.h"
#include "webserver.h"
Expand Down

0 comments on commit 8871dfd

Please sign in to comment.