--- mqtt/src/daemon.c 2012/04/24 13:54:50 1.2.2.9 +++ mqtt/src/daemon.c 2012/04/25 07:37:16 1.2.2.10 @@ -6,6 +6,7 @@ static void *startSession(sched_task_t *task); +static pthread_attr_t attr; static inline struct tagSession * @@ -281,7 +282,6 @@ startSession(sched_task_t *task) mqtthdr_connack_t cack; struct tagSession *s, *sess = NULL; int ret; - pthread_attr_t attr; ioTRACE(4); @@ -366,9 +366,6 @@ startSession(sched_task_t *task) } /* Start session thread OK ... */ - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - SESS_LOCK; TAILQ_INSERT_TAIL(&Sessions, sess, sess_node); pthread_create(&sess->sess_tid, &attr, (void*(*)(void*)) thrSession, sess); @@ -376,8 +373,6 @@ startSession(sched_task_t *task) call.LOG(logg, "Session %s started from %s for user %s (timeout=%d) OK!\n", sess->sess_cid, sess->sess_addr, sess->sess_user, sess->sess_ka); - - pthread_attr_destroy(&attr); return NULL; end: /* close client connection */ ret = mqtt_msgCONNACK(&msg, ret); @@ -456,8 +451,13 @@ Run(int sock) return -1; } + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + schedPolling(root, &pl, NULL); schedRun(root, &Kill); + + pthread_attr_destroy(&attr); /* free all undeleted elements into lists */ PUBS_LOCK;