wxSocket::Initialize() and Shutdown() are for main thread only.

Calling Initialize() from another thread could never work before but it wasn't
clear that this was the case so document it in the functions comments and
documentation now and add asserts checking that they are called from the main
thread only.

Also simplify the code as we don't actually need to do any reference-counting
here and a simple boolean flag indicating whether the sockets are initialized
is enough.

Closes #11119.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61985 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-09-21 08:44:35 +00:00
parent 7b7ad6a7f2
commit 4017f5ca49
3 changed files with 49 additions and 27 deletions

View File

@@ -179,11 +179,21 @@ public:
void SetNotify(wxSocketEventFlags flags);
void Notify(bool notify);
// initialize/shutdown the sockets (usually called automatically)
static bool IsInitialized();
// initialize/shutdown the sockets (done automatically so there is no need
// to call these functions usually)
//
// should always be called from the main thread only so one of the cases
// where they should indeed be called explicitly is when the first wxSocket
// object in the application is created in a different thread
static bool Initialize();
static void Shutdown();
// check if wxSocket had been already initialized
//
// notice that this function should be only called from the main thread as
// otherwise it is inherently unsafe because Initialize/Shutdown() may be
// called concurrently with it in the main thread
static bool IsInitialized();
// Implementation from now on
// --------------------------
@@ -264,9 +274,6 @@ private:
wxSocketEventFlags m_eventmask; // which events to notify?
wxSocketEventFlags m_eventsgot; // collects events received in OnRequest()
// the initialization count, wxSocket is initialized if > 0
static size_t m_countInit;
friend class wxSocketReadGuard;
friend class wxSocketWriteGuard;