wxUsleep() introduced (and documented) to try to work around usleep() bug in

MT programs under Solaris


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1852 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 1999-03-03 17:11:14 +00:00
parent ba6f401d45
commit afb7489128
14 changed files with 643 additions and 503 deletions

458
configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -450,7 +450,10 @@ AC_SUBST(GTK_JOYSTICK)
dnl check for vprintf/vsprintf() which are GNU extensions
AC_FUNC_VPRINTF
dnl check for vsnprintf() which is another GNU extension
AC_CHECK_FUNC(vsnprintf, AC_DEFINE(HAVE_VSNPRINTF))
AC_CHECK_FUNCS(vsnprintf)
dnl check for usleep() and nanosleep() which is better in MT programs
AC_CHECK_FUNCS(nanosleep usleep)
AC_LANG_SAVE
AC_LANG_CPLUSPLUS

View File

@ -1434,6 +1434,18 @@ This function is now obsolete, replaced by \helpref{Log functions}{logfunctions}
<wx/memory.h>
\membersection{::wxUsleep}\label{wxusleep}
\func{void}{wxUsleep}{\param{unsigned long}{ milliseconds}}
Sleeps for the specified number of milliseconds. Notice that usage of this
function is encouraged instead of calling usleep(3) directly because the
standard usleep() function is not MT safe.
\wxheading{Include files}
<wx/utils.h>
\membersection{::wxWriteResource}\label{wxwriteresource}
\func{bool}{wxWriteResource}{\param{const wxString\& }{section}, \param{const wxString\& }{entry},

View File

@ -49,13 +49,13 @@ class WXDLLEXPORT wxFrame;
#define wxToLower(C) (((C) >= 'A' && (C) <= 'Z')? (C) - 'A' + 'a': (C))
// Return a string with the current date/time
WXDLLEXPORT wxString wxNow(void);
WXDLLEXPORT wxString wxNow();
// Make a copy of this string using 'new'
WXDLLEXPORT char* copystring(const char *s);
// Generate a unique ID
WXDLLEXPORT long wxNewId(void);
WXDLLEXPORT long wxNewId();
#define NewId wxNewId
// Ensure subsequent IDs don't clash with this one
@ -63,7 +63,7 @@ WXDLLEXPORT void wxRegisterId(long id);
#define RegisterId wxRegisterId
// Return the current ID
WXDLLEXPORT long wxGetCurrentId(void);
WXDLLEXPORT long wxGetCurrentId();
// Useful buffer
WXDLLEXPORT_DATA(extern char*) wxBuffer;
@ -111,11 +111,14 @@ WXDLLEXPORT bool wxShell(const wxString& command = wxEmptyString);
// Sleep for nSecs seconds under UNIX, do nothing under Windows
WXDLLEXPORT void wxSleep(int nSecs);
// Sleep for a given amount of milliseconds
WXDLLEXPORT void wxUsleep(unsigned long milliseconds);
// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
WXDLLEXPORT long wxGetFreeMemory(void);
WXDLLEXPORT long wxGetFreeMemory();
// Consume all events until no more left
WXDLLEXPORT void wxFlushEvents(void);
WXDLLEXPORT void wxFlushEvents();
/*
* Network and username functions.
@ -166,7 +169,7 @@ WXDLLEXPORT int wxFindMenuItemId(wxFrame *frame, const wxString& menuString, con
#define wxMin(a,b) (((a) < (b)) ? (a) : (b))
// Yield to other apps/messages
WXDLLEXPORT bool wxYield(void);
WXDLLEXPORT bool wxYield();
// Format a message on the standard error (UNIX) or the debugging
// stream (Windows)
@ -184,20 +187,22 @@ WXDLLEXPORT_DATA(extern wxCursor*) wxHOURGLASS_CURSOR;
WXDLLEXPORT void wxBeginBusyCursor(wxCursor *cursor = wxHOURGLASS_CURSOR);
// Restore cursor to normal
WXDLLEXPORT void wxEndBusyCursor(void);
WXDLLEXPORT void wxEndBusyCursor();
// TRUE if we're between the above two calls
WXDLLEXPORT bool wxIsBusy(void);
WXDLLEXPORT bool wxIsBusy();
// Convenience class so we can just create a wxBusyCursor object on the stack
class WXDLLEXPORT wxBusyCursor
{
public:
inline wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR) { wxBeginBusyCursor(cursor); }
inline ~wxBusyCursor() { wxEndBusyCursor(); }
public:
wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR)
{ wxBeginBusyCursor(cursor); }
~wxBusyCursor()
{ wxEndBusyCursor(); }
};
/* Error message functions used by wxWindows */
// Error message functions used by wxWindows
// Non-fatal error (continues)
WXDLLEXPORT_DATA(extern const char*) wxInternalErrorStr;

View File

@ -374,6 +374,18 @@
/* Define if you have vsnprintf() */
#undef HAVE_VSNPRINTF
/* Define if you have usleep() */
#undef HAVE_USLEEP
/* Define if you have nanosleep() */
#undef HAVE_NANOSLEEP
/* Define if you have usleep() */
#undef HAVE_USLEEP
/* Define if you have nanosleep() */
#undef HAVE_NANOSLEEP
/* Define if your system has its own `getloadavg' function. */
#undef HAVE_GETLOADAVG

View File

@ -54,20 +54,20 @@ wxHashTable* wxClassInfo::sm_classTable = (wxHashTable*) NULL;
* wxWindows root object.
*/
wxObject::wxObject(void)
wxObject::wxObject()
{
m_refData = (wxObjectRefData *) NULL;
m_refData = (wxObjectRefData *) NULL;
#if wxUSE_SERIAL
m_serialObj = (wxObject_Serialize *)NULL;
m_serialObj = (wxObject_Serialize *)NULL;
#endif
}
wxObject::~wxObject(void)
wxObject::~wxObject()
{
UnRef();
UnRef();
#if wxUSE_SERIAL
if (m_serialObj)
delete m_serialObj;
if (m_serialObj)
delete m_serialObj;
#endif
}
@ -80,20 +80,20 @@ wxObject::~wxObject(void)
bool wxObject::IsKindOf(wxClassInfo *info) const
{
wxClassInfo *thisInfo = GetClassInfo();
if (thisInfo)
return thisInfo->IsKindOf(info);
else
return FALSE;
wxClassInfo *thisInfo = GetClassInfo();
if (thisInfo)
return thisInfo->IsKindOf(info);
else
return FALSE;
}
#if defined(__WXDEBUG__) || wxUSE_DEBUG_CONTEXT
void wxObject::Dump(ostream& str)
{
if (GetClassInfo() && GetClassInfo()->GetClassName())
str << GetClassInfo()->GetClassName();
else
str << "unknown object class";
if (GetClassInfo() && GetClassInfo()->GetClassName())
str << GetClassInfo()->GetClassName();
else
str << "unknown object class";
}
#endif
@ -103,21 +103,21 @@ void wxObject::Dump(ostream& str)
#undef new
#endif
void * wxObject::operator new (size_t size, char * fileName, int lineNum)
void *wxObject::operator new (size_t size, char * fileName, int lineNum)
{
return wxDebugAlloc(size, fileName, lineNum, TRUE);
return wxDebugAlloc(size, fileName, lineNum, TRUE);
}
void wxObject::operator delete (void * buf)
{
wxDebugFree(buf);
wxDebugFree(buf);
}
// VC++ 6.0
#if defined(__VISUALC__) && (__VISUALC__ >= 1200)
void wxObject::operator delete(void* pData, char* /* fileName */, int /* lineNum */)
{
::operator delete(pData);
::operator delete(pData);
}
#endif
@ -125,12 +125,12 @@ void wxObject::operator delete(void* pData, char* /* fileName */, int /* lineNum
#if !defined(__VISUALC__) && wxUSE_ARRAY_MEMORY_OPERATORS
void * wxObject::operator new[] (size_t size, char * fileName, int lineNum)
{
return wxDebugAlloc(size, fileName, lineNum, TRUE, TRUE);
return wxDebugAlloc(size, fileName, lineNum, TRUE, TRUE);
}
void wxObject::operator delete[] (void * buf)
{
wxDebugFree(buf, TRUE);
wxDebugFree(buf, TRUE);
}
#endif
@ -142,97 +142,97 @@ void wxObject::operator delete[] (void * buf)
wxClassInfo::wxClassInfo(char *cName, char *baseName1, char *baseName2, int sz, wxObjectConstructorFn constr)
{
m_className = cName;
m_baseClassName1 = baseName1;
m_baseClassName2 = baseName2;
m_className = cName;
m_baseClassName1 = baseName1;
m_baseClassName2 = baseName2;
m_objectSize = sz;
m_objectConstructor = constr;
m_objectSize = sz;
m_objectConstructor = constr;
m_next = sm_first;
sm_first = this;
m_next = sm_first;
sm_first = this;
m_baseInfo1 = (wxClassInfo *) NULL;
m_baseInfo2 = (wxClassInfo *) NULL;
m_baseInfo1 = (wxClassInfo *) NULL;
m_baseInfo2 = (wxClassInfo *) NULL;
}
wxObject *wxClassInfo::CreateObject(void)
wxObject *wxClassInfo::CreateObject()
{
if (m_objectConstructor)
return (wxObject *)(*m_objectConstructor)();
else
return (wxObject *) NULL;
if (m_objectConstructor)
return (wxObject *)(*m_objectConstructor)();
else
return (wxObject *) NULL;
}
wxClassInfo *wxClassInfo::FindClass(char *c)
{
wxClassInfo *p = sm_first;
while (p)
{
if (p && p->GetClassName() && strcmp(p->GetClassName(), c) == 0)
return p;
p = p->m_next;
}
return (wxClassInfo *) NULL;
wxClassInfo *p = sm_first;
while (p)
{
if (p && p->GetClassName() && strcmp(p->GetClassName(), c) == 0)
return p;
p = p->m_next;
}
return (wxClassInfo *) NULL;
}
// Climb upwards through inheritance hierarchy.
// Dual inheritance is catered for.
bool wxClassInfo::IsKindOf(wxClassInfo *info) const
{
if (info == NULL)
return FALSE;
if (info == NULL)
return FALSE;
// For some reason, when making/using a DLL, static data has to be included
// in both the DLL and the application. This can lead to duplicate
// wxClassInfo objects, so we have to test the name instead of the pointers.
// PROBABLY NO LONGER TRUE now I've done DLL creation right.
/*
// For some reason, when making/using a DLL, static data has to be included
// in both the DLL and the application. This can lead to duplicate
// wxClassInfo objects, so we have to test the name instead of the pointers.
// PROBABLY NO LONGER TRUE now I've done DLL creation right.
/*
#if WXMAKINGDLL
if (GetClassName() && info->GetClassName() && (strcmp(GetClassName(), info->GetClassName()) == 0))
return TRUE;
if (GetClassName() && info->GetClassName() && (strcmp(GetClassName(), info->GetClassName()) == 0))
return TRUE;
#else
*/
if (this == info)
return TRUE;
*/
if (this == info)
return TRUE;
if (m_baseInfo1)
if (m_baseInfo1->IsKindOf(info))
return TRUE;
if (m_baseInfo1)
if (m_baseInfo1->IsKindOf(info))
return TRUE;
if (m_baseInfo2)
return m_baseInfo2->IsKindOf(info);
if (m_baseInfo2)
return m_baseInfo2->IsKindOf(info);
return FALSE;
return FALSE;
}
// Set pointers to base class(es) to speed up IsKindOf
void wxClassInfo::InitializeClasses(void)
void wxClassInfo::InitializeClasses()
{
wxClassInfo::sm_classTable = new wxHashTable(wxKEY_STRING);
wxClassInfo::sm_classTable = new wxHashTable(wxKEY_STRING);
// Index all class infos by their class name
wxClassInfo *info = sm_first;
while (info)
{
if (info->m_className)
sm_classTable->Put(info->m_className, (wxObject *)info);
info = info->m_next;
}
// Index all class infos by their class name
wxClassInfo *info = sm_first;
while (info)
{
if (info->m_className)
sm_classTable->Put(info->m_className, (wxObject *)info);
info = info->m_next;
}
// Set base pointers for each wxClassInfo
info = sm_first;
while (info)
{
if (info->GetBaseClassName1())
info->m_baseInfo1 = (wxClassInfo *)sm_classTable->Get(info->GetBaseClassName1());
if (info->GetBaseClassName2())
info->m_baseInfo2 = (wxClassInfo *)sm_classTable->Get(info->GetBaseClassName2());
info = info->m_next;
}
// Set base pointers for each wxClassInfo
info = sm_first;
while (info)
{
if (info->GetBaseClassName1())
info->m_baseInfo1 = (wxClassInfo *)sm_classTable->Get(info->GetBaseClassName1());
if (info->GetBaseClassName2())
info->m_baseInfo2 = (wxClassInfo *)sm_classTable->Get(info->GetBaseClassName2());
info = info->m_next;
}
}
void wxClassInfo::CleanUpClasses(void)
void wxClassInfo::CleanUpClasses()
{
delete wxClassInfo::sm_classTable;
wxClassInfo::sm_classTable = NULL;
@ -270,54 +270,54 @@ wxObject *wxCreateDynamicObject(const char *name)
wxObject* wxCreateStoredObject( wxInputStream &stream )
{
wxObjectInputStream obj_s(stream);
return obj_s.LoadObject();
wxObjectInputStream obj_s(stream);
return obj_s.LoadObject();
};
void wxObject::StoreObject( wxObjectOutputStream& stream )
{
wxString obj_name = wxString(GetClassInfo()->GetClassName()) + "_Serialize";
wxLibrary *lib = wxTheLibraries.LoadLibrary("wxserial");
wxString obj_name = wxString(GetClassInfo()->GetClassName()) + "_Serialize";
wxLibrary *lib = wxTheLibraries.LoadLibrary("wxserial");
if (!lib) {
wxLogError(_("Can't load wxSerial dynamic library."));
return;
}
if (!m_serialObj) {
m_serialObj = (WXSERIAL(wxObject) *)lib->CreateObject( obj_name );
if (!m_serialObj) {
wxLogError(_("Can't find the serialization object '%s' "
"for the object '%s'."),
obj_name.c_str(),
GetClassInfo()->GetClassName());
return;
if (!lib) {
wxLogError(_("Can't load wxSerial dynamic library."));
return;
}
m_serialObj->SetObject(this);
}
if (!m_serialObj) {
m_serialObj = (WXSERIAL(wxObject) *)lib->CreateObject( obj_name );
m_serialObj->StoreObject(stream);
if (!m_serialObj) {
wxLogError(_("Can't find the serialization object '%s' "
"for the object '%s'."),
obj_name.c_str(),
GetClassInfo()->GetClassName());
return;
}
m_serialObj->SetObject(this);
}
m_serialObj->StoreObject(stream);
}
void wxObject::LoadObject( wxObjectInputStream& stream )
{
wxString obj_name = wxString(GetClassInfo()->GetClassName()) + "_Serialize";
wxLibrary *lib = wxTheLibraries.LoadLibrary("wxserial");
if (!m_serialObj) {
m_serialObj = (WXSERIAL(wxObject) *)lib->CreateObject( obj_name );
wxString obj_name = wxString(GetClassInfo()->GetClassName()) + "_Serialize";
wxLibrary *lib = wxTheLibraries.LoadLibrary("wxserial");
if (!m_serialObj) {
wxLogError(_("Can't find the serialization object '%s' "
"for the object '%s'."),
obj_name.c_str(),
GetClassInfo()->GetClassName());
return;
}
m_serialObj->SetObject(this);
}
m_serialObj = (WXSERIAL(wxObject) *)lib->CreateObject( obj_name );
m_serialObj->LoadObject(stream);
if (!m_serialObj) {
wxLogError(_("Can't find the serialization object '%s' "
"for the object '%s'."),
obj_name.c_str(),
GetClassInfo()->GetClassName());
return;
}
m_serialObj->SetObject(this);
}
m_serialObj->LoadObject(stream);
}
#endif // wxUSE_SERIAL
@ -337,7 +337,7 @@ void wxObject::Ref(const wxObject& clone)
}
}
void wxObject::UnRef(void)
void wxObject::UnRef()
{
if (m_refData) {
assert(m_refData->m_count > 0);
@ -356,7 +356,7 @@ wxObjectRefData::wxObjectRefData(void) : m_count(1)
{
}
wxObjectRefData::~wxObjectRefData(void)
wxObjectRefData::~wxObjectRefData()
{
}

View File

@ -8,7 +8,7 @@
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "app.h"
#pragma implementation "app.h"
#endif
#include "wx/app.h"
@ -20,35 +20,24 @@
#include "wx/font.h"
#include "wx/settings.h"
#include "wx/dialog.h"
#if wxUSE_WX_RESOURCES
#include "wx/resource.h"
#include "wx/resource.h"
#endif
#include "wx/module.h"
#include "wx/image.h"
#if wxUSE_THREADS
#include "wx/thread.h"
#endif
#include "unistd.h"
// many versions of Unices have this function, but it is not defined in system
// headers - please add your system here if it is the case for your OS.
// SunOS < 5.6 (i.e. Solaris < 2.6) and DG-UX are like this.
#if (defined(__SUN__) && !defined(__SunOs_5_6) && \
!defined(__SunOs_5_7) && !defined(__SUNPRO_CC)) || \
defined(__osf__)
extern "C"
{
void usleep(unsigned long usec);
};
#endif // Unices without usleep()
#include <glib.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include "glib.h"
#include "gdk/gdk.h"
#include "gtk/gtk.h"
#include "wx/gtk/win_gtk.h"
#include <unistd.h> // usleep() on solaris
//-----------------------------------------------------------------------------
// global data
//-----------------------------------------------------------------------------
@ -160,14 +149,17 @@ END_EVENT_TABLE()
gint wxapp_idle_callback( gpointer WXUNUSED(data) )
{
if (wxTheApp) while (wxTheApp->ProcessIdle()) {}
#if wxUSE_THREADS
if (wxTheApp)
{
while (wxTheApp->ProcessIdle())
{
}
}
wxMutexGuiLeave();
#endif
usleep(10000);
#if wxUSE_THREADS
wxUsleep(10);
wxMutexGuiEnter();
#endif
return TRUE;
}

View File

@ -410,9 +410,7 @@ void wxThread::Yield()
void wxThread::Sleep(unsigned long milliseconds)
{
// FIXME how to test for nanosleep() availability?
usleep(milliseconds * 1000); // usleep(3) wants microseconds
wxUsleep(milliseconds);
}
// -----------------------------------------------------------------------------

View File

@ -7,11 +7,6 @@
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
//#ifdef __GNUG__
//#pragma implementation "utils.h"
//#endif
#include "wx/utils.h"
#include "wx/string.h"
@ -32,17 +27,30 @@
#include <netdb.h>
#include <signal.h>
#include <fcntl.h> // for O_WRONLY and friends
#include <time.h> // nanosleep() and/or usleep()
#include "glib.h"
#include "gdk/gdk.h"
#include "gtk/gtk.h"
#include "gtk/gtkfeatures.h"
#include "gdk/gdkx.h"
#include <glib.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include <gtk/gtkfeatures.h>
#include <gdk/gdkx.h>
#ifdef __SVR4__
#include <sys/systeminfo.h>
#endif
// many versions of Unices have this function, but it is not defined in system
// headers - please add your system here if it is the case for your OS.
// SunOS < 5.6 (i.e. Solaris < 2.6) and DG-UX are like this.
#if (defined(__SUN__) && !defined(__SunOs_5_6) && \
!defined(__SunOs_5_7) && !defined(__SUNPRO_CC)) || \
defined(__osf__)
extern "C"
{
void usleep(unsigned long usec);
};
#endif // Unices without usleep()
// many versions of Unices have this function, but it is not defined in system
// headers - please add your system here if it is the case for your OS.
// SunOS (and Solaris) and DG-UX are like this.
@ -78,6 +86,30 @@ void wxSleep(int nSecs)
sleep(nSecs);
}
void wxUsleep(unsigned long milliseconds)
{
#if defined(HAVE_NANOSLEEP)
timespec tmReq;
tmReq.tv_sec = milliseconds / 1000;
tmReq.tv_nsec = (milliseconds % 1000) * 1000 * 1000;
// we're not interested in remaining time nor in return value
(void)nanosleep(&tmReq, (timespec *)NULL);
#elif defined(HAVE_USLEEP)
// uncomment this if you feel brave or if you are sure that your version
// of Solaris has a safe usleep() function but please notice that usleep()
// is known to lead to crashes in MT programs in Solaris 2.[67] and is not
// documented as MT-Safe
#if defined(__SUN__) && defined(wxUSE_THREADS)
#error "usleep() cannot be used in MT programs under Solaris."
#endif // Sun
usleep(milliseconds * 1000); // usleep(3) wants microseconds
#else // !sleep function
#error "usleep() or nanosleep() function required for wxUsleep"
#endif // sleep function
}
int wxKill(long pid, int sig)
{
return kill(pid, sig);

View File

@ -8,7 +8,7 @@
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "app.h"
#pragma implementation "app.h"
#endif
#include "wx/app.h"
@ -20,35 +20,24 @@
#include "wx/font.h"
#include "wx/settings.h"
#include "wx/dialog.h"
#if wxUSE_WX_RESOURCES
#include "wx/resource.h"
#include "wx/resource.h"
#endif
#include "wx/module.h"
#include "wx/image.h"
#if wxUSE_THREADS
#include "wx/thread.h"
#endif
#include "unistd.h"
// many versions of Unices have this function, but it is not defined in system
// headers - please add your system here if it is the case for your OS.
// SunOS < 5.6 (i.e. Solaris < 2.6) and DG-UX are like this.
#if (defined(__SUN__) && !defined(__SunOs_5_6) && \
!defined(__SunOs_5_7) && !defined(__SUNPRO_CC)) || \
defined(__osf__)
extern "C"
{
void usleep(unsigned long usec);
};
#endif // Unices without usleep()
#include <glib.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include "glib.h"
#include "gdk/gdk.h"
#include "gtk/gtk.h"
#include "wx/gtk/win_gtk.h"
#include <unistd.h> // usleep() on solaris
//-----------------------------------------------------------------------------
// global data
//-----------------------------------------------------------------------------
@ -160,14 +149,17 @@ END_EVENT_TABLE()
gint wxapp_idle_callback( gpointer WXUNUSED(data) )
{
if (wxTheApp) while (wxTheApp->ProcessIdle()) {}
#if wxUSE_THREADS
if (wxTheApp)
{
while (wxTheApp->ProcessIdle())
{
}
}
wxMutexGuiLeave();
#endif
usleep(10000);
#if wxUSE_THREADS
wxUsleep(10);
wxMutexGuiEnter();
#endif
return TRUE;
}

View File

@ -410,9 +410,7 @@ void wxThread::Yield()
void wxThread::Sleep(unsigned long milliseconds)
{
// FIXME how to test for nanosleep() availability?
usleep(milliseconds * 1000); // usleep(3) wants microseconds
wxUsleep(milliseconds);
}
// -----------------------------------------------------------------------------

View File

@ -7,11 +7,6 @@
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
//#ifdef __GNUG__
//#pragma implementation "utils.h"
//#endif
#include "wx/utils.h"
#include "wx/string.h"
@ -32,17 +27,30 @@
#include <netdb.h>
#include <signal.h>
#include <fcntl.h> // for O_WRONLY and friends
#include <time.h> // nanosleep() and/or usleep()
#include "glib.h"
#include "gdk/gdk.h"
#include "gtk/gtk.h"
#include "gtk/gtkfeatures.h"
#include "gdk/gdkx.h"
#include <glib.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include <gtk/gtkfeatures.h>
#include <gdk/gdkx.h>
#ifdef __SVR4__
#include <sys/systeminfo.h>
#endif
// many versions of Unices have this function, but it is not defined in system
// headers - please add your system here if it is the case for your OS.
// SunOS < 5.6 (i.e. Solaris < 2.6) and DG-UX are like this.
#if (defined(__SUN__) && !defined(__SunOs_5_6) && \
!defined(__SunOs_5_7) && !defined(__SUNPRO_CC)) || \
defined(__osf__)
extern "C"
{
void usleep(unsigned long usec);
};
#endif // Unices without usleep()
// many versions of Unices have this function, but it is not defined in system
// headers - please add your system here if it is the case for your OS.
// SunOS (and Solaris) and DG-UX are like this.
@ -78,6 +86,30 @@ void wxSleep(int nSecs)
sleep(nSecs);
}
void wxUsleep(unsigned long milliseconds)
{
#if defined(HAVE_NANOSLEEP)
timespec tmReq;
tmReq.tv_sec = milliseconds / 1000;
tmReq.tv_nsec = (milliseconds % 1000) * 1000 * 1000;
// we're not interested in remaining time nor in return value
(void)nanosleep(&tmReq, (timespec *)NULL);
#elif defined(HAVE_USLEEP)
// uncomment this if you feel brave or if you are sure that your version
// of Solaris has a safe usleep() function but please notice that usleep()
// is known to lead to crashes in MT programs in Solaris 2.[67] and is not
// documented as MT-Safe
#if defined(__SUN__) && defined(wxUSE_THREADS)
#error "usleep() cannot be used in MT programs under Solaris."
#endif // Sun
usleep(milliseconds * 1000); // usleep(3) wants microseconds
#else // !sleep function
#error "usleep() or nanosleep() function required for wxUsleep"
#endif // sleep function
}
int wxKill(long pid, int sig)
{
return kill(pid, sig);

View File

@ -6,7 +6,7 @@
// Created: 17/09/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
@ -302,12 +302,11 @@ int wxApp::MainLoop()
{
if (!ProcessIdle())
{
// TODO: Robert, what's this for?
#if wxUSE_THREADS
// leave the main loop to give other threads a chance to
// perform their GUI work
wxMutexGuiLeave();
usleep(20);
wxUsleep(20);
wxMutexGuiEnter();
#endif
}
}

View File

@ -299,6 +299,11 @@ class wxSleepTimer: public wxTimer
static wxTimer *wxTheSleepTimer = NULL;
void wxUsleep(unsigned long milliseconds)
{
::Sleep(milliseconds);
}
void wxSleep(int nSecs)
{
#if 0 // WIN32 hangs app