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

  1 karl  1.42 //%2004////////////////////////////////////////////////////////////////////////
  2 mike  1.2  //
  3 karl  1.42 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4            // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5            // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6 karl  1.34 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.42 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 mike  1.2  //
 10            // Permission is hereby granted, free of charge, to any person obtaining a copy
 11 kumpf 1.18 // of this software and associated documentation files (the "Software"), to
 12            // deal in the Software without restriction, including without limitation the
 13            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 14 mike  1.2  // sell copies of the Software, and to permit persons to whom the Software is
 15            // furnished to do so, subject to the following conditions:
 16            // 
 17 kumpf 1.18 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 18 mike  1.2  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 19            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 20 kumpf 1.18 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 21            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 22            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 23 mike  1.2  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 24            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 25            //
 26            //==============================================================================
 27            //
 28            // Author: Mike Day (mdday@us.ibm.com)
 29            //
 30            // Modified By: Markus Mueller
 31 kumpf 1.36 //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
 32 a.arora 1.37 //              Amit K Arora, IBM (amita@in.ibm.com) for PEP#101
 33 mike    1.2  //
 34              //%/////////////////////////////////////////////////////////////////////////////
 35              
 36              #ifndef Pegasus_Thread_h
 37              #define Pegasus_Thread_h
 38 kumpf   1.26 
 39              #include <cstring>
 40 mike    1.2  #include <Pegasus/Common/Config.h>
 41 mike    1.5  #include <Pegasus/Common/IPC.h>
 42 kumpf   1.23 #include <Pegasus/Common/InternalException.h>
 43 mike    1.2  #include <Pegasus/Common/DQueue.h>
 44 chuck   1.28 #include <Pegasus/Common/AcceptLanguages.h>  // l10n
 45 kumpf   1.22 #include <Pegasus/Common/Linkage.h>
 46 a.arora 1.37 #include <Pegasus/Common/AutoPtr.h>
 47 mike    1.2  
 48              PEGASUS_NAMESPACE_BEGIN
 49              
 50              class PEGASUS_COMMON_LINKAGE cleanup_handler
 51              {
 52              
 53                 public:
 54                    cleanup_handler( void (*routine)(void *), void *arg  ) : _routine(routine), _arg(arg)  {}
 55                    ~cleanup_handler()  {; }
 56                    inline Boolean operator==(const void *key) const
 57                    { 
 58              	 if(key == (void *)_routine) 
 59              	    return true; 
 60              	 return false; 
 61                    }
 62                    inline Boolean operator ==(const cleanup_handler & b) const 
 63                    {
 64              	 return(operator==((const void *)b._routine));
 65                    }
 66                 private:
 67                    void execute(void) { _routine(_arg); } 
 68 mike    1.2        cleanup_handler();
 69                    void (*_routine)(void *);
 70              
 71                    void *_arg; 
 72                    PEGASUS_CLEANUP_HANDLE _cleanup_buffer;
 73                    friend class DQueue<class cleanup_handler>;
 74                    friend class Thread;
 75              };
 76              
 77              ///////////////////////////////////////////////////////////////////////////////
 78              
 79              
 80              class  PEGASUS_COMMON_LINKAGE thread_data
 81              {
 82              
 83                 public:
 84                    static void default_delete(void *data);
 85                    
 86 kumpf   1.7        thread_data( const Sint8 *key ) : _delete_func(NULL) , _data(NULL), _size(0)
 87 mike    1.2        {
 88              	 PEGASUS_ASSERT(key != NULL);
 89              	 size_t keysize = strlen(key);
 90              	 _key = new Sint8 [keysize + 1];
 91              	 memcpy(_key, key, keysize);
 92              	 _key[keysize] = 0x00;
 93              	 
 94                    }
 95                
 96 kumpf   1.7        thread_data(const Sint8 *key, size_t size) : _delete_func(default_delete), _size(size)
 97 mike    1.2        {
 98              	 PEGASUS_ASSERT(key != NULL);
 99              	 size_t keysize = strlen(key);
100              	 _key = new Sint8 [keysize + 1];
101              	 memcpy(_key, key, keysize);
102              	 _key[keysize] = 0x00;
103              	 _data = ::operator new(_size) ;
104              
105                    }
106              
107 kumpf   1.7        thread_data(const Sint8 *key, size_t size, void *data) : _delete_func(default_delete), _size(size)
108 mike    1.2        {
109              	 PEGASUS_ASSERT(key != NULL);
110              	 PEGASUS_ASSERT(data != NULL);
111              	 size_t keysize = strlen(key);
112              
113              	 _key = new Sint8[keysize + 1];
114              	 memcpy(_key, key, keysize);
115              	 _key[keysize] = 0x00;
116              	 _data = ::operator new(_size);
117              	 memcpy(_data, data, size);
118                    }
119              
120                    ~thread_data() 
121                    { 
122              	 if( _data != NULL) 
123              	    if(_delete_func != NULL)
124 sage    1.9              {
125 mike    1.2  	       _delete_func( _data ); 
126 sage    1.9              }
127 mike    1.2  	 if( _key != NULL )
128              	    delete [] _key;
129                    }  
130              
131 konrad.r 1.40       /**
132                      * This function is used to put data in thread space.
133                      *
134                      * Be aware that there is NOTHING in place to stop 
135                      * other users of the thread to remove this data. 
136                      * Or change the data.
137                      *
138                      * You, the developer has to make sure that there are 
139                      * no situations in which this can arise (ie, have a 
140                      * lock for the function which manipulates the TSD.
141                      */
142 mike     1.2        void put_data(void (*del)(void *), size_t size, void *data ) throw(NullPointer)
143                     {
144               	 if(_data != NULL)
145               	    if(_delete_func != NULL)
146               	       _delete_func(_data);
147               
148               	 _delete_func = del;
149               	 _data = data;
150               	 _size = size;
151               	 return ;
152                     }
153               
154                     size_t get_size(void) { return _size; }
155               
156 konrad.r 1.40       /**
157                      * This function is used to retrieve data from the 
158                      * TSD, the thread specific data. 
159                      *
160                      * Be aware that there is NOTHING in place to stop 
161                      * other users of the thread to change the data you
162                      * get from this function.
163                      *
164                      * You, the developer has to make sure that there are 
165                      * no situations in which this can arise (ie, have a 
166                      * lock for the function which manipulates the TSD.
167                      */
168 mike     1.2        void get_data(void **data, size_t *size) 
169                     {  
170               	 if(data == NULL || size == NULL)
171               	    throw NullPointer();
172               	 
173               	 *data = _data;
174               	 *size = _size;
175               	 return;
176               	 
177                     }
178               
179 kumpf    1.17       void copy_data(void **buf, size_t *size) throw(NullPointer)
180 mike     1.2        {
181               	 if((buf == NULL) || (size == NULL)) 
182               	    throw NullPointer() ; 
183               	 *buf = ::operator new(_size);
184               	 *size = _size;
185               	 memcpy(*buf, _data, _size);
186               	 return;
187                     }
188                     
189                     inline Boolean operator==(const void *key) const 
190                     { 
191               	 if ( ! strcmp(_key, (Sint8 *)key)) 
192               	    return(true); 
193               	 return(false);
194                     } 
195 mday     1.8  
196 mike     1.2        inline Boolean operator==(const thread_data& b) const
197                     {
198               	 return(operator==((const void *)b._key));
199                     }
200               
201                  private:
202                     void (*_delete_func) (void *data) ;
203                     thread_data();
204                     void *_data;
205                     size_t _size;
206                     Sint8 *_key;
207               
208                     friend class DQueue<thread_data>;
209                     friend class Thread;
210               };
211               
212 denise.eckstein 1.42.2.1 enum ThreadStatus {
213                                  PEGASUS_THREAD_OK = 1, /* No problems */
214                                  PEGASUS_THREAD_INSUFFICIENT_RESOURCES, /* Can't allocate a thread. Not enough
215                                                                  memory. Try again later */
216                                  PEGASUS_THREAD_SETUP_FAILURE, /* Could not allocate into the thread specific
217                                                           data storage. */
218                                  PEGASUS_THREAD_UNAVAILABLE  /* Service is being destroyed and no new threads can
219                                                         be provided. */
220                          };
221 mike            1.2      
222                          ///////////////////////////////////////////////////////////////////////////
223                          
224                          class PEGASUS_COMMON_LINKAGE ThreadPool;
225                          
226                          class PEGASUS_COMMON_LINKAGE Thread
227                          {
228                          
229                             public:
230                                Thread( PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *start )(void *),
231                          	      void *parameter, Boolean detached );
232                          
233                                ~Thread();
234                          
235 kumpf           1.36           /**
236                                    Start the thread.
237 denise.eckstein 1.42.2.1           @return PEGASUS_THREAD_OK if the thread is started successfully,
238                                            PEGASUS_THREAD_INSUFFICIENT_RESOURCES if the resources necessary
239                                            to start the thread are not currently available.
240                                            PEGASUS_THREAD_SETUP_FAILURE if the thread could not
241                                            be create properly - check the 'errno' value for specific operating
242                                            system return code.
243 kumpf           1.36            */
244 denise.eckstein 1.42.2.1       ThreadStatus run();
245 mike            1.2      
246                                // get the user parameter 
247                                inline void *get_parm(void) { return _thread_parm; }
248                          
249                                // send the thread a signal -- may not be appropriate due to Windows 
250                                //  void kill(int signum); 
251                          
252                                // cancellation must be deferred (not asynchronous)
253                                // for user-level threads the thread itself can decide
254                                // when it should die. 
255                                void cancel(void);
256                          
257                                // cancel if there is a pending cancellation request
258 kumpf           1.25           void test_cancel(void);
259 mike            1.2      
260 mday            1.3            Boolean is_cancelled(void);
261                                
262 mike            1.2            // for user-level threads  - put the calling thread
263                                // to sleep and jump to the thread scheduler. 
264                                // platforms with preemptive scheduling and native threads 
265                                // can define this to be a no-op. 
266                                // platforms without preemptive scheduling like NetWare 
267                                // or gnu portable threads will have an existing 
268                                // routine that can be mapped to this method 
269                          
270                                void thread_switch(void);
271                          
272 david.eger      1.27     #if defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU)
273 mike            1.2            // suspend this thread 
274                                void suspend(void) ;
275                          
276                                // resume this thread
277                                void resume(void) ;
278                          #endif
279                          
280                                static void sleep(Uint32 msec) ;
281                          
282                                // block the calling thread until this thread terminates
283                                void join( void );
284                                void thread_init(void);
285                          
286                                // thread routine needs to call this function when
287                                // it is ready to exit
288 kumpf           1.25           void exit_self(PEGASUS_THREAD_RETURN return_code) ;
289 mike            1.2      
290                                // stack of functions to be called when thread terminates
291                                // will be called last in first out (LIFO)
292                                void cleanup_push( void (*routine) (void *), void *parm ) throw(IPCException);
293                                void cleanup_pop(Boolean execute = true) throw(IPCException);
294                          
295                                // create and initialize a tsd
296 kumpf           1.7            inline void create_tsd(const Sint8 *key, int size, void *buffer) throw(IPCException)
297 mike            1.2            {
298 a.arora         1.37             AutoPtr<thread_data> tsd(new thread_data(key, size, buffer));
299 a.arora         1.38             _tsd.insert_first(tsd.get());
300 a.arora         1.37             tsd.release();
301 mike            1.2            }
302                          
303                                // get the buffer associated with the key
304                                // NOTE: this call leaves the tsd LOCKED !!!! 
305 kumpf           1.7            inline void *reference_tsd(const Sint8 *key) throw(IPCException)
306 mike            1.2            {
307                          	 _tsd.lock(); 
308 kumpf           1.7      	 thread_data *tsd = _tsd.reference((const void *)key);
309 mike            1.2      	 if(tsd != NULL)
310                          	    return( (void *)(tsd->_data) );
311                          	 else
312                          	    return(NULL);
313                                }
314                          
315 kumpf           1.7            inline void *try_reference_tsd(const Sint8 *key) throw(IPCException)
316 mike            1.2            {
317                          	 _tsd.try_lock();
318 kumpf           1.7      	 thread_data *tsd = _tsd.reference((const void *)key);
319 mike            1.2      	 if(tsd != NULL)
320                          	    return((void *)(tsd->_data) );
321                          	 else
322                          	    return(NULL);
323                                }
324                                
325                          
326                                // release the lock held on the tsd
327                                // NOTE: assumes a corresponding and prior call to reference_tsd() !!!
328                                inline void dereference_tsd(void) throw(IPCException)
329                                {
330                          	 _tsd.unlock();
331                                }
332                          
333                                // delete the tsd associated with the key
334 kumpf           1.7            inline void delete_tsd(const Sint8 *key) throw(IPCException)
335 mike            1.2            {
336 a.arora         1.37              AutoPtr<thread_data> tsd(_tsd.remove((const void *)key));
337 mike            1.2            }
338                          
339 kumpf           1.14           // Note: Caller must delete the thread_data object returned (if not null)
340 kumpf           1.7            inline void *remove_tsd(const Sint8 *key) throw(IPCException)
341 mike            1.2            {
342 kumpf           1.7      	 return(_tsd.remove((const void *)key));
343 mike            1.2            }
344                                
345                                inline void empty_tsd(void) throw(IPCException)
346                                {
347 mday            1.33              
348                          	 try 
349                          	 {
350                          	    
351                          	    _tsd.try_lock();
352                          	 }
353                          	 catch(IPCException&)
354                          	 {
355                          	    return;
356                          	 }
357                          	 
358 a.arora         1.37     	 AutoPtr<thread_data> tsd(_tsd.next(0));
359                          	 while(tsd.get())
360 mday            1.33     	 {
361 a.arora         1.37     	    _tsd.remove_no_lock(tsd.get());
362                          	    tsd.reset(_tsd.next(0));
363 mday            1.33     	 }
364                          	 _tsd.unlock();
365 mike            1.2            }
366                                
367                                // create or re-initialize tsd associated with the key
368 kumpf           1.14           // if the tsd already exists, delete the existing buffer
369                                void put_tsd(const Sint8 *key, void (*delete_func)(void *), Uint32 size, void *value) 
370 mike            1.2      	 throw(IPCException)
371                          
372                                {
373                          	 PEGASUS_ASSERT(key != NULL);
374 a.arora         1.37     	 AutoPtr<thread_data> tsd ;
375                          	 tsd.reset(_tsd.remove((const void *)key));  // may throw an IPC exception 
376                          	 tsd.reset();
377                          	 AutoPtr<thread_data> ntsd(new thread_data(key));
378 mike            1.2      	 ntsd->put_data(delete_func, size, value);
379 a.arora         1.37     	 try { _tsd.insert_first(ntsd.get()); }
380                          	 catch(IPCException& e) { e = e; throw; }
381                               ntsd.release();
382 mike            1.2            }
383                                inline PEGASUS_THREAD_RETURN get_exit(void) { return _exit_code; }
384                                inline PEGASUS_THREAD_TYPE self(void) {return pegasus_thread_self(); }
385                          
386                                PEGASUS_THREAD_HANDLE getThreadHandle() {return _handle;}
387                          
388                                inline Boolean operator==(const void *key) const 
389                                { 
390                          	 if ( (void *)this == key) 
391                          	    return(true); 
392                          	 return(false);
393                                } 
394                                inline Boolean operator==(const Thread & b) const
395                                {
396                          	 return(operator==((const void *)&b ));
397                                }
398                          
399                                void detach(void);
400 chuck           1.28           
401 chuck           1.29           //
402                                //  Gets the Thread object associated with the caller's thread.
403 chuck           1.31           //  Note: this may return NULL if no Thread object is associated
404                                //  with the caller's thread.
405 chuck           1.29           //
406 chuck           1.28           static Thread * getCurrent();  // l10n
407 chuck           1.29     
408                                //
409 chuck           1.31           //  Sets the Thread object associated with the caller's thread.
410                                //  Note: the Thread object must be placed on the heap.
411 chuck           1.29           //
412                                static void setCurrent(Thread * thrd); // l10n	
413                          
414                                //
415 chuck           1.31           //  Gets the AcceptLanguages object associated with the caller's
416 chuck           1.29           //  Thread.
417 chuck           1.31           //  Note: this may return NULL if no Thread object, or no
418                                //  AcceptLanguages object, is associated with the caller's thread.  
419 chuck           1.29           //      
420 chuck           1.28           static AcceptLanguages * getLanguages(); //l10n
421                                
422 chuck           1.29           //
423 chuck           1.31           //  Sets the AcceptLanguages object associated with the caller's
424 chuck           1.29           //  Thread.
425 chuck           1.31           //  Note: a Thread object must have been previously associated with
426                                //  the caller's thread. 
427                                //  Note: the AcceptLanguages object must be placed on the heap.
428 chuck           1.29           //  
429 chuck           1.28           static void setLanguages(AcceptLanguages *langs); //l10n
430                                
431 chuck           1.29           //
432 chuck           1.31           //  Removes the AcceptLanguages object associated with the caller's
433 chuck           1.29           //  Thread.
434                                //  
435 chuck           1.28           static void clearLanguages(); //l10n      
436 mike            1.2        
437                             private:
438                                Thread();
439 chuck           1.29     
440                                static Sint8 initializeKey();  // l10n
441                          
442 kumpf           1.7            inline void create_tsd(const Sint8 *key ) throw(IPCException)
443 mike            1.2            {
444 a.arora         1.37     	 AutoPtr<thread_data> tsd(new thread_data(key));
445 a.arora         1.38     	 _tsd.insert_first(tsd.get());
446                          	 tsd.release();
447 mike            1.2            }
448                                PEGASUS_THREAD_HANDLE _handle;
449                                Boolean _is_detached;
450                                Boolean _cancel_enabled;
451                                Boolean _cancelled; 
452                            
453                                PEGASUS_SEM_HANDLE _suspend_count;
454                          
455                                // always pass this * as the void * parameter to the thread
456                                // store the user parameter in _thread_parm 
457                          
458                                PEGASUS_THREAD_RETURN  ( PEGASUS_THREAD_CDECL *_start)(void *) ;
459                                DQueue<class cleanup_handler> _cleanup;
460                                DQueue<class thread_data> _tsd;
461                          
462                                void *_thread_parm;
463                                PEGASUS_THREAD_RETURN _exit_code;
464                                static Boolean _signals_blocked;
465 chuck           1.28           static PEGASUS_THREAD_KEY_TYPE _platform_thread_key;  //l10n
466 chuck           1.30           static Boolean _key_initialized; // l10n 
467                                static Boolean _key_error; // l10n      
468 mike            1.2            friend class ThreadPool;
469                          } ;
470                          
471                          
472                          class PEGASUS_COMMON_LINKAGE ThreadPool
473                          {
474                             public:
475                          
476                                ThreadPool(Sint16 initial_size,
477 kumpf           1.7      		 const Sint8 *key,
478 mike            1.2      		 Sint16 min,
479                          		 Sint16 max,
480                          		 struct timeval & alloc_wait,
481                          		 struct timeval & dealloc_wait, 
482                          		 struct timeval & deadlock_detect);
483                                
484                                ~ThreadPool(void);
485                          
486 kumpf           1.36           /**
487                                    Allocate and start a thread to do a unit of work.
488                                    @param parm A generic parameter to pass to the thread
489                                    @param work A pointer to the function that is to be executed by
490                                                the thread
491                                    @param blocking A pointer to an optional semaphore which, if
492                                                    specified, is signaled after the thread finishes
493                                                    executing the work function
494 denise.eckstein 1.42.2.1           @return PEGASUS_THREAD_OK if the thread is started successfully,
495                                            PEGASUS_THREAD_INSUFFICIENT_RESOURCES  if the
496 kumpf           1.36                       resources necessary to start the thread are not currently
497 denise.eckstein 1.42.2.1                   available.  PEGASUS_THREAD_SETUP_FAILURE if the thread
498                                            could not be setup properly. PEGASUS_THREAD_UNAVAILABLE
499                                            if this service is shutting down and no more threads can
500                                            be allocated.
501                                    @exception IPCException
502 kumpf           1.36            */
503 denise.eckstein 1.42.2.1       ThreadStatus allocate_and_awaken(
504                                    void* parm,
505                                    PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL* work)(void *),
506                                    Semaphore* blocking = 0);
507 mday            1.8      
508                                Uint32 kill_dead_threads( void ) 
509 mike            1.2      	 throw(IPCException);
510                                
511                                void get_key(Sint8 *buf, int bufsize);
512                          
513                                inline Boolean operator==(const void *key) const 
514                                { 
515                          	 if ( ! strncmp( reinterpret_cast<Sint8 *>(const_cast<void *>(key)), _key, 16  )) 
516                          	    return(true); 
517                          	 return(false);
518                                } 
519                                inline Boolean operator==(const ThreadPool & b) const
520                                {
521                          	 return(operator==((const void *) b._key ));
522                                }
523                          
524                                inline void set_min_threads(Sint16 min)
525                                {
526                          	 _min_threads = min;
527                                }
528                                
529                                inline Sint16 get_min_threads(void) const
530 mike            1.2            {
531                          	 return _min_threads;
532                                }
533                          
534                                inline void set_max_threads(Sint16 max)
535                                {
536                          	 _max_threads = max;
537                                }
538                                
539                                inline Sint16 get_max_threads(void) const
540                                {
541                          	 return _max_threads;
542                                }
543                                
544                                inline void set_allocate_wait(const struct timeval & alloc_wait)
545                                {
546                          	 _allocate_wait.tv_sec = alloc_wait.tv_sec;
547                          	 _allocate_wait.tv_usec = alloc_wait.tv_usec;
548                                }
549                                
550                                inline struct timeval *get_allocate_wait(struct timeval *buffer) const
551 mike            1.2            {
552                          	 if(buffer == 0)
553                          	    throw NullPointer();
554                          	 buffer->tv_sec = _allocate_wait.tv_sec;
555                          	 buffer->tv_usec = _allocate_wait.tv_usec;
556                          	 return buffer;
557                                }
558                          
559                                inline void set_deallocate_wait(const struct timeval & dealloc_wait)
560                                {
561                          	 _deallocate_wait.tv_sec = dealloc_wait.tv_sec;
562                          	 _deallocate_wait.tv_usec = dealloc_wait.tv_usec;
563                                }
564                                
565                                inline struct timeval *get_deallocate_wait(struct timeval *buffer) const
566                                {
567                          	 if(buffer == 0)
568                          	    throw NullPointer();
569                          	 buffer->tv_sec = _deallocate_wait.tv_sec;
570                          	 buffer->tv_usec = _deallocate_wait.tv_usec;
571                          	 return buffer;
572 mike            1.2            }
573                          
574                                inline void set_deadlock_detect(const struct timeval & deadlock)
575                                {
576                          	 _deadlock_detect.tv_sec = deadlock.tv_sec;
577                          	 _deadlock_detect.tv_usec = deadlock.tv_usec;
578                                }
579                                
580                                inline Uint32 running_count(void)
581                                {
582                          	 return _running.count();
583                                }
584 mday            1.19           
585                                inline Uint32 pool_count(void)
586                          	{
587                          	  return _pool.count();
588                          	}
589                                inline Uint32 dead_count(void)
590                          	{
591                          	  return _dead.count();
592                          	}
593                                
594 mike            1.2            
595                                static Boolean check_time(struct timeval *start, struct timeval *interval);
596                          
597 mday            1.21           Boolean operator ==(const ThreadPool & p)
598                                {
599                          	 return operator==((const void *)&p);
600                                }
601                          
602                                Boolean operator ==(const void *p)
603                                {
604                          	 if((void *)this == p)
605                          	    return true;
606                          	 return false;
607                                }
608                                
609                                static void kill_idle_threads(void);
610                                
611 mike            1.2         private:
612                                ThreadPool(void);
613                                Sint16 _max_threads;
614                                Sint16 _min_threads;
615                                AtomicInt _current_threads;
616                                struct timeval _allocate_wait;
617                                struct timeval _deallocate_wait;
618                                struct timeval _deadlock_detect;
619                                static PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL _loop(void *);
620                                Sint8 _key[17];
621                                DQueue<Thread> _pool;
622                                DQueue<Thread> _running;
623                                DQueue<Thread> _dead;
624                                AtomicInt _dying;
625 mday            1.32           
626 mike            1.2            static void _sleep_sem_del(void *p);
627                                
628                                void _check_deadlock(struct timeval *start) throw(Deadlock);
629                                Boolean _check_deadlock_no_throw(struct timeval *start);
630                                Boolean _check_dealloc(struct timeval *start);
631                                Thread *_init_thread(void) throw(IPCException);
632                                void _link_pool(Thread *th) throw(IPCException);
633                                static PEGASUS_THREAD_RETURN  _undertaker(void *);
634 konrad.r        1.39           static PEGASUS_THREAD_RETURN  _graveyard(Thread *);
635 mday            1.21           static DQueue<ThreadPool> _pools;
636 mike            1.2       };
637                          
638                          
639                          
640                          
641                          #if defined(PEGASUS_OS_TYPE_WINDOWS)
642                          # include "ThreadWindows_inline.h"
643 sage            1.6      #elif defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
644                          # include "ThreadzOS_inline.h"
645 mike            1.2      #elif defined(PEGASUS_OS_TYPE_UNIX)
646                          # include "ThreadUnix_inline.h"
647                          #endif
648                          
649                          PEGASUS_NAMESPACE_END
650                          
651                          #endif // Pegasus_Thread_h

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2