int32_t mm_jpeg_queue_flush(mm_jpeg_queue_t* queue) { mm_jpeg_q_node_t* node = NULL; void* data = NULL; struct cam_list *head = NULL; struct cam_list *pos = NULL; pthread_mutex_lock(&queue->lock); head = &queue->head.list; pos = head->next; while(pos != head) { node = member_of(pos, mm_jpeg_q_node_t, list); cam_list_del_node(&node->list); queue->size--; /* for now we only assume there is no ptr inside data * so we free data directly */ if (NULL != node->data) { free(node->data); } free(node); pos = pos->next; } queue->size = 0; pthread_mutex_unlock(&queue->lock); return 0; }
/*=========================================================================== * FUNCTION : flushNodes * * DESCRIPTION: flush only specific nodes, depending on * the given matching function. * * PARAMETERS : * @match : matching function * * RETURN : None *==========================================================================*/ void QCameraQueue::flushNodes(match_fn_data match, void *match_data){ camera_q_node* node = NULL; struct cam_list *head = NULL; struct cam_list *pos = NULL; if ( NULL == match ) { return; } pthread_mutex_lock(&m_lock); if (m_active) { head = &m_head.list; pos = head->next; while(pos != head) { node = member_of(pos, camera_q_node, list); pos = pos->next; if ( match(node->data, m_userData, match_data) ) { cam_list_del_node(&node->list); m_size--; if (NULL != node->data) { if (m_dataFn) { m_dataFn(node->data, m_userData); } free(node->data); } free(node); } } } pthread_mutex_unlock(&m_lock); }
/*=========================================================================== * FUNCTION : flush * * DESCRIPTION: flush all nodes from the queue, queue will be empty after this * operation. * * PARAMETERS : None * * RETURN : None *==========================================================================*/ void QCameraQueue::flush(){ camera_q_node* node = NULL; struct cam_list *head = NULL; struct cam_list *pos = NULL; pthread_mutex_lock(&m_lock); if (m_active) { head = &m_head.list; pos = head->next; while(pos != head) { node = member_of(pos, camera_q_node, list); pos = pos->next; cam_list_del_node(&node->list); m_size--; if (NULL != node->data) { if (m_dataFn) { m_dataFn(node->data, m_userData); } free(node->data); } free(node); } m_size = 0; m_active = false; } pthread_mutex_unlock(&m_lock); }
/*=========================================================================== * FUNCTION : dequeue * * DESCRIPTION: dequeue data from the queue * * PARAMETERS : * @bFromHead : if true, dequeue from the head * if false, dequeue from the tail * * RETURN : data ptr. NULL if not any data in the queue. *==========================================================================*/ void* QCameraQueue::dequeue(bool bFromHead) { camera_q_node* node = NULL; void* data = NULL; struct cam_list *head = NULL; struct cam_list *pos = NULL; pthread_mutex_lock(&m_lock); if (m_active) { head = &m_head.list; if (bFromHead) { pos = head->next; } else { pos = head->prev; } if (pos != head) { node = member_of(pos, camera_q_node, list); cam_list_del_node(&node->list); m_size--; } } pthread_mutex_unlock(&m_lock); if (NULL != node) { data = node->data; free(node); } return data; }
/*=========================================================================== * FUNCTION - delete_gpu_addr_list - * * DESCRIPTION: Delete gpu address list and free allocated memory. *==========================================================================*/ static void delete_gpu_addr_list() { struct cam_list *pos1, *pos2; struct cam_list *head = &(g_list.list); gpu_addr_list_t *entry; for (pos1 = head->next, pos2 = pos1->next; pos1 != head; pos1 = pos2, pos2 = pos1->next) { entry = member_of(pos1, gpu_addr_list_t, list); unmap_gpu_addr(entry->data.origGpuAddr); cam_list_del_node(pos1); free(entry); } } /* delete_gpu_addr_list */
int SetParentState(PINO_DATABASE *db, NODE *node, unsigned int state) { int status; NCI nci; NODE *lnode; status = TreeNORMAL; for (lnode = node; lnode && (status & 1); lnode = brother_of(lnode)) { status = SetNodeParentState(db, lnode, &nci, state); if ((status & 1) && (!(nci.flags & NciM_STATE)) && (lnode->INFO.TREE_INFO.child)) status = SetParentState(db, child_of(lnode), state); if ((status & 1) && (!(nci.flags & NciM_STATE)) && (lnode->INFO.TREE_INFO.member)) status = SetParentState(db, member_of(lnode), state); } return status; }
int _TreeTurnOn(void *dbid, int nid_in) { PINO_DATABASE *dblist = (PINO_DATABASE *)dbid; NID *nid = (NID *)&nid_in; int status; int node_num; TREE_INFO *info; NCI nci; NODE *node; if (!(IS_OPEN(dblist))) return TreeNOT_OPEN; if (dblist->remote) return TreeTurnOnRemote(dbid,nid_in); nid_to_tree_nidx(dblist, nid, info, node_num); if (!info) return TreeNNF; status = TreeGetNciLw(info, node_num, &nci); if (~status & 1) return status; if (nci.flags & NciM_STATE) { bitassign(0,nci.flags,NciM_STATE); status = TreePutNci(info, node_num, &nci, 0); if (~status & 1) return status; if (!(nci.flags & NciM_PARENT_STATE)) { nid_to_node(dblist, nid, node); if (node->INFO.TREE_INFO.child) status = SetParentState(dblist, child_of(node), 0); if (node->INFO.TREE_INFO.member) status = SetParentState(dblist, member_of(node), 0); } else status = TreePARENT_OFF; } else { status = TreeUnLockNci(info, 0, node_num); if (status & 1) status = TreeALREADY_ON; } return status; }
/*=========================================================================== * FUNCTION - find_gpu_addr_item - * * DESCRIPTION: Find pmem buffer and matching gpu address entry into list. *==========================================================================*/ static uint32_t find_gpu_addr_item(int fd, uint32_t vAddr) { struct cam_list *pos; struct cam_list *head = &(g_list.list); gpu_addr_list_t *entry; CDBG("%s: Entry to find fd = %d, vAddr = 0x%x\n", __func__, fd, vAddr); for (pos = head->next; pos != head; pos = pos->next) { entry = member_of(pos, gpu_addr_list_t, list); CDBG("%s: Current Entry fd = %d vAddr = 0x%x gpuAddr = 0x%x\n", __func__, entry->data.fd, entry->data.vAddr, entry->data.gpuAddr); if ((entry->data.fd == fd) && (entry->data.vAddr == vAddr)) return entry->data.gpuAddr; } CDBG("%s: entry not found\n", __func__); return 0; } /* find_gpu_addr_item */
iterator insert_equal(reference elem) { rbtree_node* node = member_of(&elem, NodeMember); rbtree_node* parent = nullptr; rbtree_node** next = &_root; Compare cmp; while (*next) { parent = *next; if (cmp(elem, *parent_of(*next, NodeMember))) next = &(*next)->left; else next = &(*next)->right; } *next = node; node->insert(&_root, parent); return iterator(node); }
std::pair<iterator, bool> insert_unique(reference elem) { rbtree_node* node = member_of(&elem, NodeMember); rbtree_node* parent = nullptr; rbtree_node** next = &_root; Compare cmp; while (*next) { parent = *next; if (cmp(elem, *parent_of(*next, NodeMember))) next = &(*next)->left; else if (cmp(*parent_of(*next, NodeMember), elem)) next = &(*next)->right; else return std::pair<iterator, bool>(iterator(*next), false); } *next = node; node->insert(&_root, parent); return std::pair<iterator, bool>(iterator(node), true); }
/*=========================================================================== * FUNCTION : peek * * DESCRIPTION: return the head element without removing it * * PARAMETERS : None * * RETURN : data ptr. NULL if not any data in the queue. *==========================================================================*/ void* QCameraQueue::peek() { camera_q_node* node = NULL; void* data = NULL; struct cam_list *head = NULL; struct cam_list *pos = NULL; pthread_mutex_lock(&m_lock); if (m_active) { head = &m_head.list; pos = head->next; if (pos != head) { node = member_of(pos, camera_q_node, list); } } pthread_mutex_unlock(&m_lock); if (NULL != node) { data = node->data; } return data; }
void* mm_jpeg_queue_deq(mm_jpeg_queue_t* queue) { mm_jpeg_q_node_t* node = NULL; void* data = NULL; struct cam_list *head = NULL; struct cam_list *pos = NULL; pthread_mutex_lock(&queue->lock); head = &queue->head.list; pos = head->next; if (pos != head) { node = member_of(pos, mm_jpeg_q_node_t, list); cam_list_del_node(&node->list); queue->size--; } pthread_mutex_unlock(&queue->lock); if (NULL != node) { data = node->data; free(node); } return data; }
STATIC_ROUTINE void check_nid(PINO_DATABASE *dblist, NID *nid, int *count) { int bitnum = nid->node; if (!getbit(bitnum)) { NODE *node; NODE *descendent; nid_to_node(dblist, nid, node); if (count) (*count)++; setbit(bitnum); for (descendent = member_of(node); descendent; descendent = brother_of(descendent)) { NID nid; node_to_nid(dblist, descendent, (&nid)); check_nid(dblist, &nid, count); } for (descendent = child_of(node); descendent; descendent = brother_of(descendent)) { NID nid; node_to_nid(dblist, descendent, (&nid)); check_nid(dblist, &nid, count); } if (swapshort((char *)&node->conglomerate_elt)) { NID elt_nid; NODE *elt_node; unsigned short elt_num = 1; elt_nid.node = nid->node - swapshort((char *)&node->conglomerate_elt) + 1; elt_nid.tree = nid->tree; nid_to_node(dblist, (&elt_nid), elt_node); for (; swapshort((char *)&elt_node->conglomerate_elt) == elt_num; elt_nid.node++, elt_num++, elt_node++) check_nid(dblist, &elt_nid, count); } } }
extern void _TreeDeleteNodeExecute(void *dbid) { PINO_DATABASE *dblist = (PINO_DATABASE *)dbid; static NID nid; NODE *node; NODE *prevnode = 0; NODE *parent; static NCI empty_nci; NODE *firstempty = (dblist->tree_info->header->free == -1) ? (NODE *) 0 : (NODE *) ((char *) dblist->tree_info->node + dblist->tree_info->header->free); TREE_EDIT *edit = dblist->tree_info->edit; static int zero = 0; /*------------------------------------------------------------------------------ Executable: */ nid.tree = 0; nid.node = 0; while (_TreeDeleteNodeGetNid(dbid, (int*)&nid) & 1) { int found = 0; _TreeRemoveNodesTags(dbid, *(int *)&nid); _TreeSetNoSubtree(dbid, *(int *)&nid); nid_to_node(dblist, (&nid), node); parent = parent_of(node); if (child_of(parent) == node) { found = 1; if (node->INFO.TREE_INFO.brother) { link_it(parent->INFO.TREE_INFO.child,brother_of(node),parent); } else parent->INFO.TREE_INFO.child = 0; } else if (parent->INFO.TREE_INFO.child) { NODE *bro; for (bro = child_of(parent); bro->INFO.TREE_INFO.brother && (brother_of(bro) != node); bro = brother_of(bro)); if (brother_of(bro) == node) { found = 1; if (node->INFO.TREE_INFO.brother) { link_it(bro->INFO.TREE_INFO.brother,brother_of(node),bro); } else bro->INFO.TREE_INFO.brother = 0; } } if (!found) { if (member_of(parent) == node) { if (node->INFO.TREE_INFO.brother) { link_it(parent->INFO.TREE_INFO.member,brother_of(node), parent); } else parent->INFO.TREE_INFO.member = 0; } else if (parent->INFO.TREE_INFO.member) { NODE *bro; for (bro = member_of(parent); bro->INFO.TREE_INFO.brother && (brother_of(bro) != node); bro = brother_of(bro)); if (brother_of(bro) == node) { found = 1; if (node->INFO.TREE_INFO.brother) { link_it(bro->INFO.TREE_INFO.brother,brother_of(node), bro); } else bro->INFO.TREE_INFO.brother = 0; } } } if ((int)nid.node < edit->first_in_mem) { NCI old_nci; int nidx = nid.node; TreeGetNciLw(dblist->tree_info, nidx, &old_nci); TreePutNci(dblist->tree_info, nidx, &empty_nci, 1); } else memcpy(edit->nci + nid.node - edit->first_in_mem, &empty_nci, sizeof(struct nci)); memcpy(node->name,"deleted node",sizeof(node->name)); LoadShort(zero,&node->conglomerate_elt); node->INFO.TREE_INFO.member = 0; node->INFO.TREE_INFO.brother = 0; node->usage = 0; if (prevnode) { int tmp; link_it(prevnode->parent, node, prevnode); tmp = -swapint((char *)&prevnode->parent); node->INFO.TREE_INFO.child = swapint((char *)&tmp); } else { int tmp; link_it(tmp,node, dblist->tree_info->node); dblist->tree_info->header->free = swapint((char *)&tmp); node->INFO.TREE_INFO.child = 0; } if (firstempty) { int tmp; link_it(node->parent, firstempty, node); tmp = -swapint((char *)&node->parent); firstempty->INFO.TREE_INFO.child = swapint((char *)&tmp); } else node->parent = 0; prevnode = node; } dblist->modified = 1; _TreeDeleteNodeInitialize(dbid, 0, 0, 1); }
void remove(reference elem) { member_of(&elem, NodeMember)->remove(&_root); }