Use One-Time Initialization for glyph run caching to avoid duplicate glyph run genera...
[gdipp.git] / gdipp_lib / scoped_rw_lock.cpp
blobd9e58b9c05abed235e32145f3afc96b44f11c682
1 #include "stdafx.h"
2 #include "scoped_rw_lock.h"
4 namespace gdipp
7 std::vector<SRWLOCK> scoped_rw_lock::_srws;
9 void scoped_rw_lock::initialize()
11 _srws.resize(LAST_MONITOR_LOCATION);
12 for (int i = 0; i < LAST_MONITOR_LOCATION; ++i)
13 InitializeSRWLock(&_srws[i]);
16 scoped_rw_lock::scoped_rw_lock(MONITOR_LOCATION cs_location, bool is_shared)
18 _curr_srw = &_srws[cs_location];
19 _is_shared = is_shared;
21 if (is_shared)
22 AcquireSRWLockShared(_curr_srw);
23 else
24 AcquireSRWLockExclusive(_curr_srw);
27 scoped_rw_lock::~scoped_rw_lock()
29 if (_is_shared)
30 ReleaseSRWLockShared(_curr_srw);
31 else
32 ReleaseSRWLockExclusive(_curr_srw);