0N/A/*
1879N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "runtime/threadLocalStorage.hpp"
1879N/A#ifdef TARGET_OS_FAMILY_linux
1879N/A# include "os_linux.inline.hpp"
1879N/A# include "thread_linux.inline.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_OS_FAMILY_solaris
1879N/A# include "os_solaris.inline.hpp"
1879N/A# include "thread_solaris.inline.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_OS_FAMILY_windows
1879N/A# include "os_windows.inline.hpp"
1879N/A# include "thread_windows.inline.hpp"
1879N/A#endif
2796N/A#ifdef TARGET_OS_FAMILY_bsd
2796N/A# include "os_bsd.inline.hpp"
2796N/A# include "thread_bsd.inline.hpp"
2796N/A#endif
0N/A
0N/A// static member initialization
0N/Aint ThreadLocalStorage::_thread_index = -1;
0N/A
0N/AThread* ThreadLocalStorage::get_thread_slow() {
0N/A return (Thread*) os::thread_local_storage_at(ThreadLocalStorage::thread_index());
0N/A}
0N/A
0N/Avoid ThreadLocalStorage::set_thread(Thread* thread) {
0N/A pd_set_thread(thread);
0N/A
0N/A // The following ensure that any optimization tricks we have tried
0N/A // did not backfire on us:
0N/A guarantee(get_thread() == thread, "must be the same thread, quickly");
0N/A guarantee(get_thread_slow() == thread, "must be the same thread, slowly");
0N/A}
0N/A
0N/Avoid ThreadLocalStorage::init() {
242N/A assert(!is_initialized(),
242N/A "More than one attempt to initialize threadLocalStorage");
0N/A pd_init();
0N/A set_thread_index(os::allocate_thread_local_storage());
0N/A generate_code_for_get_thread();
0N/A}
242N/A
242N/Abool ThreadLocalStorage::is_initialized() {
242N/A return (thread_index() != -1);
242N/A}