00001 /* 00002 * Copyright 2004-2006 Intel Corporation 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 00018 #ifndef _OASYS_MUTEX_H_ 00019 #define _OASYS_MUTEX_H_ 00020 00021 #include "Lock.h" 00022 #include "../debug/Logger.h" 00023 00024 namespace oasys { 00025 00027 class Mutex : public Lock { 00028 friend class Monitor; // Monitor needs access to mutex_. 00029 00030 public: 00038 enum lock_type_t { 00039 TYPE_FAST = 1, 00040 TYPE_RECURSIVE 00041 }; 00042 00044 Mutex(const char* logbase, 00045 lock_type_t type = TYPE_RECURSIVE, 00046 bool keep_quiet = false); 00047 ~Mutex(); 00048 00050 int lock(const char* lock_user); 00051 int unlock(); 00052 int try_lock(const char* lock_user); 00054 00055 protected: 00056 pthread_mutex_t mutex_; 00057 lock_type_t type_; 00058 bool keep_quiet_; 00059 }; 00060 00061 } // namespace oasys 00062 00063 #endif /* _OASYS_MUTEX_H_ */ 00064