From 268fb375171668e2d85a147c7614e89ce1bd46f6 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 31 Mar 2012 15:33:34 -0700 Subject: [PATCH] Cleanup proc_had_barrier Ensure we don't try to do a universal barrier off of the main thread --- env.cpp | 88 +++++++++++++++++++++++++---------------------- env_universal.cpp | 1 + parser.cpp | 3 +- proc.cpp | 13 ++++++- proc.h | 3 +- 5 files changed, 63 insertions(+), 45 deletions(-) diff --git a/env.cpp b/env.cpp index 034a72f01..a7a263986 100644 --- a/env.cpp +++ b/env.cpp @@ -730,6 +730,7 @@ static env_node_t *env_get_node( const wcstring &key ) int env_set(const wchar_t *key, const wchar_t *val, int var_mode) { + ASSERT_IS_MAIN_THREAD(); env_node_t *node = NULL; bool has_changed_old = has_changed; bool has_changed_new = false; @@ -840,9 +841,9 @@ int env_set(const wchar_t *key, const wchar_t *val, int var_mode) } else { - if( !proc_had_barrier) + if( ! get_proc_had_barrier()) { - proc_had_barrier=1; + set_proc_had_barrier(true); env_universal_barrier(); } @@ -1062,7 +1063,8 @@ const wchar_t *env_var_t::c_str(void) const { env_var_t env_get_string( const wcstring &key ) { /* Big hack...we only allow getting the history on the main thread. Note that history_t may ask for an environment variable, so don't take the lock here (we don't need it) */ - if( key == L"history" && is_main_thread()) + const bool is_main = is_main_thread(); + if( key == L"history" && is_main) { env_var_t result; @@ -1100,42 +1102,44 @@ env_var_t env_get_string( const wcstring &key ) wcstring result; while( env != 0 ) - { - var_table_t::iterator result = env->env.find(key); - if ( result != env->env.end() ) - { - res = result->second; - } - else - { - res = 0; - } - - - if( res != 0 ) - { - if( res->val == ENV_NULL ) - { - return env_var_t::missing_var(); - } - else - { - return res->val; - } - } - - if( env->new_scope ) - { - env = global_env; - } - else - { - env = env->next; - } - } - if( !proc_had_barrier) { - proc_had_barrier=1; + var_table_t::iterator result = env->env.find(key); + if ( result != env->env.end() ) + { + res = result->second; + } + else + { + res = 0; + } + + + if( res != 0 ) + { + if( res->val == ENV_NULL ) + { + return env_var_t::missing_var(); + } + else + { + return res->val; + } + } + + if( env->new_scope ) + { + env = global_env; + } + else + { + env = env->next; + } + } + + /* Another big hack - only do a universal barrier on the main thread (since it can change variable values) */ + if(is_main && ! get_proc_had_barrier()) + { + set_proc_had_barrier(true); env_universal_barrier(); } @@ -1211,9 +1215,9 @@ int env_exist( const wchar_t *key, int mode ) if( ! (mode & ENV_LOCAL) && ! (mode & ENV_GLOBAL) ) { - if( !proc_had_barrier) + if( ! get_proc_had_barrier()) { - proc_had_barrier=1; + set_proc_had_barrier(true); env_universal_barrier(); } @@ -1453,9 +1457,9 @@ static void export_func(const std::map &envs, std::vector