diff options
Diffstat (limited to 'ace/OS.cpp')
-rw-r--r-- | ace/OS.cpp | 329 |
1 files changed, 157 insertions, 172 deletions
diff --git a/ace/OS.cpp b/ace/OS.cpp index 425bcad3dbf..30766fa8710 100644 --- a/ace/OS.cpp +++ b/ace/OS.cpp @@ -205,7 +205,6 @@ ACE_OS::netdb_release (void) ACE_EXIT_HOOK ACE_OS::exit_hook_ = 0; // Static constant representing `zero-time'. -// Note: this object requires static construction. const ACE_Time_Value ACE_Time_Value::zero; // Constant for maximum time representable. Note that this time @@ -213,7 +212,7 @@ const ACE_Time_Value ACE_Time_Value::zero; // have *their own* implementation-specific maximum time representations. // Its primary use is in time computations such as those used by the // dynamic subpriority strategies in the ACE_Dynamic_Message_Queue class. -// Note: this object requires static construction. + const ACE_Time_Value ACE_Time_Value::max_time (LONG_MAX, ACE_ONE_SECOND_IN_USECS - 1); @@ -254,7 +253,7 @@ void ACE_Time_Value::set (const FILETIME &file_time) ACE_Time_Value::operator FILETIME () const { - ACE_TRACE ("ACE_Time_Value::operator FILETIME"); + // ACE_TRACE ("ACE_Time_Value::operator FILETIME"); ULARGE_INTEGER _100ns; _100ns.QuadPart = (((DWORDLONG) this->tv_.tv_sec * (10000 * 1000) + this->tv_.tv_usec * 10) + @@ -301,7 +300,7 @@ ACE_Cleanup_Info::operator!= (const ACE_Cleanup_Info &o) const void ACE_Time_Value::dump (void) const { - ACE_TRACE ("ACE_Time_Value::dump"); + // ACE_TRACE ("ACE_Time_Value::dump"); ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("\ntv_sec_ = %d"), this->tv_.tv_sec)); ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("\ntv_usec_ = %d\n"), this->tv_.tv_usec)); @@ -399,7 +398,7 @@ ACE_Countdown_Time::~ACE_Countdown_Time (void) void ACE_OS::readPPCTimeBase (u_long &most, u_long &least) { - ACE_TRACE ("ACE_OS::readPPCTimeBase"); + // ACE_TRACE ("ACE_OS::readPPCTimeBase"); // This function can't be inline because it depends on the arguments // being in particular registers (r3 and r4), in conformance with the @@ -419,7 +418,7 @@ ACE_OS::readPPCTimeBase (u_long &most, u_long &least) void ACE_OS::readPPCTimeBase (u_long &most, u_long &least) { - ACE_TRACE ("ACE_OS::readPPCTimeBase"); + // ACE_TRACE ("ACE_OS::readPPCTimeBase"); // This function can't be inline because it defines a symbol, // aclock. If there are multiple calls to the function in a @@ -446,7 +445,7 @@ ACE_OS::readPPCTimeBase (u_long &most, u_long &least) int ACE_OS::uname (struct utsname *name) { - ACE_TRACE ("ACE_OS::uname"); + // ACE_TRACE ("ACE_OS::uname"); # if defined (ACE_WIN32) size_t maxnamelen = sizeof name->nodename; ACE_OS::strcpy (name->sysname, ACE_TEXT ("Win32")); @@ -612,7 +611,7 @@ ACE_OS::uname (struct utsname *name) struct hostent * ACE_OS::gethostbyname (const char *name) { - ACE_TRACE ("ACE_OS::gethostbyname"); + // ACE_TRACE ("ACE_OS::gethostbyname"); // not thread safe! static hostent ret; @@ -641,7 +640,7 @@ ACE_OS::gethostbyname (const char *name) struct hostent * ACE_OS::gethostbyaddr (const char *addr, int length, int type) { - ACE_TRACE ("ACE_OS::gethostbyaddr"); + // ACE_TRACE ("ACE_OS::gethostbyaddr"); if (length != 4 || type != AF_INET) { @@ -680,7 +679,7 @@ ACE_OS::gethostbyaddr_r (const char *addr, int length, int type, hostent *result, ACE_HOSTENT_DATA buffer, int *h_errnop) { - ACE_TRACE ("ACE_OS::gethostbyaddr_r"); + // ACE_TRACE ("ACE_OS::gethostbyaddr_r"); if (length != 4 || type != AF_INET) { errno = EINVAL; @@ -730,7 +729,7 @@ ACE_OS::gethostbyname_r (const char *name, hostent *result, ACE_HOSTENT_DATA buffer, int *h_errnop) { - ACE_TRACE ("ACE_OS::gethostbyname_r"); + // ACE_TRACE ("ACE_OS::gethostbyname_r"); if (ACE_OS::netdb_acquire ()) return 0; @@ -777,7 +776,7 @@ ACE_OS::gethostbyname_r (const char *name, hostent *result, void ACE_OS::ace_flock_t::dump (void) const { -ACE_TRACE ("ACE_OS::ace_flock_t::dump"); +// ACE_TRACE ("ACE_OS::ace_flock_t::dump"); ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("handle_ = %u"), this->handle_)); @@ -798,7 +797,7 @@ ACE_TRACE ("ACE_OS::ace_flock_t::dump"); void ACE_OS::mutex_lock_cleanup (void *mutex) { -ACE_TRACE ("ACE_OS::mutex_lock_cleanup"); +// ACE_TRACE ("ACE_OS::mutex_lock_cleanup"); #if defined (ACE_HAS_THREADS) # if defined (ACE_HAS_PTHREADS) ACE_mutex_t *p_lock = (ACE_mutex_t *) mutex; @@ -818,7 +817,7 @@ ACE_TRACE ("ACE_OS::mutex_lock_cleanup"); FILE * ACE_OS::fopen (const char *filename, const char *mode) { - ACE_TRACE ("ACE_OS::fopen"); + // ACE_TRACE ("ACE_OS::fopen"); int hmode = _O_TEXT; for (const char *mode_ptr = mode; *mode_ptr != 0; mode_ptr++) @@ -846,7 +845,7 @@ ACE_OS::fopen (const char *filename, const char *mode) FILE * ACE_OS::fopen (const wchar_t *filename, const wchar_t *mode) { - ACE_TRACE ("ACE_OS::fopen"); + // ACE_TRACE ("ACE_OS::fopen"); int hmode = _O_TEXT; for (const wchar_t *mode_ptr = mode; *mode_ptr != 0; mode_ptr++) @@ -878,7 +877,7 @@ ACE_OS::fopen (const wchar_t *filename, const wchar_t *mode) int ACE_OS::fprintf (FILE *fp, const char *format, ...) { - ACE_TRACE ("ACE_OS::fprintf"); + // ACE_TRACE ("ACE_OS::fprintf"); int result = 0; va_list ap; va_start (ap, format); @@ -890,7 +889,7 @@ ACE_OS::fprintf (FILE *fp, const char *format, ...) int ACE_OS::printf (const char *format, ...) { - ACE_TRACE ("ACE_OS::printf"); + // ACE_TRACE ("ACE_OS::printf"); int result; va_list ap; va_start (ap, format); @@ -903,7 +902,6 @@ int ACE_OS::sprintf (char *buf, const char *format, ...) { // ACE_TRACE ("ACE_OS::sprintf"); - int result; va_list ap; va_start (ap, format); @@ -915,7 +913,7 @@ ACE_OS::sprintf (char *buf, const char *format, ...) char * ACE_OS::gets (char *str, int n) { - ACE_TRACE ("ACE_OS::gets"); + // ACE_TRACE ("ACE_OS::gets"); int c; char *s = str; @@ -957,7 +955,7 @@ fprintf (FILE *fp, char *format, const char *msg) int ACE_OS::fprintf (FILE *fp, const wchar_t *format, ...) { - ACE_TRACE ("ACE_OS::fprintf"); + // ACE_TRACE ("ACE_OS::fprintf"); # if defined (ACE_HAS_WINCE) ACE_NOTSUP_RETURN (-1); # else @@ -973,7 +971,7 @@ ACE_OS::fprintf (FILE *fp, const wchar_t *format, ...) int ACE_OS::sprintf (wchar_t *buf, const wchar_t *format, ...) { - ACE_TRACE ("ACE_OS::sprintf"); + // ACE_TRACE ("ACE_OS::sprintf"); int result; va_list ap; va_start (ap, format); @@ -986,7 +984,7 @@ ACE_OS::sprintf (wchar_t *buf, const wchar_t *format, ...) int ACE_OS::sprintf (wchar_t *buf, const char *format, ...) { - ACE_TRACE ("ACE_OS::sprintf"); + // ACE_TRACE ("ACE_OS::sprintf"); const wchar_t *wide_format = ACE_WString (format).fast_rep (); int result; va_list ap; @@ -1003,7 +1001,7 @@ ACE_OS::sprintf (wchar_t *buf, const char *format, ...) wchar_t * ACE_OS::mktemp (wchar_t *s) { - ACE_TRACE ("ACE_OS::mktemp"); + // ACE_TRACE ("ACE_OS::mktemp"); if (s == 0) // check for null template string failed! return 0; @@ -1025,13 +1023,11 @@ ACE_OS::mktemp (wchar_t *s) // condition if multiple threads in a process use the same // template). This appears to match the behavior of the // SunOS 5.5 mktemp(). - ACE_OS::sprintf (xxxxxx, ACE_TEXT ("%05d%c"), - ACE_OS::getpid (), unique_letter); + ACE_OS::sprintf (xxxxxx, ACE_TEXT ("%05d%c"), getpid (), unique_letter); while (ACE_OS::stat (s, &sb) >= 0) { if (++unique_letter <= L'z') - ACE_OS::sprintf (xxxxxx, ACE_TEXT ("%05d%c"), - ACE_OS::getpid (), unique_letter); + ACE_OS::sprintf (xxxxxx, ACE_TEXT ("%05d%c"), getpid (), unique_letter); else { // maximum of 26 unique files per template, per process @@ -1049,7 +1045,7 @@ ACE_OS::mktemp (wchar_t *s) int ACE_OS::execl (const char * /* path */, const char * /* arg0 */, ...) { - ACE_TRACE ("ACE_OS::execl"); + // ACE_TRACE ("ACE_OS::execl"); #if defined (ACE_WIN32) || defined (VXWORKS) ACE_NOTSUP_RETURN (-1); #else @@ -1062,7 +1058,7 @@ ACE_OS::execl (const char * /* path */, const char * /* arg0 */, ...) int ACE_OS::execle (const char * /* path */, const char * /* arg0 */, ...) { - ACE_TRACE ("ACE_OS::execle"); + // ACE_TRACE ("ACE_OS::execle"); #if defined (ACE_WIN32) || defined (VXWORKS) ACE_NOTSUP_RETURN (-1); #else @@ -1075,7 +1071,7 @@ ACE_OS::execle (const char * /* path */, const char * /* arg0 */, ...) int ACE_OS::execlp (const char * /* file */, const char * /* arg0 */, ...) { - ACE_TRACE ("ACE_OS::execlp"); + // ACE_TRACE ("ACE_OS::execlp"); #if defined (ACE_WIN32) || defined (VXWORKS) ACE_NOTSUP_RETURN (-1); #else @@ -1085,6 +1081,11 @@ ACE_OS::execlp (const char * /* file */, const char * /* arg0 */, ...) #endif /* ACE_WIN32 */ } +#if defined (ACE_HAS_PRIOCNTL) +# include /**/ <sys/rtpriocntl.h> +# include /**/ <sys/tspriocntl.h> +#endif /* ACE_HAS_PRIOCNTL */ + int ACE_OS::scheduling_class (const char *class_name, ACE_id_t &id) { @@ -1254,7 +1255,7 @@ int ACE_OS::sched_params (const ACE_Sched_Params &sched_params, ACE_id_t id) { - ACE_TRACE ("ACE_OS::sched_params"); + // ACE_TRACE ("ACE_OS::sched_params"); # if defined (CHORUS) ACE_UNUSED_ARG (id); int result; @@ -1389,7 +1390,6 @@ ACE_OS::sched_params (const ACE_Sched_Params &sched_params, // ACE_thread_t, ACE_hthread_t, and ACE_thread_key_t are implemented // as structures... Under no circumstances should these be given // initial values. -// Note: these three objects require static construction. ACE_thread_t ACE_OS::NULL_thread; ACE_hthread_t ACE_OS::NULL_hthread; #if defined (ACE_HAS_TSS_EMULATION) @@ -1421,19 +1421,19 @@ int ACE_OS::socket_initialized_; ACE_TSS_Ref::ACE_TSS_Ref (ACE_thread_t id) : tid_(id) { -ACE_TRACE ("ACE_TSS_Ref::ACE_TSS_Ref"); +// ACE_TRACE ("ACE_TSS_Ref::ACE_TSS_Ref"); } ACE_TSS_Ref::ACE_TSS_Ref (void) { -ACE_TRACE ("ACE_TSS_Ref::ACE_TSS_Ref"); +// ACE_TRACE ("ACE_TSS_Ref::ACE_TSS_Ref"); } // Check for equality. int ACE_TSS_Ref::operator== (const ACE_TSS_Ref &info) const { -ACE_TRACE ("ACE_TSS_Ref::operator=="); +// ACE_TRACE ("ACE_TSS_Ref::operator=="); return this->tid_ == info.tid_; } @@ -1443,7 +1443,7 @@ inline int ACE_TSS_Ref::operator!= (const ACE_TSS_Ref &tss_ref) const { -ACE_TRACE ("ACE_TSS_Ref::operator=="); +// ACE_TRACE ("ACE_TSS_Ref::operator=="); return !(*this == tss_ref); } @@ -1460,7 +1460,7 @@ ACE_TSS_Info::ACE_TSS_Info (ACE_thread_key_t key, tss_obj_ (tss_inst), thread_count_ (-1) { -ACE_TRACE ("ACE_TSS_Info::ACE_TSS_Info"); +// ACE_TRACE ("ACE_TSS_Info::ACE_TSS_Info"); } ACE_TSS_Info::ACE_TSS_Info (void) @@ -1469,7 +1469,7 @@ ACE_TSS_Info::ACE_TSS_Info (void) tss_obj_ (0), thread_count_ (-1) { -ACE_TRACE ("ACE_TSS_Info::ACE_TSS_Info"); +// ACE_TRACE ("ACE_TSS_Info::ACE_TSS_Info"); } # if defined (ACE_HAS_NONSCALAR_THREAD_KEY_T) @@ -1490,7 +1490,7 @@ ACE_TRACE ("ACE_TSS_Info::ACE_TSS_Info"); int ACE_TSS_Info::operator== (const ACE_TSS_Info &info) const { -ACE_TRACE ("ACE_TSS_Info::operator=="); +// ACE_TRACE ("ACE_TSS_Info::operator=="); return this->key_ == info.key_; } @@ -1499,7 +1499,7 @@ ACE_TRACE ("ACE_TSS_Info::operator=="); int ACE_TSS_Info::operator!= (const ACE_TSS_Info &info) const { -ACE_TRACE ("ACE_TSS_Info::operator=="); +// ACE_TRACE ("ACE_TSS_Info::operator=="); return !(*this == info); } @@ -1655,7 +1655,7 @@ ACE_TSS_Cleanup::~ACE_TSS_Cleanup (void) void ACE_TSS_Cleanup::exit (void * /* status */) { - ACE_TRACE ("ACE_TSS_Cleanup::exit"); + // ACE_TRACE ("ACE_TSS_Cleanup::exit"); ACE_TSS_TABLE_ITERATOR key_info = table_; ACE_TSS_Info info_arr[ACE_DEFAULT_THREAD_KEYS]; @@ -1797,13 +1797,13 @@ ACE_TSS_Cleanup::ACE_TSS_Cleanup (void) , in_use_key_ (ACE_TSS_Emulation::total_keys ()) #endif /* ACE_HAS_TSS_EMULATION */ { - ACE_TRACE ("ACE_TSS_Cleanup::ACE_TSS_Cleanup"); + // ACE_TRACE ("ACE_TSS_Cleanup::ACE_TSS_Cleanup"); } ACE_TSS_Cleanup * ACE_TSS_Cleanup::instance (void) { - ACE_TRACE ("ACE_TSS_Cleanup::instance"); + // ACE_TRACE ("ACE_TSS_Cleanup::instance"); // Create and initialize thread-specific key. if (ACE_TSS_Cleanup::instance_ == 0) @@ -1827,7 +1827,7 @@ ACE_TSS_Cleanup::insert (ACE_thread_key_t key, void (*destructor)(void *), void *inst) { -ACE_TRACE ("ACE_TSS_Cleanup::insert"); +// ACE_TRACE ("ACE_TSS_Cleanup::insert"); ACE_TSS_CLEANUP_GUARD ACE_KEY_INDEX (key_index, key); @@ -1845,7 +1845,7 @@ ACE_TRACE ("ACE_TSS_Cleanup::insert"); int ACE_TSS_Cleanup::remove (ACE_thread_key_t key) { - ACE_TRACE ("ACE_TSS_Cleanup::remove"); + // ACE_TRACE ("ACE_TSS_Cleanup::remove"); ACE_TSS_CLEANUP_GUARD ACE_KEY_INDEX (key_index, key); @@ -2404,7 +2404,7 @@ ace_cleanup_destroyer (ACE_Cleanup *object, void *param) extern "C" void * ace_thread_adapter (void *args) { - ACE_TRACE ("ace_thread_adapter"); + // ACE_TRACE ("ace_thread_adapter"); #if defined (ACE_HAS_TSS_EMULATION) // As early as we can in the execution of the new thread, allocate @@ -2452,7 +2452,7 @@ ACE_Thread_Adapter::ACE_Thread_Adapter (ACE_THR_FUNC user_func, # endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */ #endif /* ACE_THREADS_DONT_INHERIT_LOG_MSG */ { -ACE_TRACE ("Ace_Thread_Adapter::Ace_Thread_Adapter"); +// ACE_TRACE ("Ace_Thread_Adapter::Ace_Thread_Adapter"); #if !defined (ACE_THREADS_DONT_INHERIT_LOG_MSG) && \ !defined (ACE_HAS_MINIMAL_ACE_OS) if (ACE_Log_Msg::exists ()) @@ -2482,7 +2482,7 @@ ACE_OS::thr_create (ACE_THR_FUNC func, size_t stacksize, ACE_Thread_Adapter *thread_adapter) { - ACE_TRACE ("ACE_OS::thr_create"); + // ACE_TRACE ("ACE_OS::thr_create"); if (ACE_BIT_DISABLED (flags, THR_DETACHED) && ACE_BIT_DISABLED (flags, THR_JOINABLE)) @@ -3319,7 +3319,7 @@ ACE_OS::thr_create (ACE_THR_FUNC func, void ACE_OS::thr_exit (void *status) { -ACE_TRACE ("ACE_OS::thr_exit"); +// ACE_TRACE ("ACE_OS::thr_exit"); # if defined (ACE_HAS_THREADS) # if defined (ACE_HAS_PTHREADS) ::pthread_exit (status); @@ -3461,7 +3461,7 @@ ACE_OS::lwp_setparams (const ACE_Sched_Params &sched_params) int ACE_OS::thr_setspecific (ACE_OS_thread_key_t key, void *data) { - // ACE_TRACE ("ACE_OS::thr_setspecific"); +// ACE_TRACE ("ACE_OS::thr_setspecific"); # if defined (ACE_HAS_THREADS) # if defined (ACE_HAS_PTHREADS) # if defined (ACE_HAS_FSU_PTHREADS) @@ -3492,7 +3492,7 @@ ACE_OS::thr_setspecific (ACE_OS_thread_key_t key, void *data) int ACE_OS::thr_setspecific (ACE_thread_key_t key, void *data) { - // ACE_TRACE ("ACE_OS::thr_setspecific"); +// ACE_TRACE ("ACE_OS::thr_setspecific"); # if defined (ACE_HAS_THREADS) # if defined (ACE_HAS_TSS_EMULATION) ACE_KEY_INDEX (key_index, key); @@ -3551,7 +3551,7 @@ ACE_OS::thr_setspecific (ACE_thread_key_t key, void *data) int ACE_OS::thr_keyfree (ACE_thread_key_t key) { -ACE_TRACE ("ACE_OS::thr_keyfree"); +// ACE_TRACE ("ACE_OS::thr_keyfree"); # if defined (ACE_HAS_THREADS) # if defined (ACE_HAS_TSS_EMULATION) return ACE_TSS_Cleanup::instance ()->remove (key); @@ -3590,7 +3590,7 @@ ACE_OS::thr_keycreate (ACE_OS_thread_key_t *key, # endif /* ACE_HAS_THR_C_DEST */ void *inst) { - // ACE_TRACE ("ACE_OS::thr_keycreate"); +// ACE_TRACE ("ACE_OS::thr_keycreate"); # if defined (ACE_HAS_THREADS) # if defined (ACE_HAS_PTHREADS) ACE_UNUSED_ARG (inst); @@ -3644,7 +3644,7 @@ ACE_OS::thr_keycreate (ACE_thread_key_t *key, # endif /* ACE_HAS_THR_C_DEST */ void *inst) { - // ACE_TRACE ("ACE_OS::thr_keycreate"); +// ACE_TRACE ("ACE_OS::thr_keycreate"); # if defined (ACE_HAS_THREADS) # if defined (ACE_HAS_TSS_EMULATION) if (ACE_TSS_Emulation::next_key (*key) == 0) @@ -4038,7 +4038,7 @@ ACE_OS::read_n (ACE_HANDLE handle, void *buf, size_t len) { - ACE_TRACE ("ACE_OS::read_n"); + // ACE_TRACE ("ACE_OS::read_n"); size_t bytes_read; ssize_t n; @@ -4066,7 +4066,7 @@ ACE_OS::read_n (ACE_HANDLE handle, ssize_t ACE_OS::send_n (ACE_HANDLE handle, const void *buf, size_t len) { - ACE_TRACE ("ACE_OS::send_n"); + // ACE_TRACE ("ACE_OS::send_n"); size_t bytes_written; ssize_t n; @@ -4103,7 +4103,7 @@ ACE_OS::write_n (ACE_HANDLE handle, const void *buf, size_t len) { - ACE_TRACE ("ACE_OS::write_n"); + // ACE_TRACE ("ACE_OS::write_n"); size_t bytes_written; ssize_t n; @@ -4132,7 +4132,7 @@ ACE_OS::write_n (ACE_HANDLE handle, extern "C" int writev (ACE_HANDLE handle, ACE_WRITEV_TYPE iov[], int n) { - ACE_TRACE ("::writev"); + // ACE_TRACE ("::writev"); size_t length = 0; int i; @@ -4178,7 +4178,7 @@ readv (ACE_HANDLE handle, ACE_READV_TYPE *iov, int n) { -ACE_TRACE ("readv"); +// ACE_TRACE ("readv"); ssize_t length = 0; int i; @@ -4234,7 +4234,7 @@ ftruncate (ACE_HANDLE handle, long len) fl.l_start = len; fl.l_type = F_WRLCK; - return ACE_OS::fcntl (handle, F_FREESP, ACE_reinterpret_cast (long, &fl)); + return ::fcntl (handle, F_FREESP, &fl); } # endif /* ACE_NEEDS_FTRUNCATE */ @@ -4242,7 +4242,7 @@ ftruncate (ACE_HANDLE handle, long len) char * ACE_OS::mktemp (char *s) { - ACE_TRACE ("ACE_OS::mktemp"); + // ACE_TRACE ("ACE_OS::mktemp"); if (s == 0) // check for null template string failed! return 0; @@ -4264,12 +4264,11 @@ ACE_OS::mktemp (char *s) // condition if multiple threads in a process use the same // template). This appears to match the behavior of the // SunOS 5.5 mktemp(). - ACE_OS::sprintf (xxxxxx, "%05d%c", ACE_OS::getpid (), unique_letter); + ACE_OS::sprintf (xxxxxx, "%05d%c", getpid (), unique_letter); while (ACE_OS::stat (s, &sb) >= 0) { if (++unique_letter <= 'z') - ACE_OS::sprintf (xxxxxx, "%05d%c", ACE_OS::getpid (), - unique_letter); + ACE_OS::sprintf (xxxxxx, "%05d%c", getpid (), unique_letter); else { // maximum of 26 unique files per template, per process @@ -4435,7 +4434,7 @@ siginfo_t::siginfo_t (ACE_HANDLE *handles) pid_t ACE_OS::fork (const char *program_name) { - ACE_TRACE ("ACE_OS::fork"); + // ACE_TRACE ("ACE_OS::fork"); # if defined (ACE_LACKS_FORK) ACE_UNUSED_ARG (program_name); ACE_NOTSUP_RETURN (pid_t (-1)); @@ -4794,7 +4793,7 @@ ACE_OS::open (const char *filename, int perms, LPSECURITY_ATTRIBUTES sa) { - ACE_TRACE ("ACE_OS::open"); + // ACE_TRACE ("ACE_OS::open"); #if defined (ACE_HAS_WINCE) ACE_UNUSED_ARG (filename); ACE_UNUSED_ARG (mode); @@ -4913,7 +4912,7 @@ ACE_OS::open (const wchar_t *filename, LPSECURITY_ATTRIBUTES sa) { ACE_UNUSED_ARG (perms); - ACE_TRACE ("ACE_OS::open"); + // ACE_TRACE ("ACE_OS::open"); // Warning: This function ignores _O_APPEND DWORD access = GENERIC_READ; if (ACE_BIT_ENABLED (mode, O_WRONLY)) @@ -5181,7 +5180,7 @@ ACE_OS::ctime_r (const time_t *clock, time_t ACE_OS::mktime (struct tm *t) { - ACE_TRACE ("ACE_OS::mktime"); + // ACE_TRACE ("ACE_OS::mktime"); # if defined (ACE_PSOS) && ! defined (ACE_PSOS_HAS_TIME) ACE_UNUSED_ARG (t); ACE_NOTSUP_RETURN (-1); @@ -5270,7 +5269,7 @@ ACE_OS::rwlock_init (ACE_rwlock_t *rw, int ACE_OS::cond_destroy (ACE_cond_t *cv) { - ACE_TRACE ("ACE_OS::cond_destroy"); + // ACE_TRACE ("ACE_OS::cond_destroy"); # if defined (ACE_HAS_THREADS) # if defined (ACE_HAS_WTHREADS) ACE_OS::event_destroy (&cv->waiters_done_); @@ -5288,7 +5287,7 @@ ACE_OS::cond_destroy (ACE_cond_t *cv) int ACE_OS::cond_init (ACE_cond_t *cv, int type, LPCTSTR name, void *arg) { -ACE_TRACE ("ACE_OS::cond_init"); +// ACE_TRACE ("ACE_OS::cond_init"); # if defined (ACE_HAS_THREADS) cv->waiters_ = 0; cv->was_broadcast_ = 0; @@ -5317,7 +5316,7 @@ ACE_TRACE ("ACE_OS::cond_init"); int ACE_OS::cond_signal (ACE_cond_t *cv) { -ACE_TRACE ("ACE_OS::cond_signal"); +// ACE_TRACE ("ACE_OS::cond_signal"); # if defined (ACE_HAS_THREADS) // If there aren't any waiters, then this is a no-op. Note that // this function *must* be called with the <external_mutex> held @@ -5342,7 +5341,7 @@ ACE_TRACE ("ACE_OS::cond_signal"); int ACE_OS::cond_broadcast (ACE_cond_t *cv) { -ACE_TRACE ("ACE_OS::cond_broadcast"); +// ACE_TRACE ("ACE_OS::cond_broadcast"); # if defined (ACE_HAS_THREADS) // The <external_mutex> must be locked before this call is made. @@ -5390,7 +5389,7 @@ int ACE_OS::cond_wait (ACE_cond_t *cv, ACE_mutex_t *external_mutex) { - ACE_TRACE ("ACE_OS::cond_wait"); + // ACE_TRACE ("ACE_OS::cond_wait"); # if defined (ACE_HAS_THREADS) // Prevent race conditions on the <waiters_> count. ACE_OS::thread_mutex_lock (&cv->waiters_lock_); @@ -5485,7 +5484,7 @@ ACE_OS::cond_timedwait (ACE_cond_t *cv, ACE_mutex_t *external_mutex, ACE_Time_Value *timeout) { - ACE_TRACE ("ACE_OS::cond_timedwait"); + // ACE_TRACE ("ACE_OS::cond_timedwait"); # if defined (ACE_HAS_THREADS) // Handle the easy case first. if (timeout == 0) @@ -5633,10 +5632,7 @@ ACE_OS::cond_timedwait (ACE_cond_t *cv, /* NOTREACHED */ } # endif /* ACE_HAS_SIGNAL_OBJECT_AND_WAIT */ - // Note that this *must* be an "if" statement rather than an "else - // if" statement since the caller may have timed out and hence the - // result would have been -1 above. - if (last_waiter) + else if (last_waiter) // Release the signaler/broadcaster if we're the last waiter. # if defined (ACE_WIN32) ACE_OS::event_signal (&cv->waiters_done_); @@ -5665,7 +5661,7 @@ ACE_OS::cond_timedwait (ACE_cond_t *cv, ACE_thread_mutex_t *external_mutex, ACE_Time_Value *timeout) { - ACE_TRACE ("ACE_OS::cond_timedwait"); + // ACE_TRACE ("ACE_OS::cond_timedwait"); # if defined (ACE_HAS_THREADS) // Handle the easy case first. if (timeout == 0) @@ -5754,7 +5750,7 @@ int ACE_OS::cond_wait (ACE_cond_t *cv, ACE_thread_mutex_t *external_mutex) { - ACE_TRACE ("ACE_OS::cond_wait"); + // ACE_TRACE ("ACE_OS::cond_wait"); # if defined (ACE_HAS_THREADS) ACE_OS::thread_mutex_lock (&cv->waiters_lock_); cv->waiters_++; @@ -5821,7 +5817,7 @@ ACE_OS::cond_wait (ACE_cond_t *cv, void ACE_OS::exit (int status) { - ACE_TRACE ("ACE_OS::exit"); + // ACE_TRACE ("ACE_OS::exit"); #if defined (ACE_HAS_NONSTATIC_OBJECT_MANAGER) && !defined (ACE_HAS_WINCE) && !defined (ACE_DOESNT_INSTANTIATE_NONSTATIC_OBJECT_MANAGER) // Shut down the ACE_Object_Manager, if it had registered its exit_hook. @@ -6123,7 +6119,7 @@ ACE_OS_WString::ACE_OS_WString (const ACE_USHORT16 *s) { size_t len = ACE_OS::strlen (s); ACE_NEW (this->rep_, - char[len+1]); + char[len]); for (size_t i = 0; i < len; i++) { @@ -6140,7 +6136,7 @@ ACE_OS_CString::ACE_OS_CString (const char *s) { size_t len = ACE_OS::strlen (s); ACE_NEW (this->rep_, - ACE_USHORT16[len+1]); + ACE_USHORT16[len]); for (size_t i = 0; i < len; i++) this->rep_[i] = s[i]; @@ -6194,6 +6190,8 @@ ACE_OS_Object_Manager_Internal_Exit_Hook () ACE_OS_Object_Manager::instance ()->fini (); } +u_int ACE_OS_Object_Manager::init_fini_count_ = 0; + ACE_OS_Object_Manager *ACE_OS_Object_Manager::instance_ = 0; void *ACE_OS_Object_Manager::preallocated_object[ @@ -6201,25 +6199,21 @@ void *ACE_OS_Object_Manager::preallocated_object[ ACE_OS_Object_Manager::ACE_OS_Object_Manager () { - // If instance_ was not 0, then another ACE_OS_Object_Manager has - // already been instantiated (it is likely to be one initialized by way - // of library/DLL loading). Let this one go through construction in - // case there really is a good reason for it (like, ACE is a static/archive - // library, and this one is the non-static instance (with - // ACE_HAS_NONSTATIC_OBJECT_MANAGER, or the user has a good reason for - // creating a separate one) but the original one will be the one retrieved - // from calls to ACE_Object_Manager::instance(). + // If Instance_ was not 0, then another ACE_OS_Object_Manager has + // already been instantiated. Because this might be the non-static + // instance (with ACE_HAS_NONSTATIC_OBJECT_MANAGER), use it and leak + // the old one. We can't destroy it, because the application might + // be using some of its resources, via static constructors. - // Be sure that no further instances are created via instance (). - if (instance_ == 0) - instance_ = this; + // Store the address of the instance so that instance () doesn't + // allocate a new one when called. + instance_ = this; init (); } ACE_OS_Object_Manager::~ACE_OS_Object_Manager () { - dynamically_allocated_ = 0; // Don't delete this again in fini() fini (); } @@ -6237,7 +6231,9 @@ ACE_OS_Object_Manager::instance (void) ACE_NEW_RETURN (instance_pointer, ACE_OS_Object_Manager, 0); ACE_ASSERT (instance_pointer == instance_); +#if defined (ACE_HAS_NONSTATIC_OBJECT_MANAGER) instance_pointer->dynamically_allocated_ = 1; +#endif /* ACE_HAS_NONSTATIC_OBJECT_MANAGER */ } @@ -6247,50 +6243,49 @@ ACE_OS_Object_Manager::instance (void) int ACE_OS_Object_Manager::init (void) { + ++init_fini_count_; + if (starting_up_i ()) { - // First, indicate that this ACE_OS_Object_Manager instance is being + // First, indicate that the ACE_OS_Object_Manager instance is being // initialized. object_manager_state_ = OBJ_MAN_INITIALIZING; - if (this == instance_) - { # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) - ACE_OS_PREALLOCATE_OBJECT (ACE_thread_mutex_t, ACE_OS_MONITOR_LOCK) - if (ACE_OS::thread_mutex_init (ACE_reinterpret_cast ( + ACE_OS_PREALLOCATE_OBJECT (ACE_thread_mutex_t, ACE_OS_MONITOR_LOCK) + if (ACE_OS::thread_mutex_init (ACE_reinterpret_cast ( ACE_thread_mutex_t *, ACE_OS_Object_Manager::preallocated_object[ACE_OS_MONITOR_LOCK])) != 0) - ACE_ERROR ((LM_ERROR, - ASYS_TEXT("%p\n"), - ASYS_TEXT("ACE_OS_Object_Manager::init (1)"))); - ACE_OS_PREALLOCATE_OBJECT (ACE_recursive_thread_mutex_t, - ACE_TSS_CLEANUP_LOCK) - if (ACE_OS::recursive_mutex_init (ACE_reinterpret_cast ( + ACE_ERROR ((LM_ERROR, + ASYS_TEXT("%p\n"), + ASYS_TEXT("ACE_OS_Object_Manager::init (1)"))); + ACE_OS_PREALLOCATE_OBJECT (ACE_recursive_thread_mutex_t, + ACE_TSS_CLEANUP_LOCK) + if (ACE_OS::recursive_mutex_init (ACE_reinterpret_cast ( ACE_recursive_thread_mutex_t *, ACE_OS_Object_Manager::preallocated_object[ACE_TSS_CLEANUP_LOCK])) != 0) - ACE_ERROR ((LM_ERROR, - ASYS_TEXT("%p\n"), - ASYS_TEXT("ACE_OS_Object_Manager::init (2)"))); + ACE_ERROR ((LM_ERROR, + ASYS_TEXT("%p\n"), + ASYS_TEXT("ACE_OS_Object_Manager::init (2)"))); # if defined (ACE_HAS_TSS_EMULATION) && \ defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) - ACE_OS_PREALLOCATE_OBJECT (ACE_recursive_thread_mutex_t, - ACE_TSS_BASE_LOCK) - if (ACE_OS::recursive_mutex_init (ACE_reinterpret_cast ( - ACE_recursive_thread_mutex_t *, - ACE_OS_Object_Manager::preallocated_object[ACE_TSS_BASE_LOCK])) != 0) - ACE_ERROR ((LM_ERROR, - ASYS_TEXT("%p\n"), - ASYS_TEXT("ACE_OS_Object_Manager::init (3)"))); + ACE_OS_PREALLOCATE_OBJECT (ACE_recursive_thread_mutex_t, + ACE_TSS_BASE_LOCK) + if (ACE_OS::recursive_mutex_init (ACE_reinterpret_cast ( + ACE_recursive_thread_mutex_t *, + ACE_OS_Object_Manager::preallocated_object[ACE_TSS_BASE_LOCK])) != 0) + ACE_ERROR ((LM_ERROR, + ASYS_TEXT("%p\n"), + ASYS_TEXT("ACE_OS_Object_Manager::init (3)"))); # endif /* ACE_HAS_TSS_EMULATION && ACE_HAS_THREAD_SPECIFIC_STORAGE */ # endif /* ACE_MT_SAFE */ - // Open Winsock (no-op on other platforms). - ACE_OS::socket_init (ACE_WSOCK_VERSION); + // Open Winsock (no-op on other platforms). + ACE_OS::socket_init (ACE_WSOCK_VERSION); - // Register the exit hook, for use by ACE_OS::exit (). - ACE_OS::set_exit_hook (ACE_OS_Object_Manager_Internal_Exit_Hook); - } + // Register the exit hook, for use by ACE_OS::exit (). + ACE_OS::set_exit_hook (ACE_OS_Object_Manager_Internal_Exit_Hook); // Finally, indicate that the ACE_OS_Object_Manager instance has // been initialized. @@ -6303,13 +6298,18 @@ ACE_OS_Object_Manager::init (void) } } -// Clean up an ACE_OS_Object_Manager. There can be instances of this object -// other than The Instance. This can happen if a user creates one for some -// reason. All objects clean up their per-object information and managed -// objects, but only The Instance cleans up the static preallocated objects. int ACE_OS_Object_Manager::fini (void) { + if (init_fini_count_ > 0) + { + if (--init_fini_count_ > 0) + // Wait for remaining fini () calls. + return 1; + } + else + return -1; + if (instance_ == 0 || shutting_down_i ()) // Too late. Or, maybe too early. Either fini () has already // been called, or init () was never called. @@ -6330,66 +6330,51 @@ ACE_OS_Object_Manager::fini (void) next_ = 0; // Protect against recursive calls. } - // Only clean up preallocated objects when the singleton Instance is being - // destroyed. - if (this == instance_) - { - // Close down Winsock (no-op on other platforms). - ACE_OS::socket_fini (); + // Close down Winsock (no-op on other platforms). + ACE_OS::socket_fini (); #if ! defined (ACE_HAS_STATIC_PREALLOCATION) - // Cleanup the dynamically preallocated objects. + // Cleanup the dynamically preallocated objects. # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) -# if !defined (__Lynx__) - // LynxOS 3.0.0 has problems with this after fork. - if (ACE_OS::thread_mutex_destroy (ACE_reinterpret_cast ( - ACE_thread_mutex_t *, - ACE_OS_Object_Manager::preallocated_object[ACE_OS_MONITOR_LOCK])) != 0) - ACE_ERROR ((LM_ERROR, - ASYS_TEXT("%p\n"), - ASYS_TEXT("ACE_OS_Object_Manager::fini (1)"))); -# endif /* ! __Lynx__ */ - ACE_OS_DELETE_PREALLOCATED_OBJECT (ACE_thread_mutex_t, - ACE_OS_MONITOR_LOCK) -# if !defined (__Lynx__) - // LynxOS 3.0.0 has problems with this after fork. - if (ACE_OS::recursive_mutex_destroy (ACE_reinterpret_cast ( - ACE_recursive_thread_mutex_t *, - ACE_OS_Object_Manager::preallocated_object[ACE_TSS_CLEANUP_LOCK])) != 0) - ACE_ERROR ((LM_ERROR, - ASYS_TEXT("%p\n"), - ASYS_TEXT("ACE_OS_Object_Manager::fini (2)"))); -# endif /* ! __Lynx__ */ - ACE_OS_DELETE_PREALLOCATED_OBJECT (ACE_recursive_thread_mutex_t, - ACE_TSS_CLEANUP_LOCK) + if (ACE_OS::thread_mutex_destroy (ACE_reinterpret_cast ( + ACE_thread_mutex_t *, + ACE_OS_Object_Manager::preallocated_object[ACE_OS_MONITOR_LOCK])) != 0) + ACE_ERROR ((LM_ERROR, + ASYS_TEXT("%p\n"), + ASYS_TEXT("ACE_OS_Object_Manager::fini (1)"))); + ACE_OS_DELETE_PREALLOCATED_OBJECT (ACE_thread_mutex_t, ACE_OS_MONITOR_LOCK) + if (ACE_OS::recursive_mutex_destroy (ACE_reinterpret_cast ( + ACE_recursive_thread_mutex_t *, + ACE_OS_Object_Manager::preallocated_object[ACE_TSS_CLEANUP_LOCK])) != 0) + ACE_ERROR ((LM_ERROR, + ASYS_TEXT("%p\n"), + ASYS_TEXT("ACE_OS_Object_Manager::fini (2)"))); + ACE_OS_DELETE_PREALLOCATED_OBJECT (ACE_recursive_thread_mutex_t, + ACE_TSS_CLEANUP_LOCK) # if defined (ACE_HAS_TSS_EMULATION) && \ defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) -# if !defined (__Lynx__) - // LynxOS 3.0.0 has problems with this after fork. - if (ACE_OS::recursive_mutex_destroy (ACE_reinterpret_cast ( - ACE_recursive_thread_mutex_t *, - ACE_OS_Object_Manager::preallocated_object[ACE_TSS_BASE_LOCK])) != 0) - ACE_ERROR ((LM_ERROR, - ASYS_TEXT("%p\n"), - ASYS_TEXT("ACE_OS_Object_Manager::fini (3)"))); -# endif /* ! __Lynx__ */ - ACE_OS_DELETE_PREALLOCATED_OBJECT (ACE_recursive_thread_mutex_t, - ACE_TSS_BASE_LOCK) + if (ACE_OS::recursive_mutex_destroy (ACE_reinterpret_cast ( + ACE_recursive_thread_mutex_t *, + ACE_OS_Object_Manager::preallocated_object[ACE_TSS_BASE_LOCK])) != 0) + ACE_ERROR ((LM_ERROR, + ASYS_TEXT("%p\n"), + ASYS_TEXT("ACE_OS_Object_Manager::fini (3)"))); + ACE_OS_DELETE_PREALLOCATED_OBJECT (ACE_recursive_thread_mutex_t, + ACE_TSS_BASE_LOCK) # endif /* ACE_HAS_TSS_EMULATION && ACE_HAS_THREAD_SPECIFIC_STORAGE */ # endif /* ACE_MT_SAFE */ #endif /* ! ACE_HAS_STATIC_PREALLOCATION */ - } - // Indicate that this ACE_OS_Object_Manager instance has been shut down. + // Indicate that the ACE_OS_Object_Manager instance has been shut down. object_manager_state_ = OBJ_MAN_SHUT_DOWN; +#if defined (ACE_HAS_NONSTATIC_OBJECT_MANAGER) if (dynamically_allocated_) { - delete this; + delete instance_; + instance_ = 0; } - - if (this == instance_) - instance_ = 0; +#endif /* ACE_HAS_NONSTATIC_OBJECT_MANAGER */ return 0; } |