Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConrad Scott <conrad.scott@dsl.pipex.com>2002-07-01 01:19:56 +0400
committerConrad Scott <conrad.scott@dsl.pipex.com>2002-07-01 01:19:56 +0400
commit49b9a7830fc5ac08b845332594bae4d7344435a3 (patch)
treeee2f6ba076e538b7095fc146a4823c14e5248e04 /winsup/cygwin
parentc89053b489bdd8adfdc16a1a11fb5e82db4c1769 (diff)
* 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')
-rw-r--r--winsup/cygwin/ChangeLog8
-rwxr-xr-xwinsup/cygwin/cygserver_shm.cc28
2 files changed, 33 insertions, 3 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 726647f38..f78a7609c 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,13 @@
2002-06-30 Conrad Scott <conrad.scott@dsl.pipex.com>
+ * 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.
+
+2002-06-30 Conrad Scott <conrad.scott@dsl.pipex.com>
+
* woutsup.h: Remove all uses of the C++ new and delete operators
throughout cygserver until they are fully thread-safe.
(safe_new0): New macro to replace the C++ new operator.
diff --git a/winsup/cygwin/cygserver_shm.cc b/winsup/cygwin/cygserver_shm.cc
index 51c3d3b85..8d69e07af 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 ()
*---------------------------------------------------------------------------*/