Commit 1a460a9d authored by Martti Mela's avatar Martti Mela

cygwin pthreads in nua

darcs-hash:20051219144220-1b897-9f6c9ad941ada3414cb4aec7907df4843cadb8db.gz
parent 0491bbe8
......@@ -148,7 +148,11 @@ nua_handle_t *nh_create_handle(nua_t *nua, nua_hmagic_t *hmagic,
}
#if HAVE_PTHREAD_H
#if __CYGWIN__
SU_PORT_INITREF(nh);
#else
pthread_rwlock_init(nh->nh_refcount, NULL);
#endif
#endif
nh->nh_valid = nua_handle;
......
......@@ -245,7 +245,11 @@ int ua_init(su_root_t *root, nua_t *nua)
nh_append(nua, dnh);
#if SU_HAVE_PTHREADS
#if __CYGWIN__
SU_PORT_INITREF(dnh);
#else
pthread_rwlock_init(dnh->nh_refcount, NULL);
#endif
#endif
dnh->nh_valid = nua_handle;
dnh->nh_nua = nua;
......
......@@ -49,6 +49,36 @@
#include "soa.h"
#if __CYGWIN__
/* Debugging versions */
#define SU_PORT_INITREF(p) (pthread_mutex_init((p)->sup_reflock, NULL), printf("initref(%p)\n", (p)))
#define SU_PORT_INCREF(p, f) (pthread_mutex_lock(p->sup_reflock), p->sup_ref++, pthread_mutex_unlock(p->sup_reflock), printf("incref(%p) by %s\n", (p), f))
#define SU_PORT_DECREF(p, f) do { \
pthread_mutex_lock(p->sup_reflock); p->sup_ref--; pthread_mutex_unlock(p->sup_reflock); \
if ((p->sup_ref) == 0) { \
SU_DEBUG_9(("nua(%p): zapped\n", nh)); \
su_home_zap(p->nh_home); } \
else { printf("decref(%p) to %u by %s\n", (p), p->sup_ref, f); } } while(0)
#define SU_PORT_ZAPREF(p, f) do { printf("zapref(%p) by %s\n", (p), f), \
pthread_mutex_lock(p->sup_reflock); p->sup_ref--; pthread_mutex_unlock(p->sup_reflock); \
if ((p->sup_ref) != 0) { \
assert(!"SU_PORT_ZAPREF"); } \
su_port_destroy(p); } while(0)
#define SU_PORT_INITLOCK(p) \
(pthread_mutex_init((p)->sup_mutex, NULL), printf("init_lock(%p)\n", p))
#define SU_PORT_LOCK(p, f) \
(printf("%ld at %s locking(%p)...", pthread_self(), f, p), pthread_mutex_lock((p)->sup_mutex), printf(" ...%ld at %s locked(%p)...", pthread_self(), f, p))
#define SU_PORT_UNLOCK(p, f) \
(pthread_mutex_unlock((p)->sup_mutex), printf(" ...%ld at %s unlocked(%p)\n", pthread_self(), f, p))
#endif /* __CYGWIN__ */
typedef struct event_s event_t;
#define NONE ((void *)-1)
......@@ -416,7 +446,12 @@ struct nua_handle_s
tagi_t *nh_tags; /**< Default tags */
#if HAVE_PTHREAD_H
#if __CYGWIN__
pthread_mutex_t sup_reflock[1];
int sup_ref;
#else
pthread_rwlock_t nh_refcount[1];
#endif
#else
unsigned nh_refcount;
#endif
......@@ -564,7 +599,11 @@ nua_handle_t *nh_incref(nua_handle_t *nh)
if (nh) {
#if HAVE_PTHREAD_H
#if __CYGWIN__
SU_PORT_INCREF(nh, (char *) NULL);
#else
pthread_rwlock_rdlock(nh->nh_refcount);
#endif
#else
nh->nh_refcount++; /* XXX */
#endif
......@@ -582,12 +621,16 @@ int nh_decref(nua_handle_t *nh)
return 1;
#if HAVE_PTHREAD_H
#if __CYGWIN__
SU_PORT_DECREF(nh, (char *) NULL);
#else
pthread_rwlock_unlock(nh->nh_refcount);
if (pthread_rwlock_trywrlock(nh->nh_refcount) == 0) {
SU_DEBUG_9(("nua(%p): zapped\n", nh));
su_home_zap(nh->nh_home);
return 0;
}
#endif
return 1;
#else
if (--nh->nh_refcount == 0) {
......
......@@ -87,6 +87,10 @@ char const help[] =
;
int getopt(int argc, char * const argv[], char const *opstring);
#if __CYGWIN__
int c_optind;
#define optind c_optind
#endif
extern int optind;
void usage(void)
......
......@@ -114,6 +114,11 @@ char const help[] =
"\t-h Host-internal addresses\n";
int getopt(int argc, char * const argv[], char const *opstring);
#if __CYGWIN__
int c_optind;
#define optind c_optind
#endif
extern int optind;
void usage(int returncode)
......
......@@ -1961,6 +1961,8 @@ int tport_bind_server(tport_master_t *mr,
for (i = 0; transports[i]; i++) {
su_addrinfo_t *ai, *res, hints[1];
int tried = 0;
proto = transports[i];
error = EPROTONOSUPPORT;
......@@ -2014,6 +2016,8 @@ int tport_bind_server(tport_master_t *mr,
ai->ai_socktype = hints->ai_socktype;
ai->ai_protocol = hints->ai_protocol;
tried = 1;
pri = tport_listen(mr, ai, canon, proto, p, tags);
if (pri) {
......@@ -2053,6 +2057,9 @@ int tport_bind_server(tport_master_t *mr,
while (*tbf)
tport_zap_primary(*tbf);
if (!tried)
not_supported = 1;
if (ephemeral_port != 0 && ephemeral_port != -1) {
p += 4025; /* relative prime to 65536 - 1024 */
if (p >= 65536) p -= (65536 - 1024);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment