From 71da9925ec7ce1454d4d5e557fa69fc2fa8bdce5 Mon Sep 17 00:00:00 2001 From: dimitr Date: Thu, 20 Mar 2008 16:41:17 +0000 Subject: [PATCH] 1) Added proper handle validation for dbb. 2) Changed dbb_sync lifestyle handling. 3) Sync'ed access to the att_long_locks. --- src/common/classes/PublicHandle.cpp | 73 +++++++++++++++++++++++++++++ src/common/classes/PublicHandle.h | 47 +++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 src/common/classes/PublicHandle.cpp create mode 100644 src/common/classes/PublicHandle.h diff --git a/src/common/classes/PublicHandle.cpp b/src/common/classes/PublicHandle.cpp new file mode 100644 index 0000000000..f6db47d1b6 --- /dev/null +++ b/src/common/classes/PublicHandle.cpp @@ -0,0 +1,73 @@ +/* + * The contents of this file are subject to the Initial + * Developer's Public License Version 1.0 (the "License"); + * you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl. + * + * Software distributed under the License is distributed AS IS, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. + * See the License for the specific language governing rights + * and limitations under the License. + * + * The Original Code was created by Dmitry Yemanov + * for the Firebird Open Source RDBMS project. + * + * Copyright (c) 2008 Dmitry Yemanov + * and all contributors signed below. + * + * All Rights Reserved. + * Contributor(s): ______________________________________. + */ + +#include "firebird.h" +#include "../jrd/gdsassert.h" +#include "PublicHandle.h" + +namespace Firebird +{ + GlobalPtr > PublicHandle::handles; + GlobalPtr PublicHandle::sync; + + PublicHandle::PublicHandle() + { + WriteLockGuard guard(sync); + + size_t pos; + if (handles->find(this, pos)) + { + fb_assert(false); + } + else + { + handles->add(this); + } + } + + PublicHandle::~PublicHandle() + { + WriteLockGuard guard(sync); + + size_t pos; + if (handles->find(this, pos)) + { + handles->remove(pos); + } + else + { + fb_assert(false); + } + } + + bool PublicHandle::isKnownHandle() const + { + if (!this) + { + return false; + } + + ReadLockGuard guard(sync); + return handles->exist(this); + } + +} // namespace diff --git a/src/common/classes/PublicHandle.h b/src/common/classes/PublicHandle.h new file mode 100644 index 0000000000..1954dbc350 --- /dev/null +++ b/src/common/classes/PublicHandle.h @@ -0,0 +1,47 @@ +/* + * The contents of this file are subject to the Initial + * Developer's Public License Version 1.0 (the "License"); + * you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl. + * + * Software distributed under the License is distributed AS IS, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. + * See the License for the specific language governing rights + * and limitations under the License. + * + * The Original Code was created by Dmitry Yemanov + * for the Firebird Open Source RDBMS project. + * + * Copyright (c) 2008 Dmitry Yemanov + * and all contributors signed below. + * + * All Rights Reserved. + * Contributor(s): ______________________________________. + */ + +#ifndef COMMON_PUBLIC_HANDLE +#define COMMON_PUBLIC_HANDLE + +#include "../common/classes/array.h" +#include "../common/classes/rwlock.h" +#include "../common/classes/init.h" + +namespace Firebird +{ + class PublicHandle + { + public: + PublicHandle(); + ~PublicHandle(); + + bool isKnownHandle() const; + + private: + static GlobalPtr > handles; + static GlobalPtr sync; + }; + +}; // namespace + +#endif // COMMON_PUBLIC_HANDLE