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
#ifndef BOOST_BASIC_TIMED_MUTEX_WIN32_HPP #define BOOST_BASIC_TIMED_MUTEX_WIN32_HPP // basic_timed_mutex_win32.hpp // // (C) Copyright 2006 Anthony Williams // // 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) #include
#include "thread_primitives.hpp" #include "interlocked_read.hpp" #include
#include
namespace boost { namespace detail { struct basic_timed_mutex { BOOST_STATIC_CONSTANT(long,lock_flag_value=0x80000000); long active_count; void* event; void initialize() { active_count=0; event=0; } void destroy() { #ifdef BOOST_MSVC #pragma warning(push) #pragma warning(disable:4312) #endif void* const old_event=BOOST_INTERLOCKED_EXCHANGE_POINTER(&event,0); #ifdef BOOST_MSVC #pragma warning(pop) #endif if(old_event) { win32::CloseHandle(old_event); } } bool try_lock() { long old_count=active_count&~lock_flag_value; do { long const current_count=BOOST_INTERLOCKED_COMPARE_EXCHANGE(&active_count,(old_count+1)|lock_flag_value,old_count); if(current_count==old_count) { return true; } old_count=current_count; } while(!(old_count&lock_flag_value)); return false; } void lock() { BOOST_VERIFY(timed_lock(::boost::detail::get_system_time_sentinel())); } bool timed_lock(::boost::system_time const& wait_until) { long old_count=active_count; #ifdef BOOST_MSVC #pragma warning(push) #pragma warning(disable:4127) #endif while(true) #ifdef BOOST_MSVC #pragma warning(pop) #endif { long const current_count=BOOST_INTERLOCKED_COMPARE_EXCHANGE(&active_count,(old_count+1)|lock_flag_value,old_count); if(current_count==old_count) { break; } old_count=current_count; } if(old_count&lock_flag_value) { bool lock_acquired=false; void* const sem=get_event(); ++old_count; // we're waiting, too do { old_count-=(lock_flag_value+1); // there will be one less active thread on this mutex when it gets unlocked if(win32::WaitForSingleObject(sem,::boost::detail::get_milliseconds_until(wait_until))!=0) { BOOST_INTERLOCKED_DECREMENT(&active_count); return false; } do { long const current_count=BOOST_INTERLOCKED_COMPARE_EXCHANGE(&active_count,old_count|lock_flag_value,old_count); if(current_count==old_count) { break; } old_count=current_count; } while(!(old_count&lock_flag_value)); lock_acquired=!(old_count&lock_flag_value); } while(!lock_acquired); } return true; } template
bool timed_lock(Duration const& timeout) { return timed_lock(get_system_time()+timeout); } long get_active_count() { return ::boost::detail::interlocked_read_acquire(&active_count); } void unlock() { long const offset=lock_flag_value+1; long old_count=BOOST_INTERLOCKED_EXCHANGE_ADD(&active_count,(~offset)+1); if(old_count>offset) { win32::SetEvent(get_event()); } } bool locked() { return get_active_count()>=lock_flag_value; } private: void* get_event() { void* current_event=::boost::detail::interlocked_read_acquire(&event); if(!current_event) { void* const new_event=win32::create_anonymous_event(win32::auto_reset_event,win32::event_initially_reset); #ifdef BOOST_MSVC #pragma warning(push) #pragma warning(disable:4311) #pragma warning(disable:4312) #endif void* const old_event=BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(&event,new_event,0); #ifdef BOOST_MSVC #pragma warning(pop) #endif if(old_event!=0) { win32::CloseHandle(new_event); return old_event; } else { return new_event; } } return current_event; } }; } } #define BOOST_BASIC_TIMED_MUTEX_INITIALIZER {0} #endif
basic_timed_mutex.hpp
Page URL
File URL
Prev
2/12
Next
Download
( 5 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.