Changeset 13757


Ignore:
Timestamp:
Jan 4, 2013, 6:35:08 AM (8 years ago)
Author:
jordan
Message:

(gtk) #5203 transmission-gtk shouldn't use gdk_threads_enter() and gdk_threads_leave() -- when we get an RPC notification, delegate the work back to the gtk thread.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/main.c

    r13683 r13757  
    335335***/
    336336
    337 struct rpc_idle_data
     337struct on_rpc_changed_struct
    338338{
    339339  TrCore * core;
    340   int id;
    341   gboolean delete_files;
     340  tr_rpc_callback_type type;
     341  int torrent_id;
    342342};
    343343
    344344static gboolean
    345 rpc_torrent_remove_idle (gpointer gdata)
    346 {
    347   struct rpc_idle_data * data = gdata;
    348 
    349   gtr_core_remove_torrent (data->core, data->id, data->delete_files);
    350 
    351   g_free (data);
    352   return FALSE; /* tell g_idle not to call this func twice */
    353 }
    354 
    355 static gboolean
    356 rpc_torrent_add_idle (gpointer gdata)
     345on_rpc_changed_idle (gpointer gdata)
    357346{
    358347  tr_torrent * tor;
    359   struct rpc_idle_data * data = gdata;
    360 
    361   if ((tor = gtr_core_find_torrent (data->core, data->id)))
    362     gtr_core_add_torrent (data->core, tor, TRUE);
    363 
    364   g_free (data);
    365   return FALSE; /* tell g_idle not to call this func twice */
    366 }
    367 
    368 static tr_rpc_callback_status
    369 on_rpc_changed (tr_session            * session,
    370                 tr_rpc_callback_type    type,
    371                 struct tr_torrent     * tor,
    372                 void                  * gdata)
    373 {
    374   tr_rpc_callback_status status = TR_RPC_OK;
    375   struct cbdata * cbdata = gdata;
    376   gdk_threads_enter ();
    377 
    378   switch (type)
     348  struct on_rpc_changed_struct * data = gdata;
     349
     350  switch (data->type)
    379351    {
    380352      case TR_RPC_SESSION_CLOSE:
     
    382354        break;
    383355
    384       case TR_RPC_TORRENT_ADDED: {
    385         struct rpc_idle_data * data = g_new0 (struct rpc_idle_data, 1);
    386         data->id = tr_torrentId (tor);
    387         data->core = cbdata->core;
    388         gdk_threads_add_idle (rpc_torrent_add_idle, data);
    389         break;
    390       }
     356      case TR_RPC_TORRENT_ADDED:
     357        if ((tor = gtr_core_find_torrent (data->core, data->torrent_id)))
     358          gtr_core_add_torrent (data->core, tor, true);
     359        break;
    391360
    392361      case TR_RPC_TORRENT_REMOVING:
    393       case TR_RPC_TORRENT_TRASHING: {
    394         struct rpc_idle_data * data = g_new0 (struct rpc_idle_data, 1);
    395         data->id = tr_torrentId (tor);
    396         data->core = cbdata->core;
    397         data->delete_files = type == TR_RPC_TORRENT_TRASHING;
    398         gdk_threads_add_idle (rpc_torrent_remove_idle, data);
    399         status = TR_RPC_NOREMOVE;
    400         break;
    401       }
     362        gtr_core_remove_torrent (data->core, data->torrent_id, false);
     363        break;
     364
     365      case TR_RPC_TORRENT_TRASHING:
     366        gtr_core_remove_torrent (data->core, data->torrent_id, true);
     367        break;
    402368
    403369      case TR_RPC_SESSION_CHANGED: {
     
    409375        GSList * l;
    410376        GSList * changed_keys = NULL;
     377        tr_session * session = gtr_core_session (data->core);
    411378        tr_variantInitDict (&tmp, 100);
    412379        tr_sessionGetSettings (session, &tmp);
     
    434401
    435402        for (l=changed_keys; l!=NULL; l=l->next)
    436           gtr_core_pref_changed (cbdata->core, GPOINTER_TO_INT(l->data));
     403          gtr_core_pref_changed (data->core, GPOINTER_TO_INT(l->data));
    437404
    438405        g_slist_free (changed_keys);
     
    450417    }
    451418
    452   gdk_threads_leave ();
    453   return status;
     419  g_free (data);
     420  return G_SOURCE_REMOVE;
     421}
     422
     423static tr_rpc_callback_status
     424on_rpc_changed (tr_session            * session G_GNUC_UNUSED,
     425                tr_rpc_callback_type    type,
     426                struct tr_torrent     * tor,
     427                void                  * gdata)
     428{
     429  struct cbdata * cbdata = gdata;
     430  struct on_rpc_changed_struct * data;
     431
     432  data = g_new (struct on_rpc_changed_struct, 1);
     433  data->core = cbdata->core;
     434  data->type = type;
     435  data->torrent_id = tr_torrentId (tor);
     436  gdk_threads_add_idle (on_rpc_changed_idle, data);
     437 
     438  return TR_RPC_NOREMOVE;
    454439}
    455440
Note: See TracChangeset for help on using the changeset viewer.