mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-16 22:21:11 +08:00
[lock]: use AutoMutex to replace Mutex::Autolock
[mpp_mem]: add lock to mem_list and add dump memory status function git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@526 6e48237b-75ef-9749-8fc9-41990f28c85a
This commit is contained in:
@@ -1485,9 +1485,9 @@ static RK_S32 split_nal_units(HEVCContext *s, RK_U8 *buf, RK_U32 length)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (buf[0] != 0 || buf[1] != 0 || buf[2] != 1) {
|
if (buf[0] != 0 || buf[1] != 0 || buf[2] != 1) {
|
||||||
uint32_t state = -1;
|
RK_U32 state = (RK_U32)-1;
|
||||||
int has_nal = 0;
|
int has_nal = 0;
|
||||||
for (i = 0; i < length; i++) {
|
for (i = 0; i < (RK_S32)length; i++) {
|
||||||
state = (state << 8) | buf[i];
|
state = (state << 8) | buf[i];
|
||||||
if (((state >> 8) & 0xFFFFFF) == START_CODE){
|
if (((state >> 8) & 0xFFFFFF) == START_CODE){
|
||||||
has_nal = 1;
|
has_nal = 1;
|
||||||
|
@@ -549,7 +549,7 @@ MPP_RET mpp_buf_slot_setup(MppBufSlots slots, RK_S32 count)
|
|||||||
buf_slot_dbg(BUF_SLOT_DBG_SETUP, "slot %p setup: count %d\n", slots, count);
|
buf_slot_dbg(BUF_SLOT_DBG_SETUP, "slot %p setup: count %d\n", slots, count);
|
||||||
|
|
||||||
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
||||||
Mutex::Autolock auto_lock(impl->lock);
|
AutoMutex auto_lock(impl->lock);
|
||||||
|
|
||||||
if (NULL == impl->slots) {
|
if (NULL == impl->slots) {
|
||||||
// first slot setup
|
// first slot setup
|
||||||
@@ -576,7 +576,7 @@ RK_U32 mpp_buf_slot_is_changed(MppBufSlots slots)
|
|||||||
}
|
}
|
||||||
|
|
||||||
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
||||||
Mutex::Autolock auto_lock(impl->lock);
|
AutoMutex auto_lock(impl->lock);
|
||||||
return impl->info_changed;
|
return impl->info_changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -590,7 +590,7 @@ MPP_RET mpp_buf_slot_ready(MppBufSlots slots)
|
|||||||
buf_slot_dbg(BUF_SLOT_DBG_SETUP, "slot %p is ready now\n", slots);
|
buf_slot_dbg(BUF_SLOT_DBG_SETUP, "slot %p is ready now\n", slots);
|
||||||
|
|
||||||
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
||||||
Mutex::Autolock auto_lock(impl->lock);
|
AutoMutex auto_lock(impl->lock);
|
||||||
slot_assert(impl, impl->info_changed);
|
slot_assert(impl, impl->info_changed);
|
||||||
slot_assert(impl, impl->slots);
|
slot_assert(impl, impl->slots);
|
||||||
|
|
||||||
@@ -632,7 +632,7 @@ MPP_RET mpp_buf_slot_get_unused(MppBufSlots slots, RK_S32 *index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
||||||
Mutex::Autolock auto_lock(impl->lock);
|
AutoMutex auto_lock(impl->lock);
|
||||||
RK_S32 i;
|
RK_S32 i;
|
||||||
MppBufSlotEntry *slot = impl->slots;
|
MppBufSlotEntry *slot = impl->slots;
|
||||||
for (i = 0; i < impl->buf_count; i++, slot++) {
|
for (i = 0; i < impl->buf_count; i++, slot++) {
|
||||||
@@ -659,7 +659,7 @@ MPP_RET mpp_buf_slot_set_flag(MppBufSlots slots, RK_S32 index, SlotUsageType typ
|
|||||||
}
|
}
|
||||||
|
|
||||||
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
||||||
Mutex::Autolock auto_lock(impl->lock);
|
AutoMutex auto_lock(impl->lock);
|
||||||
slot_assert(impl, (index >= 0) && (index < impl->buf_count));
|
slot_assert(impl, (index >= 0) && (index < impl->buf_count));
|
||||||
slot_ops_with_log(impl, &impl->slots[index], set_flag_op[type]);
|
slot_ops_with_log(impl, &impl->slots[index], set_flag_op[type]);
|
||||||
return MPP_OK;
|
return MPP_OK;
|
||||||
@@ -673,7 +673,7 @@ MPP_RET mpp_buf_slot_clr_flag(MppBufSlots slots, RK_S32 index, SlotUsageType typ
|
|||||||
}
|
}
|
||||||
|
|
||||||
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
||||||
Mutex::Autolock auto_lock(impl->lock);
|
AutoMutex auto_lock(impl->lock);
|
||||||
slot_assert(impl, (index >= 0) && (index < impl->buf_count));
|
slot_assert(impl, (index >= 0) && (index < impl->buf_count));
|
||||||
MppBufSlotEntry *slot = &impl->slots[index];
|
MppBufSlotEntry *slot = &impl->slots[index];
|
||||||
slot_ops_with_log(impl, slot, clr_flag_op[type]);
|
slot_ops_with_log(impl, slot, clr_flag_op[type]);
|
||||||
@@ -693,7 +693,7 @@ MPP_RET mpp_buf_slot_enqueue(MppBufSlots slots, RK_S32 index, SlotQueueType type
|
|||||||
}
|
}
|
||||||
|
|
||||||
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
||||||
Mutex::Autolock auto_lock(impl->lock);
|
AutoMutex auto_lock(impl->lock);
|
||||||
slot_assert(impl, (index >= 0) && (index < impl->buf_count));
|
slot_assert(impl, (index >= 0) && (index < impl->buf_count));
|
||||||
MppBufSlotEntry *slot = &impl->slots[index];
|
MppBufSlotEntry *slot = &impl->slots[index];
|
||||||
slot_ops_with_log(impl, slot, SLOT_ENQUEUE);
|
slot_ops_with_log(impl, slot, SLOT_ENQUEUE);
|
||||||
@@ -712,7 +712,7 @@ MPP_RET mpp_buf_slot_dequeue(MppBufSlots slots, RK_S32 *index, SlotQueueType typ
|
|||||||
}
|
}
|
||||||
|
|
||||||
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
||||||
Mutex::Autolock auto_lock(impl->lock);
|
AutoMutex auto_lock(impl->lock);
|
||||||
if (list_empty(&impl->queue[type]))
|
if (list_empty(&impl->queue[type]))
|
||||||
return MPP_NOK;
|
return MPP_NOK;
|
||||||
|
|
||||||
@@ -738,7 +738,7 @@ MPP_RET mpp_buf_slot_set_prop(MppBufSlots slots, RK_S32 index, SlotPropType type
|
|||||||
}
|
}
|
||||||
|
|
||||||
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
||||||
Mutex::Autolock auto_lock(impl->lock);
|
AutoMutex auto_lock(impl->lock);
|
||||||
slot_assert(impl, (index >= 0) && (index < impl->buf_count));
|
slot_assert(impl, (index >= 0) && (index < impl->buf_count));
|
||||||
MppBufSlotEntry *slot = &impl->slots[index];
|
MppBufSlotEntry *slot = &impl->slots[index];
|
||||||
slot_ops_with_log(impl, slot, set_val_op[type]);
|
slot_ops_with_log(impl, slot, set_val_op[type]);
|
||||||
@@ -821,7 +821,7 @@ MPP_RET mpp_buf_slot_get_prop(MppBufSlots slots, RK_S32 index, SlotPropType type
|
|||||||
}
|
}
|
||||||
|
|
||||||
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
||||||
Mutex::Autolock auto_lock(impl->lock);
|
AutoMutex auto_lock(impl->lock);
|
||||||
slot_assert(impl, (index >= 0) && (index < impl->buf_count));
|
slot_assert(impl, (index >= 0) && (index < impl->buf_count));
|
||||||
MppBufSlotEntry *slot = &impl->slots[index];
|
MppBufSlotEntry *slot = &impl->slots[index];
|
||||||
|
|
||||||
@@ -863,7 +863,7 @@ MPP_RET mpp_slots_set_prop(MppBufSlots slots, SlotsPropType type, void *val)
|
|||||||
}
|
}
|
||||||
|
|
||||||
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
||||||
Mutex::Autolock auto_lock(impl->lock);
|
AutoMutex auto_lock(impl->lock);
|
||||||
RK_U32 value = *((RK_U32*)val);
|
RK_U32 value = *((RK_U32*)val);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SLOTS_EOS: {
|
case SLOTS_EOS: {
|
||||||
@@ -905,7 +905,7 @@ MPP_RET mpp_slots_get_prop(MppBufSlots slots, SlotsPropType type, void *val)
|
|||||||
}
|
}
|
||||||
|
|
||||||
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
||||||
Mutex::Autolock auto_lock(impl->lock);
|
AutoMutex auto_lock(impl->lock);
|
||||||
MPP_RET ret = MPP_OK;
|
MPP_RET ret = MPP_OK;
|
||||||
RK_U32 value = 0;
|
RK_U32 value = 0;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -945,7 +945,7 @@ MPP_RET mpp_buf_slot_reset(MppBufSlots slots, RK_S32 index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
|
||||||
Mutex::Autolock auto_lock(impl->lock);
|
AutoMutex auto_lock(impl->lock);
|
||||||
slot_assert(impl, (index >= 0) && (index < impl->buf_count));
|
slot_assert(impl, (index >= 0) && (index < impl->buf_count));
|
||||||
MppBufSlotEntry *slot = &impl->slots[index];
|
MppBufSlotEntry *slot = &impl->slots[index];
|
||||||
|
|
||||||
|
@@ -257,7 +257,7 @@ static MPP_RET try_proc_dec_task(Mpp *mpp, DecTask *task)
|
|||||||
*/
|
*/
|
||||||
if (!dec->mpp_pkt_in && !task->status.curr_task_rdy) {
|
if (!dec->mpp_pkt_in && !task->status.curr_task_rdy) {
|
||||||
mpp_list *packets = mpp->mPackets;
|
mpp_list *packets = mpp->mPackets;
|
||||||
Mutex::Autolock autoLock(packets->mutex());
|
AutoMutex autoLock(packets->mutex());
|
||||||
if (packets->list_size()) {
|
if (packets->list_size()) {
|
||||||
/*
|
/*
|
||||||
* packet will be destroyed outside, here just copy the content
|
* packet will be destroyed outside, here just copy the content
|
||||||
|
@@ -37,7 +37,7 @@ void *mpp_enc_control_thread(void *data)
|
|||||||
char *buf = mpp_malloc(char, size);
|
char *buf = mpp_malloc(char, size);
|
||||||
|
|
||||||
while (MPP_THREAD_RUNNING == thd_enc->get_status()) {
|
while (MPP_THREAD_RUNNING == thd_enc->get_status()) {
|
||||||
Mutex::Autolock auto_lock(frames->mutex());
|
AutoMutex auto_lock(frames->mutex());
|
||||||
if (frames->list_size()) {
|
if (frames->list_size()) {
|
||||||
frames->del_at_head(&frame, sizeof(frame));
|
frames->del_at_head(&frame, sizeof(frame));
|
||||||
|
|
||||||
|
@@ -129,7 +129,7 @@ MPP_RET hal_task_get_hnd(HalTaskGroup group, MppTaskStatus status, HalTaskHnd *h
|
|||||||
|
|
||||||
*hnd = NULL;
|
*hnd = NULL;
|
||||||
HalTaskGroupImpl *p = (HalTaskGroupImpl *)group;
|
HalTaskGroupImpl *p = (HalTaskGroupImpl *)group;
|
||||||
Mutex::Autolock auto_lock(p->lock);
|
AutoMutex auto_lock(p->lock);
|
||||||
struct list_head *list = &p->list[status];
|
struct list_head *list = &p->list[status];
|
||||||
if (list_empty(list))
|
if (list_empty(list))
|
||||||
return MPP_NOK;
|
return MPP_NOK;
|
||||||
@@ -147,7 +147,7 @@ MPP_RET hal_task_check_empty(HalTaskGroup group, MppTaskStatus status)
|
|||||||
return MPP_ERR_UNKNOW;
|
return MPP_ERR_UNKNOW;
|
||||||
}
|
}
|
||||||
HalTaskGroupImpl *p = (HalTaskGroupImpl *)group;
|
HalTaskGroupImpl *p = (HalTaskGroupImpl *)group;
|
||||||
Mutex::Autolock auto_lock(p->lock);
|
AutoMutex auto_lock(p->lock);
|
||||||
struct list_head *list = &p->list[status];
|
struct list_head *list = &p->list[status];
|
||||||
if (list_empty(list)) {
|
if (list_empty(list)) {
|
||||||
return MPP_OK;
|
return MPP_OK;
|
||||||
@@ -162,7 +162,7 @@ MPP_RET hal_task_get_count(HalTaskGroup group, MppTaskStatus status, RK_U32 *cou
|
|||||||
}
|
}
|
||||||
|
|
||||||
HalTaskGroupImpl *p = (HalTaskGroupImpl *)group;
|
HalTaskGroupImpl *p = (HalTaskGroupImpl *)group;
|
||||||
Mutex::Autolock auto_lock(p->lock);
|
AutoMutex auto_lock(p->lock);
|
||||||
*count = p->task_count[status];
|
*count = p->task_count[status];
|
||||||
return MPP_OK;
|
return MPP_OK;
|
||||||
}
|
}
|
||||||
@@ -179,7 +179,7 @@ MPP_RET hal_task_hnd_set_status(HalTaskHnd hnd, MppTaskStatus status)
|
|||||||
mpp_assert(group);
|
mpp_assert(group);
|
||||||
mpp_assert(impl->index < group->count);
|
mpp_assert(impl->index < group->count);
|
||||||
|
|
||||||
Mutex::Autolock auto_lock(group->lock);
|
AutoMutex auto_lock(group->lock);
|
||||||
list_del_init(&impl->list);
|
list_del_init(&impl->list);
|
||||||
list_add_tail(&impl->list, &group->list[status]);
|
list_add_tail(&impl->list, &group->list[status]);
|
||||||
group->task_count[impl->status]--;
|
group->task_count[impl->status]--;
|
||||||
@@ -198,7 +198,7 @@ MPP_RET hal_task_hnd_set_info(HalTaskHnd hnd, HalTaskInfo *task)
|
|||||||
HalTaskImpl *impl = (HalTaskImpl *)hnd;
|
HalTaskImpl *impl = (HalTaskImpl *)hnd;
|
||||||
HalTaskGroupImpl *group = impl->group;
|
HalTaskGroupImpl *group = impl->group;
|
||||||
mpp_assert(impl->index < group->count);
|
mpp_assert(impl->index < group->count);
|
||||||
Mutex::Autolock auto_lock(group->lock);
|
AutoMutex auto_lock(group->lock);
|
||||||
memcpy(&impl->task, task, sizeof(impl->task));
|
memcpy(&impl->task, task, sizeof(impl->task));
|
||||||
return MPP_OK;
|
return MPP_OK;
|
||||||
}
|
}
|
||||||
@@ -213,7 +213,7 @@ MPP_RET hal_task_hnd_get_info(HalTaskHnd hnd, HalTaskInfo *task)
|
|||||||
HalTaskImpl *impl = (HalTaskImpl *)hnd;
|
HalTaskImpl *impl = (HalTaskImpl *)hnd;
|
||||||
HalTaskGroupImpl *group = impl->group;
|
HalTaskGroupImpl *group = impl->group;
|
||||||
mpp_assert(impl->index < group->count);
|
mpp_assert(impl->index < group->count);
|
||||||
Mutex::Autolock auto_lock(group->lock);
|
AutoMutex auto_lock(group->lock);
|
||||||
memcpy(task, &impl->task, sizeof(impl->task));
|
memcpy(task, &impl->task, sizeof(impl->task));
|
||||||
return MPP_OK;
|
return MPP_OK;
|
||||||
}
|
}
|
||||||
|
@@ -189,7 +189,7 @@ void Mpp::clear()
|
|||||||
|
|
||||||
MPP_RET Mpp::put_packet(MppPacket packet)
|
MPP_RET Mpp::put_packet(MppPacket packet)
|
||||||
{
|
{
|
||||||
Mutex::Autolock autoLock(mPackets->mutex());
|
AutoMutex autoLock(mPackets->mutex());
|
||||||
RK_U32 eos = mpp_packet_get_eos(packet);
|
RK_U32 eos = mpp_packet_get_eos(packet);
|
||||||
if (mPackets->list_size() < 4 || eos) {
|
if (mPackets->list_size() < 4 || eos) {
|
||||||
MppPacket pkt;
|
MppPacket pkt;
|
||||||
@@ -204,7 +204,7 @@ MPP_RET Mpp::put_packet(MppPacket packet)
|
|||||||
|
|
||||||
MPP_RET Mpp::get_frame(MppFrame *frame)
|
MPP_RET Mpp::get_frame(MppFrame *frame)
|
||||||
{
|
{
|
||||||
Mutex::Autolock autoLock(mFrames->mutex());
|
AutoMutex autoLock(mFrames->mutex());
|
||||||
MppFrame first = NULL;
|
MppFrame first = NULL;
|
||||||
|
|
||||||
if (0 == mFrames->list_size()) {
|
if (0 == mFrames->list_size()) {
|
||||||
@@ -238,7 +238,7 @@ MPP_RET Mpp::get_frame(MppFrame *frame)
|
|||||||
|
|
||||||
MPP_RET Mpp::put_frame(MppFrame frame)
|
MPP_RET Mpp::put_frame(MppFrame frame)
|
||||||
{
|
{
|
||||||
Mutex::Autolock autoLock(mFrames->mutex());
|
AutoMutex autoLock(mFrames->mutex());
|
||||||
if (mFrames->list_size() < 4) {
|
if (mFrames->list_size() < 4) {
|
||||||
mFrames->add_at_tail(frame, sizeof(MppFrameImpl));
|
mFrames->add_at_tail(frame, sizeof(MppFrameImpl));
|
||||||
mThreadCodec->signal();
|
mThreadCodec->signal();
|
||||||
@@ -250,7 +250,7 @@ MPP_RET Mpp::put_frame(MppFrame frame)
|
|||||||
|
|
||||||
MPP_RET Mpp::get_packet(MppPacket *packet)
|
MPP_RET Mpp::get_packet(MppPacket *packet)
|
||||||
{
|
{
|
||||||
Mutex::Autolock autoLock(mPackets->mutex());
|
AutoMutex autoLock(mPackets->mutex());
|
||||||
if (0 == mPackets->list_size()) {
|
if (0 == mPackets->list_size()) {
|
||||||
mThreadCodec->signal();
|
mThreadCodec->signal();
|
||||||
if (mOutputBlock)
|
if (mOutputBlock)
|
||||||
|
@@ -186,7 +186,7 @@ static void dump_buffer_info(MppBufferImpl *buffer)
|
|||||||
|
|
||||||
MPP_RET mpp_buffer_create(const char *tag, const char *caller, RK_U32 group_id, MppBufferInfo *info)
|
MPP_RET mpp_buffer_create(const char *tag, const char *caller, RK_U32 group_id, MppBufferInfo *info)
|
||||||
{
|
{
|
||||||
Mutex::Autolock auto_lock(&service.mLock);
|
AutoMutex auto_lock(&service.mLock);
|
||||||
|
|
||||||
MppBufferGroupImpl *group = SEARCH_GROUP_NORMAL(group_id);
|
MppBufferGroupImpl *group = SEARCH_GROUP_NORMAL(group_id);
|
||||||
if (NULL == group) {
|
if (NULL == group) {
|
||||||
@@ -239,7 +239,7 @@ MPP_RET mpp_buffer_create(const char *tag, const char *caller, RK_U32 group_id,
|
|||||||
|
|
||||||
MPP_RET mpp_buffer_destroy(MppBufferImpl *buffer)
|
MPP_RET mpp_buffer_destroy(MppBufferImpl *buffer)
|
||||||
{
|
{
|
||||||
Mutex::Autolock auto_lock(&service.mLock);
|
AutoMutex auto_lock(&service.mLock);
|
||||||
|
|
||||||
deinit_buffer_no_lock(buffer);
|
deinit_buffer_no_lock(buffer);
|
||||||
|
|
||||||
@@ -248,7 +248,7 @@ MPP_RET mpp_buffer_destroy(MppBufferImpl *buffer)
|
|||||||
|
|
||||||
MPP_RET mpp_buffer_ref_inc(MppBufferImpl *buffer)
|
MPP_RET mpp_buffer_ref_inc(MppBufferImpl *buffer)
|
||||||
{
|
{
|
||||||
Mutex::Autolock auto_lock(&service.mLock);
|
AutoMutex auto_lock(&service.mLock);
|
||||||
return inc_buffer_ref_no_lock(buffer);
|
return inc_buffer_ref_no_lock(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,7 +260,7 @@ MPP_RET mpp_buffer_ref_dec(MppBufferImpl *buffer)
|
|||||||
return MPP_NOK;
|
return MPP_NOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mutex::Autolock auto_lock(&service.mLock);
|
AutoMutex auto_lock(&service.mLock);
|
||||||
|
|
||||||
buffer->ref_count--;
|
buffer->ref_count--;
|
||||||
if (0 == buffer->ref_count) {
|
if (0 == buffer->ref_count) {
|
||||||
@@ -293,7 +293,7 @@ MppBufferImpl *mpp_buffer_get_unused(MppBufferGroupImpl *p, size_t size)
|
|||||||
{
|
{
|
||||||
MppBufferImpl *buffer = NULL;
|
MppBufferImpl *buffer = NULL;
|
||||||
|
|
||||||
Mutex::Autolock auto_lock(&service.mLock);
|
AutoMutex auto_lock(&service.mLock);
|
||||||
|
|
||||||
if (!list_empty(&p->list_unused)) {
|
if (!list_empty(&p->list_unused)) {
|
||||||
MppBufferImpl *pos, *n;
|
MppBufferImpl *pos, *n;
|
||||||
@@ -325,7 +325,7 @@ MPP_RET mpp_buffer_group_init(MppBufferGroupImpl **group, const char *tag, const
|
|||||||
|
|
||||||
mpp_assert(caller);
|
mpp_assert(caller);
|
||||||
|
|
||||||
Mutex::Autolock auto_lock(&service.mLock);
|
AutoMutex auto_lock(&service.mLock);
|
||||||
|
|
||||||
INIT_LIST_HEAD(&p->list_group);
|
INIT_LIST_HEAD(&p->list_group);
|
||||||
INIT_LIST_HEAD(&p->list_used);
|
INIT_LIST_HEAD(&p->list_used);
|
||||||
@@ -372,7 +372,7 @@ MPP_RET mpp_buffer_group_deinit(MppBufferGroupImpl *p)
|
|||||||
return MPP_ERR_NULL_PTR;
|
return MPP_ERR_NULL_PTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mutex::Autolock auto_lock(&service.mLock);
|
AutoMutex auto_lock(&service.mLock);
|
||||||
|
|
||||||
// remove unused list
|
// remove unused list
|
||||||
if (!list_empty(&p->list_unused)) {
|
if (!list_empty(&p->list_unused)) {
|
||||||
@@ -405,7 +405,7 @@ MPP_RET mpp_buffer_group_reset(MppBufferGroupImpl *p)
|
|||||||
return MPP_ERR_NULL_PTR;
|
return MPP_ERR_NULL_PTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mutex::Autolock auto_lock(&service.mLock);
|
AutoMutex auto_lock(&service.mLock);
|
||||||
|
|
||||||
if (!list_empty(&p->list_used)) {
|
if (!list_empty(&p->list_used)) {
|
||||||
MppBufferImpl *pos, *n;
|
MppBufferImpl *pos, *n;
|
||||||
@@ -433,7 +433,7 @@ MPP_RET mpp_buffer_group_set_listener(MppBufferGroupImpl *p, void *listener)
|
|||||||
return MPP_ERR_NULL_PTR;
|
return MPP_ERR_NULL_PTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mutex::Autolock auto_lock(&service.mLock);
|
AutoMutex auto_lock(&service.mLock);
|
||||||
p->listener = listener;
|
p->listener = listener;
|
||||||
|
|
||||||
return MPP_OK;
|
return MPP_OK;
|
||||||
|
@@ -43,6 +43,7 @@
|
|||||||
|
|
||||||
static RK_S32 osal_mem_flag = -1;
|
static RK_S32 osal_mem_flag = -1;
|
||||||
static struct list_head mem_list;
|
static struct list_head mem_list;
|
||||||
|
static pthread_mutex_t mem_list_lock;
|
||||||
|
|
||||||
struct mem_node {
|
struct mem_node {
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
@@ -57,6 +58,7 @@ static void get_osal_mem_flag()
|
|||||||
{
|
{
|
||||||
if (osal_mem_flag < 0) {
|
if (osal_mem_flag < 0) {
|
||||||
RK_U32 val;
|
RK_U32 val;
|
||||||
|
|
||||||
osal_mem_flag = 0;
|
osal_mem_flag = 0;
|
||||||
mpp_env_get_u32(CONFIG_OSAL_MEM_LIST, &val, 0);
|
mpp_env_get_u32(CONFIG_OSAL_MEM_LIST, &val, 0);
|
||||||
if (val) {
|
if (val) {
|
||||||
@@ -66,7 +68,14 @@ static void get_osal_mem_flag()
|
|||||||
if (val) {
|
if (val) {
|
||||||
osal_mem_flag |= OSAL_MEM_STUFF_EN;
|
osal_mem_flag |= OSAL_MEM_STUFF_EN;
|
||||||
}
|
}
|
||||||
|
|
||||||
INIT_LIST_HEAD(&mem_list);
|
INIT_LIST_HEAD(&mem_list);
|
||||||
|
|
||||||
|
pthread_mutexattr_t attr;
|
||||||
|
pthread_mutexattr_init(&attr);
|
||||||
|
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||||
|
pthread_mutex_init(&mem_list_lock, &attr);
|
||||||
|
pthread_mutexattr_destroy(&attr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,10 +88,13 @@ void *mpp_osal_malloc(const char *tag, size_t size)
|
|||||||
if (osal_mem_flag & OSAL_MEM_LIST_EN) {
|
if (osal_mem_flag & OSAL_MEM_LIST_EN) {
|
||||||
struct mem_node *node = (struct mem_node *)malloc(sizeof(struct mem_node));
|
struct mem_node *node = (struct mem_node *)malloc(sizeof(struct mem_node));
|
||||||
INIT_LIST_HEAD(&node->list);
|
INIT_LIST_HEAD(&node->list);
|
||||||
list_add_tail(&node->list, &mem_list);
|
|
||||||
node->ptr = ptr;
|
node->ptr = ptr;
|
||||||
node->size = size;
|
node->size = size;
|
||||||
snprintf(node->tag, sizeof(node->tag), "%s", tag);
|
snprintf(node->tag, sizeof(node->tag), "%s", tag);
|
||||||
|
|
||||||
|
pthread_mutex_lock(&mem_list_lock);
|
||||||
|
list_add_tail(&node->list, &mem_list);
|
||||||
|
pthread_mutex_unlock(&mem_list_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
@@ -112,7 +124,9 @@ void *mpp_osal_realloc(const char *tag, void *ptr, size_t size)
|
|||||||
|
|
||||||
if (osal_mem_flag & OSAL_MEM_LIST_EN) {
|
if (osal_mem_flag & OSAL_MEM_LIST_EN) {
|
||||||
struct mem_node *pos, *n;
|
struct mem_node *pos, *n;
|
||||||
|
|
||||||
ret = NULL;
|
ret = NULL;
|
||||||
|
pthread_mutex_lock(&mem_list_lock);
|
||||||
list_for_each_entry_safe(pos, n, &mem_list, struct mem_node, list) {
|
list_for_each_entry_safe(pos, n, &mem_list, struct mem_node, list) {
|
||||||
if (ptr == pos->ptr) {
|
if (ptr == pos->ptr) {
|
||||||
if (MPP_OK == os_realloc(ptr, &pos->ptr, RK_OSAL_MEM_ALIGN, size)) {
|
if (MPP_OK == os_realloc(ptr, &pos->ptr, RK_OSAL_MEM_ALIGN, size)) {
|
||||||
@@ -126,6 +140,7 @@ void *mpp_osal_realloc(const char *tag, void *ptr, size_t size)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pthread_mutex_unlock(&mem_list_lock);
|
||||||
} else {
|
} else {
|
||||||
os_realloc(ptr, &ret, RK_OSAL_MEM_ALIGN, size);
|
os_realloc(ptr, &ret, RK_OSAL_MEM_ALIGN, size);
|
||||||
}
|
}
|
||||||
@@ -145,6 +160,8 @@ void mpp_osal_free(void *ptr)
|
|||||||
|
|
||||||
if (osal_mem_flag & OSAL_MEM_LIST_EN) {
|
if (osal_mem_flag & OSAL_MEM_LIST_EN) {
|
||||||
struct mem_node *pos, *n;
|
struct mem_node *pos, *n;
|
||||||
|
|
||||||
|
pthread_mutex_lock(&mem_list_lock);
|
||||||
list_for_each_entry_safe(pos, n, &mem_list, struct mem_node, list) {
|
list_for_each_entry_safe(pos, n, &mem_list, struct mem_node, list) {
|
||||||
if (ptr == pos->ptr) {
|
if (ptr == pos->ptr) {
|
||||||
list_del_init(&pos->list);
|
list_del_init(&pos->list);
|
||||||
@@ -152,6 +169,7 @@ void mpp_osal_free(void *ptr)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pthread_mutex_unlock(&mem_list_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
os_free(ptr);
|
os_free(ptr);
|
||||||
@@ -163,6 +181,12 @@ void mpp_osal_free(void *ptr)
|
|||||||
*/
|
*/
|
||||||
void mpp_show_mem_status()
|
void mpp_show_mem_status()
|
||||||
{
|
{
|
||||||
// TODO: add memory dump implement
|
struct mem_node *pos, *n;
|
||||||
|
|
||||||
|
pthread_mutex_lock(&mem_list_lock);
|
||||||
|
list_for_each_entry_safe(pos, n, &mem_list, struct mem_node, list) {
|
||||||
|
mpp_log("unfree memory %p size %d tag %s", pos->ptr, pos->size, pos->tag);
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&mem_list_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user