src/os/solaris/vm/threadCritical_solaris.cpp

changeset 435
a61af66fc99e
child 1845
f03d0a26bf83
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/os/solaris/vm/threadCritical_solaris.cpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,83 @@
     1.4 +/*
     1.5 + * Copyright 2001-2003 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "incls/_precompiled.incl"
    1.29 +#include "incls/_threadCritical_solaris.cpp.incl"
    1.30 +
    1.31 +// OS-includes here
    1.32 +#include <thread.h>
    1.33 +#include <synch.h>
    1.34 +
    1.35 +//
    1.36 +// See threadCritical.hpp for details of this class.
    1.37 +//
    1.38 +// For some reason, we don't do locking until the
    1.39 +// os::init() call completes. I'm not sure why this
    1.40 +// is, and have left it that way for now. This should
    1.41 +// be reviewed later.
    1.42 +
    1.43 +static  mutex_t  global_mut;
    1.44 +static  thread_t global_mut_owner = -1;
    1.45 +static  int      global_mut_count = 0;
    1.46 +static  bool     initialized = false;
    1.47 +
    1.48 +ThreadCritical::ThreadCritical() {
    1.49 +  if (initialized) {
    1.50 +    thread_t owner = thr_self();
    1.51 +    if (global_mut_owner != owner) {
    1.52 +      if (os::Solaris::mutex_lock(&global_mut))
    1.53 +        fatal1("ThreadCritical::ThreadCritical: mutex_lock failed (%s)", strerror(errno));
    1.54 +      assert(global_mut_count == 0, "must have clean count");
    1.55 +      assert(global_mut_owner == -1, "must have clean owner");
    1.56 +    }
    1.57 +    global_mut_owner = owner;
    1.58 +    ++global_mut_count;
    1.59 +  } else {
    1.60 +    assert (Threads::number_of_threads() == 0, "valid only during initialization");
    1.61 +  }
    1.62 +}
    1.63 +
    1.64 +ThreadCritical::~ThreadCritical() {
    1.65 +  if (initialized) {
    1.66 +    assert(global_mut_owner == thr_self(), "must have correct owner");
    1.67 +    assert(global_mut_count > 0, "must have correct count");
    1.68 +    --global_mut_count;
    1.69 +    if (global_mut_count == 0) {
    1.70 +      global_mut_owner = -1;
    1.71 +      if (os::Solaris::mutex_unlock(&global_mut))
    1.72 +        fatal1("ThreadCritical::~ThreadCritical: mutex_unlock failed (%s)", strerror(errno));
    1.73 +    }
    1.74 +  } else {
    1.75 +    assert (Threads::number_of_threads() == 0, "valid only during initialization");
    1.76 +  }
    1.77 +}
    1.78 +
    1.79 +void ThreadCritical::initialize() {
    1.80 +  // This method is called at the end of os::init(). Until
    1.81 +  // then, we don't do real locking.
    1.82 +  initialized = true;
    1.83 +}
    1.84 +
    1.85 +void ThreadCritical::release() {
    1.86 +}

mercurial