[complement-svn] SF.net SVN: complement: [1525] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-02-12 12:17:56
|
Revision: 1525 http://svn.sourceforge.net/complement/?rev=1525&view=rev Author: complement Date: 2007-02-12 04:17:50 -0800 (Mon, 12 Feb 2007) Log Message: ----------- use Init technique to initialize static idx [thread-specific data index]---avoid global mutex initialization [lead to problems after fork?]; reinitilize idx after fork; libsockios: Version 1.11.0 Modified Paths: -------------- trunk/complement/explore/include/sockios/sockmgr.h trunk/complement/explore/lib/sockios/ChangeLog trunk/complement/explore/lib/sockios/Makefile.inc trunk/complement/explore/lib/sockios/_sockmgr.cc Modified: trunk/complement/explore/include/sockios/sockmgr.h =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.h 2007-02-12 11:22:03 UTC (rev 1524) +++ trunk/complement/explore/include/sockios/sockmgr.h 2007-02-12 12:17:50 UTC (rev 1525) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/02/01 16:10:07 ptr> +// -*- C++ -*- Time-stamp: <07/02/12 14:50:57 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 @@ -52,22 +52,23 @@ class basic_sockmgr : public sock_base { + private: + class Init + { + public: + Init(); + ~Init(); + private: + static void _guard( int ); + static void __at_fork_prepare(); + static void __at_fork_child(); + static void __at_fork_parent(); + }; + public: - basic_sockmgr() : - _errno( 0 ), - _mode( ios_base::in | ios_base::out ), - _state( ios_base::goodbit ), - _fd( -1 ) - { - xmt::Locker _l( _idx_lck ); - if ( _idx == -1 ) { - _idx = xmt::Thread::xalloc(); - } - } + basic_sockmgr(); + virtual ~basic_sockmgr(); - virtual ~basic_sockmgr() - { basic_sockmgr::close(); } - protected: __FIT_DECLSPEC void open( const in_addr& addr, int port, sock_base::stype type, sock_base::protocol prot ); __FIT_DECLSPEC void open( unsigned long addr, int port, sock_base::stype type, sock_base::protocol prot ); @@ -109,10 +110,8 @@ protected: static int _idx; + friend class Init; - private: - static xmt::Mutex _idx_lck; - protected: xmt::Mutex _fd_lck; xmt::Condition _loop_cnd; @@ -274,7 +273,7 @@ bool accept_udp(); private: - xmt::Thread loop_id; + xmt::Thread loop_id; protected: typedef sockmgr_stream_MP<Connect> _Self_type; Modified: trunk/complement/explore/lib/sockios/ChangeLog =================================================================== --- trunk/complement/explore/lib/sockios/ChangeLog 2007-02-12 11:22:03 UTC (rev 1524) +++ trunk/complement/explore/lib/sockios/ChangeLog 2007-02-12 12:17:50 UTC (rev 1525) @@ -1,3 +1,12 @@ +2007-02-12 Petr Ovtchenkov <pt...@is...> + + * sockmgr.h, _sockmgr.cc: use Init technique to initialize + static idx [thread-specific data index]---avoid global + mutex initialization [lead to problems after fork?]; + reinitilize idx after fork; + + * libsockios: Version 1.11.0 + 2007-02-01 Petr Ovtchenkov <pt...@is...> * sockmgr.cc: clean container with sockstreams, Modified: trunk/complement/explore/lib/sockios/Makefile.inc =================================================================== --- trunk/complement/explore/lib/sockios/Makefile.inc 2007-02-12 11:22:03 UTC (rev 1524) +++ trunk/complement/explore/lib/sockios/Makefile.inc 2007-02-12 12:17:50 UTC (rev 1525) @@ -2,8 +2,8 @@ LIBNAME = sockios MAJOR = 1 -MINOR = 10 -PATCH = 4 +MINOR = 11 +PATCH = 0 SRC_CC = _sockstream.cc _sockmgr.cc SRC_C = freebsd/getaddrinfo.c \ freebsd/ns_parse.c \ Modified: trunk/complement/explore/lib/sockios/_sockmgr.cc =================================================================== --- trunk/complement/explore/lib/sockios/_sockmgr.cc 2007-02-12 11:22:03 UTC (rev 1524) +++ trunk/complement/explore/lib/sockios/_sockmgr.cc 2007-02-12 12:17:50 UTC (rev 1525) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/06/28 10:35:10 ptr> +// -*- C++ -*- Time-stamp: <07/02/12 14:49:26 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -35,8 +35,58 @@ #endif int basic_sockmgr::_idx = -1; -xmt::Mutex basic_sockmgr::_idx_lck; +void basic_sockmgr::Init::__at_fork_prepare() +{ +} + +void basic_sockmgr::Init::__at_fork_child() +{ + basic_sockmgr::_idx = xmt::Thread::xalloc(); +} + +void basic_sockmgr::Init::__at_fork_parent() +{ +} + +void basic_sockmgr::Init::_guard( int direction ) +{ + static xmt::Mutex _init_lock; + static int _count = 0; + + if ( direction ) { + if ( _count++ == 0 ) { +#ifdef _PTHREADS + pthread_atfork( __at_fork_prepare, __at_fork_parent, __at_fork_child ); +#endif + basic_sockmgr::_idx = xmt::Thread::xalloc(); + } + } +} + +basic_sockmgr::Init::Init() +{ _guard( 1 ); } + +basic_sockmgr::Init::~Init() +{ _guard( 0 ); } + +char Init_buf[128]; + +basic_sockmgr::basic_sockmgr() : + _errno( 0 ), + _mode( ios_base::in | ios_base::out ), + _state( ios_base::goodbit ), + _fd( -1 ) +{ + new( Init_buf ) Init(); +} + +basic_sockmgr::~basic_sockmgr() +{ + basic_sockmgr::close(); + ((Init *)Init_buf)->~Init(); +} + void basic_sockmgr::open( const in_addr& addr, int port, sock_base::stype type, sock_base::protocol prot ) { MT_REENTRANT( _fd_lck, _1 ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |