[complement-svn] SF.net SVN: complement: [1937] trunk/complement/explore/lib/mt
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2008-07-01 14:42:06
|
Revision: 1937 http://complement.svn.sourceforge.net/complement/?rev=1937&view=rev Author: complement Date: 2008-07-01 07:42:03 -0700 (Tue, 01 Jul 2008) Log Message: ----------- fix generation of uid Fix not good: reopen file for every call Modified Paths: -------------- trunk/complement/explore/lib/mt/uid.cc trunk/complement/explore/lib/mt/ut/mt_test_suite.cc trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc trunk/complement/explore/lib/mt/ut/mt_test_wg21.h Modified: trunk/complement/explore/lib/mt/uid.cc =================================================================== --- trunk/complement/explore/lib/mt/uid.cc 2008-07-01 14:41:48 UTC (rev 1936) +++ trunk/complement/explore/lib/mt/uid.cc 2008-07-01 14:42:03 UTC (rev 1937) @@ -9,7 +9,7 @@ */ #include <mt/uid.h> -#include <mt/xmt.h> +#include <mt/mutex> #include <fstream> #include <sstream> #include <iomanip> @@ -21,6 +21,7 @@ using namespace std; using namespace xmt; +using namespace std::tr2; class __uid_init { @@ -34,21 +35,13 @@ uuid_type __uid_init::_host_id; char __uid_init::_host_id_str[48]; -class __uuid_init -{ - public: - __uuid_init(); +// ifstream _uuid; - static ifstream _uuid; -}; - -ifstream __uuid_init::_uuid; - __uid_init::__uid_init() { static mutex _lk; - scoped_lock lock( _lk ); + lock_guard<mutex> lock( _lk ); ifstream f( "/proc/sys/kernel/random/boot_id" ); string tmp; @@ -93,20 +86,10 @@ >> reinterpret_cast<unsigned&>(_host_id.u.b[15]); } -__uuid_init::__uuid_init() -{ - static mutex _lk; - - scoped_lock lock( _lk ); - - if ( !_uuid.is_open() ) { - _uuid.open( "/proc/sys/kernel/random/uuid" ); - } -} - } // namespace detail using namespace std; +using namespace std::tr2; const char *hostid_str() { @@ -122,15 +105,20 @@ std::string uid_str() { - static detail::__uuid_init _uid; - static mutex _lk; - scoped_lock lock( _lk ); + lock_guard<mutex> lock( _lk ); + // if ( !detail::_uuid.is_open() ) { + // detail::_uuid.open( "/proc/sys/kernel/random/uuid" ); + // } + + ifstream _uuid( "/proc/sys/kernel/random/uuid" ); + std::string tmp; - getline( _uid._uuid, tmp ); + // getline( detail::_uuid, tmp ).clear(); // clear eof bit + getline( _uuid, tmp ); return tmp; } Modified: trunk/complement/explore/lib/mt/ut/mt_test_suite.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test_suite.cc 2008-07-01 14:41:48 UTC (rev 1936) +++ trunk/complement/explore/lib/mt/ut/mt_test_suite.cc 2008-07-01 14:42:03 UTC (rev 1937) @@ -75,6 +75,7 @@ t.add( &mt_test_wg21::barrier, test_wg21, "mt_test_wg21::barrier" ); t.add( &mt_test_wg21::semaphore, test_wg21, "mt_test_wg21::semaphore" ); t.add( &mt_test_wg21::fork, test_wg21, "mt_test_wg21::fork" ); + t.add( &mt_test_wg21::uid, test_wg21, "mt_test_wg21::uid" ); return t.girdle(); }; Modified: trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc 2008-07-01 14:41:48 UTC (rev 1936) +++ trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc 2008-07-01 14:42:03 UTC (rev 1937) @@ -23,6 +23,10 @@ #include <sys/ipc.h> #include <sys/shm.h> +#include <mt/uid.h> + +#include <string> + int EXAM_IMPL(mt_test_wg21::date_time) { // using namespace std::tr2; @@ -314,3 +318,18 @@ return EXAM_RESULT; } +int EXAM_IMPL(mt_test_wg21::uid) +{ + std::string u1 = xmt::uid_str(); + + EXAM_CHECK( !u1.empty() ); + + std::string u2 = xmt::uid_str(); + + EXAM_CHECK( !u2.empty() ); + + EXAM_CHECK( u1 != u2 ); + + return EXAM_RESULT; +} + Modified: trunk/complement/explore/lib/mt/ut/mt_test_wg21.h =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test_wg21.h 2008-07-01 14:41:48 UTC (rev 1936) +++ trunk/complement/explore/lib/mt/ut/mt_test_wg21.h 2008-07-01 14:42:03 UTC (rev 1937) @@ -25,6 +25,7 @@ int EXAM_DECL(barrier); int EXAM_DECL(semaphore); int EXAM_DECL(fork); + int EXAM_DECL(uid); private: // static xmt::Thread::ret_t thread_entry_call( void * ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |