}
static gboolean
+process_completed (void)
+{
+ gpointer call;
+
+ g_assert (completed_queue);
+
+ call = g_async_queue_try_pop (completed_queue);
+ if (call) {
+ process_result (call, NULL);
+ g_object_unref (call);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static gboolean
completed_prepare(GSource* source, gint *timeout)
{
gboolean have;
static gboolean
completed_dispatch(GSource* source, GSourceFunc callback, gpointer user_data)
{
- gpointer *call;
-
- g_assert (completed_queue);
- g_assert (callback);
-
- call = g_async_queue_try_pop (completed_queue);
- if (call) {
- ((GFunc)callback) (call, user_data);
- g_object_unref (call);
- }
-
+ process_completed ();
return TRUE;
}
gobject_class->finalize = _gp11_call_finalize;
g_assert (!thread_pool);
- thread_pool = g_thread_pool_new ((GFunc)process_async_call, NULL, -1, FALSE, &err);
+ thread_pool = g_thread_pool_new ((GFunc)process_async_call, NULL, 16, FALSE, &err);
if (!thread_pool) {
g_critical ("couldn't create thread pool: %s",
err && err->message ? err->message : "");
g_assert (!completed_id);
src = g_source_new (&completed_functions, sizeof (GSource));
completed_id = g_source_attach (src, context);
- g_source_set_callback (src, (GSourceFunc)process_result, NULL, NULL);
+ g_source_set_callback (src, NULL, NULL, NULL);
g_source_unref (src);
}
g_assert (GP11_IS_CALL (call));
g_assert (call->args->pkcs11);
+ /* To keep things balanced, process at one completed event */
+ process_completed();
+
g_assert (thread_pool);
g_thread_pool_push (thread_pool, call, NULL);
}
g_assert (GP11_IS_SESSION (session));
/* Hold onto this session for the length of the call */
- g_object_set_data_full (G_OBJECT (call), "call-opened-session", session, g_object_unref);
+ g_object_set_data_full (G_OBJECT (call), "call-opened-session",
+ g_object_ref (session), g_object_unref);
_gp11_call_async_object (call, session);
_gp11_call_async_go (call);
if (!session) {
_gp11_call_async_short (user_data, err->code);
g_error_free (err);
+ return;
}
run_call_with_session (GP11_CALL (user_data), session);
+ g_object_unref (session);
}
static void
result = g_array_index (pool->sessions, CK_SESSION_HANDLE, pool->sessions->len - 1);
g_assert (result != 0);
g_array_remove_index_fast (pool->sessions, pool->sessions->len - 1);
+ if (!pool->sessions->len)
+ g_hash_table_remove(pv->open_sessions, &flags);
return result;
}
*/
flags = g_object_get_data (G_OBJECT (session), "gp11-open-session-flags");
g_return_if_fail (flags);
- if ((*flags & info.flags) != *flags)
+ if ((*flags & info.flags) != *flags) {
+g_message ("discarding session, wrong flags");
return;
+ }
/* Keep this one around for later use */
push_session_table (slot, *flags, session->handle);
session->handle = 0;
+g_message ("keeping the session for reuse");
}
static GP11Session*