T_SYMBOL intern(char *c_str) { if (!sym_map) parser_init(); c_str = strdup(c_str); for (int i = 0; c_str[i]; i++) c_str[i] = toupper(c_str[i]); debug("intern: %s %u\n",c_str,hash(c_str)); SYMBOL *sym = newSYMBOL(hash(c_str)); STRING *str = newSTRING(c_str); NODE *entry; while ((entry = binmap_find(sym,sym_map))) { debugVal(entry,"matching: "); if (cmpSTRING((STRING*)entry->addr,str)) { decRef(entry); sym->sym++; } else { break; } } if (!entry) { debug("adding symbol: %s\n",c_str); binmap_put(sym,str,sym_map); return sym->sym; } else { decRef(sym); decRef(str); decRef(entry); return ((SYMBOL*)entry->data)->sym; } }
void IndexReader::close() { SyncLock syncLock(this); if (!closed) { decRef(); closed = true; } }
/** * @brief Cleans up refCounter dependent allocations */ void sidexDict::cleanUp(){ if (decRef() == 0){ if (NULL != m_hashTable) delete (m_hashTable); m_hashTable = NULL; } }
void work_fail(Job *job) { MemBlock *block = new_response(MSG_WORK_FAIL, strlen(job->handle), (unsigned char*)job->handle); incRef(block); // Make sure the first listener doesn't decRef to 0 causing the block to be returned g_ptr_array_foreach(job->listeners, (GFunc)client_send, block); decRef(block); remove_job(job); }
void egl_object_t::terminate() { // this marks the object as "terminated" display->removeObject(this); if (decRef() == 1) { // shouldn't happen because this is called from LocalRef ALOGE("egl_object_t::terminate() removed the last reference!"); } }
void IndexFileDeleter::decRef(SegmentInfos* segmentInfos) { int32_t size = segmentInfos->size(); for(int32_t i=0;i<size;i++) { SegmentInfo* segmentInfo = segmentInfos->info(i); if (segmentInfo->dir == directory) { decRef(segmentInfo->files()); } } }
VALUE* eval_string(char *prog_str, NODE *static_scope, NODE *macro_map) { NODE *prog = parseForms(prog_str); debugVal(prog,"before macroexpand: "); prog = (NODE*)macroexpand(prog,static_scope,macro_map); debugVal(prog,"after macroexpand: "); VALUE *val = evaluate((VALUE*)prog,static_scope); decRef(prog); return val; }
void Context::cleanup() { incRef(); clear(); std::vector<Context*> subs; std::swap(mSubs, subs); for (size_t i=0; i<subs.size(); ++i) { subs[i]->cleanup(); } decRef(); }
SharedHandle& SharedHandle::operator =(const SharedHandle& rhs) { decRef(); m_handle = rhs.m_handle; m_serverHandle = rhs.m_serverHandle; m_pSharedCount = rhs.m_pSharedCount; incRef(); return *this; }
const char* sym_str(SYMBOL *sym) { NODE *entry = binmap_find(sym,sym_map); if (entry) { const char* str = ((STRING*)entry->addr)->str; decRef(entry); return str; } else { return NIL; } }
const char* prim_str(PRIMFUNC *prim) { NODE *entry = binmap_find(prim,literal_name_map); if (entry) { const char* str = ((STRING*)entry->addr)->str; decRef(entry); return str; } else { return NIL; } }
void emitDecodeCufIter(IRGS& env, int32_t iterId, Offset relOffset) { auto const src = popC(env); auto const type = src->type(); if (type.subtypeOfAny(TArr, TStr, TObj)) { auto const res = gen( env, DecodeCufIter, TBool, IterId(iterId), src, fp(env) ); decRef(env, src); implCondJmp(env, bcOff(env) + relOffset, true, res); } else { decRef(env, src); jmpImpl(env, bcOff(env) + relOffset); } }
/** * For definition of "check point32_t" see IndexWriter comments: * "Clarification: Check Point32_ts (and commits)". * * Writer calls this when it has made a "consistent * change" to the index, meaning new files are written to * the index and the in-memory SegmentInfos have been * modified to point32_t to those files. * * This may or may not be a commit (segments_N may or may * not have been written). * * We simply incref the files referenced by the new * SegmentInfos and decref the files we had previously * seen (if any). * * If this is a commit, we also call the policy to give it * a chance to remove other commits. If any commits are * removed, we decref their files as well. */ void IndexFileDeleter::checkpoint(SegmentInfos* segmentInfos, bool isCommit) { if (infoStream != NULL) { message(string("now checkpoint \"") + segmentInfos->getCurrentSegmentFileName() + "\" [" + Misc::toString(segmentInfos->size()) + " segments ; isCommit = " + Misc::toString(isCommit) + "]"); } // Try again now to delete any previously un-deletable // files (because they were in use, on Windows): deletePendingFiles(); // Incref the files: incRef(segmentInfos, isCommit); const vector<string>* docWriterFiles = NULL; if (docWriter != NULL) { docWriterFiles = &docWriter->files(); if (!docWriterFiles->empty()) incRef(*docWriterFiles); else docWriterFiles = NULL; } if (isCommit) { // Append to our commits list: commits.push_back(_CLNEW CommitPoint(this, segmentInfos)); // Tell policy so it can remove commits: policy->onCommit(commits); // Decref files for commits that were deleted by the policy: deleteCommits(); } // DecRef old files from the last checkpoint, if any: int32_t size = lastFiles.size(); if (size > 0) { for(int32_t i=0;i<size;i++) decRef(lastFiles[i]); lastFiles.clear(); } if (!isCommit) { // Save files so we can decr on next checkpoint/commit: size = segmentInfos->size(); for(int32_t i=0;i<size;i++) { SegmentInfo* segmentInfo = segmentInfos->info(i); if (segmentInfo->dir == directory) { const vector<string>& files = segmentInfo->files(); lastFiles.insert(lastFiles.end(), files.begin(), files.end()); } } } if (docWriterFiles != NULL) lastFiles.insert(lastFiles.end(), docWriterFiles->begin(),docWriterFiles->end()); }
int process_client(Client *cli) { assert( cli != NULL ); if ( (cli->buffer_in == NULL) || (cli->buffer_in->nbytes < HEADER_SIZE) ) return 0; uint32_t size = ntohl(*(uint32_t*)(cli->buffer_in->bytes + HEADER_OFFSET_SIZE)); /* Check if there's a full packet's worth of data */ if (cli->buffer_in->nbytes < size+HEADER_SIZE) { // #ifdef DEBUG // g_debug("[%s] Waiting for more data: %d / %d", // cli->id, cli->buffer_in->nbytes, size+HEADER_SIZE); // #endif return 0; } int ret = 0; int type = ntohl(*(uint32_t*)(cli->buffer_in->bytes + HEADER_OFFSET_TYPE)); unsigned char *arg = cli->buffer_in->bytes + HEADER_SIZE; int argsize = cli->buffer_in->nbytes - HEADER_SIZE; arg[argsize] = 0; switch(type) { case MSG_CAN_DO: ret = msg_can_do(cli, arg, argsize, FALSE); break; case MSG_CANT_DO: ret = msg_can_do(cli, arg, argsize, TRUE); break; case MSG_CAN_DO_TIMEOUT: ret = msg_can_do_timeout(cli, arg, argsize); break; case MSG_RESET_ABILITIES: ret = msg_reset_abilities(cli, arg, argsize); break; case MSG_SET_CLIENT_ID: ret = msg_set_client_id(cli, arg, argsize); break; case MSG_PRE_SLEEP: ret = msg_pre_sleep(cli, arg, argsize); break; case MSG_SUBMIT_JOB: ret = msg_submit_job(cli, arg, argsize, FALSE, FALSE); break; case MSG_SUBMIT_JOB_HIGH: ret = msg_submit_job(cli, arg, argsize, FALSE, TRUE); break; case MSG_SUBMIT_JOB_BG: ret = msg_submit_job(cli, arg, argsize, TRUE, FALSE); break; case MSG_GRAB_JOB: ret = msg_grab_job(cli, arg, argsize); break; case MSG_WORK_STATUS: ret = msg_work_status(cli, cli->buffer_in); break; case MSG_WORK_COMPLETE: ret = msg_work_complete(cli, cli->buffer_in); break; case MSG_WORK_FAIL: ret = msg_work_fail(cli, cli->buffer_in); break; case MSG_GET_STATUS: ret = msg_get_status(cli, arg, argsize); break; case MSG_ECHO_REQ: ret = msg_echo_req(cli, cli->buffer_in); break; default: g_warning("[%s] Unknown message received of type %.4x", cli->id, type); ret = -1; } /* We are now done with the input buffer */ decRef(cli->buffer_in); cli->buffer_in = NULL; return ret; }
void emitIsTypeC(IRGS& env, IsTypeOp subop) { if (subop == IsTypeOp::Scalar) return implIsScalarC(env); auto const t = typeOpToDataType(subop); auto const src = popC(env, DataTypeSpecific); if (t == KindOfObject) { push(env, optimizedCallIsObject(env, src)); } else { push(env, gen(env, IsType, Type(t), src)); } decRef(env, src); }
bool MGPExecutor::_mapRun(GPPieces* output, GPPieces** inputs, int inputNumber) const { MGPASSERT(NULL!=output); MGPASSERT(NULL!=inputs); MGPASSERT(inputNumber>0); GPPtr<IGPKeyIterator> iterator = mFactory->create(inputs, inputNumber, output); MGPKeyMatcher matcher(iterator.get()); auto keymaps = matcher.get(); MGPMutex inputMutex; MGPMutex outputMutex; int pos = 0; auto threadNum = mPool->getThreadNumber(); std::vector<std::vector<MGPThreadPool::Runnable*>> runnableList; for (int i=0; i<threadNum; ++i) { std::vector<MGPThreadPool::Runnable*> r; runnableList.push_back(r); } for (auto& k : keymaps) { MapRunnable* runnable = new MapRunnable(inputs, inputNumber, k.second[0]->getKey(), k.second[0]->getKeyNumber(), output, k.first->getKey(), k.first->getKeyNumber(), mVariableKey, inputMutex, outputMutex); runnableList[pos%threadNum].push_back(runnable); pos++; } std::vector<GPPtr<MGPSema>> waitSemas; for (int i=1; i<threadNum; ++i) { //FUNC_PRINT(runnableList[i].size()); GPPtr<MGPSema> sema = mPool->pushTask(MGPThreadPool::mergeRunnables(runnableList[i])); MGPASSERT(NULL!=sema.get()); waitSemas.push_back(sema); } auto main_runnable = MGPThreadPool::mergeRunnables(runnableList[0]); main_runnable->vRun(mMainData); main_runnable->decRef(); for (auto s : waitSemas) { //GPCLOCK; s->wait(); } return true; }
void GPFormulaTreePoint::replaceNameByPoint(const std::string& name, GPFormulaTreePoint* point) { GPASSERT(NUM!=mT); for (int i=0; i<mChildren.size(); ++i) { auto p = GPCONVERT(GPFormulaTreePoint, mChildren[i]); if (p->mT == NUM && p->mName == name) { point->addRef(); mChildren[i] = point; p->decRef(); } else if (p->mChildren.size() > 0) { p->replaceNameByPoint(name, point); } } }
/** * Remove the CommitPoints in the commitsToDelete List by * DecRef'ing all files from each segmentInfos-> */ void IndexFileDeleter::deleteCommits() { int32_t size = commitsToDelete.size(); if (size > 0) { // First decref all files that had been referred to by // the now-deleted commits: for(int32_t i=0;i<size;i++) { CommitPoint* commit = commitsToDelete[i]; if (infoStream != NULL) { message("deleteCommits: now remove commit \"" + commit->getSegmentsFileName() + "\""); } decRef(commit->files); } commitsToDelete.clear(); // Now compact commits to remove deleted ones (preserving the sort): size = commits.size(); int32_t readFrom = 0; int32_t writeTo = 0; while(readFrom < size) { CommitPoint* commit = (CommitPoint*)commits[readFrom]; if (!commit->deleted) { if (writeTo != readFrom) { commits.remove(readFrom,true); commits.remove(writeTo,false);//delete this one... if ( commits.size() == writeTo ) commits.push_back(commit); else commits[writeTo] = commit; } writeTo++; } readFrom++; } while(size > writeTo) { commits.remove(size-1); size--; } } }
int main(int argc, char **argv) { NODE *static_scope = scope_push(NIL); NODE *macro_map = binmap(newSYMBOL(intern("NIL")),NIL); for (int i = 1; i < argc; i++) { debug("loading file: %s\n",argv[i]); FILE *f = fopen(argv[i],"rb"); if (!f) error("Could not open file %s",argv[i]); fseek(f, 0, SEEK_END); size_t len = ftell(f); rewind(f); char *prog_str = malloc(len+1); fread(prog_str,1,len,f); prog_str[len] = '\0'; fclose(f); debug("program(%u):\n%s",(unsigned int)len,prog_str); VALUE *val = eval_string(prog_str,static_scope,macro_map); decRef(val); } }
virtual void vRun(void* threadData) override { MGPExecutor::ThreadData* data = (MGPExecutor::ThreadData*)threadData; auto function = data->get(); GPContents* oldContent = mCollector->lock(); GPContents* input = NULL; GPContents* mergeInput = NULL; { MGPAutoMutex __m(mInputMutex); auto tempMergeInput = new GPContents; input = _loadContent(mInputNum, mInput, mInputKeys); for (int i=0; i<mVariableKey.size(); ++i) { auto v = mVariableKey[i]; MGPASSERT(v.first<=1); if (v.first == 1) { tempMergeInput->pushContent(oldContent->getContent(v.second)); } else { tempMergeInput->pushContent(input->getContent(v.second)); } } mergeInput = tempMergeInput->copyAsNoOwner(); tempMergeInput->decRef(); } GPContents* tempOutput = function->vRun(mergeInput); { MGPAutoMutex __m(mInputMutex); mergeInput->decRef(); input->decRef(); } { oldContent->setContent(0, tempOutput->getContent(0)); tempOutput->decRef(); mCollector->unlock(oldContent); } }
void emitOODeclExists(IRGS& env, OODeclExistsOp subop) { auto const tAutoload = popC(env); auto const tCls = popC(env); assertx(tCls->isA(TStr)); // result of CastString assertx(tAutoload->isA(TBool)); // result of CastBool ClassKind kind; switch (subop) { case OODeclExistsOp::Class: kind = ClassKind::Class; break; case OODeclExistsOp::Trait: kind = ClassKind::Trait; break; case OODeclExistsOp::Interface: kind = ClassKind::Interface; break; } auto const val = gen( env, OODeclExists, ClassKindData { kind }, tCls, tAutoload ); push(env, val); decRef(env, tCls); }
void emitInstanceOf(IRGS& env) { auto const t1 = popC(env); auto const t2 = popC(env); // t2 instanceof t1 if (t1->isA(TObj) && t2->isA(TObj)) { auto const c2 = gen(env, LdObjClass, t2); auto const c1 = gen(env, LdObjClass, t1); push(env, gen(env, InstanceOf, c2, c1)); decRef(env, t2); decRef(env, t1); return; } if (!t1->isA(TStr)) PUNT(InstanceOf-NotStr); if (t2->isA(TObj)) { auto const rds = gen(env, LookupClsRDSHandle, t1); auto const c1 = gen(env, DerefClsRDSHandle, rds); auto const c2 = gen(env, LdObjClass, t2); push(env, gen(env, InstanceOf, c2, c1)); decRef(env, t2); decRef(env, t1); return; } push( env, t2->isA(TArr) ? gen(env, InterfaceSupportsArr, t1) : t2->isA(TInt) ? gen(env, InterfaceSupportsInt, t1) : t2->isA(TStr) ? gen(env, InterfaceSupportsStr, t1) : t2->isA(TDbl) ? gen(env, InterfaceSupportsDbl, t1) : cns(env, false) ); decRef(env, t2); decRef(env, t1); }
void egl_object_t::destroy() { if (decRef() == 1) { delete this; } }
String::~String() { decRef(); }
SharedHandle::~SharedHandle() { decRef(); }
/****************************************************************** * This function is called when an event occurs on a client socket ******************************************************************/ void client_cb(int fd, short events, void *arg) { assert(arg != NULL); Client *cli = arg; int free = 0; // g_hash_table_foreach(g_jobqueue, _print_queue, NULL); if ((events & EV_WRITE) != 0) { event_del(&cli->evt); cli->evt.ev_events = EV_READ|EV_PERSIST; event_add(&cli->evt, NULL); if (client_flush(cli) < 0) { free = 1; } } if ((events & EV_READ) != 0) { int ret = 0; if (!cli->buffer_in) { cli->buffer_in = getBlock(HEADER_SIZE); incRef(cli->buffer_in); ret = client_recv(cli, HEADER_SIZE); } if (ret >= 0) { /* Make sure we don't over-read into the next packet */ int psize = HEADER_SIZE; if (cli->buffer_in->nbytes >= HEADER_SIZE) { if (ntohl(*(uint32_t*)(cli->buffer_in->bytes + HEADER_OFFSET_MAGIC)) != MAGIC_REQUEST) { free = 1; g_warning("[%s] Invalid MAGIC", cli->id); goto free_client; } psize = HEADER_SIZE + ntohl(*(uint32_t*)(cli->buffer_in->bytes + HEADER_OFFSET_SIZE)); /* If the input block isn't large enough to receive the entire packet then switch to one that is */ if (psize > cli->buffer_in->size) { #if DEBUG g_debug("Switching to bigger block (pktsize=%d)", psize); #endif /* Create new (bigger) block */ MemBlock *block = getBlock(psize + 1); /* +1 for terminating NULL to make args easier to work with */ if (!block) { g_error("Failed to get block of size %d", psize); free = 1; goto free_client; } incRef(block); /* Copy bytes into new block */ block->nbytes = cli->buffer_in->nbytes; memmove(block->bytes, cli->buffer_in->bytes, cli->buffer_in->nbytes); /* Swap blocks */ decRef(cli->buffer_in); cli->buffer_in = block; } } int num = psize - cli->buffer_in->nbytes; if (num > 0) ret = client_recv(cli, num); } if (ret < 0) { #if DEBUG g_debug("[%s] Connection on closed", cli->id); #endif free = 1; } else if (ret >= 0) { if (process_client(cli) != 0) { g_warning("[%s] Processing of client failed", cli->id); free = 1; } } } /*if ((events & (EV_READ|EV_WRITE)) == 0) { g_warning("[%s] unhandled event %d", __func__, events); }*/ free_client: if (free != 0) { #if DEBUG g_message("[%s] Client disconnected", cli->id); #endif /*printf("[%s] Removing client %d\n", __func__, cli->fd);*/ close(cli->fd); cli->fd = -1; fail_working_jobs(cli); stop_all_listening(cli); unregister_all_abilities(cli); event_del(&cli->evt); g_ptr_array_remove_fast(g_clients, cli); client_free(cli); } }
void IndexFileDeleter::decRef(const vector<string>& files) { int32_t size = files.size(); for(int32_t i=0;i<size;i++) { decRef(files[i]); } }
void emitInstanceOfD(IRGS& env, const StringData* className) { auto const src = popC(env); push(env, implInstanceOfD(env, src, className)); decRef(env, src); }
void useRefCountOf(const ReferenceBase& arg) { decRef(); m_pRefCount = arg.m_pRefCount; incRef(); }
XBuf::~XBuf() { if (mDataInter != NULL) mDataInter.decRef(); }