1 /* 2 * priority_buffer_queue.cpp - priority buffer queue 3 * 4 * Copyright (c) 2015 Intel Corporation 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 * Author: Wind Yuan <feng.yuan@intel.com> 19 */ 20 21 #include "priority_buffer_queue.h" 22 23 #define XCAM_PRIORITY_BUFFER_FIXED_DELAY 8 24 25 namespace XCam { 26 27 bool priority_greater_than(const PriorityBuffer & buf) const28PriorityBuffer::priority_greater_than (const PriorityBuffer& buf) const 29 { 30 int32_t result = 31 ((int32_t)(buf.seq_num - this->seq_num) * XCAM_PRIORITY_BUFFER_FIXED_DELAY + 32 (int32_t)(buf.rank - this->rank)); 33 if (result == 0) { 34 return (int32_t)(buf.seq_num - this->seq_num) > 0; 35 } 36 return result > 0; 37 } 38 39 40 bool push_priority_buf(const SmartPtr<PriorityBuffer> & buf)41PriorityBufferQueue::push_priority_buf (const SmartPtr<PriorityBuffer> &buf) 42 { 43 XCAM_ASSERT (buf.ptr ()); 44 SmartLock lock (_mutex); 45 46 ObjList::iterator iter = _obj_list.begin (); 47 48 for (; iter != _obj_list.end (); ++iter) { 49 SmartPtr<PriorityBuffer> ¤t = *iter; 50 XCAM_ASSERT (current.ptr ()); 51 if (buf->priority_greater_than (*current.ptr())) 52 break; 53 } 54 55 _obj_list.insert (iter, buf); 56 _new_obj_cond.signal (); 57 return true; 58 } 59 60 }; 61