SAGA Adaptor CPI v.1.0
|
00001 // Copyright (c) 2005-2009 Hartmut Kaiser 00002 // 00003 // Distributed under the Boost Software License, Version 1.0. (See accompanying 00004 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 00005 00006 #include <boost/thread.hpp> 00007 #include <saga/saga/base.hpp> 00008 00010 namespace saga 00011 { 00012 namespace detail 00013 { 00014 // this global mutex is used to protect the getenv function which is not 00015 // reenterant 00016 static boost::mutex &mutex_instance() 00017 { 00018 static boost::mutex mutex; 00019 return mutex; 00020 } 00021 static void mutex_init() 00022 { 00023 mutex_instance(); 00024 } 00025 00027 00028 char *safe_getenv(char const* name) 00029 { 00030 static boost::once_flag been_here = BOOST_ONCE_INIT; 00031 boost::call_once(mutex_init, been_here); 00032 00033 boost::mutex::scoped_lock l(mutex_instance()); 00034 return getenv(name); 00035 } 00037 00038 } // detail 00039 } // saga