Changeset 2056

Show
Ignore:
Timestamp:
02/21/10 05:52:19 (5 months ago)
Author:
tpgww
Message:

use atomic changes for some static blockers and flags

Location:
trunk/src
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/config/e2_option_tree.c

    r1949 r2056  
    11/* $Id$ 
    22 
    3 Copyright (C) 2003-2009 tooar <tooar@emelfm2.net> 
     3Copyright (C) 2003-2010 tooar <tooar@emelfm2.net> 
    44 
    55This file is part of emelFM2. 
     
    781781typedef struct _E2_KeyBlock 
    782782{ 
    783         gboolean blocked; 
     783        gint blocked; //flag for preventing re-entrance 
    784784        E2_KeyChangeData *data; 
    785785} E2_KeyBlock; 
    786786//static data used cuz only one config dialog can exist 
    787787//Otherwise need to send variable data to callback via each relevant button 
    788 E2_KeyBlock blocknow = {FALSE, NULL}; 
     788E2_KeyBlock blocknow = {0, NULL}; 
    789789 
    790790#define KEYCHANGEKEY "_e2-binding-key_" 
     
    807807        printd (DEBUG, "_e2_option_tree_mnemonic_cb"); 
    808808//      E2_KeyBlock *bdata = g_object_get_data (G_OBJECT(button), KEYCHANGEKEY); 
    809         if (bdata != NULL && bdata->blocked && bdata->data != NULL) 
     809        if (bdata != NULL && bdata->data != NULL && g_atomic_int_get (&bdata->blocked) != 0) 
    810810        { 
    811811                GList *child, *all = gtk_widget_list_mnemonic_labels (button); 
     
    823823                                e2_keybinding_unblock (config_dialog, NULL); 
    824824                                //unblock all button-mnemonics 
    825                                 bdata->blocked = FALSE; 
     825                                g_atomic_int_set (&bdata->blocked, 0); 
    826826                                bdata->data = NULL; //will have been cleared downstream 
    827827                                break; 
     
    832832        } 
    833833        else if (bdata != NULL) 
    834                 return bdata->blocked; 
     834                return (g_atomic_int_get (&bdata->blocked) != 0); 
    835835        else 
    836836                return FALSE; 
     
    872872{ 
    873873//      printd (DEBUG, "_e2_option_tree_unblock_mnemonics"); 
    874         blocknow.blocked = FALSE; 
     874        g_atomic_int_set (&blocknow.blocked, 0); 
    875875        if (blocknow.data != NULL) 
    876876        { 
     
    914914                e2_keybinding_block (config_dialog, NULL); 
    915915                //or of any dialog-button mnemonic 
    916                 blocknow.blocked = TRUE; 
     916                g_atomic_int_set (&blocknow.blocked, 1); 
    917917                blocknow.data = data; 
    918918/* if static data not viable 
  • trunk/src/dialogs/e2_config_dialog.c

    r2018 r2056  
    11/* $Id$ 
    22 
    3 Copyright (C) 2003-2009 tooar <tooar@emelfm2.net> 
     3Copyright (C) 2003-2010 tooar <tooar@emelfm2.net> 
    44Portions copyright (C) 1999 Michael Clark 
    55 
     
    819819} */ 
    820820 
    821 //this flag is ok because only 1 config dialog, and only 1 edit, at any time 
    822 static gboolean cancel_blocked = FALSE; 
     821//this static flag is ok because only 1 config dialog, and only 1 edit, at any time 
     822static gint cancel_blocked = 0; 
    823823/** 
    824824@brief allow <Esc> press to cancel editing of the entry text without closing the dialog 
     
    833833        E2_OptionSet *set) 
    834834{ 
    835         if (!cancel_blocked) 
     835        if (g_atomic_int_get (&cancel_blocked) == 0) 
    836836        { 
    837837                g_signal_handlers_block_by_func (G_OBJECT (config_dialog), 
    838838                        e2_dialog_key_neg_cb, config_dialog); 
    839                 cancel_blocked = TRUE; 
     839                g_atomic_int_set (&cancel_blocked, 1); 
    840840        } 
    841841        else if (event->keyval == GDK_Escape 
     
    853853                g_signal_handlers_unblock_by_func (G_OBJECT (config_dialog), 
    854854                        e2_dialog_key_neg_cb, config_dialog); 
    855                 cancel_blocked = FALSE; 
     855                g_atomic_int_set (&cancel_blocked, 0); 
    856856                return (event->keyval == GDK_Escape); 
    857857        } 
     
    872872        gpointer data) 
    873873{ 
    874         if (cancel_blocked) 
     874        if (g_atomic_int_get (&cancel_blocked) != 0) 
    875875        { 
    876876                g_signal_handlers_unblock_by_func (G_OBJECT (config_dialog), 
    877877                        e2_dialog_key_neg_cb, config_dialog); 
    878                 cancel_blocked = FALSE; 
     878                g_atomic_int_set (&cancel_blocked, 0); 
    879879        } 
    880880        return FALSE; 
  • trunk/src/e2_filelist.c

    r2024 r2056  
    11/* $Id$ 
    22 
    3 Copyright (C) 2004-2009 tooar <tooar@emelfm2.net>. 
     3Copyright (C) 2004-2010 tooar <tooar@emelfm2.net>. 
    44 
    55This file is part of emelFM2. 
     
    4949 
    5050//disable-refresh counter for both filelists 
    51 gint refresh_refcount; 
     51volatile gint refresh_refcount; 
    5252//disable-refresh counter for single filelists 
    53 static gint refresh_active_refcount; 
    54 static gint refresh_inactive_refcount; 
     53static volatile gint refresh_active_refcount; 
     54static volatile gint refresh_inactive_refcount; 
    5555//refresh deferral counters 
    5656static gint pane1repeats = 0; 
     
    9595        if (_e2_filelist_check_active_pane (pane)) 
    9696        { 
    97                 refresh_active_refcount++; 
    98                 if (refresh_active_refcount == 1) 
     97                if (g_atomic_int_exchange_and_add (&refresh_active_refcount, 1) == 0) 
    9998                { 
    10099                        LISTS_LOCK 
     
    105104        else 
    106105        { 
    107                 refresh_inactive_refcount++; 
    108                 if (refresh_inactive_refcount == 1) 
     106                if (g_atomic_int_exchange_and_add (&refresh_inactive_refcount, 1) == 0) 
    109107                { 
    110108                        LISTS_LOCK 
     
    125123        if (_e2_filelist_check_active_pane (pane)) 
    126124        { 
    127                 refresh_active_refcount--; 
    128                 if (refresh_active_refcount == 0 && refresh_refcount == 0) 
     125                if (g_atomic_int_exchange_and_add (&refresh_active_refcount, -1) == 1 
     126                        && g_atomic_int_get (&refresh_refcount) == 0) 
    129127                { 
    130128                        LISTS_LOCK 
     
    133131                } 
    134132                if (refresh_active_refcount < 0) 
    135                         refresh_active_refcount = 0; 
     133                        g_atomic_int_set (&refresh_active_refcount, 0); 
    136134        } 
    137135        else 
    138136        { 
    139                 refresh_inactive_refcount--; 
    140                 if (refresh_inactive_refcount == 0 && refresh_refcount == 0) 
     137                if (g_atomic_int_exchange_and_add (&refresh_inactive_refcount, -1) == 1 
     138                        && g_atomic_int_get (&refresh_refcount) == 0) 
    141139                { 
    142140                        LISTS_LOCK 
     
    145143                } 
    146144                if (refresh_inactive_refcount < 0) 
    147                         refresh_inactive_refcount = 0; 
     145                        g_atomic_int_set (&refresh_inactive_refcount, 0); 
    148146        } 
    149147} 
     
    181179void e2_filelist_reset_refresh (void) 
    182180{ 
    183         if (refresh_refcount != 0) 
    184         { 
    185                 refresh_refcount = 1; 
     181        if (g_atomic_int_get (&refresh_refcount) != 0) 
     182        { 
     183                g_atomic_int_set (&refresh_refcount, 1); 
    186184                e2_filelist_enable_refresh (); 
    187185        } 
     
    194192@brief  disable refreshing of pane filelists and config data 
    195193 
    196 Increase ref count, if == 1, stop the timer process which calls the refresh fns 
     194Increases the ref-count, then if 1, stop the timer process which calls the refresh fns 
    197195Why is config data check bundled here ? 
    198196Expects BGL open? 
     
    202200void e2_filelist_disable_refresh (void) 
    203201{ 
    204         refresh_refcount++; 
     202        gint preinc = g_atomic_int_exchange_and_add (&refresh_refcount, 1); 
    205203#ifdef E2_REFRESH_DEBUG 
    206         printd (DEBUG, "disable refresh, refresh ref now = %d", refresh_refcount); 
    207 #endif 
    208         if (refresh_refcount == 1) 
     204        printd (DEBUG, "disable refresh, refresh ref now = %d", preinc + 1); 
     205#endif 
     206        if (preinc == 0) 
    209207        { 
    210208                if (app.timers[REFRESHBEGIN_T] > 0) 
     
    242240@brief re-enable polling of pane filelists and config data 
    243241 
    244 Decrease ref count, if == 0, re-enable/restart the processes which detect 
     242Decreases the ref-count, then if 0, re-enable/restart the processes which detect 
    245243changes of filelist content and/or config data 
    246244Config timer is bundled here because the same func refreshes the panes 
     
    251249void e2_filelist_enable_refresh (void) 
    252250{ 
    253         refresh_refcount--; 
     251        gint predec = g_atomic_int_exchange_and_add (&refresh_refcount, -1); 
    254252#ifdef E2_REFRESH_DEBUG 
    255         printd (DEBUG, "enable refresh, refresh ref now = %d", refresh_refcount); 
    256 #endif 
    257         if (refresh_refcount < 0) 
    258         { 
    259                 printd (WARN, "The auto-refresh refresh count is < 0"); 
    260                 gdk_threads_enter (); 
    261                 e2_window_output_show (NULL, NULL); 
    262                 e2_output_print_error ( 
    263                 _("Something is wrong with the auto-refresh mechanism"), FALSE); 
    264                 gdk_threads_leave (); 
    265         } 
    266  
    267         if (refresh_refcount == 0) 
     253        printd (DEBUG, "enable refresh, refresh ref now = %d", predec - 1); 
     254#endif 
     255        if (predec == 1) 
    268256        { 
    269257                if (e2_option_bool_get ("auto-refresh")) 
     
    287275                e2_window_enable_status_update (-1); 
    288276#endif 
     277        } 
     278        else if (predec < 1) 
     279        { 
     280                printd (WARN, "The auto-refresh refresh count is < 0"); 
     281                gdk_threads_enter (); 
     282                e2_window_output_show (NULL, NULL); 
     283                e2_output_print_error ( 
     284                _("Something is wrong with the auto-refresh mechanism"), FALSE); 
     285                gdk_threads_leave (); 
    289286        } 
    290287} 
  • trunk/src/e2_main.c

    r2041 r2056  
    11/* $Id$ 
    22 
    3 Copyright (C) 2003-2009 tooar <tooar@emelfm2.net> 
     3Copyright (C) 2003-2010 tooar <tooar@emelfm2.net> 
    44Portions copyright (C) 1999 Michael Clark. 
    55 
     
    127127#define UPGRADE_PNAME "e2p_upgrade.so" 
    128128 
    129 extern gint refresh_refcount; 
     129extern volatile gint refresh_refcount; 
    130130extern GList *open_history; 
    131131#ifdef USE_GLIB2_10 
     
    472472        pthread_cleanup_push ((gpointer)e2_filelist_reset_refresh, NULL); 
    473473                //enable refresh 
    474                 saverefcount = refresh_refcount; 
     474                saverefcount = g_atomic_int_get (&refresh_refcount); 
    475475                if (saverefcount > 0) 
    476476                { 
     
    785785#endif 
    786786        //set refresh counter to its real initial value 
    787         refresh_refcount = 0; 
     787        g_atomic_int_set (&refresh_refcount, 0); 
    788788#ifdef E2_REFRESH_DEBUG 
    789789        printd (DEBUG, "disable refresh, session start before filelists built"); 
  • trunk/src/e2_task.c

    r2028 r2056  
    11/* $Id$ 
    22 
    3 Copyright (C) 2003-2009 tooar <tooar@emelfm2.net> 
     3Copyright (C) 2003-2010 tooar <tooar@emelfm2.net> 
    44 
    55This file is part of emelFM2. 
     
    3939 
    4040GList *open_history = NULL;  //history list for open-with dialog 
    41 extern gint refresh_refcount; 
     41extern volatile gint refresh_refcount; 
    4242 
    4343pthread_mutex_t task_mutex = PTHREAD_MUTEX_INITIALIZER; //PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP not needed 
     
    231231E2_TaskRuntime *e2_task_set_data (glong pid, E2_TaskDataType mode, gchar *command) 
    232232{ 
    233         static gboolean blocked = FALSE; 
    234         if (blocked) 
     233        static gint blocked = 0; 
     234 
     235        if (!g_atomic_int_compare_and_exchange (&blocked, 0, 1)) 
    235236                return NULL; 
    236         else 
    237                 blocked = TRUE; 
    238237 
    239238        E2_TaskRuntime *rt = e2_task_find_running_task (pid); 
     
    249248                { 
    250249                        printd (WARN, "not enough memory for task history data"); 
    251                         blocked = FALSE; 
     250                        g_atomic_int_set (&blocked, 0); 
    252251                        return GINT_TO_POINTER (1); 
    253252                } 
     
    297296                        printd (WARN, "tried to register a process with bad mode flag"); 
    298297                        DEALLOCATE (E2_TaskRuntime, rt); 
    299                         blocked = FALSE; 
     298                        g_atomic_int_set (&blocked, 0); 
    300299                        return GINT_TO_POINTER (1); 
    301300                } 
     
    314313        {       //found an entry with matching pid 
    315314                printd (DEBUG, "tried to re-register a process"); 
    316                 blocked = FALSE; 
    317                 return GINT_TO_POINTER (1); 
    318         } 
    319  
    320         blocked = FALSE; 
     315                rt = GINT_TO_POINTER (1); 
     316        } 
     317 
     318        g_atomic_int_set (&blocked, 0); 
    321319        return rt; 
    322320} 
  • trunk/src/e2_toolbar.c

    r2042 r2056  
    11/* $Id$ 
    22 
    3 Copyright (C) 2003-2009 tooar <tooar@emelfm2.net> 
     3Copyright (C) 2003-2010 tooar <tooar@emelfm2.net> 
    44 
    55This file is part of emelFM2. 
     
    9090static void _e2_toolbar_hide_cb (GtkMenuItem *menuitem, E2_ToolbarRuntime *rt) 
    9191{ 
    92         if (!rt->blocked)  //bar's menu is not now being created 
     92        if (g_atomic_int_get (&rt->blocked) == 0)  //bar's menu is not now being created 
    9393        { 
    9494                e2_option_bool_toggle_direct (rt->show);  //now FALSE 
     
    108108static void _e2_toolbar_toggle_tt_cb (GtkMenuItem *menuitem, E2_ToolbarRuntime *rt) 
    109109{ 
    110         if (!rt->blocked) //bar's menu is not now being created 
     110        if (g_atomic_int_get (&rt->blocked) == 0) //bar's menu is not now being created 
    111111        { 
    112112                gtk_toolbar_set_tooltips (GTK_TOOLBAR (rt->toolbar), 
     
    128128static void _e2_toolbar_update_space_cb (GtkMenuItem *menuitem, E2_ToolbarRuntime *rt) 
    129129{ 
    130         if (!rt->blocked) //bar's menu is not now being created 
     130        if (g_atomic_int_get (&rt->blocked) == 0) //bar's menu is not now being created 
    131131        { 
    132132                GSList *group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menuitem)); 
     
    152152static void _e2_toolbar_toggle_hori_cb (GtkMenuItem *menuitem, E2_ToolbarRuntime *rt) 
    153153{ 
    154         if (!rt->blocked) //bar's menu is not now being created 
     154        if (g_atomic_int_get (&rt->blocked) == 0) //bar's menu is not now being created 
    155155        { 
    156156                e2_option_bool_toggle_direct (rt->hori); 
     
    172172static void _e2_toolbar_update_type_cb (GtkMenuItem *menuitem, E2_ToolbarRuntime *rt) 
    173173{ 
    174         if (!rt->blocked) //bar's menu is not now being created 
     174        if (g_atomic_int_get (&rt->blocked) == 0) //bar's menu is not now being created 
    175175        { 
    176176                GSList *group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menuitem)); 
     
    196196static void _e2_toolbar_increase_priority_cb (GtkMenuItem *menuitem, E2_ToolbarRuntime *rt) 
    197197{ 
    198         if (!rt->blocked) //bar's menu is not now being created 
     198        if (g_atomic_int_get (&rt->blocked) == 0) //bar's menu is not now being created 
    199199        { 
    200200                gint i = e2_option_int_get_direct (rt->priority); 
     
    217217static void _e2_toolbar_decrease_priority_cb (GtkMenuItem *menuitem, E2_ToolbarRuntime *rt) 
    218218{ 
    219         if (!rt->blocked) //bar's menu is not now being created 
     219        if (g_atomic_int_get (&rt->blocked) == 0) //bar's menu is not now being created 
    220220        { 
    221221                gint i = e2_option_int_get_direct (rt->priority); 
     
    237237static void _e2_toolbar_reset_priority_cb (GtkMenuItem *menuitem, E2_ToolbarRuntime *rt) 
    238238{ 
    239         if (!rt->blocked && (e2_option_int_get_direct (rt->priority) != 0)) 
     239        if (g_atomic_int_get (&rt->blocked) == 0 //bar's menu is not now being created 
     240        && (e2_option_int_get_direct (rt->priority) != 0)) 
    240241        { 
    241242                e2_option_int_set_direct (rt->priority, 0); 
     
    256257static void _e2_toolbar_toggle_relief_cb (GtkCheckMenuItem *menuitem, E2_ToolbarRuntime *rt) 
    257258{ 
    258         if (!rt->blocked) //bar's menu is not now being created 
     259        if (g_atomic_int_get (&rt->blocked) == 0) //bar's menu is not now being created 
    259260        { 
    260261                e2_option_bool_toggle_direct (rt->relief); 
     
    275276static void _e2_toolbar_toggle_same_cb (GtkMenuItem *menuitem, E2_ToolbarRuntime *rt) 
    276277{ 
    277         if (!rt->blocked) //bar's menu is not now being created 
     278        if (g_atomic_int_get (&rt->blocked) == 0) //bar's menu is not now being created 
    278279        { 
    279280                e2_option_bool_toggle_direct (rt->same); 
     
    296297static void _e2_toolbar_update_style_cb (GtkMenuItem *menuitem, E2_ToolbarRuntime *rt) 
    297298{ 
    298         if (!rt->blocked) //bar's menu is not now being created 
     299        if (g_atomic_int_get (&rt->blocked) == 0) //bar's menu is not now being created 
    299300        { 
    300301                GSList *group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menuitem)); 
     
    320321static void _e2_toolbar_update_isize_cb (GtkMenuItem *menuitem, E2_ToolbarRuntime *rt) 
    321322{ 
    322         if (!rt->blocked) //bar's menu is not now being created 
     323        if (g_atomic_int_get (&rt->blocked) == 0) //bar's menu is not now being created 
    323324        { 
    324325                GSList *group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menuitem)); 
     
    356357           ) 
    357358        { 
     359                GtkWidget *menu, *submenu; 
    358360                //block local callbacks while the menu is being constructed 
    359                 rt->blocked = TRUE; 
    360                 GtkWidget *menu, *submenu; 
     361                if (!g_atomic_int_compare_and_exchange (&rt->blocked, 0, 1)) 
     362                        return FALSE; 
    361363                menu = gtk_menu_new (); 
    362364                e2_menu_add_check (menu, _("Show _bar"), 
     
    444446 
    445447                e2_menu_popup (menu, 3, event->time); 
    446                 rt->blocked = FALSE; 
     448                g_atomic_int_set (&rt->blocked, 0); 
    447449                return TRUE; 
    448450        } 
     
    26802682        rt->name = barname; 
    26812683//      rt->public_name = app.bars[barnum]->public_name; 
    2682         rt->blocked = FALSE; 
     2684        rt->blocked = 0; 
    26832685        rt->hidden = FALSE; 
    26842686        rt->has_toggle = FALSE;