-#endif
-
-
-//-----------------------------------------------------------------------------------
-//
-// class SimpleThread POSIX implementation
-//
-//-----------------------------------------------------------------------------------
-#if defined(POSIX)
-#define HAVE_IMP
-
-struct PosixThreadImplementation
-{
- pthread_t fThread;
-};
-
-extern "C" void* SimpleThreadProc(void *arg)
-{
- // This is the code that is run in the new separate thread.
- SimpleThread *This = (SimpleThread *)arg;
- This->run();
- return 0;
-}
-
-SimpleThread::SimpleThread()
-{
- PosixThreadImplementation *imp = new PosixThreadImplementation;
- fImplementation = imp;
-}
-
-SimpleThread::~SimpleThread()
-{
- PosixThreadImplementation *imp = (PosixThreadImplementation*)fImplementation;
- delete imp;
- fImplementation = (void *)0xdeadbeef;
-}
-
-int32_t SimpleThread::start()
-{
- int32_t rc;
- static pthread_attr_t attr;
- static UBool attrIsInitialized = FALSE;
-
- PosixThreadImplementation *imp = (PosixThreadImplementation*)fImplementation;
-
- if (attrIsInitialized == FALSE) {
- rc = pthread_attr_init(&attr);
-#if U_PLATFORM == U_PF_OS390
- {
- int detachstate = 0; // jdc30: detach state of zero causes
- //threads created with this attr to be in
- //an undetached state. An undetached
- //thread will keep its resources after
- //termination.
- pthread_attr_setdetachstate(&attr, &detachstate);
- }
-#else
- // pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
-#endif
- attrIsInitialized = TRUE;
- }
- rc = pthread_create(&(imp->fThread), &attr, &SimpleThreadProc, (void*)this);
-
- if (rc != 0) {
- // some kind of error occured, the thread did not start.
- }
-
- return rc;
-}
-
-void SimpleThread::join() {
- PosixThreadImplementation *imp = (PosixThreadImplementation*)fImplementation;
- pthread_join(imp->fThread, NULL);
-}
-
-#endif
-// end POSIX
-
-
-#ifndef HAVE_IMP
-#error No implementation for threads! Cannot test.
-#endif