Basic FreeType renderer implementation.
[gdipp.git] / gdipp_server / dc_pool.cpp
blob2a26e6c501df387cb3e8099026df2e8814fa8592
1 #include "stdafx.h"
2 #include "dc_pool.h"
3 #include "gdipp_lib/lock.h"
5 namespace gdipp
8 dc_pool::~dc_pool()
10 // TODO: change to blockingly wait until _busy.empty() is true
11 assert(_busy.empty());
13 BOOL b_ret;
15 for (std::list<HDC>::const_iterator free_iter = _free.begin(); free_iter != _free.end(); ++free_iter)
17 b_ret = DeleteDC(*free_iter);
18 assert(b_ret);
22 HDC dc_pool::claim()
24 // acquire a resource from the pool
25 // if no resource exists, create one by calling create() of the template class
26 // otherwise, remove one from the free resource set and add to busy set
28 lock l(lock::SERVER_DC_POOL);
30 HDC hdc;
32 if (_free.empty())
34 hdc = CreateCompatibleDC(NULL);
36 else
38 hdc = _free.front();
39 _free.pop_front();
41 _busy.insert(hdc);
43 return hdc;
46 bool dc_pool::free(HDC hdc)
48 // return claimed resource back to the pool
50 lock l(lock::SERVER_DC_POOL);
52 std::set<HDC>::const_iterator busy_iter = _busy.find(hdc);
53 if (busy_iter == _busy.end())
54 return false;
56 _free.push_back(*busy_iter);
57 _busy.erase(busy_iter);
59 return true;