*/
static int set_main_context(struct sr_session *session)
{
- GMainContext *def_context;
+ GMainContext *main_context;
+
+ g_mutex_lock(&session->main_mutex);
/* May happen if sr_session_start() is called a second time
* while the session is still running.
*/
if (session->main_context) {
sr_err("Main context already set.");
+
+ g_mutex_unlock(&session->main_mutex);
return SR_ERR;
}
-
- g_mutex_lock(&session->main_mutex);
-
- def_context = g_main_context_get_thread_default();
-
- if (!def_context)
- def_context = g_main_context_default();
+ main_context = g_main_context_ref_thread_default();
/*
* Try to use an existing main context if possible, but only if we
* can make it owned by the current thread. Otherwise, create our
* own main context so that event source callbacks can execute in
* the session thread.
*/
- if (g_main_context_acquire(def_context)) {
- g_main_context_release(def_context);
+ if (g_main_context_acquire(main_context)) {
+ g_main_context_release(main_context);
sr_dbg("Using thread-default main context.");
-
- session->main_context = def_context;
- session->main_context_is_default = TRUE;
} else {
- sr_dbg("Creating our own main context.");
+ g_main_context_unref(main_context);
- session->main_context = g_main_context_new();
- session->main_context_is_default = FALSE;
+ sr_dbg("Creating our own main context.");
+ main_context = g_main_context_new();
}
+ session->main_context = main_context;
+
g_mutex_unlock(&session->main_mutex);
return SR_OK;
g_mutex_lock(&session->main_mutex);
if (session->main_context) {
- if (!session->main_context_is_default)
- g_main_context_unref(session->main_context);
-
+ g_main_context_unref(session->main_context);
session->main_context = NULL;
ret = SR_OK;
} else {
* @param session The session to use. Must not be NULL.
* @param key The key which identifies the event source.
* @param source An event source object. Must not be NULL.
+ *
* @retval SR_OK Success.
* @retval SR_ERR_ARG Invalid argument.
* @retval SR_ERR_BUG Event source with @a key already installed.
* @retval SR_ERR Other error.
+ *
+ * @private
*/
SR_PRIV int sr_session_source_add_internal(struct sr_session *session,
void *key, GSource *source)
* @retval SR_ERR_ARG Invalid argument.
*
* @since 0.3.0
+ * @private
*/
-SR_API int sr_session_source_add(struct sr_session *session, int fd,
+SR_PRIV int sr_session_source_add(struct sr_session *session, int fd,
int events, int timeout, sr_receive_data_callback cb, void *cb_data)
{
if (fd < 0 && timeout < 0) {
* @retval SR_ERR_ARG Invalid argument.
*
* @since 0.3.0
+ * @private
*/
-SR_API int sr_session_source_add_pollfd(struct sr_session *session,
+SR_PRIV int sr_session_source_add_pollfd(struct sr_session *session,
GPollFD *pollfd, int timeout, sr_receive_data_callback cb,
void *cb_data)
{
* @retval SR_ERR_ARG Invalid argument.
*
* @since 0.3.0
+ * @private
*/
-SR_API int sr_session_source_add_channel(struct sr_session *session,
+SR_PRIV int sr_session_source_add_channel(struct sr_session *session,
GIOChannel *channel, int events, int timeout,
sr_receive_data_callback cb, void *cb_data)
{
*
* @retval SR_OK Success
* @retval SR_ERR_BUG No event source for poll_object found.
+ *
+ * @private
*/
SR_PRIV int sr_session_source_remove_internal(struct sr_session *session,
void *key)
* @retval SR_ERR_BUG Internal error.
*
* @since 0.3.0
+ * @private
*/
-SR_API int sr_session_source_remove(struct sr_session *session, int fd)
+SR_PRIV int sr_session_source_remove(struct sr_session *session, int fd)
{
return sr_session_source_remove_internal(session, GINT_TO_POINTER(fd));
}
* internal errors.
*
* @since 0.2.0
+ * @private
*/
-SR_API int sr_session_source_remove_pollfd(struct sr_session *session,
+SR_PRIV int sr_session_source_remove_pollfd(struct sr_session *session,
GPollFD *pollfd)
{
if (!pollfd) {
* @return SR_ERR_BUG Internal error.
*
* @since 0.2.0
+ * @private
*/
-SR_API int sr_session_source_remove_channel(struct sr_session *session,
+SR_PRIV int sr_session_source_remove_channel(struct sr_session *session,
GIOChannel *channel)
{
if (!channel) {
* @retval SR_OK Success.
* @retval SR_ERR_BUG Event source for @a key does not match @a source.
* @retval SR_ERR Other error.
+ *
+ * @private
*/
SR_PRIV int sr_session_source_destroyed(struct sr_session *session,
void *key, GSource *source)