diff options
author | scottc <scottc> | 2002-06-30 21:19:55 +0000 |
---|---|---|
committer | scottc <scottc> | 2002-06-30 21:19:55 +0000 |
commit | e870768222de52de607227a6898e877780b41305 (patch) | |
tree | 51dee1c5b443b81786c71368499af16cde6aebaa /winsup/cygwin/cygserver_shm.cc | |
parent | 779931699c4284209e9607b7df2449beb4abbac2 (diff) | |
download | gdb-e870768222de52de607227a6898e877780b41305.tar.gz |
* cygserver_shm.cc (server_shmmgr::_instance): New static field.
(server_shmmgr::_instance_once): Ditto.
(server_shmmgr::initialise_instance): New static method.
(server_shmmgr::instance): Use a pthread_once_t rather than
relying on a local static variable.
Diffstat (limited to 'winsup/cygwin/cygserver_shm.cc')
-rwxr-xr-x | winsup/cygwin/cygserver_shm.cc | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/winsup/cygwin/cygserver_shm.cc b/winsup/cygwin/cygserver_shm.cc index 51c3d3b850f..8d69e07af14 100755 --- a/winsup/cygwin/cygserver_shm.cc +++ b/winsup/cygwin/cygserver_shm.cc @@ -112,6 +112,11 @@ public: int shmget (key_t, size_t, int shmflg, pid_t, uid_t, gid_t); private: + static server_shmmgr *_instance; + static pthread_once_t _instance_once; + + static void initialise_instance (); + CRITICAL_SECTION _segments_lock; segment_t *_segments_head; // A list sorted by shmid. @@ -134,16 +139,21 @@ private: void delete_segment (segment_t *); }; +/* static */ server_shmmgr *server_shmmgr::_instance = NULL; +/* static */ pthread_once_t server_shmmgr::_instance_once = PTHREAD_ONCE_INIT; + /*---------------------------------------------------------------------------* * server_shmmgr::instance () *---------------------------------------------------------------------------*/ -server_shmmgr & +/* static */ server_shmmgr & server_shmmgr::instance () { - static server_shmmgr instance; + pthread_once (&_instance_once, &initialise_instance); - return instance; + assert (_instance); + + return *_instance; } /*---------------------------------------------------------------------------* @@ -334,6 +344,18 @@ server_shmmgr::shmget (const key_t key, const size_t size, const int shmflg, } /*---------------------------------------------------------------------------* + * server_shmmgr::initialise_instance () + *---------------------------------------------------------------------------*/ + +/* static */ void +server_shmmgr::initialise_instance () +{ + assert (!_instance); + + _instance = safe_new0 (server_shmmgr); +} + +/*---------------------------------------------------------------------------* * server_shmmgr::server_shmmgr () *---------------------------------------------------------------------------*/ |