src/hotspot/os/bsd/threadCritical_bsd.cpp
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 14583 hotspot/src/os/bsd/vm/threadCritical_bsd.cpp@d70ee55535f4
child 47524 97569cf468f4
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     1
/*
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     2
 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     4
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     8
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    13
 * accompanied this code).
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    14
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    18
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    21
 * questions.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    22
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    23
 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    24
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    25
#include "precompiled.hpp"
14583
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents: 10565
diff changeset
    26
#include "runtime/thread.inline.hpp"
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    27
#include "runtime/threadCritical.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    28
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    29
// put OS-includes here
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    30
# include <pthread.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    31
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    32
//
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    33
// See threadCritical.hpp for details of this class.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    34
//
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    35
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    36
static pthread_t             tc_owner = 0;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    37
static pthread_mutex_t       tc_mutex = PTHREAD_MUTEX_INITIALIZER;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    38
static int                   tc_count = 0;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    39
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    40
void ThreadCritical::initialize() {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    41
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    42
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    43
void ThreadCritical::release() {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    44
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    45
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    46
ThreadCritical::ThreadCritical() {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    47
  pthread_t self = pthread_self();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    48
  if (self != tc_owner) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    49
    int ret = pthread_mutex_lock(&tc_mutex);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    50
    guarantee(ret == 0, "fatal error with pthread_mutex_lock()");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    51
    assert(tc_count == 0, "Lock acquired with illegal reentry count.");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    52
    tc_owner = self;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    53
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    54
  tc_count++;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    55
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    56
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    57
ThreadCritical::~ThreadCritical() {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    58
  assert(tc_owner == pthread_self(), "must have correct owner");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    59
  assert(tc_count > 0, "must have correct count");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    60
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    61
  tc_count--;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    62
  if (tc_count == 0) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    63
    tc_owner = 0;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    64
    int ret = pthread_mutex_unlock(&tc_mutex);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    65
    guarantee(ret == 0, "fatal error with pthread_mutex_unlock()");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    66
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    67
}