From: Bert Vermeulen Date: Mon, 21 Jul 2014 13:08:17 +0000 (+0200) Subject: Get rid of global session. X-Git-Tag: libsigrok-0.4.0~1231 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=3337e9a1c9e853a57beed80084d1f5ca93e0a3db;p=libsigrok.git Get rid of global session. --- diff --git a/backend.c b/backend.c index 03e5f64f..f650fe12 100644 --- a/backend.c +++ b/backend.c @@ -27,8 +27,6 @@ #define LOG_PREFIX "backend" /** @endcond */ -extern struct sr_session *sr_current_session; - /** * @mainpage libsigrok API * @@ -360,7 +358,6 @@ SR_API int sr_init(struct sr_context **ctx) *ctx = context; context = NULL; - sr_current_session = NULL; ret = SR_OK; done: diff --git a/hwdriver.c b/hwdriver.c index ec0afbac..4434a5b7 100644 --- a/hwdriver.c +++ b/hwdriver.c @@ -127,8 +127,6 @@ static struct sr_config_info sr_config_info_data[] = { {0, 0, NULL, NULL, NULL}, }; -extern struct sr_session *sr_current_session; - /** * Return the list of supported hardware drivers. * diff --git a/session.c b/session.c index 4c6095e0..d8a3b00b 100644 --- a/session.c +++ b/session.c @@ -59,10 +59,6 @@ struct datafeed_callback { void *cb_data; }; -/* There can currently only be one session at a time. */ -/* 'sr_current_session' is not static, it's used elsewhere (via 'extern'). */ -struct sr_session *sr_current_session; - /** * Create a new session. * Currently, there can be only one session at a time within the same process. @@ -72,21 +68,18 @@ struct sr_session *sr_current_session; * * @since 0.4.0 */ -SR_API int sr_session_new(struct sr_session **session) +SR_API int sr_session_new(struct sr_session **new_session) { - if (sr_current_session) { - sr_err("%s: session already exists", __func__); - return SR_ERR_BUG; - } + struct sr_session *session; - sr_current_session = g_malloc0(sizeof(struct sr_session)); + session = g_malloc0(sizeof(struct sr_session)); - sr_current_session->source_timeout = -1; - sr_current_session->running = FALSE; - sr_current_session->abort_session = FALSE; - g_mutex_init(&sr_current_session->stop_mutex); + session->source_timeout = -1; + session->running = FALSE; + session->abort_session = FALSE; + g_mutex_init(&session->stop_mutex); - *session = sr_current_session; + *new_session = session; return SR_OK; } @@ -114,9 +107,6 @@ SR_API int sr_session_destroy(struct sr_session *session) g_free(session); - if (session == sr_current_session) - sr_current_session = NULL; - return SR_OK; } @@ -342,9 +332,8 @@ SR_API int sr_session_trigger_set(struct sr_session *session, struct sr_trigger * @retval SR_OK Success. * @retval SR_ERR Error occured. */ -static int sr_session_iteration(gboolean block) +static int sr_session_iteration(struct sr_session *session, gboolean block) { - struct sr_session *session = sr_current_session; unsigned int i; int ret; @@ -501,7 +490,7 @@ SR_API int sr_session_run(struct sr_session *session) } else { /* Real sources, use g_poll() main loop. */ while (session->num_sources) - sr_session_iteration(TRUE); + sr_session_iteration(session, TRUE); } return SR_OK; @@ -649,7 +638,7 @@ SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi, return SR_ERR_ARG; } - for (l = sr_current_session->datafeed_callbacks; l; l = l->next) { + for (l = sdi->session->datafeed_callbacks; l; l = l->next) { if (sr_log_loglevel_get() >= SR_LOG_DBG) datafeed_dump(packet); cb_struct = l->data;