(file) Return to Thread.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

Diff for /pegasus/src/Pegasus/Common/Thread.cpp between version 1.90 and 1.90.2.3

version 1.90, 2006/07/11 18:39:28 version 1.90.2.3, 2006/07/28 20:46:41
Line 43 
Line 43 
  
 #include "Thread.h" #include "Thread.h"
 #include <exception> #include <exception>
 #include <Pegasus/Common/IPC.h>  
 #include <Pegasus/Common/Tracer.h> #include <Pegasus/Common/Tracer.h>
   #include "Time.h"
  
 #if defined(PEGASUS_OS_TYPE_WINDOWS) #if defined(PEGASUS_OS_TYPE_WINDOWS)
 # include "ThreadWindows.cpp" # include "ThreadWindows.cpp"
Line 81 
Line 81 
 Boolean Thread::_signals_blocked = false; Boolean Thread::_signals_blocked = false;
 // l10n // l10n
 #ifndef PEGASUS_OS_ZOS #ifndef PEGASUS_OS_ZOS
 PEGASUS_THREAD_KEY_TYPE Thread::_platform_thread_key = PEGASUS_THREAD_KEY_TYPE(-1);  TSDKeyType Thread::_platform_thread_key = TSDKeyType(-1);
 #else #else
 PEGASUS_THREAD_KEY_TYPE Thread::_platform_thread_key;  TSDKeyType Thread::_platform_thread_key;
 #endif #endif
 Boolean Thread::_key_initialized = false; Boolean Thread::_key_initialized = false;
 Boolean Thread::_key_error = false; Boolean Thread::_key_error = false;
Line 117 
Line 117 
  
  
 #ifndef PEGASUS_THREAD_EXIT_NATIVE #ifndef PEGASUS_THREAD_EXIT_NATIVE
 void Thread::exit_self(PEGASUS_THREAD_RETURN exit_code)  void Thread::exit_self(ThreadReturnType exit_code)
 { {
     // execute the cleanup stack and then return     // execute the cleanup stack and then return
    while( _cleanup.size() )    while( _cleanup.size() )
Line 133 
Line 133 
        }        }
    }    }
    _exit_code = exit_code;    _exit_code = exit_code;
    exit_thread(exit_code);     Threads::exit(exit_code);
    _handle.thid = 0;     Threads::clear(_handle.thid);
 } }
  
  
Line 153 
Line 153 
             return -1;             return -1;
         }         }
  
         if (pegasus_key_create(&Thread::_platform_thread_key) == 0)          if (TSDKey::create(&Thread::_platform_thread_key) == 0)
         {         {
             Tracer::trace(TRC_THREAD, Tracer::LEVEL4,             Tracer::trace(TRC_THREAD, Tracer::LEVEL4,
                 "Thread: able to create a thread key");                 "Thread: able to create a thread key");
Line 180 
Line 180 
         return NULL;         return NULL;
     }     }
     PEG_METHOD_EXIT();     PEG_METHOD_EXIT();
     return (Thread *)pegasus_get_thread_specific(_platform_thread_key);      return (Thread *)TSDKey::get_thread_specific(_platform_thread_key);
 } }
  
 void Thread::setCurrent(Thread * thrd) void Thread::setCurrent(Thread * thrd)
Line 188 
Line 188 
     PEG_METHOD_ENTER(TRC_THREAD, "Thread::setCurrent");     PEG_METHOD_ENTER(TRC_THREAD, "Thread::setCurrent");
     if (Thread::initializeKey() == 0)     if (Thread::initializeKey() == 0)
     {     {
         if (pegasus_set_thread_specific(          if (TSDKey::set_thread_specific(
                Thread::_platform_thread_key, (void *) thrd) == 0)                Thread::_platform_thread_key, (void *) thrd) == 0)
         {         {
             Tracer::trace(TRC_THREAD, Tracer::LEVEL4,             Tracer::trace(TRC_THREAD, Tracer::LEVEL4,
Line 314 
Line 314 
             }             }
             else             else
             {             {
                 pegasus_yield();                  Threads::yield();
             }             }
         }         }
     }     }
Line 323 
Line 323 
     }     }
 } }
  
 PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL ThreadPool::_loop(void* parm)  ThreadReturnType PEGASUS_THREAD_CDECL ThreadPool::_loop(void* parm)
 { {
     PEG_METHOD_ENTER(TRC_THREAD, "ThreadPool::_loop");     PEG_METHOD_ENTER(TRC_THREAD, "ThreadPool::_loop");
  
Line 362 
Line 362 
             pool->_idleThreads.remove(myself);             pool->_idleThreads.remove(myself);
             pool->_currentThreads--;             pool->_currentThreads--;
             PEG_METHOD_EXIT();             PEG_METHOD_EXIT();
             return((PEGASUS_THREAD_RETURN)1);              return((ThreadReturnType)1);
         }         }
  
         while (1)         while (1)
Line 379 
Line 379 
                 pool->_idleThreads.remove(myself);                 pool->_idleThreads.remove(myself);
                 pool->_currentThreads--;                 pool->_currentThreads--;
                 PEG_METHOD_EXIT();                 PEG_METHOD_EXIT();
                 return((PEGASUS_THREAD_RETURN)1);                  return((ThreadReturnType)1);
             }             }
  
             // When we awaken we reside on the _runningThreads queue, not the             // When we awaken we reside on the _runningThreads queue, not the
             // _idleThreads queue.             // _idleThreads queue.
  
             PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL* work)(void *) = 0;              ThreadReturnType (PEGASUS_THREAD_CDECL* work)(void *) = 0;
             void* parm = 0;             void* parm = 0;
             Semaphore* blocking_sem = 0;             Semaphore* blocking_sem = 0;
  
             try             try
             {             {
                 work = (PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *)(void *))                  work = (ThreadReturnType (PEGASUS_THREAD_CDECL *)(void *))
                     myself->reference_tsd("work func");                     myself->reference_tsd("work func");
                 myself->dereference_tsd();                 myself->dereference_tsd();
                 parm = myself->reference_tsd("work parm");                 parm = myself->reference_tsd("work parm");
Line 408 
Line 408 
                 pool->_idleThreads.remove(myself);                 pool->_idleThreads.remove(myself);
                 pool->_currentThreads--;                 pool->_currentThreads--;
                 PEG_METHOD_EXIT();                 PEG_METHOD_EXIT();
                 return((PEGASUS_THREAD_RETURN)1);                  return((ThreadReturnType)1);
             }             }
  
             if (work == 0)             if (work == 0)
Line 418 
Line 418 
                 break;                 break;
             }             }
  
             gettimeofday(lastActivityTime, NULL);              Time::gettimeofday(lastActivityTime);
  
             try             try
             {             {
Line 449 
Line 449 
             // put myself back onto the available list             // put myself back onto the available list
             try             try
             {             {
                 gettimeofday(lastActivityTime, NULL);                  Time::gettimeofday(lastActivityTime);
                 if (blocking_sem != 0)                 if (blocking_sem != 0)
                 {                 {
                     blocking_sem->signal();                     blocking_sem->signal();
Line 465 
Line 465 
                 PEGASUS_ASSERT(false);                 PEGASUS_ASSERT(false);
                 pool->_currentThreads--;                 pool->_currentThreads--;
                 PEG_METHOD_EXIT();                 PEG_METHOD_EXIT();
                 return((PEGASUS_THREAD_RETURN)1);                  return((ThreadReturnType)1);
             }             }
         }         }
     }     }
Line 481 
Line 481 
     }     }
  
     PEG_METHOD_EXIT();     PEG_METHOD_EXIT();
     return((PEGASUS_THREAD_RETURN)0);      return((ThreadReturnType)0);
 } }
  
 ThreadStatus ThreadPool::allocate_and_awaken( ThreadStatus ThreadPool::allocate_and_awaken(
     void* parm,     void* parm,
     PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL* work)(void *),      ThreadReturnType (PEGASUS_THREAD_CDECL* work)(void *),
     Semaphore* blocking)     Semaphore* blocking)
 { {
     PEG_METHOD_ENTER(TRC_THREAD, "ThreadPool::allocate_and_awaken");     PEG_METHOD_ENTER(TRC_THREAD, "ThreadPool::allocate_and_awaken");
Line 504 
Line 504 
             return PEGASUS_THREAD_UNAVAILABLE;             return PEGASUS_THREAD_UNAVAILABLE;
         }         }
         struct timeval start;         struct timeval start;
         gettimeofday(&start, NULL);          Time::gettimeofday(&start);
         Thread* th = 0;         Thread* th = 0;
  
         th = _idleThreads.remove_front();         th = _idleThreads.remove_front();
Line 539 
Line 539 
  
         th->delete_tsd("work func");         th->delete_tsd("work func");
         th->put_tsd("work func", NULL,         th->put_tsd("work func", NULL,
             sizeof( PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *)(void *)),              sizeof( ThreadReturnType (PEGASUS_THREAD_CDECL *)(void *)),
             (void *)work);             (void *)work);
         th->delete_tsd("work parm");         th->delete_tsd("work parm");
         th->put_tsd("work parm", NULL, sizeof(void *), parm);         th->put_tsd("work parm", NULL, sizeof(void *), parm);
Line 638 
Line 638 
     thread->delete_tsd("work func");     thread->delete_tsd("work func");
     thread->put_tsd(     thread->put_tsd(
         "work func", 0,         "work func", 0,
         sizeof(PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *)(void *)),          sizeof(ThreadReturnType (PEGASUS_THREAD_CDECL *)(void *)),
         (void *) 0);         (void *) 0);
     thread->delete_tsd("work parm");     thread->delete_tsd("work parm");
     thread->put_tsd("work parm", 0, sizeof(void *), 0);     thread->put_tsd("work parm", 0, sizeof(void *), 0);
Line 667 
Line 667 
  
     struct timeval now, finish, remaining;     struct timeval now, finish, remaining;
     Uint32 usec;     Uint32 usec;
     pegasus_gettimeofday(&now);      Time::gettimeofday(&now);
     pegasus_gettimeofday(&remaining);    // Avoid valgrind error      Time::gettimeofday(&remaining);    // Avoid valgrind error
  
     finish.tv_sec = start->tv_sec + interval->tv_sec;     finish.tv_sec = start->tv_sec + interval->tv_sec;
     usec = start->tv_usec + interval->tv_usec;     usec = start->tv_usec + interval->tv_usec;
Line 676 
Line 676 
     usec %= 1000000;     usec %= 1000000;
     finish.tv_usec = usec;     finish.tv_usec = usec;
  
     return (timeval_subtract(&remaining, &finish, &now) != 0);      return (Time::subtract(&remaining, &finish, &now) != 0);
 } }
  
 void ThreadPool::_deleteSemaphore(void *p) void ThreadPool::_deleteSemaphore(void *p)
Line 699 
Line 699 
  
     struct timeval* lastActivityTime =     struct timeval* lastActivityTime =
         (struct timeval *) ::operator new(sizeof(struct timeval));         (struct timeval *) ::operator new(sizeof(struct timeval));
     pegasus_gettimeofday(lastActivityTime);      Time::gettimeofday(lastActivityTime);
  
     th->put_tsd("last activity time", thread_data::default_delete,     th->put_tsd("last activity time", thread_data::default_delete,
         sizeof(struct timeval), (void *)lastActivityTime);         sizeof(struct timeval), (void *)lastActivityTime);
Line 713 
Line 713 
         return 0;         return 0;
     }     }
     _currentThreads++;     _currentThreads++;
     pegasus_yield();      Threads::yield();
  
     PEG_METHOD_EXIT();     PEG_METHOD_EXIT();
     return th;     return th;
Line 740 
Line 740 
     }     }
 } }
  
   // ATTN: not sure where to put this!
   #ifdef PEGASUS_ZOS_SECURITY
   bool isEnhancedSecurity=99;
   #endif
   
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.90  
changed lines
  Added in v.1.90.2.3

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2