Click here to Skip to main content
15,881,139 members
Articles / Programming Languages / C

How to develop a virtual disk for Windows

,
Rate me:
Please Sign up or sign in to vote.
4.99/5 (98 votes)
15 Feb 2010CPOL10 min read 195.2K   8.2K   335  
This article is oriented to Windows-developers and considers how to create virtual disk in Windows system.
// cmnprotectedlist.h
#ifndef CMN_PROTECTED_LIST_H
#define CMN_PROTECTED_LIST_H
#include "auto_resource.h"
#include "list"
namespace utils
{

template<class T, class Sync, class Event>
class ProtectedList
{
    std::list<T> list_;
    mutable Sync guard_;
    Event ownNotEmptyEvent_;
    Event& notEmptyEvent_;
    ProtectedList(const ProtectedList& );
    const ProtectedList& operator=(const ProtectedList& );

protected:
    virtual std::list<T> & get_list() { return list_; }
    virtual const std::list<T> & get_list() const { return list_; }
    virtual Sync & get_lock() const { return guard_; }
    virtual void on_pop(){}
public:
    ProtectedList()
        : notEmptyEvent_(ownNotEmptyEvent_)
    {
    }
    ProtectedList(Event& notEmptyEvent)
        : notEmptyEvent_(notEmptyEvent)
    {
    }
    virtual ~ProtectedList()
    {
    }
    
    Event * get_event_ptr()
    {
        return &notEmptyEvent_;
    }
    
    void push(const T& val)
    {
        AutoResource<Sync> guard(guard_);
        list_.push_front(val);
        if(list_.size() == 1)
            notEmptyEvent_.set();
    }
    void push_back(const T& val)
    {
        AutoResource<Sync> guard(guard_);
        list_.push_back(val);
        if(list_.size() == 1)
            notEmptyEvent_.set();
    }
    bool pop(T& val)
    {
        AutoResource<Sync> guard(guard_);
        if(list_.empty())
            return false;
        val = list_.front();
        list_.pop_front();
        if(list_.empty())
            notEmptyEvent_.reset();
        on_pop();
        return true;
    }

    bool pop_swap(T& val)
    {
        AutoResource<Sync> guard(guard_);
        if(list_.empty())
            return false;
        
        list_.front().swap(val);
        list_.pop_front();

        if(list_.empty())
            notEmptyEvent_.reset();
        
        on_pop();
        return true;
    }

    size_t size()
    {
        AutoResource<Sync> guard(guard_);
        return list_.size();
    }

    void clear()
    {
        AutoResource<Sync> guard(guard_);
        list_.clear();
    }
};

}//namespace utils
#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer Apriorit Inc.
United States United States
ApriorIT is a software research and development company specializing in cybersecurity and data management technology engineering. We work for a broad range of clients from Fortune 500 technology leaders to small innovative startups building unique solutions.

As Apriorit offers integrated research&development services for the software projects in such areas as endpoint security, network security, data security, embedded Systems, and virtualization, we have strong kernel and driver development skills, huge system programming expertise, and are reals fans of research projects.

Our specialty is reverse engineering, we apply it for security testing and security-related projects.

A separate department of Apriorit works on large-scale business SaaS solutions, handling tasks from business analysis, data architecture design, and web development to performance optimization and DevOps.

Official site: https://www.apriorit.com
Clutch profile: https://clutch.co/profile/apriorit
This is a Organisation

33 members

Written By
Team Leader ApriorIT
Ukraine Ukraine
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions