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. // ////////////////////////////////////////////////////////////////////////////// #ifndef BOOST_INTERPROCESS_FILE_LOCK_HPP #define BOOST_INTERPROCESS_FILE_LOCK_HPP #if (defined _MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif #include
#include
#include
#include
#include
#include
//!\file //!Describes a class that wraps file locking capabilities. namespace boost { namespace interprocess { //!A file lock, is a mutual exclusion utility similar to a mutex using a //!file. A file lock has sharable and exclusive locking capabilities and //!can be used with scoped_lock and sharable_lock classes. class file_lock { /// @cond //Non-copyable file_lock(); file_lock(const file_lock &); file_lock &operator=(const file_lock &); /// @endcond public: //!Opens a file lock. Throws interprocess_exception if the file does not //!exist or there are no operating system resources. file_lock(const char *name); //!Closes a file lock. Does not throw. ~file_lock(); //Exclusive locking //!Effects: The calling thread tries to obtain exclusive ownership of the mutex, //! and if another thread has exclusive, or sharable ownership of //! the mutex, it waits until it can obtain the ownership. //!Throws: interprocess_exception on error. void lock(); //!Effects: The calling thread tries to acquire exclusive ownership of the mutex //! without waiting. If no other thread has exclusive, or sharable //! ownership of the mutex this succeeds. //!Returns: If it can acquire exclusive ownership immediately returns true. //! If it has to wait, returns false. //!Throws: interprocess_exception on error. bool try_lock(); //!Effects: The calling thread tries to acquire exclusive ownership of the mutex //! waiting if necessary until no other thread has has exclusive, or sharable //! ownership of the mutex or abs_time is reached. //!Returns: If acquires exclusive ownership, returns true. Otherwise returns false. //!Throws: interprocess_exception on error. bool timed_lock(const boost::posix_time::ptime &abs_time); //!Precondition: The thread must have exclusive ownership of the mutex. //!Effects: The calling thread releases the exclusive ownership of the mutex. //!Throws: An exception derived from interprocess_exception on error. void unlock(); //Sharable locking //!Effects: The calling thread tries to obtain sharable ownership of the mutex, //! and if another thread has exclusive ownership of the mutex, waits until //! it can obtain the ownership. //!Throws: interprocess_exception on error. void lock_sharable(); //!Effects: The calling thread tries to acquire sharable ownership of the mutex //! without waiting. If no other thread has has exclusive ownership of the //! mutex this succeeds. //!Returns: If it can acquire sharable ownership immediately returns true. If it //! has to wait, returns false. //!Throws: interprocess_exception on error. bool try_lock_sharable(); //!Effects: The calling thread tries to acquire sharable ownership of the mutex //! waiting if necessary until no other thread has has exclusive ownership of //! the mutex or abs_time is reached. //!Returns: If acquires sharable ownership, returns true. Otherwise returns false. //!Throws: interprocess_exception on error. bool timed_lock_sharable(const boost::posix_time::ptime &abs_time); //!Precondition: The thread must have sharable ownership of the mutex. //!Effects: The calling thread releases the sharable ownership of the mutex. //!Throws: An exception derived from interprocess_exception on error. void unlock_sharable(); /// @cond private: file_handle_t m_file_hnd; bool timed_acquire_file_lock (file_handle_t hnd, bool &acquired, const boost::posix_time::ptime &abs_time) { //Obtain current count and target time boost::posix_time::ptime now = microsec_clock::universal_time(); using namespace boost::detail; if(now >= abs_time) return false; do{ if(!try_acquire_file_lock(hnd, acquired)) return false; if(acquired) return true; else{ now = microsec_clock::universal_time(); if(now >= abs_time){ acquired = false; return true; } // relinquish current time slice winapi::sched_yield(); } }while (true); } bool timed_acquire_file_lock_sharable (file_handle_t hnd, bool &acquired, const boost::posix_time::ptime &abs_time) { //Obtain current count and target time boost::posix_time::ptime now = microsec_clock::universal_time(); using namespace boost::detail; if(now >= abs_time) return false; do{ if(!try_acquire_file_lock_sharable(hnd, acquired)) return false; if(acquired) return true; else{ now = microsec_clock::universal_time(); if(now >= abs_time){ acquired = false; return true; } // relinquish current time slice winapi::sched_yield(); } }while (true); } bool timed_acquire_file_lock (file_handle_t hnd, bool &acquired, const boost::posix_time::ptime &abs_time) { //Obtain current count and target time boost::posix_time::ptime now = microsec_clock::universal_time(); using namespace boost::detail; if(now >= abs_time) return false; do{ if(!try_acquire_file_lock(hnd, acquired)) return false; if(acquired) return true; else{ now = microsec_clock::universal_time(); if(now >= abs_time){ acquired = false; return true; } // relinquish current time slice sleep(0); } }while (true); } bool timed_acquire_file_lock_sharable (file_handle_t hnd, bool &acquired, const boost::posix_time::ptime &abs_time) { //Obtain current count and target time boost::posix_time::ptime now = microsec_clock::universal_time(); using namespace boost::detail; if(now >= abs_time) return false; do{ if(!try_acquire_file_lock_sharable(hnd, acquired)) return false; if(acquired) return true; else{ now = microsec_clock::universal_time(); if(now >= abs_time){ acquired = false; return true; } // relinquish current time slice ::sleep(0); } }while (true); } /// @endcond }; inline file_lock::file_lock(const char *name) { m_file_hnd = detail::open_existing_file(name); if(m_file_hnd == detail::invalid_file()){ error_info err(system_error_code()); throw interprocess_exception(err); } } inline file_lock::~file_lock() { if(m_file_hnd != detail::invalid_file()){ detail::close_file(m_file_hnd); m_file_hnd = detail::invalid_file(); } } inline void file_lock::lock() { if(!detail::acquire_file_lock(m_file_hnd)){ error_info err(system_error_code()); throw interprocess_exception(err); } } inline bool file_lock::try_lock() { bool result; if(!detail::try_acquire_file_lock(m_file_hnd, result)){ error_info err(system_error_code()); throw interprocess_exception(err); } return result; } inline bool file_lock::timed_lock(const boost::posix_time::ptime &abs_time) { bool result; if(!detail::timed_acquire_file_lock(m_file_hnd, result, abs_time)){ error_info err(system_error_code()); throw interprocess_exception(err); } return result; } inline void file_lock::unlock() { if(!detail::release_file_lock(m_file_hnd)){ error_info err(system_error_code()); throw interprocess_exception(err); } } inline void file_lock::lock_sharable() { if(!detail::acquire_file_lock_sharable(m_file_hnd)){ error_info err(system_error_code()); throw interprocess_exception(err); } } inline bool file_lock::try_lock_sharable() { bool result; if(!detail::try_acquire_file_lock_sharable(m_file_hnd, result)){ error_info err(system_error_code()); throw interprocess_exception(err); } return result; } inline bool file_lock::timed_lock_sharable(const boost::posix_time::ptime &abs_time) { bool result; if(!detail::timed_acquire_file_lock_sharable(m_file_hnd, result, abs_time)){ error_info err(system_error_code()); throw interprocess_exception(err); } return result; } inline void file_lock::unlock_sharable() { if(!detail::release_file_lock_sharable(m_file_hnd)){ error_info err(system_error_code()); throw interprocess_exception(err); } } } //namespace interprocess { } //namespace boost { #include
#endif //BOOST_INTERPROCESS_FILE_LOCK_HPP
file_lock.hpp
Page URL
File URL
Prev 1/18
Next
Download
( 9 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.