2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "image-load-thread.h"
30 LoadingTask::LoadingTask(BitmapLoader loader, uint32_t packPositionX, uint32_t packPositionY, uint32_t width, uint32_t height )
32 packRect( packPositionX, packPositionY, width, height )
36 LoadQueue::LoadQueue()
40 LoadQueue::~LoadQueue()
44 LoadingTask* LoadQueue::NextTask()
46 // Lock while popping task out from the queue
47 ConditionalWait::ScopedLock lock( mConditionalWait );
49 while( mTasks.Empty() )
51 mConditionalWait.Wait( lock );
54 Vector< LoadingTask* >::Iterator next = mTasks.Begin();
55 LoadingTask* nextTask = *next;
61 void LoadQueue::AddTask( LoadingTask* task )
63 bool wasEmpty = false;
66 // Lock while adding task to the queue
67 ConditionalWait::ScopedLock lock( mConditionalWait );
68 wasEmpty = mTasks.Empty();
69 mTasks.PushBack( task );
74 // wake up the image loading thread
75 mConditionalWait.Notify();
79 CompleteQueue::CompleteQueue(EventThreadCallback* trigger)
83 CompleteQueue::~CompleteQueue()
88 LoadingTask* CompleteQueue::NextTask()
90 // Lock while popping task out from the queue
91 Mutex::ScopedLock lock( mMutex );
98 Vector< LoadingTask* >::Iterator next = mTasks.Begin();
99 LoadingTask* nextTask = *next;
100 mTasks.Erase( next );
105 void CompleteQueue::AddTask( LoadingTask* task )
107 // Lock while adding task to the queue
108 Mutex::ScopedLock lock( mMutex );
109 mTasks.PushBack( task );
111 // wake up the main thread
116 ImageLoadThread::ImageLoadThread( LoadQueue& loadQueue, CompleteQueue& completeQueue )
117 : mLoadQueue( loadQueue ),
118 mCompleteQueue( completeQueue )
122 ImageLoadThread::~ImageLoadThread()
126 void ImageLoadThread::Run()
128 while( LoadingTask* task = mLoadQueue.NextTask() )
131 mCompleteQueue.AddTask( task );
135 } // namespace Internal
137 } // namespace Toolkit