diff --git a/src/core/context.c b/src/core/context.c index 5cb96e9..d0d12cb 100644 --- a/src/core/context.c +++ b/src/core/context.c @@ -20,15 +20,15 @@ return g_bctx; } -void bot_set_ctx(BotXmppCtx * const ctx) +void bot_set_ctx(BotXmppCtx * const bctx) { - pthread_mutex_lock(&g_ctxLock); + pthread_mutex_lock(&bctx->lock); if(g_bctx) { fprintf(stderr, "Dev error: cannot set XMPP ctx twice in the same program run.\n"); } else { - g_bctx = ctx; + g_bctx = bctx; } - pthread_mutex_unlock(&g_ctxLock); + pthread_mutex_unlock(&bctx->lock); } void bot_free_user_data(struct BotUserInfo user, GString *filename, bool freeSegment) @@ -174,6 +174,8 @@ xmpp_conn_set_jid(newCon, user.jid->str); xmpp_conn_set_pass(newCon, user.pass->str); + /* no need to lock here as this is the only thread */ + pthread_mutex_init (&bctx->lock, NULL); bctx->log = newLog; bctx->ctx = newCtx; bctx->conn = newCon; diff --git a/src/core/context.h b/src/core/context.h index d0d25b8..16af50a 100644 --- a/src/core/context.h +++ b/src/core/context.h @@ -14,6 +14,7 @@ } BotUserInfo; typedef struct BotXmppCtx { + pthread_mutex_t lock; xmpp_log_t* log; xmpp_ctx_t* ctx; xmpp_conn_t* conn; @@ -30,9 +31,6 @@ /* teardown and free ctx and connection in bctx */ void bot_xmpp_shutdown(); -/* send a reminder when SIGALARM is triggered */ -void bot_reminder_alarm_func(int s); - /* static-lifetime context for signal handling */ BotXmppCtx *bot_get_ctx(); void bot_set_ctx(BotXmppCtx * const bctx);