Path: blob/master/src/hotspot/os/aix/misc_aix.hpp
40930 views
/*1* Copyright (c) 2012, 2015 SAP SE. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/232425#ifndef OS_AIX_MISC_AIX_HPP26#define OS_AIX_MISC_AIX_HPP2728// misc_aix.hpp, misc_aix.cpp: convenience functions needed for the OpenJDK AIX29// port.30#include "utilities/globalDefinitions.hpp"31#include "runtime/globals.hpp"32#include "utilities/debug.hpp"3334#include <pthread.h>3536// Trace if verbose to tty.37#define trcVerbose(fmt, ...) { \38if (Verbose) { \39fprintf(stderr, fmt, ##__VA_ARGS__); \40fputc('\n', stderr); fflush(stderr); \41} \42}4344#define assert0(b) assert((b), "")45#define guarantee0(b) guarantee((b), "")46template <class T1, class T2> bool is_aligned_to(T1 what, T2 alignment) {47return (((uintx)(what)) & (((uintx)(alignment)) - 1)) == 0 ? true : false;48}4950// CritSect: simple critical section implementation using pthread mutexes.51namespace MiscUtils {52typedef pthread_mutex_t critsect_t;5354void init_critsect(MiscUtils::critsect_t* cs);55void free_critsect(MiscUtils::critsect_t* cs);56void enter_critsect(MiscUtils::critsect_t* cs);57void leave_critsect(MiscUtils::critsect_t* cs);5859// Need to wrap this in an object because we need to dynamically initialize60// critical section (because of windows, where there is no way to initialize61// a CRITICAL_SECTION statically. On Unix, we could use62// PTHREAD_MUTEX_INITIALIZER).6364// Note: The critical section does NOT get cleaned up in the destructor. That is65// by design: the CritSect class is only ever used as global objects whose66// lifetime spans the whole VM life; in that context we don't want the lock to67// be cleaned up when global C++ objects are destroyed, but to continue to work68// correctly right to the very end of the process life.69class CritSect {70critsect_t _cs;71public:72CritSect() { init_critsect(&_cs); }73//~CritSect() { free_critsect(&_cs); }74void enter() { enter_critsect(&_cs); }75void leave() { leave_critsect(&_cs); }76};7778class AutoCritSect {79CritSect* const _pcsobj;80public:81AutoCritSect(CritSect* pcsobj)82: _pcsobj(pcsobj)83{84_pcsobj->enter();85}86~AutoCritSect() {87_pcsobj->leave();88}89};90}9192#endif // OS_AIX_MISC_AIX_HPP939495