X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltooling%2FLockable.h;h=c10c2bf6451c433938c2f4b9742649a56225cf50;hb=56a73c1c7b1e63f1ff1717b25a76ebd480594d5a;hp=cb633536f3e07a287e71011b564adf374ac1e222;hpb=5cb314df178f78c6fa7b9826c2c5a5298ec7a473;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltooling/Lockable.h b/xmltooling/Lockable.h index cb63353..c10c2bf 100644 --- a/xmltooling/Lockable.h +++ b/xmltooling/Lockable.h @@ -1,23 +1,27 @@ -/* - * Copyright 2001-2007 Internet2 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at +/** + * Licensed to the University Corporation for Advanced Internet + * Development, Inc. (UCAID) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. * - * http://www.apache.org/licenses/LICENSE-2.0 + * UCAID licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the + * License at * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. */ /** - * @file Lockable.h + * @file xmltooling/Lockable.h * - * Locking abstraction + * Locking abstraction. */ #ifndef __xmltooling_lockable_h__ @@ -30,9 +34,12 @@ namespace xmltooling { /** * Abstract mixin interface for interfaces that support locking */ - struct XMLTOOL_API Lockable + class XMLTOOL_API Lockable { - virtual ~Lockable() {} + protected: + Lockable(); + public: + virtual ~Lockable(); /** * Lock the associated object for exclusive access. @@ -60,12 +67,7 @@ namespace xmltooling { * @param lockee pointer to an object to hold, and optionally lock * @param lock true iff object is not yet locked */ - Locker(Lockable* lockee=NULL, bool lock=true) { - if (lockee && lock) - m_lockee=lockee->lock(); - else - m_lockee=lockee; - } + Locker(Lockable* lockee=nullptr, bool lock=true); /** * Optionally locks an object and stores it for later release. @@ -74,23 +76,12 @@ namespace xmltooling { * @param lockee pointer to an object to hold, and optionally lock * @param lock true iff object is not yet locked */ - void assign(Lockable* lockee=NULL, bool lock=true) { - if (m_lockee) - m_lockee->unlock(); - m_lockee=NULL; - if (lockee && lock) - m_lockee=lockee->lock(); - else - m_lockee=lockee; - } + void assign(Lockable* lockee=nullptr, bool lock=true); /** * Destructor releases lock on held pointer, if any. */ - ~Locker() { - if (m_lockee) - m_lockee->unlock(); - } + ~Locker(); private: Lockable* m_lockee;