BOOL DLLCALL listSwapNodes(list_node_t* node1, list_node_t* node2) { list_node_t tmp; if(node1==NULL || node2==NULL || node1==node2) return(FALSE); if(listNodeIsLocked(node1) || listNodeIsLocked(node2)) return(FALSE); if(node1->list==NULL || node2->list==NULL) return(FALSE); #if defined(LINK_LIST_THREADSAFE) listLock(node1->list); if(node1->list != node2->list) listLock(node2->list); #endif tmp=*node1; node1->tag=node2->tag; node1->data=node2->data; node1->flags=node2->flags; node2->tag=tmp.tag; node2->data=tmp.data; node2->flags=tmp.flags; #if defined(LINK_LIST_THREADSAFE) listUnlock(node1->list); if(node1->list != node2->list) listUnlock(node2->list); #endif return(TRUE); }
void App::Periodic() { while (!shutdown_.load()) { std::time_t now = std::time(nullptr); // Make sure list is not edited while we iterate std::lock_guard<std::mutex> listLock(task_list_lock_); for (auto& task : periodic_task_list) { if ((now - std::get<0>(task)) > std::get<1>(task)) { // set "last performed" std::get<0>(task) = now; // run the task in an independent thread auto taskThread = std::thread(std::get<2>(task)); taskThread.detach(); } } // This method has its own interval checking. Run here to avoid // spawning unnecessary threads. if (nullptr != storage_) { storage_->RunGC(); } Log::Sleep(std::chrono::milliseconds(100)); } }
GrabberList MetaGrabberScript::GetList(GrabberType type, bool refresh) { InitializeStaticMaps(); GrabberList tmpGrabberList, retGrabberList; { QMutexLocker listLock(&grabberLock); QDateTime now = MythDate::current(); // refresh grabber scripts every 60 seconds // this might have to be revised, or made more intelligent if // the delay during refreshes is too great if (refresh || !grabberAge.isValid() || (grabberAge.secsTo(now) > kGrabberRefresh)) { grabberList.clear(); LOG(VB_GENERAL, LOG_DEBUG, LOC + "Clearing grabber cache"); // loop through different types of grabber scripts and the // directories they are stored in QMap<GrabberType, GrabberOpts>::const_iterator it; for (it = grabberTypes.begin(); it != grabberTypes.end(); ++it) { QString path = (it->path).arg(GetShareDir()); QStringList scripts = QDir(path).entryList(QDir::Files); if (scripts.count() == 0) // no scripts found continue; // loop through discovered scripts QStringList::const_iterator it2 = scripts.begin(); for (; it2 != scripts.end(); ++it2) { QString cmd = QString("%1%2").arg(path).arg(*it2); MetaGrabberScript script(cmd); if (script.IsValid()) { LOG(VB_GENERAL, LOG_DEBUG, LOC + "Adding " + script.m_command); grabberList.append(script); } } } grabberAge = now; } tmpGrabberList = grabberList; } GrabberList::const_iterator it = tmpGrabberList.begin(); for (; it != tmpGrabberList.end(); ++it) { if ((type == kGrabberAll) || (it->GetType() == type)) retGrabberList.append(*it); } return retGrabberList; }
long DLLCALL listFreeNodes(link_list_t* list) { list_node_t* node; list_node_t* next; if(list==NULL) return(-1); listLock(list); for(node=list->first; node!=NULL; node=next) { if(node->flags&LINK_LIST_LOCKED) break; if(((list->flags&LINK_LIST_ALWAYS_FREE) || (node->flags&LINK_LIST_MALLOC)) && !(list->flags&LINK_LIST_NEVER_FREE)) listFreeNodeData(node); next = node->next; free(node); if(list->count) list->count--; } list->first = node; if(!list->count) list->last = NULL; listUnlock(list); return(list->count); }
void DWFileResumeList::SetListItem(LPWSTR name, LPWSTR value) { if (!name || !value) return; //do search for name and load resume time CAutoLock listLock(&m_listLock); std::vector<DWFileResumeListItem *>::iterator it = m_list.begin(); for ( ; it < m_list.end() ; it++ ) { if (_wcsicmp((*it)->name, name) == 0) { strCopy((*it)->resume, value); return; } } // If not found then push it onto the list DWFileResumeListItem *resumeItem = new DWFileResumeListItem(); strCopy(resumeItem->name, name); strCopy(resumeItem->resume, value); m_list.push_back(resumeItem); return; }
BOOL DLLCALL listLockNode(list_node_t* node) { if(node==NULL || (node->flags&LINK_LIST_LOCKED)) return(FALSE); listLock(node->list); node->flags|=LINK_LIST_LOCKED; listUnlock(node->list); return(TRUE); }
long DLLCALL listAttach(link_list_t* list) { if(list==NULL) return(-1); listLock(list); list->refs++; listUnlock(list); return(list->refs); }
BOOL DLLCALL listUnlockNode(list_node_t* node) { if(!listNodeIsLocked(node)) return(FALSE); listLock(node->list); node->flags&=~LINK_LIST_LOCKED; listUnlock(node->list); return(TRUE); }
HRESULT DWFileResumeList::Destroy() { CAutoLock listLock(&m_listLock); std::vector<DWFileResumeListItem *>::iterator it = m_list.begin(); for ( ; it < m_list.end() ; it++ ) { if (*it) delete *it; } m_list.clear(); return S_OK; }
list_node_t* DLLCALL listFirstNode(link_list_t* list) { list_node_t* node; if(list==NULL) return(NULL); listLock(list); node=list->first; listUnlock(list); return(node); }
void* DLLCALL listNodeData(const list_node_t* node) { void* data; if(node==NULL) return(NULL); listLock(node->list); data=node->data; listUnlock(node->list); return(data); }
list_node_t* DLLCALL listNextNode(const list_node_t* node) { list_node_t* next; if(node==NULL) return(NULL); listLock(node->list); next=node->next; listUnlock(node->list); return(next); }
list_node_t* DLLCALL listPrevNode(const list_node_t* node) { list_node_t* prev; if(node==NULL) return(NULL); listLock(node->list); prev=node->prev; listUnlock(node->list); return(prev); }
void* DLLCALL listSetPrivateData(link_list_t* list, void* p) { void* old; if(list==NULL) return(NULL); listLock(list); old=list->private_data; list->private_data=p; listUnlock(list); return(old); }
long DLLCALL listDettach(link_list_t* list) { int refs; if(list==NULL || list->refs<1) return(-1); listLock(list); if((refs=--list->refs)==0) listFree(list); else listUnlock(list); return(refs); }
void* DLLCALL listRemoveNode(link_list_t* list, list_node_t* node, BOOL free_data) { void* data; if(list==NULL) return(NULL); listLock(list); data = list_remove_node(list, node, free_data); listUnlock(list); return(data); }
list_node_t* DLLCALL listNodeAt(link_list_t* list, long index) { long i=0; list_node_t* node; if(list==NULL || index<0) return(NULL); listLock(list); for(node=list->first; node!=NULL && i<index; node=node->next) i++; listUnlock(list); return(node); }
void* DLLCALL listRemoveTaggedNode(link_list_t* list, list_node_tag_t tag, BOOL free_data) { void* data=NULL; list_node_t* node; if(list==NULL) return(NULL); listLock(list); if((node=listFindTaggedNode(list, tag)) != NULL) data = list_remove_node(list, node, free_data); listUnlock(list); return(data); }
list_node_t* DLLCALL listLastNode(link_list_t* list) { list_node_t* node; list_node_t* last=NULL; if(list==NULL) return(NULL); listLock(list); if(list->last!=NULL) last=list->last; else for(node=list->first; node!=NULL; node=node->next) last=node; listUnlock(list); return(last); }
HRESULT DWFileResumeList::FindListItem(LPWSTR name, int *pIndex) { if (!pIndex) return E_INVALIDARG; *pIndex = 0; CAutoLock listLock(&m_listLock); std::vector<DWFileResumeListItem *>::iterator it = m_list.begin(); for ( ; it < m_list.end() ; it++ ) { if (_wcsicmp((*it)->name, name) == 0) return S_OK; (*pIndex)++; } return E_FAIL; }
long DLLCALL listRemoveNodes(link_list_t* list, list_node_t* node, long max, BOOL free_data) { long count; if(list==NULL) return(-1); listLock(list); if(node==FIRST_NODE) node=list->first; for(count=0; node!=NULL && count<max; node=node->next, count++) if(listRemoveNode(list, node, free_data)==NULL) break; listUnlock(list); return(count); }
LPWSTR DWFileResumeList::GetListItem(LPWSTR name, long nIndex) { CAutoLock listLock(&m_listLock); if (nIndex >= (long)m_list.size()) return NULL; long startsWithLength = strStartsWith(name, m_dataListName); if (startsWithLength > 0) { name += startsWithLength; DWFileResumeListItem *resumeItem = m_list.at(nIndex); if (_wcsicmp(name, L".resume") == 0) return resumeItem->resume; else if (_wcsicmp(name, L".name") == 0) return resumeItem->name; } return NULL; }
long DLLCALL listCountNodes(link_list_t* list) { long count=0; list_node_t* node; if(list==NULL) return(-1); if(list->count) return(list->count); listLock(list); for(node=list->first; node!=NULL; node=node->next) count++; listUnlock(list); return(count); }
long DLLCALL listNodeIndex(link_list_t* list, list_node_t* find_node) { long i=0; list_node_t* node; if(list==NULL) return(-1); listLock(list); for(node=list->first; node!=NULL; node=node->next) if(node==find_node) break; listUnlock(list); if(node==NULL) return(-1); return(i); }
static list_node_t* DLLCALL list_add_node(link_list_t* list, list_node_t* node, list_node_t* after) { if(list==NULL) return(NULL); listLock(list); node->list = list; if(after==LAST_NODE) /* e.g. listPushNode() */ after=list->last; node->prev = after; if(after==list->last) /* append to list */ list->last = node; if(after==FIRST_NODE) { /* insert at beginning of list */ node->next = list->first; if(node->next!=NULL) node->next->prev = node; list->first = node; } else { if(after->next!=NULL) { after->next->prev = node; node->next = after->next; } after->next = node; } list->count++; listUnlock(list); #if defined(LINK_LIST_THREADSAFE) if(list->flags&LINK_LIST_SEMAPHORE) listSemPost(list); #endif return(node); }
str_list_t DLLCALL listStringList(link_list_t* list) { list_node_t* node; str_list_t str_list; size_t count=0; if(list==NULL) return(NULL); if((str_list=strListInit())==NULL) return(NULL); listLock(list); for(node=list->first; node!=NULL; node=node->next) { if(node->data!=NULL) strListAppend(&str_list, (char*)node->data, count++); } listUnlock(list); return(str_list); }
list_node_t* DLLCALL listFindNode(link_list_t* list, const void* data, size_t length) { list_node_t* node; if(list==NULL) return(NULL); listLock(list); for(node=list->first; node!=NULL; node=node->next) { if(length==0) { if(node->data==data) break; } else if(data==NULL) { if(node->tag==(list_node_tag_t)length) break; } else if(node->data!=NULL && memcmp(node->data,data,length)==0) break; } listUnlock(list); return(node); }
str_list_t DLLCALL listSubStringList(const list_node_t* node, long max) { long count; str_list_t str_list; link_list_t* list; if(node==NULL) return(NULL); if((str_list=strListInit())==NULL) return(NULL); list=node->list; listLock(list); for(count=0; count<max && node!=NULL; node=node->next) { if(node->data!=NULL) strListAppend(&str_list, (char*)node->data, count++); } listUnlock(list); return(str_list); }
long DWFileResumeList::GetListSize() { CAutoLock listLock(&m_listLock); return m_list.size(); }