version 1.2, 2006/08/09 21:12:42
|
version 1.6, 2006/11/10 18:14:58
|
|
|
// | // |
//============================================================================== | //============================================================================== |
// | // |
// 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" |
|
|
else | else |
{ | { |
// sleep for loop seconds | // sleep for loop seconds |
sleep(msec / 1000); |
::sleep(msec / 1000); |
// Usleep the remaining micro seconds | // Usleep the remaining micro seconds |
usleep( (msec*1000) % 1000000 ); | usleep( (msec*1000) % 1000000 ); |
} | } |
#elif defined(PEGASUS_OS_VMS) | #elif defined(PEGASUS_OS_VMS) |
| |
sleep(msec / 1000); |
::sleep(msec / 1000); |
| |
#endif | #endif |
} | } |
|
|
// | // |
//============================================================================== | //============================================================================== |
| |
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 */ |