fixed thread eternal sleep in case of bad connection close;

v0.5.xx
Alexander Vdolainen 9 years ago
parent e7a522bcb2
commit 1496e247a6

@ -511,9 +511,31 @@ static int __eval_syssexp(conn_t *co, sexp_t *sx)
return rentry->rpcf((void *)co, sx);
}
#ifdef _NO_SNTLMP
#define _CONN_INUSE(co) (co)->usecount++;
#define _CONN_NOTINUSE(co) (co)->usecount--;
#define _CONN_UCOUNT(co) (co)->usecount
#else
static inline void _CONN_INUSE(conn_t *co) {
pthread_rwlock_wrlock(&co->ssys->rwlock);
co->usecount++;
pthread_rwlock_unlock(&co->ssys->rwlock);
}
static inline void _CONN_NOTINUSE(conn_t *co) {
pthread_rwlock_wrlock(&co->ssys->rwlock);
co->usecount--;
pthread_rwlock_unlock(&co->ssys->rwlock);
}
static inline int _CONN_UCOUNT(conn_t *co) {
int r;
pthread_rwlock_rdlock(&co->ssys->rwlock);
r = co->usecount;
pthread_rwlock_unlock(&co->ssys->rwlock);
return r;
}
#endif
static void __connection_destroy(conn_t *co)
{
@ -643,7 +665,7 @@ static void *__sntll_thread(void *b)
/* check up a thread */
if(pthread_equal(self, co->thrd_poll[7])) /* dispatcher */
dispatch = 0;
dispatch = 1;
/* update use count */
_CONN_INUSE(co);
@ -702,7 +724,10 @@ static void *__sntll_thread(void *b)
} else printf("connread(head) µS: %ld\n", end.tv_usec - beg.tv_usec);
#endif
if(co->flags & SNSX_CLOSED) goto __finish; /* go away if required asap */
if(co->flags & SNSX_CLOSED) {
pthread_mutex_unlock(&(co->sslinout[0]));
goto __finish; /* go away if required asap */
}
#ifdef _VERBOSE_DEBUG
dumphead(mhead);
@ -755,7 +780,7 @@ static void *__sntll_thread(void *b)
pthread_mutex_lock(&(co->sslinout[1]));
wr = __conn_write(co, mhead, sizeof(sntllv2_head_t));
pthread_mutex_unlock(&(co->sslinout[1]));
if(wr < 0) goto __finish;
if(wr == -1) goto __finish;
else goto __again;
}
} else pthread_mutex_unlock(&(co->sslinout[0]));
@ -920,6 +945,7 @@ static void *__sntll_thread(void *b)
}
__finish:
co->flags |= SNSX_CLOSED;
__connection_destroy(co);
__sntll_bundle_destroy(b); /* destroy bundle */

Loading…
Cancel
Save