version 1.3, 2006/08/15 17:17:30
|
version 1.8, 2007/02/18 05:28:26
|
|
|
// | // |
//============================================================================== | //============================================================================== |
// | // |
// Author: Mike Brasher (m.brasher@inovadevelopment.com) |
|
// |
|
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
|
#include <errno.h> |
#include "Threads.h" | #include "Threads.h" |
#include "IDFactory.h" | #include "IDFactory.h" |
#include "TSDKey.h" | #include "TSDKey.h" |
#include "Once.h" | #include "Once.h" |
| |
#if defined(PEGASUS_PLATFORM_WIN32_IX86_MSVC) |
#if defined(PEGASUS_OS_TYPE_WINDOWS) |
# include <sys/timeb.h> | # include <sys/timeb.h> |
#endif | #endif |
| |
|
|
{ | { |
#if defined(PEGASUS_HAVE_NANOSLEEP) | #if defined(PEGASUS_HAVE_NANOSLEEP) |
| |
struct timespec wait; |
struct timespec wait, remwait; |
wait.tv_sec = msec / 1000; | wait.tv_sec = msec / 1000; |
wait.tv_nsec = (msec % 1000) * 1000000; | wait.tv_nsec = (msec % 1000) * 1000000; |
nanosleep(&wait, NULL); |
|
|
while ((nanosleep(&wait, &remwait) == -1) && (errno == EINTR)) |
|
{ |
|
wait.tv_sec = remwait.tv_sec; |
|
wait.tv_nsec = remwait.tv_nsec; |
|
} |
| |
#elif defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM) | #elif defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM) |
| |
|
|
usleep(microsecs - (loop*1000000)); | usleep(microsecs - (loop*1000000)); |
} | } |
| |
#elif defined(PEGASUS_PLATFORM_WIN32_IX86_MSVC) |
#elif defined(PEGASUS_OS_TYPE_WINDOWS) |
| |
if (msec == 0) | if (msec == 0) |
{ | { |
|
|
// | // |
//============================================================================== | //============================================================================== |
| |
static IDFactory _thread_ids(2); /* 1 reserved for main thread */ |
|
|
|
#if defined(PEGASUS_HAVE_PTHREADS) | #if defined(PEGASUS_HAVE_PTHREADS) |
| |
int Threads::create( | int Threads::create( |
|
|
| |
// Create thread: | // Create thread: |
| |
pthread_t thr; |
int rc = pthread_create(&thread.thread, &attr, start, arg); |
int rc = pthread_create(&thr, &attr, start, arg); |
|
| |
if (rc != 0) | if (rc != 0) |
{ | { |
|
|
return rc; | return rc; |
} | } |
| |
// Assign thread id (and put into thread specific storage). |
|
|
|
Uint32 id = _thread_ids.getID(); |
|
_set_id_tsd(id); |
|
|
|
// Destroy attributes now. | // Destroy attributes now. |
| |
pthread_attr_destroy(&attr); | pthread_attr_destroy(&attr); |
| |
// Return: | // Return: |
| |
thread = ThreadType(thr, id); |
|
return 0; | return 0; |
} | } |
| |
ThreadType Threads::self() | ThreadType Threads::self() |
{ | { |
return ThreadType(pthread_self(), _get_id_tsd()); |
ThreadType tt; |
|
tt.thread = pthread_self(); |
|
return tt; |
} | } |
| |
#endif /* PEGASUS_HAVE_PTHREADS */ | #endif /* PEGASUS_HAVE_PTHREADS */ |