x
Yes
No
Do you want to visit DriveHQ English website?
Inicio
Características
Precios
Prueba gratuita
Software cliente
Acerca de nosotros
Servidor de archivos
|
Solución de copias de seguridad
|
Servidor FTP
|
Servidor de correo electrónico
|
Alojamiento web
|
Software cliente
Servidor de archivos
Solución de copia de seguridad
Servidor FTP
Servidor de correo electrónico
Alojamiento web
Software cliente
condition_variable.hpp - Hosted on DriveHQ Cloud IT Platform
Arriba
Subir
Descargar
Compartir
Publicar
Nueva carpeta
Nuevo archivo
Copiar
Cortar
Eliminar
Pegar
Clasificación
Actualizar
Ruta de la carpeta: \\game3dprogramming\materials\GameFactory\GameFactoryDemo\references\boost_1_35_0\boost\thread\win32\condition_variable.hpp
Girar
Efecto
Propiedad
Historial
#ifndef BOOST_THREAD_CONDITION_VARIABLE_WIN32_HPP #define BOOST_THREAD_CONDITION_VARIABLE_WIN32_HPP // 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 #include
#include "thread_primitives.hpp" #include
#include
#include
#include
#include
#include "interlocked_read.hpp" #include
namespace boost { namespace detail { class basic_condition_variable { boost::mutex internal_mutex; long total_count; unsigned active_generation_count; struct list_entry { detail::win32::handle semaphore; long count; bool notified; list_entry(): semaphore(0),count(0),notified(0) {} }; BOOST_STATIC_CONSTANT(unsigned,generation_count=3); list_entry generations[generation_count]; detail::win32::handle wake_sem; static bool no_waiters(list_entry const& entry) { return entry.count==0; } void shift_generations_down() { list_entry* const last_active_entry=std::remove_if(generations,generations+generation_count,no_waiters); if(last_active_entry==generations+generation_count) { broadcast_entry(generations[generation_count-1],false); } else { active_generation_count=unsigned(last_active_entry-generations)+1; } #ifdef BOOST_MSVC #pragma warning(push) #pragma warning(disable:4996) #endif std::copy_backward(generations,generations+active_generation_count-1,generations+active_generation_count); #ifdef BOOST_MSVC #pragma warning(pop) #endif generations[0]=list_entry(); } void broadcast_entry(list_entry& entry,bool wake) { long const count_to_wake=entry.count; detail::interlocked_write_release(&total_count,total_count-count_to_wake); if(wake) { detail::win32::ReleaseSemaphore(wake_sem,count_to_wake,0); } detail::win32::ReleaseSemaphore(entry.semaphore,count_to_wake,0); entry.count=0; dispose_entry(entry); } void dispose_entry(list_entry& entry) { if(entry.semaphore) { BOOST_VERIFY(detail::win32::CloseHandle(entry.semaphore)); entry.semaphore=0; } entry.notified=false; } template
struct relocker { lock_type& lock; bool unlocked; relocker(lock_type& lock_): lock(lock_),unlocked(false) {} void unlock() { lock.unlock(); unlocked=true; } ~relocker() { if(unlocked) { lock.lock(); } } private: void operator=(relocker&); }; template
void start_wait_loop_first_time(relocker
& locker, detail::win32::handle_manager& local_wake_sem) { locker.unlock(); if(!wake_sem) { wake_sem=detail::win32::create_anonymous_semaphore(0,LONG_MAX); BOOST_ASSERT(wake_sem); } local_wake_sem=detail::win32::duplicate_handle(wake_sem); if(generations[0].notified) { shift_generations_down(); } else if(!active_generation_count) { active_generation_count=1; } } template
void start_wait_loop(relocker
& locker, detail::win32::handle_manager& local_wake_sem, detail::win32::handle_manager& sem) { boost::mutex::scoped_lock internal_lock(internal_mutex); detail::interlocked_write_release(&total_count,total_count+1); if(!local_wake_sem) { start_wait_loop_first_time(locker,local_wake_sem); } if(!generations[0].semaphore) { generations[0].semaphore=detail::win32::create_anonymous_semaphore(0,LONG_MAX); BOOST_ASSERT(generations[0].semaphore); } ++generations[0].count; sem=detail::win32::duplicate_handle(generations[0].semaphore); } protected: template
bool do_wait(lock_type& lock,timeout wait_until) { detail::win32::handle_manager local_wake_sem; detail::win32::handle_manager sem; bool woken=false; relocker
locker(lock); while(!woken) { start_wait_loop(locker,local_wake_sem,sem); if(!this_thread::interruptible_wait(sem,wait_until)) { return false; } unsigned long const woken_result=detail::win32::WaitForSingleObject(local_wake_sem,0); BOOST_ASSERT(woken_result==detail::win32::timeout || woken_result==0); woken=(woken_result==0); } return woken; } template
bool do_wait(lock_type& m,timeout const& wait_until,predicate_type pred) { while (!pred()) { if(!do_wait(m, wait_until)) return pred(); } return true; } basic_condition_variable(const basic_condition_variable& other); basic_condition_variable& operator=(const basic_condition_variable& other); public: basic_condition_variable(): total_count(0),active_generation_count(0),wake_sem(0) {} ~basic_condition_variable() { for(unsigned i=0;i
& m) { do_wait(m,detail::timeout::sentinel()); } template
void wait(unique_lock
& m,predicate_type pred) { while(!pred()) wait(m); } bool timed_wait(unique_lock
& m,boost::system_time const& wait_until) { return do_wait(m,wait_until); } bool timed_wait(unique_lock
& m,boost::xtime const& wait_until) { return do_wait(m,system_time(wait_until)); } template
bool timed_wait(unique_lock
& m,duration_type const& wait_duration) { return do_wait(m,wait_duration.total_milliseconds()); } template
bool timed_wait(unique_lock
& m,boost::system_time const& wait_until,predicate_type pred) { return do_wait(m,wait_until,pred); } template
bool timed_wait(unique_lock
& m,boost::xtime const& wait_until,predicate_type pred) { return do_wait(m,system_time(wait_until),pred); } template
bool timed_wait(unique_lock
& m,duration_type const& wait_duration,predicate_type pred) { return do_wait(m,wait_duration.total_milliseconds(),pred); } }; class condition_variable_any: public detail::basic_condition_variable { public: template
void wait(lock_type& m) { do_wait(m,detail::timeout::sentinel()); } template
void wait(lock_type& m,predicate_type pred) { while(!pred()) wait(m); } template
bool timed_wait(lock_type& m,boost::system_time const& wait_until) { return do_wait(m,wait_until); } template
bool timed_wait(lock_type& m,boost::xtime const& wait_until) { return do_wait(m,system_time(wait_until)); } template
bool timed_wait(lock_type& m,duration_type const& wait_duration) { return do_wait(m,wait_duration.total_milliseconds()); } template
bool timed_wait(lock_type& m,boost::system_time const& wait_until,predicate_type pred) { return do_wait(m,wait_until,pred); } template
bool timed_wait(lock_type& m,boost::xtime const& wait_until,predicate_type pred) { return do_wait(m,system_time(wait_until),pred); } template
bool timed_wait(lock_type& m,duration_type const& wait_duration,predicate_type pred) { return do_wait(m,wait_duration.total_milliseconds(),pred); } }; } #endif
condition_variable.hpp
Dirección de la página
Dirección del archivo
Anterior
3/12
Siguiente
Descargar
( 12 KB )
Comments
Total ratings:
0
Average rating:
No clasificado
of 10
Would you like to comment?
Join now
, or
Logon
if you are already a member.