views:

19

answers:

3

To apply a general lock, I can do this:

CAutoLock(CCritSec * plock)

But how can I set read and write lock respectively?

A: 

This post talks about using reader-writer locks.

rtdecl
For directshow, there's already pretty nice locking primitives built-in, so I'd steer clear of any home-brewed/third-party stuff.
kidjan
A: 

I would just use two separate locks...it might be possible otherwise tho.

rogerdpack
A: 

Simply have two separate CCritSec objects:

CCritSec writeLock, readLock;

void Blah::SomeMethod()
{
    CAutoLock writeAutoLock( &writeLock );
    ...
}

void Blah::SomeOtherMethod()
{
    CAutoLock readAutoLock( &readLock );
}

You can also lock without the auto-lock class, but I wouldn't recommend it unless your functions/methods are short and there's no possible way you'd forget to unlock.

kidjan