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

  1 karl  1.6 //%2006////////////////////////////////////////////////////////////////////////
  2 gs.keenan 1.1 //
  3               // 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               // IBM Corp.; EMC Corporation, The Open Group.
  7               // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8               // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 carson.hovey 1.2 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10                  // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl         1.6 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12                  // EMC Corporation; Symantec Corporation; The Open Group.
 13 gs.keenan    1.1 //
 14                  // Permission is hereby granted, free of charge, to any person obtaining a copy
 15                  // of this software and associated documentation files (the "Software"), to
 16                  // deal in the Software without restriction, including without limitation the
 17                  // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 18                  // sell copies of the Software, and to permit persons to whom the Software is
 19                  // furnished to do so, subject to the following conditions:
 20                  // 
 21                  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22                  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 23                  // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 24                  // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 25                  // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 26                  // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 27                  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 28                  // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 29                  //
 30                  //==============================================================================
 31                  //
 32                  // Author: Markus Mueller (sedgewick_de@yahoo.de)
 33                  //
 34 gs.keenan    1.3 // Modified By: Sean Keenan, Hewlett-Packard Company (sean.keenan@hp.com)
 35 gs.keenan    1.1 //
 36                  //%/////////////////////////////////////////////////////////////////////////////
 37                  
 38 gs.keenan    1.5 // These must be global to all threads
 39                  
 40                  static int stackMul = 2;
 41                  static bool doneOnce = false;
 42                  
 43 gs.keenan    1.1 PEGASUS_NAMESPACE_BEGIN
 44                  
 45 gs.keenan    1.4 static sigset_t *block_signal_mask(sigset_t * sig)
 46 gs.keenan    1.1 {
 47 gs.keenan    1.4   sigemptyset(sig);
 48                    // should not be used for main()
 49                    sigaddset(sig, SIGHUP);
 50                    sigaddset(sig, SIGINT);
 51                    // maybe useless, since KILL can't be blocked according to POSIX
 52                    sigaddset(sig, SIGKILL);
 53                  
 54                    sigaddset(sig, SIGABRT);
 55                    sigaddset(sig, SIGALRM);
 56                    sigaddset(sig, SIGPIPE);
 57 gs.keenan    1.3 
 58 gs.keenan    1.4   sigprocmask(SIG_BLOCK, sig, NULL);
 59                    return sig;
 60 gs.keenan    1.1 }
 61                  
 62                  ////////////////////////////////////////////////////////////////////////////
 63                  
 64 gs.keenan    1.3 Thread::Thread(
 65 gs.keenan    1.4 	PEGASUS_THREAD_RETURN(PEGASUS_THREAD_CDECL * start) (void *),
 66                  	void *parameter,
 67                  	Boolean detached)
 68 gs.keenan    1.5 :_is_detached(detached),
 69                  _cancel_enabled(true),
 70                  _cancelled(false),
 71                  _suspend_count(),
 72                  _start(start),
 73                  _cleanup(true),
 74                  _tsd(true),
 75                  _thread_parm(parameter),
 76                  _exit_code(0)
 77 gs.keenan    1.1 {
 78 gs.keenan    1.4   pthread_attr_init(&_handle.thatt);
 79                    size_t stacksize;
 80                  
 81                    // 
 82 gs.keenan    1.5   // This code uses a, 'hidden' (non-documented), VMS only, logical 
 83                    //  name (environment variable), PEGASUS_VMS_THREAD_STACK_MULTIPLIER,
 84                    //  to allow in the field adjustment of the thread stack size.
 85                    //
 86                    // We only check for the logical name once to not have an
 87                    //  impact on performance.
 88                    // 
 89                    // Note:  This code may have problems in a multithreaded environment
 90                    //  with the setting of doneOnce to true.
 91                    // 
 92                    // Current code in Cimserver and the clients do some serial thread
 93                    //  creations first so this is not a problem now.
 94                    // 
 95                    if (!doneOnce)
 96                    {
 97                      // 
 98                      // Test for the logical name.
 99                      // 
100                      const char *env = getenv("PEGASUS_VMS_THREAD_STACK_MULTIPLIER");
101                      if (env)
102                      {
103 gs.keenan    1.5       // 
104                        // The logical is defined, convert it to a number and
105                        //  test it's validity.
106                        // 
107                        char *end = NULL;
108                        stackMul = strtol(env, &end, 10);
109                        if (*end)
110                        {
111                          // 
112                          // Not valid, set to the default multiplier
113                          // 
114                          stackMul = 2;
115                        }
116                      }
117                      // 
118                      // Don't come through here again.
119                      // 
120                      doneOnce = true;
121                    }
122                  
123                    // 
124 gs.keenan    1.4   // Get the system default thread stack size
125                    // 
126                    if (pthread_attr_getstacksize(&_handle.thatt, &stacksize) == 0)
127                    {
128                      // 
129 gs.keenan    1.5     // Replace it with the VMS default thread stack size.
130 gs.keenan    1.4     // 
131 gs.keenan    1.5     int rc = pthread_attr_setstacksize(&_handle.thatt, stacksize * stackMul);
132 gs.keenan    1.4     // 
133                      // Make sure it succeeded
134                      // 
135                      PEGASUS_ASSERT(rc == 0);
136                    }
137 gs.keenan    1.1 
138 gs.keenan    1.4   _handle.thid = 0;
139 gs.keenan    1.1 }
140                  
141                  Thread::~Thread()
142                  {
143 gs.keenan    1.4   try
144                    {
145                      join();
146                      pthread_attr_destroy(&_handle.thatt);
147                  
148                      empty_tsd();
149                    }
150                    catch(...)
151                    {
152                      // Do not allow the destructor to throw an exception
153                    }
154 gs.keenan    1.1 }
155                  
156                  PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2