DriveHQ Start Menu
Cloud Drive Mapping
Folder Sync
Cloud Backup
True Drop Box
FTP/SFTP Hosting
Group Account
DriveHQ Start Menu
Online File Server
My Storage
|
Manage Shares
|
Publishes
|
Drop Boxes
|
Group Account
WebDAV Drive Mapping
Cloud Drive Home
|
WebDAV Guide
|
Drive Mapping Tool
|
Drive Mapping URL
Complete Data Backup
Backup Guide
|
Online Backup Tool
|
Cloud-to-Cloud Backup
FTP, Email & Web Service
FTP Home
|
FTP Hosting FAQ
|
Email Hosting
|
EmailManager
|
Web Hosting
Help & Resources
About
|
Enterprise Service
|
Partnership
|
Comparisons
|
Support
Quick Links
Security and Privacy
Download Software
Service Manual
Use Cases
Group Account
Online Help
Blog
Contact
Cloud Surveillance
Sign Up
Login
Features
Business Features
Online File Server
FTP Hosting
Cloud Drive Mapping
Cloud File Backup
Email Backup & Hosting
Cloud File Sharing
Folder Synchronization
Group Management
True Drop Box
Full-text Search
AD Integration/SSO
Mobile Access
IP Camera & DVR Solution
More...
Personal Features
Personal Cloud Drive
Backup All Devices
Mobile APPs
Personal Web Hosting
Sub-Account (for Kids)
Home/PC/Kids Monitoring
More...
Software
DriveHQ Drive Mapping Tool
DriveHQ FileManager
DriveHQ Online Backup
DriveHQ Mobile Apps
Pricing
Business Plans & Pricing
Personal Plans & Pricing
Price Comparison with Others
Feature Comparison with Others
Install Mobile App
Sign up
Creating account...
Invalid character in username! Only 0-9, a-z, A-Z, _, -, . allowed.
Username is required!
Invalid email address!
E-mail is required!
Password is required!
Password is invalid!
Password and confirmation do not match.
Confirm password is required!
I accept
Membership Agreement
Please read the Membership Agreement and check "I accept"!
Free Quick Sign-up
Sign-up Page
Log in
Signing in...
Username or e-mail address is required!
Password is required!
Keep me logged in
Quick Login
Forgot Password
Up
Upload
Download
Share
Publish
New Folder
New File
Copy
Cut
Delete
Paste
Rate
Upgrade
Rotate
Effect
Edit
Slide
History
////////////////////////////////////////////////////////////////////////////// // // (C) Copyright Ion Gaztanaga 2005-2008. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/interprocess for documentation. // ////////////////////////////////////////////////////////////////////////////// // // This interface is inspired by Howard Hinnant's lock proposal. // http://home.twcny.rr.com/hinnant/cpp_extensions/threads_move.html // ////////////////////////////////////////////////////////////////////////////// #ifndef BOOST_INTERPROCESS_SHARABLE_LOCK_HPP #define BOOST_INTERPROCESS_SHARABLE_LOCK_HPP #if (defined _MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif #include
#include
#include
#include
#include
//Ig#include
#include
//!\file //!Describes the upgradable_lock class that serves to acquire the upgradable //!lock of a mutex. namespace boost { namespace interprocess { template
class scoped_lock; template
class upgradable_lock; //!sharable_lock is meant to carry out the tasks for sharable-locking //!(such as read-locking), unlocking, try-sharable-locking and timed-sharable-locking //!(recursive or not) for the Mutex. The Mutex need not supply all of this //!functionality. If the client of sharable_lock
does not use functionality which //!the Mutex does not supply, no harm is done. Mutex ownership can be shared among //!sharable_locks, and a single upgradable_lock. sharable_lock does not support //!copy semantics. But sharable_lock supports ownership transfer from an sharable_lock, //!upgradable_lock and scoped_lock via trasfer_lock syntax.*/ template
class sharable_lock { public: typedef SharableMutex mutex_type; /// @cond private: typedef sharable_lock
this_type; sharable_lock(sharable_lock const&); explicit sharable_lock(scoped_lock
const&); typedef bool this_type::*unspecified_bool_type; sharable_lock& operator=(sharable_lock const&); sharable_lock& operator=(scoped_lock
const&); /// @endcond public: //!Effects: Default constructs a sharable_lock. //!Postconditions: owns() == false and mutex() == 0. sharable_lock() : mp_mutex(0), m_locked(false) {} //!Effects: m.lock_sharable(). //!Postconditions: owns() == true and mutex() == &m. //!Notes: The constructor will take sharable-ownership of the mutex. If //! another thread already owns the mutex with exclusive ownership //! (scoped_lock), this thread will block until the mutex is released. //! If another thread owns the mutex with sharable or upgradable ownership, //! then no blocking will occur. Whether or not this constructor handles //! recursive locking depends upon the mutex. explicit sharable_lock(mutex_type& m) : mp_mutex(&m), m_locked(false) { mp_mutex->lock_sharable(); m_locked = true; } //!Postconditions: owns() == false, and mutex() == &m. //!Notes: The constructor will not take ownership of the mutex. There is no effect //! required on the referenced mutex. sharable_lock(mutex_type& m, detail::defer_lock_type) : mp_mutex(&m), m_locked(false) {} //!Postconditions: owns() == true, and mutex() == &m. //!Notes: The constructor will suppose that the mutex is already sharable //! locked. There is no effect required on the referenced mutex. sharable_lock(mutex_type& m, detail::accept_ownership_type) : mp_mutex(&m), m_locked(true) {} //!Effects: m.try_lock_sharable() //!Postconditions: mutex() == &m. owns() == the return value of the //! m.try_lock_sharable() executed within the constructor. //!Notes: The constructor will take sharable-ownership of the mutex if it //! can do so without waiting. Whether or not this constructor handles //! recursive locking depends upon the mutex. If the mutex_type does not //! support try_lock_sharable, this constructor will fail at compile //! time if instantiated, but otherwise have no effect. sharable_lock(mutex_type& m, detail::try_to_lock_type) : mp_mutex(&m), m_locked(false) { m_locked = mp_mutex->try_lock_sharable(); } //!Effects: m.timed_lock_sharable(abs_time) //!Postconditions: mutex() == &m. owns() == the return value of the //! m.timed_lock_sharable() executed within the constructor. //!Notes: The constructor will take sharable-ownership of the mutex if it //! can do so within the time specified. Whether or not this constructor //! handles recursive locking depends upon the mutex. If the mutex_type //! does not support timed_lock_sharable, this constructor will fail at //! compile time if instantiated, but otherwise have no effect. sharable_lock(mutex_type& m, const boost::posix_time::ptime& abs_time) : mp_mutex(&m), m_locked(false) { m_locked = mp_mutex->timed_lock_sharable(abs_time); } //!Postconditions: mutex() == upgr.mutex(). owns() == the value of upgr.owns() //! before the construction. upgr.owns() == false after the construction. //!Notes: If the upgr sharable_lock owns the mutex, ownership is moved to this //! sharable_lock with no blocking. If the upgr sharable_lock does not own the mutex, then //! neither will this sharable_lock. Only a moved sharable_lock's will match this //! signature. An non-moved sharable_lock can be moved with the expression: //! "move(lock);". This constructor does not alter the state of the mutex, //! only potentially who owns it. #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE explicit sharable_lock(detail::moved_object
> upgr) : mp_mutex(0), m_locked(upgr.get().owns()) { mp_mutex = upgr.get().release(); } #else explicit sharable_lock(sharable_lock
&&upgr) : mp_mutex(0), m_locked(upgr.owns()) { mp_mutex = upgr.release(); } #endif //!Effects: If upgr.owns() then calls unlock_upgradable_and_lock_sharable() on the //! referenced mutex. //!Postconditions: mutex() == the value upgr.mutex() had before the construction. //! upgr.mutex() == 0 owns() == the value of upgr.owns() before construction. //! upgr.owns() == false after the construction. //!Notes: If upgr is locked, this constructor will lock this sharable_lock while //! unlocking upgr. Only a moved sharable_lock's will match this //! signature. An non-moved upgradable_lock can be moved with the expression: //! "move(lock);".*/ #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE explicit sharable_lock(detail::moved_object
> upgr) : mp_mutex(0), m_locked(false) { upgradable_lock
&u_lock = upgr.get(); if(u_lock.owns()){ u_lock.mutex()->unlock_upgradable_and_lock_sharable(); m_locked = true; } mp_mutex = u_lock.release(); } #else explicit sharable_lock(upgradable_lock
&&upgr) : mp_mutex(0), m_locked(false) { upgradable_lock
&u_lock = upgr; if(u_lock.owns()){ u_lock.mutex()->unlock_upgradable_and_lock_sharable(); m_locked = true; } mp_mutex = u_lock.release(); } #endif //!Effects: If scop.owns() then calls unlock_and_lock_sharable() on the //! referenced mutex. //!Postconditions: mutex() == the value scop.mutex() had before the construction. //! scop.mutex() == 0 owns() == scop.owns() before the constructor. After the //! construction, scop.owns() == false. //!Notes: If scop is locked, this constructor will transfer the exclusive ownership //! to a sharable-ownership of this sharable_lock. //! Only a moved scoped_lock's will match this //! signature. An non-moved scoped_lock can be moved with the expression: //! "move(lock);".*/ #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE explicit sharable_lock(detail::moved_object
> scop) : mp_mutex(0), m_locked(false) { scoped_lock
&e_lock = scop.get(); if(e_lock.owns()){ e_lock.mutex()->unlock_and_lock_sharable(); m_locked = true; } mp_mutex = e_lock.release(); } #else explicit sharable_lock(scoped_lock
&&scop) : mp_mutex(0), m_locked(false) { scoped_lock
&e_lock = scop; if(e_lock.owns()){ e_lock.mutex()->unlock_and_lock_sharable(); m_locked = true; } mp_mutex = e_lock.release(); } #endif //!Effects: if (owns()) mp_mutex->unlock_sharable(). //!Notes: The destructor behavior ensures that the mutex lock is not leaked. ~sharable_lock() { try{ if(m_locked && mp_mutex) mp_mutex->unlock_sharable(); } catch(...){} } //!Effects: If owns() before the call, then unlock_sharable() is called on mutex(). //! *this gets the state of upgr and upgr gets set to a default constructed state. //!Notes: With a recursive mutex it is possible that both this and upgr own the mutex //! before the assignment. In this case, this will own the mutex after the assignment //! (and upgr will not), but the mutex's lock count will be decremented by one. #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE sharable_lock &operator=(detail::moved_object
> upgr) { if(this->owns()) this->unlock(); m_locked = upgr.get().owns(); mp_mutex = upgr.get().release(); return *this; } #else sharable_lock &operator=(sharable_lock
&&upgr) { if(this->owns()) this->unlock(); m_locked = upgr.owns(); mp_mutex = upgr.release(); return *this; } #endif //!Effects: If mutex() == 0 or already locked, throws a lock_exception() //! exception. Calls lock_sharable() on the referenced mutex. //!Postconditions: owns() == true. //!Notes: The sharable_lock changes from a state of not owning the //! mutex, to owning the mutex, blocking if necessary. void lock() { if(!mp_mutex || m_locked) throw lock_exception(); mp_mutex->lock_sharable(); m_locked = true; } //!Effects: If mutex() == 0 or already locked, throws a lock_exception() //! exception. Calls try_lock_sharable() on the referenced mutex. //!Postconditions: owns() == the value returned from //! mutex()->try_lock_sharable(). //!Notes: The sharable_lock changes from a state of not owning the mutex, //! to owning the mutex, but only if blocking was not required. If the //! mutex_type does not support try_lock_sharable(), this function will //! fail at compile time if instantiated, but otherwise have no effect. bool try_lock() { if(!mp_mutex || m_locked) throw lock_exception(); m_locked = mp_mutex->try_lock_sharable(); return m_locked; } //!Effects: If mutex() == 0 or already locked, throws a lock_exception() //! exception. Calls timed_lock_sharable(abs_time) on the referenced mutex. //!Postconditions: owns() == the value returned from //! mutex()->timed_lock_sharable(elps_time). //!Notes: The sharable_lock changes from a state of not owning the mutex, //! to owning the mutex, but only if it can obtain ownership within the //! specified time interval. If the mutex_type does not support //! timed_lock_sharable(), this function will fail at compile time if //! instantiated, but otherwise have no effect. bool timed_lock(const boost::posix_time::ptime& abs_time) { if(!mp_mutex || m_locked) throw lock_exception(); m_locked = mp_mutex->timed_lock_sharable(abs_time); return m_locked; } //!Effects: If mutex() == 0 or not locked, throws a lock_exception() exception. //! Calls unlock_sharable() on the referenced mutex. //!Postconditions: owns() == false. //!Notes: The sharable_lock changes from a state of owning the mutex, to //! not owning the mutex. void unlock() { if(!mp_mutex || !m_locked) throw lock_exception(); mp_mutex->unlock_sharable(); m_locked = false; } //!Effects: Returns true if this scoped_lock has //!acquired the referenced mutex. bool owns() const { return m_locked && mp_mutex; } //!Conversion to bool. //!Returns owns(). operator unspecified_bool_type() const { return m_locked? &this_type::m_locked : 0; } //!Effects: Returns a pointer to the referenced mutex, or 0 if //!there is no mutex to reference. mutex_type* mutex() const { return mp_mutex; } //!Effects: Returns a pointer to the referenced mutex, or 0 if there is no //! mutex to reference. //!Postconditions: mutex() == 0 and owns() == false. mutex_type* release() { mutex_type *mut = mp_mutex; mp_mutex = 0; m_locked = false; return mut; } //!Effects: Swaps state with moved lock. //!Throws: Nothing. #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE void swap(detail::moved_object
> other) { std::swap(mp_mutex, other.get().mp_mutex); std::swap(m_locked, other.get().m_locked); } #else void swap(sharable_lock
&&other) { std::swap(mp_mutex, other.mp_mutex); std::swap(m_locked, other.m_locked); } #endif /// @cond private: mutex_type *mp_mutex; bool m_locked; /// @endcond }; /// @cond //!This class is movable template
struct is_movable
> { enum { value = true }; }; /// @endcond } // namespace interprocess } // namespace boost #include
#endif // BOOST_INTERPROCESS_SHARABLE_LOCK_HPP
sharable_lock.hpp
Page URL
File URL
Prev
17/18
Next
Download
( 14 KB )
Note: The DriveHQ service banners will NOT be displayed if the file owner is a paid member.
Comments
Total ratings:
0
Average rating:
Not Rated
Would you like to comment?
Join DriveHQ
for a free account, or
Logon
if you are already a member.