* Posix/SGI/No threads added
* Updated configure.in file (Threads and Joystick detection) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@89 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
457
install/gtk/configure
vendored
457
install/gtk/configure
vendored
File diff suppressed because it is too large
Load Diff
@@ -419,6 +419,13 @@ AC_CHECK_HEADER(sys/time.h)
|
||||
dnl defines HAVE_SYS_TIME_H
|
||||
AC_CHECK_HEADER(unistd.h)
|
||||
dnl defines HAVE_UNISTD_H
|
||||
dnl As it needs Linux 2.1.x for the moment: check whether the file exists (GL).
|
||||
AC_CHECK_HEADER(linux/joystick.h)
|
||||
GTK_JOYSTICK=""
|
||||
if test "$ac_cv_header_linux_joystick_h" != ""; then
|
||||
GTK_JOYSTICK="gtk/joystick.cpp"
|
||||
fi
|
||||
AC_SUBST(GTK_JOYSTICK)
|
||||
|
||||
dnl ###################
|
||||
dnl # checks typedefs #
|
||||
@@ -487,10 +494,22 @@ dnl ############################
|
||||
dnl # checks library functions #
|
||||
dnl ############################
|
||||
|
||||
UNIX_THREAD=gtk/threadno.cpp
|
||||
AC_CHECK_LIB(pthread, pthread_create, [UNIX_THREAD=gtk/threadpsx.cpp])
|
||||
|
||||
dnl ##########################
|
||||
dnl # checks system services #
|
||||
dnl ##########################
|
||||
|
||||
|
||||
dnl ##### Threads #####
|
||||
UNIX_THREAD="gtk/threadno.cpp"
|
||||
AC_CHECK_LIB(pthread, pthread_create, [UNIX_THREAD="gtk/threadpsx.cpp"])
|
||||
AC_CHECK_LIB(pthreads, pthread_create, [UNIX_THREAD="gtk/threadpsx.cpp"])
|
||||
AC_CHECK_HEADER(sys/prctl.h, [UNIX_THREAD="gtk/threadsgi.cpp"])
|
||||
AC_SUBST(UNIX_THREAD)
|
||||
dnl defines UNIX_THREAD it contains the source file to use for threads. (GL)
|
||||
|
||||
AC_SYS_LONG_FILE_NAMES
|
||||
dnl defines HAVE_LONG_FILENAMES if filenames longer then
|
||||
dnl 14 chars are supported
|
||||
|
@@ -20,8 +20,8 @@ NONE =
|
||||
|
||||
# define library name
|
||||
LIB_TARGET=wx_gtk
|
||||
LIB_MAJOR=1
|
||||
LIB_MINOR=90
|
||||
LIB_MAJOR=0
|
||||
LIB_MINOR=12
|
||||
|
||||
# define library sources
|
||||
|
||||
@@ -58,13 +58,11 @@ LIB_CPP_SRC=\
|
||||
\
|
||||
gtk/app.cpp \
|
||||
gtk/bitmap.cpp \
|
||||
gtk/bmpbuttn.cpp \
|
||||
gtk/brush.cpp \
|
||||
gtk/button.cpp \
|
||||
gtk/checkbox.cpp \
|
||||
gtk/choice.cpp \
|
||||
gtk/colour.cpp \
|
||||
gtk/combobox.cpp \
|
||||
gtk/control.cpp \
|
||||
gtk/cursor.cpp \
|
||||
gtk/data.cpp \
|
||||
@@ -77,13 +75,11 @@ LIB_CPP_SRC=\
|
||||
gtk/filedlg.cpp \
|
||||
gtk/font.cpp \
|
||||
gtk/frame.cpp \
|
||||
gtk/gauge.cpp \
|
||||
gtk/gdiobj.cpp \
|
||||
gtk/icon.cpp \
|
||||
gtk/listbox.cpp \
|
||||
gtk/mdi.cpp \
|
||||
gtk/menu.cpp \
|
||||
gtk/notebook.cpp \
|
||||
gtk/palette.cpp \
|
||||
gtk/pen.cpp \
|
||||
gtk/radiobox.cpp \
|
||||
@@ -93,7 +89,6 @@ LIB_CPP_SRC=\
|
||||
gtk/settings.cpp \
|
||||
gtk/slider.cpp \
|
||||
gtk/statbox.cpp \
|
||||
gtk/statbmp.cpp \
|
||||
gtk/stattext.cpp \
|
||||
gtk/tbargtk.cpp \
|
||||
gtk/textctrl.cpp \
|
||||
@@ -101,6 +96,8 @@ LIB_CPP_SRC=\
|
||||
gtk/utilsgtk.cpp \
|
||||
gtk/utilsres.cpp \
|
||||
gtk/window.cpp \
|
||||
@GTK_JOYSTICK@ \
|
||||
@UNIX_THREAD@ \
|
||||
\
|
||||
generic/choicdgg.cpp \
|
||||
generic/colrdlgg.cpp \
|
||||
@@ -182,10 +179,7 @@ clean::
|
||||
|
||||
#additional things needed for compile
|
||||
ADD_COMPILE= \
|
||||
-DHAVE_LIBPNG -DDJPEG_PROG=\"\" -DCJPEG_PROG=\"\" \
|
||||
-I$(WXBASEDIR)/src/png \
|
||||
-I$(WXBASEDIR)/src/zlib \
|
||||
-I$(WXBASEDIR)/src/gdk_imlib
|
||||
-DHAVE_LIBPNG -DDJPEG_PROG=\"\" -DCJPEG_PROG=\"\"
|
||||
|
||||
# include the definitions now
|
||||
include ../../template.mak
|
||||
|
@@ -67,4 +67,5 @@ s|*TOOLBAR*|@TOOLBAR@|g
|
||||
s|*CONSTRAINTS*|@CONSTRAINTS@|g
|
||||
s|*RPC*|@RPC@|g
|
||||
s|*VIRLISTBOX*|@VIRLISTBOX@|g
|
||||
|
||||
s|*GTK_JOYSTICK*|@GTK_JOYSTICK@|g
|
||||
s|*UNIX_THREAD*|@UNIX_THREAD@|g
|
||||
|
65
src/gtk/threadgui.inc
Normal file
65
src/gtk/threadgui.inc
Normal file
@@ -0,0 +1,65 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: threadgui.inc
|
||||
// Purpose: GUI thread manager for GTK
|
||||
// Author: Original from Wolfram Gloger/Guilhem Lavaux
|
||||
// Modified by:
|
||||
// Created: 04/22/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Wolfram Gloger (1996, 1997); Guilhem Lavaux (1998)
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
// for select()
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef __sgi
|
||||
#include <bstring.h>
|
||||
#endif
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Static variables
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static int p_thrd_pipe[2] = { -1, -1 };
|
||||
// WorkProc in GTK
|
||||
static gint p_thrd_inid;
|
||||
|
||||
#define THREAD_SEND_EXIT_MSG(ptr) write(p_thrd_pipe[1], &ptr, sizeof(ptr));
|
||||
|
||||
static void
|
||||
ThreadExitProc(gpointer WXUNUSED(client), gint fid,
|
||||
GdkInputCondition WXUNUSED(cond))
|
||||
{
|
||||
wxThread* ptr;
|
||||
|
||||
if (fid != p_thrd_pipe[0])
|
||||
return;
|
||||
if (read(fid, &ptr, sizeof(ptr)) == sizeof(ptr)) {
|
||||
//fprintf(stderr, "calling OnExit %p\n", ptr);
|
||||
ptr->OnExit();
|
||||
} else {
|
||||
//fprintf(stderr, "this should never happen\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Global initialization
|
||||
static void wxThreadGuiInit(void)
|
||||
{
|
||||
pipe(p_thrd_pipe);
|
||||
p_thrd_inid = gdk_input_add(p_thrd_pipe[0], GDK_INPUT_READ,
|
||||
ThreadExitProc, 0);
|
||||
}
|
||||
|
||||
// Global cleanup
|
||||
static void wxThreadGuiExit(void)
|
||||
{
|
||||
gdk_input_remove(p_thrd_inid);
|
||||
close(p_thrd_pipe[0]);
|
||||
close(p_thrd_pipe[1]);
|
||||
}
|
156
src/gtk/threadno.cpp
Normal file
156
src/gtk/threadno.cpp
Normal file
@@ -0,0 +1,156 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: thread.cpp
|
||||
// Purpose: No thread support
|
||||
// Author: Original from Wolfram Gloger/Guilhem Lavaux
|
||||
// Modified by:
|
||||
// Created: 04/22/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Wolfram Gloger (1996, 1997); Guilhem Lavaux (1998)
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "thread.h"
|
||||
#endif
|
||||
|
||||
#include "wx/wx.h"
|
||||
|
||||
wxMutex::wxMutex(void)
|
||||
{
|
||||
m_locked = FALSE;
|
||||
}
|
||||
|
||||
wxMutex::~wxMutex(void)
|
||||
{
|
||||
}
|
||||
|
||||
MutexError wxMutex::Lock(void)
|
||||
{
|
||||
m_locked = TRUE;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
MutexError wxMutex::TryLock(void)
|
||||
{
|
||||
m_locked = TRUE;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
MutexError wxMutex::Unlock(void)
|
||||
{
|
||||
m_locked = FALSE;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
wxCondition::wxCondition(void)
|
||||
{
|
||||
}
|
||||
|
||||
wxCondition::~wxCondition(void)
|
||||
{
|
||||
}
|
||||
|
||||
void wxCondition::Wait(wxMutex& WXUNUSED(mutex))
|
||||
{
|
||||
}
|
||||
|
||||
bool wxCondition::Wait(wxMutex& WXUNUSED(mutex), unsigned long WXUNUSED(sec),
|
||||
unsigned long WXUNUSED(nsec))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void wxCondition::Signal(void)
|
||||
{
|
||||
}
|
||||
|
||||
void wxCondition::Broadcast(void)
|
||||
{
|
||||
}
|
||||
|
||||
struct wxThreadPrivate {
|
||||
int thread_id;
|
||||
void* exit_status;
|
||||
};
|
||||
|
||||
ThreadError wxThread::Create(void)
|
||||
{
|
||||
p_internal->exit_status = Entry();
|
||||
OnExit();
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
ThreadError wxThread::Destroy(void)
|
||||
{
|
||||
return RUNNING;
|
||||
}
|
||||
|
||||
void wxThread::DifferDestroy(void)
|
||||
{
|
||||
}
|
||||
|
||||
void wxThread::TestDestroy(void)
|
||||
{
|
||||
}
|
||||
|
||||
void *wxThread::Join()
|
||||
{
|
||||
return p_internal->exit_status;
|
||||
}
|
||||
|
||||
unsigned long wxThread::GetID()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool wxThread::IsMain(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxThread::IsAlive(void)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void wxThread::SetPriority(int WXUNUSED(prio)) { }
|
||||
int wxThread::GetPriority(void) { }
|
||||
|
||||
wxMutex wxMainMutex; // controls access to all GUI functions
|
||||
|
||||
wxThread::wxThread()
|
||||
{
|
||||
p_internal = new wxThreadPrivate();
|
||||
}
|
||||
|
||||
wxThread::~wxThread()
|
||||
{
|
||||
Cancel();
|
||||
Join();
|
||||
delete p_internal;
|
||||
}
|
||||
|
||||
// The default callback just joins the thread and throws away the result.
|
||||
void wxThread::OnExit()
|
||||
{
|
||||
Join();
|
||||
}
|
||||
|
||||
// Global initialization
|
||||
static void wxThreadInit(void *WXUNUSED(client))
|
||||
{
|
||||
wxMainMutex.Lock();
|
||||
}
|
||||
|
||||
// Global cleanup
|
||||
static void wxThreadExit(void *WXUNUSED(client))
|
||||
{
|
||||
wxMainMutex.Unlock();
|
||||
}
|
||||
|
||||
// Let automatic initialization be performed from wxCommonInit().
|
||||
static struct
|
||||
wxThreadGlobal {
|
||||
wxThreadGlobal() {
|
||||
wxRegisterModuleFunction(wxThreadInit, wxThreadExit, NULL);
|
||||
}
|
||||
} dummy;
|
317
src/gtk/threadpsx.cpp
Normal file
317
src/gtk/threadpsx.cpp
Normal file
@@ -0,0 +1,317 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: threadpsx.cpp
|
||||
// Purpose: wxThread (Posix) Implementation
|
||||
// Author: Original from Wolfram Gloger/Guilhem Lavaux
|
||||
// Modified by:
|
||||
// Created: 04/22/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Wolfram Gloger (1996, 1997); Guilhem Lavaux (1998)
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "thread.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sched.h>
|
||||
#include <pthread.h>
|
||||
|
||||
enum thread_state {
|
||||
STATE_IDLE = 0,
|
||||
STATE_RUNNING,
|
||||
STATE_CANCELED,
|
||||
STATE_EXITED
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Static variables
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "thread.h"
|
||||
|
||||
static pthread_t p_mainid;
|
||||
wxMutex wxMainMutex; // controls access to all GUI functions
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// GUI thread manager
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#include "threadgui.inc"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// wxThread: Posix Thread implementation (Mutex)
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class wxMutexInternal {
|
||||
public:
|
||||
pthread_mutex_t p_mutex;
|
||||
};
|
||||
|
||||
wxMutex::wxMutex(void)
|
||||
{
|
||||
p_internal = new wxMutexInternal;
|
||||
pthread_mutex_init(&(p_internal->p_mutex), NULL);
|
||||
m_locked = false;
|
||||
}
|
||||
|
||||
wxMutex::~wxMutex(void)
|
||||
{
|
||||
if (m_locked)
|
||||
pthread_mutex_unlock(&(p_internal->p_mutex));
|
||||
pthread_mutex_destroy(&(p_internal->p_mutex));
|
||||
delete p_internal;
|
||||
}
|
||||
|
||||
wxMutexError wxMutex::Lock(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = pthread_mutex_lock(&(p_internal->p_mutex));
|
||||
switch (err) {
|
||||
case EDEADLK: return MUTEX_DEAD_LOCK;
|
||||
}
|
||||
m_locked++;
|
||||
return MUTEX_NO_ERROR;
|
||||
}
|
||||
|
||||
wxMutexError wxMutex::TryLock(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (m_locked)
|
||||
return MUTEX_BUSY;
|
||||
err = pthread_mutex_trylock(&(p_internal->p_mutex));
|
||||
switch (err) {
|
||||
case EBUSY: return MUTEX_BUSY;
|
||||
}
|
||||
m_locked++;
|
||||
return MUTEX_NO_ERROR;
|
||||
}
|
||||
|
||||
wxMutexError wxMutex::Unlock(void)
|
||||
{
|
||||
if (m_locked > 0) m_locked--;
|
||||
pthread_mutex_unlock(&(p_internal->p_mutex));
|
||||
return MUTEX_NO_ERROR;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// wxThread: Posix Thread implementation (Condition)
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class wxConditionInternal {
|
||||
public:
|
||||
pthread_cond_t p_condition;
|
||||
};
|
||||
|
||||
wxCondition::wxCondition(void)
|
||||
{
|
||||
p_internal = new wxConditionInternal;
|
||||
pthread_cond_init(&(p_internal->p_condition), NULL);
|
||||
}
|
||||
|
||||
wxCondition::~wxCondition(void)
|
||||
{
|
||||
pthread_cond_destroy(&(p_internal->p_condition));
|
||||
delete p_internal;
|
||||
}
|
||||
|
||||
void wxCondition::Wait(wxMutex& mutex)
|
||||
{
|
||||
pthread_cond_wait(&(p_internal->p_condition), &(mutex.p_internal->p_mutex));
|
||||
}
|
||||
|
||||
bool wxCondition::Wait(wxMutex& mutex, unsigned long sec, unsigned long nsec)
|
||||
{
|
||||
struct timespec tspec;
|
||||
|
||||
tspec.tv_sec = time(NULL)+sec;
|
||||
tspec.tv_nsec = nsec;
|
||||
return (pthread_cond_timedwait(&(p_internal->p_condition), &(mutex.p_internal->p_mutex), &tspec) != ETIMEDOUT);
|
||||
}
|
||||
|
||||
void wxCondition::Signal(void)
|
||||
{
|
||||
pthread_cond_signal(&(p_internal->p_condition));
|
||||
}
|
||||
|
||||
void wxCondition::Broadcast(void)
|
||||
{
|
||||
pthread_cond_broadcast(&(p_internal->p_condition));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// wxThread: Posix Thread implementation (Thread)
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class wxThreadInternal {
|
||||
public:
|
||||
wxThreadInternal() { state = STATE_IDLE; }
|
||||
~wxThreadInternal() {}
|
||||
static void *PthreadStart(void *ptr);
|
||||
pthread_t thread_id;
|
||||
int state;
|
||||
int prio;
|
||||
};
|
||||
|
||||
void *wxThreadInternal::PthreadStart(void *ptr)
|
||||
{
|
||||
wxThread *thread = (wxThread *)ptr;
|
||||
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
||||
void* status = thread->Entry();
|
||||
thread->Exit(status);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wxThreadError wxThread::Create()
|
||||
{
|
||||
pthread_attr_t a;
|
||||
int min_prio, max_prio, p;
|
||||
struct sched_param sp;
|
||||
|
||||
if (p_internal->state != STATE_IDLE)
|
||||
return THREAD_RUNNING;
|
||||
|
||||
// Change thread priority
|
||||
pthread_attr_init(&a);
|
||||
pthread_attr_getschedpolicy(&a, &p);
|
||||
|
||||
min_prio = sched_get_priority_min(p);
|
||||
max_prio = sched_get_priority_max(p);
|
||||
|
||||
pthread_attr_getschedparam(&a, &sp);
|
||||
sp.sched_priority = min_prio +
|
||||
(p_internal->prio*(max_prio-min_prio))/100;
|
||||
pthread_attr_setschedparam(&a, &sp);
|
||||
|
||||
// this is the point of no return
|
||||
p_internal->state = STATE_RUNNING;
|
||||
if (pthread_create(&p_internal->thread_id, &a,
|
||||
wxThreadInternal::PthreadStart, (void *)this) != 0) {
|
||||
p_internal->state = STATE_IDLE;
|
||||
pthread_attr_destroy(&a);
|
||||
return THREAD_NO_RESOURCE;
|
||||
}
|
||||
pthread_attr_destroy(&a);
|
||||
return THREAD_NO_ERROR;
|
||||
}
|
||||
|
||||
void wxThread::SetPriority(int prio)
|
||||
{
|
||||
if (p_internal->state == STATE_RUNNING)
|
||||
return;
|
||||
|
||||
if (prio > 100)
|
||||
prio = 100;
|
||||
if (prio < 0)
|
||||
prio = 0;
|
||||
p_internal->prio = prio;
|
||||
}
|
||||
|
||||
int wxThread::GetPriority(void)
|
||||
{
|
||||
return p_internal->prio;
|
||||
}
|
||||
|
||||
void wxThread::DeferDestroy(bool on)
|
||||
{
|
||||
if (on)
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
|
||||
else
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
||||
}
|
||||
|
||||
wxThreadError wxThread::Destroy(void)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
if (p_internal->state == STATE_RUNNING) {
|
||||
res = pthread_cancel(p_internal->thread_id);
|
||||
if (res == 0)
|
||||
p_internal->state = STATE_CANCELED;
|
||||
}
|
||||
return THREAD_NO_ERROR;
|
||||
}
|
||||
|
||||
void *wxThread::Join()
|
||||
{
|
||||
void* status = 0;
|
||||
|
||||
if (p_internal->state != STATE_IDLE) {
|
||||
bool do_unlock = wxThread::IsMain();
|
||||
|
||||
while (p_internal->state == STATE_RUNNING)
|
||||
wxYield();
|
||||
|
||||
if (do_unlock)
|
||||
wxMainMutex.Unlock();
|
||||
pthread_join(p_internal->thread_id, &status);
|
||||
if (do_unlock)
|
||||
wxMainMutex.Lock();
|
||||
p_internal->state = STATE_IDLE;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
unsigned long wxThread::GetID()
|
||||
{
|
||||
return (unsigned long)p_internal->thread_id;
|
||||
}
|
||||
|
||||
void wxThread::Exit(void *status)
|
||||
{
|
||||
wxThread* ptr = this;
|
||||
|
||||
THREAD_SEND_EXIT_MSG(ptr);
|
||||
p_internal->state = STATE_EXITED;
|
||||
pthread_exit(status);
|
||||
}
|
||||
|
||||
void wxThread::TestDestroy()
|
||||
{
|
||||
pthread_testcancel();
|
||||
}
|
||||
|
||||
bool wxThread::IsMain(void)
|
||||
{
|
||||
return (bool)pthread_equal(pthread_self(), p_mainid);
|
||||
}
|
||||
|
||||
wxThread::wxThread()
|
||||
{
|
||||
p_internal = new wxThreadInternal();
|
||||
}
|
||||
|
||||
wxThread::~wxThread()
|
||||
{
|
||||
Destroy();
|
||||
Join();
|
||||
delete p_internal;
|
||||
}
|
||||
|
||||
// The default callback just joins the thread and throws away the result.
|
||||
void wxThread::OnExit()
|
||||
{
|
||||
}
|
||||
|
||||
// Automatic initialization
|
||||
class wxThreadModule : public wxModule {
|
||||
DECLARE_DYNAMIC_CLASS(wxThreadModule)
|
||||
public:
|
||||
virtual bool OnInit(void) {
|
||||
wxThreadGuiInit();
|
||||
p_mainid = pthread_self();
|
||||
wxMainMutex.Lock();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
virtual void OnExit(void) {
|
||||
wxMainMutex.Unlock();
|
||||
wxThreadGuiExit();
|
||||
}
|
||||
};
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
|
216
src/gtk/threadsgi.cpp
Normal file
216
src/gtk/threadsgi.cpp
Normal file
@@ -0,0 +1,216 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: threadsgi.cpp
|
||||
// Purpose: wxThread (SGI) Implementation
|
||||
// Author: Original from Wolfram Gloger/Guilhem Lavaux
|
||||
// Modified by:
|
||||
// Created: 04/22/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Wolfram Gloger (1996, 1997); Guilhem Lavaux (1998)
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "thread.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/prctl.h>
|
||||
|
||||
enum thread_state {
|
||||
STATE_IDLE = 0,
|
||||
STATE_RUNNING,
|
||||
STATE_CANCELED,
|
||||
STATE_EXITED
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Static variables
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static int p_mainid;
|
||||
wxMutex wxMainMutex;
|
||||
|
||||
#include "threadgui.inc"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Unix implementations (SGI threads)
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class wxMutexInternal {
|
||||
public:
|
||||
abilock_t p_mutex;
|
||||
};
|
||||
|
||||
wxMutex::wxMutex()
|
||||
{
|
||||
p_internal = new wxMutexInternal;
|
||||
init_lock(&(p_internal->p_mutex));
|
||||
}
|
||||
|
||||
wxMutex::~wxMutex()
|
||||
{
|
||||
}
|
||||
|
||||
wxMutex::MutexError wxMutex::Lock(void)
|
||||
{
|
||||
spin_lock(&(p_internal->p_mutex));
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
wxMutex::MutexError wxMutex::TryLock(void)
|
||||
{
|
||||
if (acquire_lock(&(p_internal->p_mutex)) != 0)
|
||||
return BUSY;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
wxMutex::MutexError wxMutex::Unlock(void)
|
||||
{
|
||||
release_lock(&(p_internal->p_mutex));
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
// GLH: Don't now how it works on SGI. Wolfram ?
|
||||
|
||||
wxCondition::wxCondition(void) {}
|
||||
wxCondition::~wxCondition(void) {}
|
||||
int wxCondition::Wait(wxMutex& WXUNUSED(mutex)) { return 0;}
|
||||
int wxCondition::Wait(wxMutex& WXUNUSED(mutex), unsigned long WXUNUSED(sec),
|
||||
unsigned long WXUNUSED(nsec)) { return 0; }
|
||||
int wxCondition::Signal(void) { return 0; }
|
||||
int wxCondition::Broadcast(void) { return 0; }
|
||||
|
||||
class
|
||||
wxThreadPrivate {
|
||||
public:
|
||||
wxThreadPrivate() { thread_id = 0; state = STATE_IDLE; }
|
||||
~wxThreadPrivate() {}
|
||||
static void SprocStart(void *ptr);
|
||||
static void SignalHandler(int sig);
|
||||
public:
|
||||
int state, thread_id;
|
||||
void* exit_status;
|
||||
};
|
||||
|
||||
void wxThreadPrivate::SprocStart(void *ptr)
|
||||
{
|
||||
void* status;
|
||||
|
||||
wxThread *thr = (wxThread *)ptr;
|
||||
|
||||
thr->p_internal->thread_id = getpid();
|
||||
thr->p_internal->exit_status = 0;
|
||||
status = thr->Entry();
|
||||
thr->Exit(status);
|
||||
}
|
||||
|
||||
void wxThread::Exit(void* status)
|
||||
{
|
||||
wxThread* ptr = this;
|
||||
THREAD_SEND_EXIT_MSG(ptr);
|
||||
p_internal->state = STATE_EXITED;
|
||||
p_internal->exit_status = status;
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
wxThread::ThreadError wxThread::Create()
|
||||
{
|
||||
if (p_internal->state != STATE_IDLE)
|
||||
return RUNNING;
|
||||
p_internal->state = STATE_RUNNING;
|
||||
if (sproc(p_internal->SprocStart, PR_SALL, this) < 0) {
|
||||
p_internal->state = STATE_IDLE;
|
||||
return NO_RESOURCE;
|
||||
}
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
void wxThread::Destroy()
|
||||
{
|
||||
if (p_internal->state == STATE_RUNNING)
|
||||
p_internal->state = STATE_CANCELED;
|
||||
}
|
||||
|
||||
void *wxThread::Join()
|
||||
{
|
||||
if (p_internal->state != STATE_IDLE) {
|
||||
bool do_unlock = wxThread::IsMain();
|
||||
int stat;
|
||||
|
||||
if (do_unlock)
|
||||
wxMainMutex.Unlock();
|
||||
waitpid(p_internal->thread_id, &stat, 0);
|
||||
if (do_unlock)
|
||||
wxMainMutex.Lock();
|
||||
if (!WIFEXITED(stat) && !WIFSIGNALED(stat))
|
||||
return 0;
|
||||
p_internal->state = STATE_IDLE;
|
||||
return p_internal->exit_status;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned long wxThread::GetID()
|
||||
{
|
||||
return (unsigned long)p_internal->thread_id;
|
||||
}
|
||||
|
||||
void wxThread::TestDestroy()
|
||||
{
|
||||
if (p_internal->state == STATE_CANCELED) {
|
||||
p_internal->exit_status = 0;
|
||||
_exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
void wxThread::SetPriority(int prio)
|
||||
{
|
||||
}
|
||||
|
||||
int wxThread::GetPriority(void)
|
||||
{
|
||||
}
|
||||
|
||||
bool wxThreadIsMain()
|
||||
{
|
||||
return (int)getpid() == main_id;
|
||||
}
|
||||
|
||||
wxThread::wxThread()
|
||||
{
|
||||
p_internal = new wxThreadPrivate();
|
||||
}
|
||||
|
||||
wxThread::~wxThread()
|
||||
{
|
||||
Cancel();
|
||||
Join();
|
||||
delete p_internal;
|
||||
}
|
||||
|
||||
// The default callback just joins the thread and throws away the result.
|
||||
void wxThread::OnExit()
|
||||
{
|
||||
Join();
|
||||
}
|
||||
|
||||
// Global initialization
|
||||
class wxThreadModule : public wxModule {
|
||||
DECLARE_DYNAMIC_CLASS(wxThreadModule)
|
||||
public:
|
||||
virtual bool OnInit(void) {
|
||||
wxThreadGuiInit();
|
||||
p_mainid = (int)getpid();
|
||||
wxMainMutex.Lock();
|
||||
}
|
||||
|
||||
virtual void OnExit(void) {
|
||||
wxMainMutex.Unlock();
|
||||
wxThreadGuiExit();
|
||||
}
|
||||
};
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
|
@@ -67,4 +67,5 @@ s|*TOOLBAR*|@TOOLBAR@|g
|
||||
s|*CONSTRAINTS*|@CONSTRAINTS@|g
|
||||
s|*RPC*|@RPC@|g
|
||||
s|*VIRLISTBOX*|@VIRLISTBOX@|g
|
||||
|
||||
s|*GTK_JOYSTICK*|@GTK_JOYSTICK@|g
|
||||
s|*UNIX_THREAD*|@UNIX_THREAD@|g
|
||||
|
65
src/gtk1/threadgui.inc
Normal file
65
src/gtk1/threadgui.inc
Normal file
@@ -0,0 +1,65 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: threadgui.inc
|
||||
// Purpose: GUI thread manager for GTK
|
||||
// Author: Original from Wolfram Gloger/Guilhem Lavaux
|
||||
// Modified by:
|
||||
// Created: 04/22/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Wolfram Gloger (1996, 1997); Guilhem Lavaux (1998)
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
// for select()
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef __sgi
|
||||
#include <bstring.h>
|
||||
#endif
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Static variables
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static int p_thrd_pipe[2] = { -1, -1 };
|
||||
// WorkProc in GTK
|
||||
static gint p_thrd_inid;
|
||||
|
||||
#define THREAD_SEND_EXIT_MSG(ptr) write(p_thrd_pipe[1], &ptr, sizeof(ptr));
|
||||
|
||||
static void
|
||||
ThreadExitProc(gpointer WXUNUSED(client), gint fid,
|
||||
GdkInputCondition WXUNUSED(cond))
|
||||
{
|
||||
wxThread* ptr;
|
||||
|
||||
if (fid != p_thrd_pipe[0])
|
||||
return;
|
||||
if (read(fid, &ptr, sizeof(ptr)) == sizeof(ptr)) {
|
||||
//fprintf(stderr, "calling OnExit %p\n", ptr);
|
||||
ptr->OnExit();
|
||||
} else {
|
||||
//fprintf(stderr, "this should never happen\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Global initialization
|
||||
static void wxThreadGuiInit(void)
|
||||
{
|
||||
pipe(p_thrd_pipe);
|
||||
p_thrd_inid = gdk_input_add(p_thrd_pipe[0], GDK_INPUT_READ,
|
||||
ThreadExitProc, 0);
|
||||
}
|
||||
|
||||
// Global cleanup
|
||||
static void wxThreadGuiExit(void)
|
||||
{
|
||||
gdk_input_remove(p_thrd_inid);
|
||||
close(p_thrd_pipe[0]);
|
||||
close(p_thrd_pipe[1]);
|
||||
}
|
156
src/gtk1/threadno.cpp
Normal file
156
src/gtk1/threadno.cpp
Normal file
@@ -0,0 +1,156 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: thread.cpp
|
||||
// Purpose: No thread support
|
||||
// Author: Original from Wolfram Gloger/Guilhem Lavaux
|
||||
// Modified by:
|
||||
// Created: 04/22/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Wolfram Gloger (1996, 1997); Guilhem Lavaux (1998)
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "thread.h"
|
||||
#endif
|
||||
|
||||
#include "wx/wx.h"
|
||||
|
||||
wxMutex::wxMutex(void)
|
||||
{
|
||||
m_locked = FALSE;
|
||||
}
|
||||
|
||||
wxMutex::~wxMutex(void)
|
||||
{
|
||||
}
|
||||
|
||||
MutexError wxMutex::Lock(void)
|
||||
{
|
||||
m_locked = TRUE;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
MutexError wxMutex::TryLock(void)
|
||||
{
|
||||
m_locked = TRUE;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
MutexError wxMutex::Unlock(void)
|
||||
{
|
||||
m_locked = FALSE;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
wxCondition::wxCondition(void)
|
||||
{
|
||||
}
|
||||
|
||||
wxCondition::~wxCondition(void)
|
||||
{
|
||||
}
|
||||
|
||||
void wxCondition::Wait(wxMutex& WXUNUSED(mutex))
|
||||
{
|
||||
}
|
||||
|
||||
bool wxCondition::Wait(wxMutex& WXUNUSED(mutex), unsigned long WXUNUSED(sec),
|
||||
unsigned long WXUNUSED(nsec))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void wxCondition::Signal(void)
|
||||
{
|
||||
}
|
||||
|
||||
void wxCondition::Broadcast(void)
|
||||
{
|
||||
}
|
||||
|
||||
struct wxThreadPrivate {
|
||||
int thread_id;
|
||||
void* exit_status;
|
||||
};
|
||||
|
||||
ThreadError wxThread::Create(void)
|
||||
{
|
||||
p_internal->exit_status = Entry();
|
||||
OnExit();
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
ThreadError wxThread::Destroy(void)
|
||||
{
|
||||
return RUNNING;
|
||||
}
|
||||
|
||||
void wxThread::DifferDestroy(void)
|
||||
{
|
||||
}
|
||||
|
||||
void wxThread::TestDestroy(void)
|
||||
{
|
||||
}
|
||||
|
||||
void *wxThread::Join()
|
||||
{
|
||||
return p_internal->exit_status;
|
||||
}
|
||||
|
||||
unsigned long wxThread::GetID()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool wxThread::IsMain(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxThread::IsAlive(void)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void wxThread::SetPriority(int WXUNUSED(prio)) { }
|
||||
int wxThread::GetPriority(void) { }
|
||||
|
||||
wxMutex wxMainMutex; // controls access to all GUI functions
|
||||
|
||||
wxThread::wxThread()
|
||||
{
|
||||
p_internal = new wxThreadPrivate();
|
||||
}
|
||||
|
||||
wxThread::~wxThread()
|
||||
{
|
||||
Cancel();
|
||||
Join();
|
||||
delete p_internal;
|
||||
}
|
||||
|
||||
// The default callback just joins the thread and throws away the result.
|
||||
void wxThread::OnExit()
|
||||
{
|
||||
Join();
|
||||
}
|
||||
|
||||
// Global initialization
|
||||
static void wxThreadInit(void *WXUNUSED(client))
|
||||
{
|
||||
wxMainMutex.Lock();
|
||||
}
|
||||
|
||||
// Global cleanup
|
||||
static void wxThreadExit(void *WXUNUSED(client))
|
||||
{
|
||||
wxMainMutex.Unlock();
|
||||
}
|
||||
|
||||
// Let automatic initialization be performed from wxCommonInit().
|
||||
static struct
|
||||
wxThreadGlobal {
|
||||
wxThreadGlobal() {
|
||||
wxRegisterModuleFunction(wxThreadInit, wxThreadExit, NULL);
|
||||
}
|
||||
} dummy;
|
317
src/gtk1/threadpsx.cpp
Normal file
317
src/gtk1/threadpsx.cpp
Normal file
@@ -0,0 +1,317 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: threadpsx.cpp
|
||||
// Purpose: wxThread (Posix) Implementation
|
||||
// Author: Original from Wolfram Gloger/Guilhem Lavaux
|
||||
// Modified by:
|
||||
// Created: 04/22/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Wolfram Gloger (1996, 1997); Guilhem Lavaux (1998)
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "thread.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sched.h>
|
||||
#include <pthread.h>
|
||||
|
||||
enum thread_state {
|
||||
STATE_IDLE = 0,
|
||||
STATE_RUNNING,
|
||||
STATE_CANCELED,
|
||||
STATE_EXITED
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Static variables
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "thread.h"
|
||||
|
||||
static pthread_t p_mainid;
|
||||
wxMutex wxMainMutex; // controls access to all GUI functions
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// GUI thread manager
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#include "threadgui.inc"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// wxThread: Posix Thread implementation (Mutex)
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class wxMutexInternal {
|
||||
public:
|
||||
pthread_mutex_t p_mutex;
|
||||
};
|
||||
|
||||
wxMutex::wxMutex(void)
|
||||
{
|
||||
p_internal = new wxMutexInternal;
|
||||
pthread_mutex_init(&(p_internal->p_mutex), NULL);
|
||||
m_locked = false;
|
||||
}
|
||||
|
||||
wxMutex::~wxMutex(void)
|
||||
{
|
||||
if (m_locked)
|
||||
pthread_mutex_unlock(&(p_internal->p_mutex));
|
||||
pthread_mutex_destroy(&(p_internal->p_mutex));
|
||||
delete p_internal;
|
||||
}
|
||||
|
||||
wxMutexError wxMutex::Lock(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = pthread_mutex_lock(&(p_internal->p_mutex));
|
||||
switch (err) {
|
||||
case EDEADLK: return MUTEX_DEAD_LOCK;
|
||||
}
|
||||
m_locked++;
|
||||
return MUTEX_NO_ERROR;
|
||||
}
|
||||
|
||||
wxMutexError wxMutex::TryLock(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (m_locked)
|
||||
return MUTEX_BUSY;
|
||||
err = pthread_mutex_trylock(&(p_internal->p_mutex));
|
||||
switch (err) {
|
||||
case EBUSY: return MUTEX_BUSY;
|
||||
}
|
||||
m_locked++;
|
||||
return MUTEX_NO_ERROR;
|
||||
}
|
||||
|
||||
wxMutexError wxMutex::Unlock(void)
|
||||
{
|
||||
if (m_locked > 0) m_locked--;
|
||||
pthread_mutex_unlock(&(p_internal->p_mutex));
|
||||
return MUTEX_NO_ERROR;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// wxThread: Posix Thread implementation (Condition)
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class wxConditionInternal {
|
||||
public:
|
||||
pthread_cond_t p_condition;
|
||||
};
|
||||
|
||||
wxCondition::wxCondition(void)
|
||||
{
|
||||
p_internal = new wxConditionInternal;
|
||||
pthread_cond_init(&(p_internal->p_condition), NULL);
|
||||
}
|
||||
|
||||
wxCondition::~wxCondition(void)
|
||||
{
|
||||
pthread_cond_destroy(&(p_internal->p_condition));
|
||||
delete p_internal;
|
||||
}
|
||||
|
||||
void wxCondition::Wait(wxMutex& mutex)
|
||||
{
|
||||
pthread_cond_wait(&(p_internal->p_condition), &(mutex.p_internal->p_mutex));
|
||||
}
|
||||
|
||||
bool wxCondition::Wait(wxMutex& mutex, unsigned long sec, unsigned long nsec)
|
||||
{
|
||||
struct timespec tspec;
|
||||
|
||||
tspec.tv_sec = time(NULL)+sec;
|
||||
tspec.tv_nsec = nsec;
|
||||
return (pthread_cond_timedwait(&(p_internal->p_condition), &(mutex.p_internal->p_mutex), &tspec) != ETIMEDOUT);
|
||||
}
|
||||
|
||||
void wxCondition::Signal(void)
|
||||
{
|
||||
pthread_cond_signal(&(p_internal->p_condition));
|
||||
}
|
||||
|
||||
void wxCondition::Broadcast(void)
|
||||
{
|
||||
pthread_cond_broadcast(&(p_internal->p_condition));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// wxThread: Posix Thread implementation (Thread)
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class wxThreadInternal {
|
||||
public:
|
||||
wxThreadInternal() { state = STATE_IDLE; }
|
||||
~wxThreadInternal() {}
|
||||
static void *PthreadStart(void *ptr);
|
||||
pthread_t thread_id;
|
||||
int state;
|
||||
int prio;
|
||||
};
|
||||
|
||||
void *wxThreadInternal::PthreadStart(void *ptr)
|
||||
{
|
||||
wxThread *thread = (wxThread *)ptr;
|
||||
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
||||
void* status = thread->Entry();
|
||||
thread->Exit(status);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wxThreadError wxThread::Create()
|
||||
{
|
||||
pthread_attr_t a;
|
||||
int min_prio, max_prio, p;
|
||||
struct sched_param sp;
|
||||
|
||||
if (p_internal->state != STATE_IDLE)
|
||||
return THREAD_RUNNING;
|
||||
|
||||
// Change thread priority
|
||||
pthread_attr_init(&a);
|
||||
pthread_attr_getschedpolicy(&a, &p);
|
||||
|
||||
min_prio = sched_get_priority_min(p);
|
||||
max_prio = sched_get_priority_max(p);
|
||||
|
||||
pthread_attr_getschedparam(&a, &sp);
|
||||
sp.sched_priority = min_prio +
|
||||
(p_internal->prio*(max_prio-min_prio))/100;
|
||||
pthread_attr_setschedparam(&a, &sp);
|
||||
|
||||
// this is the point of no return
|
||||
p_internal->state = STATE_RUNNING;
|
||||
if (pthread_create(&p_internal->thread_id, &a,
|
||||
wxThreadInternal::PthreadStart, (void *)this) != 0) {
|
||||
p_internal->state = STATE_IDLE;
|
||||
pthread_attr_destroy(&a);
|
||||
return THREAD_NO_RESOURCE;
|
||||
}
|
||||
pthread_attr_destroy(&a);
|
||||
return THREAD_NO_ERROR;
|
||||
}
|
||||
|
||||
void wxThread::SetPriority(int prio)
|
||||
{
|
||||
if (p_internal->state == STATE_RUNNING)
|
||||
return;
|
||||
|
||||
if (prio > 100)
|
||||
prio = 100;
|
||||
if (prio < 0)
|
||||
prio = 0;
|
||||
p_internal->prio = prio;
|
||||
}
|
||||
|
||||
int wxThread::GetPriority(void)
|
||||
{
|
||||
return p_internal->prio;
|
||||
}
|
||||
|
||||
void wxThread::DeferDestroy(bool on)
|
||||
{
|
||||
if (on)
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
|
||||
else
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
||||
}
|
||||
|
||||
wxThreadError wxThread::Destroy(void)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
if (p_internal->state == STATE_RUNNING) {
|
||||
res = pthread_cancel(p_internal->thread_id);
|
||||
if (res == 0)
|
||||
p_internal->state = STATE_CANCELED;
|
||||
}
|
||||
return THREAD_NO_ERROR;
|
||||
}
|
||||
|
||||
void *wxThread::Join()
|
||||
{
|
||||
void* status = 0;
|
||||
|
||||
if (p_internal->state != STATE_IDLE) {
|
||||
bool do_unlock = wxThread::IsMain();
|
||||
|
||||
while (p_internal->state == STATE_RUNNING)
|
||||
wxYield();
|
||||
|
||||
if (do_unlock)
|
||||
wxMainMutex.Unlock();
|
||||
pthread_join(p_internal->thread_id, &status);
|
||||
if (do_unlock)
|
||||
wxMainMutex.Lock();
|
||||
p_internal->state = STATE_IDLE;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
unsigned long wxThread::GetID()
|
||||
{
|
||||
return (unsigned long)p_internal->thread_id;
|
||||
}
|
||||
|
||||
void wxThread::Exit(void *status)
|
||||
{
|
||||
wxThread* ptr = this;
|
||||
|
||||
THREAD_SEND_EXIT_MSG(ptr);
|
||||
p_internal->state = STATE_EXITED;
|
||||
pthread_exit(status);
|
||||
}
|
||||
|
||||
void wxThread::TestDestroy()
|
||||
{
|
||||
pthread_testcancel();
|
||||
}
|
||||
|
||||
bool wxThread::IsMain(void)
|
||||
{
|
||||
return (bool)pthread_equal(pthread_self(), p_mainid);
|
||||
}
|
||||
|
||||
wxThread::wxThread()
|
||||
{
|
||||
p_internal = new wxThreadInternal();
|
||||
}
|
||||
|
||||
wxThread::~wxThread()
|
||||
{
|
||||
Destroy();
|
||||
Join();
|
||||
delete p_internal;
|
||||
}
|
||||
|
||||
// The default callback just joins the thread and throws away the result.
|
||||
void wxThread::OnExit()
|
||||
{
|
||||
}
|
||||
|
||||
// Automatic initialization
|
||||
class wxThreadModule : public wxModule {
|
||||
DECLARE_DYNAMIC_CLASS(wxThreadModule)
|
||||
public:
|
||||
virtual bool OnInit(void) {
|
||||
wxThreadGuiInit();
|
||||
p_mainid = pthread_self();
|
||||
wxMainMutex.Lock();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
virtual void OnExit(void) {
|
||||
wxMainMutex.Unlock();
|
||||
wxThreadGuiExit();
|
||||
}
|
||||
};
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
|
216
src/gtk1/threadsgi.cpp
Normal file
216
src/gtk1/threadsgi.cpp
Normal file
@@ -0,0 +1,216 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: threadsgi.cpp
|
||||
// Purpose: wxThread (SGI) Implementation
|
||||
// Author: Original from Wolfram Gloger/Guilhem Lavaux
|
||||
// Modified by:
|
||||
// Created: 04/22/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Wolfram Gloger (1996, 1997); Guilhem Lavaux (1998)
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "thread.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/prctl.h>
|
||||
|
||||
enum thread_state {
|
||||
STATE_IDLE = 0,
|
||||
STATE_RUNNING,
|
||||
STATE_CANCELED,
|
||||
STATE_EXITED
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Static variables
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static int p_mainid;
|
||||
wxMutex wxMainMutex;
|
||||
|
||||
#include "threadgui.inc"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Unix implementations (SGI threads)
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class wxMutexInternal {
|
||||
public:
|
||||
abilock_t p_mutex;
|
||||
};
|
||||
|
||||
wxMutex::wxMutex()
|
||||
{
|
||||
p_internal = new wxMutexInternal;
|
||||
init_lock(&(p_internal->p_mutex));
|
||||
}
|
||||
|
||||
wxMutex::~wxMutex()
|
||||
{
|
||||
}
|
||||
|
||||
wxMutex::MutexError wxMutex::Lock(void)
|
||||
{
|
||||
spin_lock(&(p_internal->p_mutex));
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
wxMutex::MutexError wxMutex::TryLock(void)
|
||||
{
|
||||
if (acquire_lock(&(p_internal->p_mutex)) != 0)
|
||||
return BUSY;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
wxMutex::MutexError wxMutex::Unlock(void)
|
||||
{
|
||||
release_lock(&(p_internal->p_mutex));
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
// GLH: Don't now how it works on SGI. Wolfram ?
|
||||
|
||||
wxCondition::wxCondition(void) {}
|
||||
wxCondition::~wxCondition(void) {}
|
||||
int wxCondition::Wait(wxMutex& WXUNUSED(mutex)) { return 0;}
|
||||
int wxCondition::Wait(wxMutex& WXUNUSED(mutex), unsigned long WXUNUSED(sec),
|
||||
unsigned long WXUNUSED(nsec)) { return 0; }
|
||||
int wxCondition::Signal(void) { return 0; }
|
||||
int wxCondition::Broadcast(void) { return 0; }
|
||||
|
||||
class
|
||||
wxThreadPrivate {
|
||||
public:
|
||||
wxThreadPrivate() { thread_id = 0; state = STATE_IDLE; }
|
||||
~wxThreadPrivate() {}
|
||||
static void SprocStart(void *ptr);
|
||||
static void SignalHandler(int sig);
|
||||
public:
|
||||
int state, thread_id;
|
||||
void* exit_status;
|
||||
};
|
||||
|
||||
void wxThreadPrivate::SprocStart(void *ptr)
|
||||
{
|
||||
void* status;
|
||||
|
||||
wxThread *thr = (wxThread *)ptr;
|
||||
|
||||
thr->p_internal->thread_id = getpid();
|
||||
thr->p_internal->exit_status = 0;
|
||||
status = thr->Entry();
|
||||
thr->Exit(status);
|
||||
}
|
||||
|
||||
void wxThread::Exit(void* status)
|
||||
{
|
||||
wxThread* ptr = this;
|
||||
THREAD_SEND_EXIT_MSG(ptr);
|
||||
p_internal->state = STATE_EXITED;
|
||||
p_internal->exit_status = status;
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
wxThread::ThreadError wxThread::Create()
|
||||
{
|
||||
if (p_internal->state != STATE_IDLE)
|
||||
return RUNNING;
|
||||
p_internal->state = STATE_RUNNING;
|
||||
if (sproc(p_internal->SprocStart, PR_SALL, this) < 0) {
|
||||
p_internal->state = STATE_IDLE;
|
||||
return NO_RESOURCE;
|
||||
}
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
void wxThread::Destroy()
|
||||
{
|
||||
if (p_internal->state == STATE_RUNNING)
|
||||
p_internal->state = STATE_CANCELED;
|
||||
}
|
||||
|
||||
void *wxThread::Join()
|
||||
{
|
||||
if (p_internal->state != STATE_IDLE) {
|
||||
bool do_unlock = wxThread::IsMain();
|
||||
int stat;
|
||||
|
||||
if (do_unlock)
|
||||
wxMainMutex.Unlock();
|
||||
waitpid(p_internal->thread_id, &stat, 0);
|
||||
if (do_unlock)
|
||||
wxMainMutex.Lock();
|
||||
if (!WIFEXITED(stat) && !WIFSIGNALED(stat))
|
||||
return 0;
|
||||
p_internal->state = STATE_IDLE;
|
||||
return p_internal->exit_status;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned long wxThread::GetID()
|
||||
{
|
||||
return (unsigned long)p_internal->thread_id;
|
||||
}
|
||||
|
||||
void wxThread::TestDestroy()
|
||||
{
|
||||
if (p_internal->state == STATE_CANCELED) {
|
||||
p_internal->exit_status = 0;
|
||||
_exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
void wxThread::SetPriority(int prio)
|
||||
{
|
||||
}
|
||||
|
||||
int wxThread::GetPriority(void)
|
||||
{
|
||||
}
|
||||
|
||||
bool wxThreadIsMain()
|
||||
{
|
||||
return (int)getpid() == main_id;
|
||||
}
|
||||
|
||||
wxThread::wxThread()
|
||||
{
|
||||
p_internal = new wxThreadPrivate();
|
||||
}
|
||||
|
||||
wxThread::~wxThread()
|
||||
{
|
||||
Cancel();
|
||||
Join();
|
||||
delete p_internal;
|
||||
}
|
||||
|
||||
// The default callback just joins the thread and throws away the result.
|
||||
void wxThread::OnExit()
|
||||
{
|
||||
Join();
|
||||
}
|
||||
|
||||
// Global initialization
|
||||
class wxThreadModule : public wxModule {
|
||||
DECLARE_DYNAMIC_CLASS(wxThreadModule)
|
||||
public:
|
||||
virtual bool OnInit(void) {
|
||||
wxThreadGuiInit();
|
||||
p_mainid = (int)getpid();
|
||||
wxMainMutex.Lock();
|
||||
}
|
||||
|
||||
virtual void OnExit(void) {
|
||||
wxMainMutex.Unlock();
|
||||
wxThreadGuiExit();
|
||||
}
|
||||
};
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
|
Reference in New Issue
Block a user