00001 /* 00002 * Sun Public License Notice 00003 * 00004 * The contents of this file are subject to the Sun Public License 00005 * Version 1.0 (the "License"); you may not use this file except 00006 * in compliance with the License. A copy of the License is available 00007 * at http://www.sun.com/ 00008 * 00009 * The Original Code is the Java Profiler module. The Initial Developers 00010 * of the Original Code are Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, 00011 * Lukas Petru and Marek Przeczek. 00012 * 00013 * Portions created by Jan Stola are Copyright (C) 2000-2001. 00014 * All Rights Reserved. 00015 * 00016 * Portions created by Pavel Vacha are Copyright (C) 2000-2001. 00017 * All Rights Reserved. 00018 * 00019 * Portions created by Michal Pise are Copyright (C) 2000-2001. 00020 * All Rights Reserved. 00021 * 00022 * Portions created by Petr Luner are Copyright (C) 2000-2001. 00023 * All Rights Reserved. 00024 * 00025 * Portions created by Lukas Petru are Copyright (C) 2000-2001. 00026 * All Rights Reserved. 00027 * 00028 * Portions created by Marek Przeczek are Copyright (C) 2000-2001. 00029 * All Rights Reserved. 00030 * 00031 * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, 00032 * Lukas Petru and Marek Przeczek. 00033 */ 00034 00035 #ifndef _SYNCHRONIZED_H_ 00036 #define _SYNCHRONIZED_H_ 00037 00038 #include "../main/includes.h" 00039 #include "../prof/lock.h" 00040 00051 class Synchronized { 00052 00054 Lock& _lock; 00055 00057 int _released; 00058 00059 public: 00060 00073 Synchronized( Lock& lock, int entr = 1) : 00074 00075 _lock( lock), 00076 _released( 1) { 00077 00078 if( entr) enter(); 00079 } 00080 00085 ~Synchronized() { release();} 00086 00092 void release() { 00093 00094 if( !_released) _lock.release(); 00095 _released = 1; 00096 } 00097 00103 void enter() { 00104 00105 _lock.wait(); 00106 _released = 0; 00107 } 00108 }; 00109 00110 #endif // _SYNCHRONIZED_H_