VirtualBox

Changeset 55200 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Apr 13, 2015 3:22:12 AM (10 years ago)
Author:
vboxsync
Message:

Main/HostDnsService: use <iprt/cpp/lock.h> instead of a roll-your-own version.

Location:
trunk/src/VBox/Main/src-server
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/HostDnsService.cpp

    r55199 r55200  
    3838static void dumpHostDnsStrVector(const std::string&, const std::vector<std::string>&);
    3939
    40 /* Lockee */
    41 Lockee::Lockee()
    42 {
    43     RTCritSectInit(&mLock);
    44 }
    45 
    46 Lockee::~Lockee()
    47 {
    48     RTCritSectDelete(&mLock);
    49 }
    50 
    51 const RTCRITSECT* Lockee::lock() const
    52 {
    53     return &mLock;
    54 }
    55 
    56 /* ALock */
    57 ALock::ALock(const Lockee *aLockee)
    58   : lockee(aLockee)
    59 {
    60     RTCritSectEnter(const_cast<PRTCRITSECT>(lockee->lock()));
    61 }
    62 
    63 ALock::~ALock()
    64 {
    65     RTCritSectLeave(const_cast<PRTCRITSECT>(lockee->lock()));
    66 }
    67 
    68 /* HostDnsInformation */
    6940
    7041bool HostDnsInformation::equals(const HostDnsInformation &info) const
     
    165136void HostDnsMonitor::addMonitorProxy(PCHostDnsMonitorProxy proxy) const
    166137{
    167     ALock l(this);
     138    RTCLock grab(m_LockMtx);
    168139    m->proxies.push_back(proxy);
    169140    proxy->notify();
     
    172143void HostDnsMonitor::releaseMonitorProxy(PCHostDnsMonitorProxy proxy) const
    173144{
    174     ALock l(this);
     145    RTCLock grab(m_LockMtx);
    175146    std::vector<PCHostDnsMonitorProxy>::iterator it;
    176147    it = std::find(m->proxies.begin(), m->proxies.end(), proxy);
     
    198169void HostDnsMonitor::setInfo(const HostDnsInformation &info)
    199170{
    200     ALock l(this);
     171    RTCLock grab(m_LockMtx);
    201172
    202173    if (info.equals(m->info))
     
    279250{
    280251    AssertReturn(m && m->info, E_FAIL);
    281     ALock l(this);
     252    RTCLock grab(m_LockMtx);
    282253
    283254    if (m->fModified)
     
    295266{
    296267    AssertReturn(m && m->info, E_FAIL);
    297     ALock l(this);
     268    RTCLock grab(m_LockMtx);
    298269
    299270    if (m->fModified)
     
    311282{
    312283    AssertReturn(m && m->info, E_FAIL);
    313     ALock l(this);
     284    RTCLock grab(m_LockMtx);
    314285
    315286    if (m->fModified)
  • trunk/src/VBox/Main/src-server/HostDnsService.h

    r55198 r55200  
    2121
    2222#include <iprt/cdefs.h>
    23 #include <iprt/critsect.h>
    2423#include <iprt/types.h>
     24#include <iprt/cpp/lock.h>
    2525
    2626#include <list>
     
    3232class HostDnsMonitorProxy;
    3333typedef const HostDnsMonitorProxy *PCHostDnsMonitorProxy;
    34 
    35 class Lockee
    36 {
    37   public:
    38     Lockee();
    39     virtual ~Lockee();
    40     const RTCRITSECT* lock() const;
    41 
    42   private:
    43     RTCRITSECT mLock;
    44 };
    45 
    46 class ALock
    47 {
    48   public:
    49     explicit ALock(const Lockee *l);
    50     ~ALock();
    51 
    52   private:
    53     const Lockee *lockee;
    54 };
    5534
    5635class HostDnsInformation
     
    6746 * it lifecycle starts and ends together with VBoxSVC.
    6847 */
    69 class HostDnsMonitor : public Lockee
     48class HostDnsMonitor
    7049{
    7150  public:
     
    9675    static int threadMonitoringRoutine(RTTHREAD, void *);
    9776
     77  protected:
     78    mutable RTCLockMtx m_LockMtx;
     79
    9880  public:
    9981    struct Data;
     
    10486 * This class supposed to be a proxy for events on changing Host Name Resolving configurations.
    10587 */
    106 class HostDnsMonitorProxy : public Lockee
     88class HostDnsMonitorProxy
    10789{
    10890    public:
     
    120102    private:
    121103    void updateInfo();
     104 
     105  private:
     106    mutable RTCLockMtx m_LockMtx;
    122107
    123108    private:
  • trunk/src/VBox/Main/src-server/darwin/HostDnsServiceDarwin.cpp

    r54662 r55200  
    7777    HostDnsServiceDarwin *pThis = (HostDnsServiceDarwin *)info;
    7878
    79     ALock l(pThis);
     79    RTCLock grab(pThis->m_LockMtx);
    8080    pThis->updateInfo();
    8181}
     
    116116void HostDnsServiceDarwin::monitorThreadShutdown()
    117117{
    118     ALock l(this);
     118    RTCLock grab(m_LockMtx);
    119119    if (!m->m_fStop)
    120120    {
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette