0

To apply a general lock, I can do this:

CAutoLock(CCritSec * plock)

But how can I set read and write lock respectively?

Alan
  • 5,029
  • 5
  • 32
  • 37

3 Answers3

0

This post talks about using reader-writer locks.

Community
  • 1
  • 1
Rishabh
  • 674
  • 1
  • 9
  • 19
  • For directshow, there's already pretty nice locking primitives built-in, so I'd steer clear of any home-brewed/third-party stuff. – kidjan Sep 17 '10 at 00:14
0

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

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
0

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
  • 1,471
  • 14
  • 16