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
// 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) // (C) Copyright 2007 Anthony Williams #ifndef BOOST_THREAD_LOCKS_HPP #define BOOST_THREAD_LOCKS_HPP #include
#include
#include
#include
#include
namespace boost { struct defer_lock_t {}; struct try_to_lock_t {}; struct adopt_lock_t {}; const defer_lock_t defer_lock={}; const try_to_lock_t try_to_lock={}; const adopt_lock_t adopt_lock={}; template
class shared_lock; template
class upgrade_lock; template
class lock_guard { private: Mutex& m; explicit lock_guard(lock_guard&); lock_guard& operator=(lock_guard&); public: explicit lock_guard(Mutex& m_): m(m_) { m.lock(); } lock_guard(Mutex& m_,adopt_lock_t): m(m_) {} ~lock_guard() { m.unlock(); } }; template
class unique_lock { private: Mutex* m; bool is_locked; explicit unique_lock(unique_lock&); unique_lock& operator=(unique_lock&); public: explicit unique_lock(Mutex& m_): m(&m_),is_locked(false) { lock(); } unique_lock(Mutex& m_,adopt_lock_t): m(&m_),is_locked(true) {} unique_lock(Mutex& m_,defer_lock_t): m(&m_),is_locked(false) {} unique_lock(Mutex& m_,try_to_lock_t): m(&m_),is_locked(false) { try_lock(); } unique_lock(Mutex& m_,system_time const& target_time): m(&m_),is_locked(false) { timed_lock(target_time); } unique_lock(detail::thread_move_t
> other): m(other->m),is_locked(other->is_locked) { other->is_locked=false; other->m=0; } unique_lock(detail::thread_move_t
> other); operator detail::thread_move_t
>() { return move(); } detail::thread_move_t
> move() { return detail::thread_move_t
>(*this); } unique_lock& operator=(detail::thread_move_t
> other) { unique_lock temp(other); swap(temp); return *this; } unique_lock& operator=(detail::thread_move_t
> other) { unique_lock temp(other); swap(temp); return *this; } void swap(unique_lock& other) { std::swap(m,other.m); std::swap(is_locked,other.is_locked); } void swap(detail::thread_move_t
> other) { std::swap(m,other->m); std::swap(is_locked,other->is_locked); } ~unique_lock() { if(owns_lock()) { m->unlock(); } } void lock() { if(owns_lock()) { throw boost::lock_error(); } m->lock(); is_locked=true; } bool try_lock() { if(owns_lock()) { throw boost::lock_error(); } is_locked=m->try_lock(); return is_locked; } template
bool timed_lock(TimeDuration const& relative_time) { is_locked=m->timed_lock(relative_time); return is_locked; } bool timed_lock(::boost::system_time const& absolute_time) { is_locked=m->timed_lock(absolute_time); return is_locked; } void unlock() { if(!owns_lock()) { throw boost::lock_error(); } m->unlock(); is_locked=false; } typedef void (unique_lock::*bool_type)(); operator bool_type() const { return is_locked?&unique_lock::lock:0; } bool operator!() const { return !owns_lock(); } bool owns_lock() const { return is_locked; } Mutex* mutex() const { return m; } Mutex* release() { Mutex* const res=m; m=0; is_locked=false; return res; } friend class shared_lock
; friend class upgrade_lock
; }; template
inline detail::thread_move_t
> move(unique_lock
& x) { return x.move(); } template
inline detail::thread_move_t
> move(detail::thread_move_t
> x) { return x; } template
class shared_lock { protected: Mutex* m; bool is_locked; private: explicit shared_lock(shared_lock&); shared_lock& operator=(shared_lock&); public: explicit shared_lock(Mutex& m_): m(&m_),is_locked(false) { lock(); } shared_lock(Mutex& m_,adopt_lock_t): m(&m_),is_locked(true) {} shared_lock(Mutex& m_,defer_lock_t): m(&m_),is_locked(false) {} shared_lock(Mutex& m_,try_to_lock_t): m(&m_),is_locked(false) { try_lock(); } shared_lock(Mutex& m_,system_time const& target_time): m(&m_),is_locked(false) { timed_lock(target_time); } shared_lock(detail::thread_move_t
> other): m(other->m),is_locked(other->is_locked) { other->is_locked=false; } shared_lock(detail::thread_move_t
> other): m(other->m),is_locked(other->is_locked) { other->is_locked=false; if(is_locked) { m->unlock_and_lock_shared(); } } shared_lock(detail::thread_move_t
> other): m(other->m),is_locked(other->is_locked) { other->is_locked=false; if(is_locked) { m->unlock_upgrade_and_lock_shared(); } } operator detail::thread_move_t
>() { return move(); } detail::thread_move_t
> move() { return detail::thread_move_t
>(*this); } shared_lock& operator=(detail::thread_move_t
> other) { shared_lock temp(other); swap(temp); return *this; } shared_lock& operator=(detail::thread_move_t
> other) { shared_lock temp(other); swap(temp); return *this; } shared_lock& operator=(detail::thread_move_t
> other) { shared_lock temp(other); swap(temp); return *this; } void swap(shared_lock& other) { std::swap(m,other.m); std::swap(is_locked,other.is_locked); } ~shared_lock() { if(owns_lock()) { m->unlock_shared(); } } void lock() { if(owns_lock()) { throw boost::lock_error(); } m->lock_shared(); is_locked=true; } bool try_lock() { if(owns_lock()) { throw boost::lock_error(); } is_locked=m->try_lock_shared(); return is_locked; } bool timed_lock(boost::system_time const& target_time) { if(owns_lock()) { throw boost::lock_error(); } is_locked=m->timed_lock_shared(target_time); return is_locked; } void unlock() { if(!owns_lock()) { throw boost::lock_error(); } m->unlock_shared(); is_locked=false; } typedef void (shared_lock::*bool_type)(); operator bool_type() const { return is_locked?&shared_lock::lock:0; } bool operator!() const { return !owns_lock(); } bool owns_lock() const { return is_locked; } }; template
inline detail::thread_move_t
> move(shared_lock
& x) { return x.move(); } template
inline detail::thread_move_t
> move(detail::thread_move_t
> x) { return x; } template
class upgrade_lock { protected: Mutex* m; bool is_locked; private: explicit upgrade_lock(upgrade_lock&); upgrade_lock& operator=(upgrade_lock&); public: explicit upgrade_lock(Mutex& m_): m(&m_),is_locked(false) { lock(); } upgrade_lock(Mutex& m_,bool do_lock): m(&m_),is_locked(false) { if(do_lock) { lock(); } } upgrade_lock(detail::thread_move_t
> other): m(other->m),is_locked(other->is_locked) { other->is_locked=false; } upgrade_lock(detail::thread_move_t
> other): m(other->m),is_locked(other->is_locked) { other->is_locked=false; if(is_locked) { m->unlock_and_lock_upgrade(); } } operator detail::thread_move_t
>() { return move(); } detail::thread_move_t
> move() { return detail::thread_move_t
>(*this); } upgrade_lock& operator=(detail::thread_move_t
> other) { upgrade_lock temp(other); swap(temp); return *this; } upgrade_lock& operator=(detail::thread_move_t
> other) { upgrade_lock temp(other); swap(temp); return *this; } void swap(upgrade_lock& other) { std::swap(m,other.m); std::swap(is_locked,other.is_locked); } ~upgrade_lock() { if(owns_lock()) { m->unlock_upgrade(); } } void lock() { if(owns_lock()) { throw boost::lock_error(); } m->lock_upgrade(); is_locked=true; } bool try_lock() { if(owns_lock()) { throw boost::lock_error(); } is_locked=m->try_lock_upgrade(); return is_locked; } void unlock() { if(!owns_lock()) { throw boost::lock_error(); } m->unlock_upgrade(); is_locked=false; } typedef void (upgrade_lock::*bool_type)(); operator bool_type() const { return is_locked?&upgrade_lock::lock:0; } bool operator!() const { return !owns_lock(); } bool owns_lock() const { return is_locked; } friend class shared_lock
; friend class unique_lock
; }; template
inline detail::thread_move_t
> move(upgrade_lock
& x) { return x.move(); } template
inline detail::thread_move_t
> move(detail::thread_move_t
> x) { return x; } template
unique_lock
::unique_lock(detail::thread_move_t
> other): m(other->m),is_locked(other->is_locked) { other->is_locked=false; if(is_locked) { m->unlock_upgrade_and_lock(); } } template
class upgrade_to_unique_lock { private: upgrade_lock
* source; unique_lock
exclusive; explicit upgrade_to_unique_lock(upgrade_to_unique_lock&); upgrade_to_unique_lock& operator=(upgrade_to_unique_lock&); public: explicit upgrade_to_unique_lock(upgrade_lock
& m_): source(&m_),exclusive(move(*source)) {} ~upgrade_to_unique_lock() { if(source) { *source=move(exclusive); } } upgrade_to_unique_lock(detail::thread_move_t
> other): source(other->source),exclusive(move(other->exclusive)) { other->source=0; } upgrade_to_unique_lock& operator=(detail::thread_move_t
> other) { upgrade_to_unique_lock temp(other); swap(temp); return *this; } void swap(upgrade_to_unique_lock& other) { std::swap(source,other.source); exclusive.swap(other.exclusive); } typedef void (upgrade_to_unique_lock::*bool_type)(upgrade_to_unique_lock&); operator bool_type() const { return exclusive.owns_lock()?&upgrade_to_unique_lock::swap:0; } bool operator!() const { return !owns_lock(); } bool owns_lock() const { return exclusive.owns_lock(); } }; } #endif
locks.hpp
Page URL
File URL
Prev
5/13
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.