|
1 /* |
|
2 * Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <new> |
|
19 #include <queue> |
|
20 #include <stdio.h> |
|
21 #include <stdlib.h> |
|
22 #include <cstring> |
|
23 #include <string> |
|
24 |
|
25 #include <thread/condition_variable.hpp> |
|
26 |
|
27 #include "cache/cacheexception.hpp" |
|
28 #include "cache/cacheentry.hpp" |
|
29 #include "cache/cacheablelist.hpp" |
|
30 |
|
31 |
|
32 CacheableList* CacheableList::Only = (CacheableList*)0; |
|
33 |
|
34 |
|
35 CacheableList* CacheableList::GetInstance(void) throw (CacheException) |
|
36 { |
|
37 if(! CacheableList::Only) |
|
38 { |
|
39 CacheableList::Only = new (std::nothrow) CacheableList(); |
|
40 if(! CacheableList::Only) |
|
41 throw CacheException(CacheException::RESOURCE_ALLOCATION_FAILURE); |
|
42 } |
|
43 |
|
44 return CacheableList::Only; |
|
45 } |
|
46 |
|
47 |
|
48 void CacheableList::AddCacheable(CacheEntry* EntryRef) |
|
49 { |
|
50 if(1) |
|
51 { |
|
52 boost::mutex::scoped_lock lock(this->queuemutex); |
|
53 this->filelist.push(EntryRef); |
|
54 } |
|
55 |
|
56 this->queuecond.notify_all(); |
|
57 |
|
58 return; |
|
59 } |
|
60 |
|
61 |
|
62 CacheEntry* CacheableList::GetCacheable(void) |
|
63 { |
|
64 boost::mutex::scoped_lock lock(this->queuemutex); |
|
65 while(this->filelist.empty()) |
|
66 this->queuecond.wait(lock); |
|
67 |
|
68 CacheEntry* resref = this->filelist.front(); |
|
69 this->filelist.pop(); |
|
70 |
|
71 return resref; |
|
72 } |
|
73 |
|
74 |
|
75 CacheableList::~CacheableList(void) |
|
76 { |
|
77 return; |
|
78 } |
|
79 |
|
80 |
|
81 CacheableList::CacheableList(void) |
|
82 { |
|
83 return; |
|
84 } |