void sendFileTo(char* message, int to, int from){ char *file_contents; long input_file_size; //remove \n at end of string message[strlen(message)-1]=0; FILE* input_file = fopen(message,"r"); if(input_file != NULL){ fseek(input_file, 0, SEEK_END); input_file_size = ftell(input_file); rewind(input_file); file_contents = malloc(input_file_size * (sizeof(char))); fread(file_contents, sizeof(char), input_file_size, input_file); fclose(input_file); char* buf; int size = input_file_size+sizeof(message)+MAX_USR_LENGTH + 30; char tmp[size]; memset(tmp,0,size); strcat(tmp,"ENDOFFILE"); strcat(tmp," ; "); strcat(tmp,file_contents); buf = parseMessage(tmp,strlen(tmp)); printf("N%s\n",buf); printf("Envoie au client : %d\n",to); if (Writeline(ctx.socketFd[to], buf, strlen(buf)+1) < 0){ debugTrace("Message issue"); } else { debugTrace("Message sent\n"); } free(buf); } }
void sendAll(unsigned char* message, int actuel){ int i = 0; char* buf; int size = strlen((char*)message)+MAX_USR_LENGTH + 20; char tmp[size]; for(i=0;i<LISTENQ;i++){ memset(tmp,0,size); if(ctx.socketFd[i] != -1 && (i != actuel)){ strcat(tmp,usrDatas[actuel].name); strcat(tmp," : "); strcat(tmp,(char*)message); buf = parseMessage(tmp,strlen(tmp)); printf("Envoie au client : %d\n",i); if (Writeline(ctx.socketFd[i], buf, strlen(buf)+1) < 0){ debugTrace("Message issue"); } else { debugTrace("Message sent\n"); } free(buf); } } }
int isFile(int messageSize){ if(messageSize < 10000000){//10Mo, msg debugTrace("This is a message"); return 1; } else{ debugTrace("This is a file"); return 2; } }
void printError(int err){ switch(err){ case 0: debugTrace("deconnection"); break; case -1: debugTrace("Known error"); break; case -2: debugTrace("Is this possible ?"); break; } }
void moreCapabilities (nat from USED_IF_THREADS, nat to USED_IF_THREADS) { #if defined(THREADED_RTS) nat i; Capability **old_capabilities = capabilities; capabilities = stgMallocBytes(to * sizeof(Capability*), "moreCapabilities"); if (to == 1) { // THREADED_RTS must work on builds that don't have a mutable // BaseReg (eg. unregisterised), so in this case // capabilities[0] must coincide with &MainCapability. capabilities[0] = &MainCapability; } for (i = 0; i < to; i++) { if (i < from) { capabilities[i] = old_capabilities[i]; } else { capabilities[i] = stgMallocBytes(sizeof(Capability), "moreCapabilities"); initCapability(capabilities[i], i); } } debugTrace(DEBUG_sched, "allocated %d more capabilities", to - from); if (old_capabilities != NULL) { stgFree(old_capabilities); } #endif }
/* GC for the spark pool, called inside Capability.c for all capabilities in turn. Blindly "evac"s complete spark pool. */ void traverseSparkQueue (evac_fn evac, void *user, Capability *cap) { StgClosure **sparkp; SparkPool *pool; StgWord top,bottom, modMask; pool = cap->sparks; ASSERT_WSDEQUE_INVARIANTS(pool); top = pool->top; bottom = pool->bottom; sparkp = (StgClosurePtr*)pool->elements; modMask = pool->moduloSize; while (top < bottom) { /* call evac for all closures in range (wrap-around via modulo) * In GHC-6.10, evac takes an additional 1st argument to hold a * GC-specific register, see rts/sm/GC.c::mark_root() */ evac( user , sparkp + (top & modMask) ); top++; } debugTrace(DEBUG_sparks, "traversed spark queue, len=%ld; (hd=%ld; tl=%ld)", sparkPoolSize(pool), pool->bottom, pool->top); }
void HttpUpdateDownloader::on(Complete, HttpConnection*, const string&) throw() { #ifdef _DEBUG debugTrace("on(ModeChange)\n"); #endif if (!fileError && file != INVALID_HANDLE_VALUE) { CloseHandle(file); if (m_currentSize != m_fileSize) { char buffer[2048]; snprintf(buffer, sizeof(buffer), "Size mismatch %s (downloaded %d, expected %d)", Util::getFileName(Text::fromT(targetPath)).c_str(), m_currentSize, m_fileSize); LOG_MESSAGE(buffer); DeleteFile(getTempFile().c_str()); return; } const string currentMD5 = m_digest.digestAsString(); if (Util::stricmp(currentMD5, m_fileMD5) != 0) { char buffer[2048]; snprintf(buffer, sizeof(buffer), "MD5 mismatch %s (downloaded %s, expected %s)", Util::getFileName(Text::fromT(targetPath)).c_str(), currentMD5.c_str(), m_fileMD5.c_str()); LOG_MESSAGE(buffer); DeleteFile(getTempFile().c_str()); return; } LOG_MESSAGE("Successfully downloaded " + Text::fromT(targetPath)); try { File::atomicRename(getTempFile(), targetPath); // файл скачался if (m_listener != NULL) { m_listener->onDownloadComplete(this); } } catch (const Exception& e) { LOG_MESSAGE("Error updating " + Text::fromT(targetPath) + ": " + e.getError()); } } }
void freeExec (void *addr) { StgPtr p = (StgPtr)addr - 1; bdescr *bd = Bdescr((StgPtr)p); if ((bd->flags & BF_EXEC) == 0) { barf("freeExec: not executable"); } if (*(StgPtr)p == 0) { barf("freeExec: already free?"); } ACQUIRE_SM_LOCK; bd->gen_no -= *(StgPtr)p; *(StgPtr)p = 0; if (bd->gen_no == 0) { // Free the block if it is empty, but not if it is the block at // the head of the queue. if (bd != exec_block) { debugTrace(DEBUG_gc, "free exec block %p", bd->start); dbl_link_remove(bd, &exec_block); setExecutable(bd->start, bd->blocks * BLOCK_SIZE, rtsFalse); freeGroup(bd); } else { bd->free = bd->start; } } RELEASE_SM_LOCK }
nat freeTaskManager (void) { Task *task, *next; nat tasksRunning = 0; ACQUIRE_LOCK(&all_tasks_mutex); for (task = all_tasks; task != NULL; task = next) { next = task->all_next; if (task->stopped) { freeTask(task); } else { tasksRunning++; } } debugTrace(DEBUG_sched, "freeing task manager, %d tasks still running", tasksRunning); all_tasks = NULL; RELEASE_LOCK(&all_tasks_mutex); #if defined(THREADED_RTS) closeMutex(&all_tasks_mutex); #if !defined(MYTASK_USE_TLV) freeThreadLocalKey(¤tTaskKey); #endif #endif tasksInitialized = 0; return tasksRunning; }
// // Resize each of the nurseries to the specified size. // static void resizeNurseriesEach (W_ blocks) { uint32_t i, node; bdescr *bd; W_ nursery_blocks; nursery *nursery; for (i = 0; i < n_nurseries; i++) { nursery = &nurseries[i]; nursery_blocks = nursery->n_blocks; if (nursery_blocks == blocks) continue; node = capNoToNumaNode(i); if (nursery_blocks < blocks) { debugTrace(DEBUG_gc, "increasing size of nursery to %d blocks", blocks); nursery->blocks = allocNursery(node, nursery->blocks, blocks-nursery_blocks); } else { bdescr *next_bd; debugTrace(DEBUG_gc, "decreasing size of nursery to %d blocks", blocks); bd = nursery->blocks; while (nursery_blocks > blocks) { next_bd = bd->link; next_bd->u.back = NULL; nursery_blocks -= bd->blocks; // might be a large block freeGroup(bd); bd = next_bd; } nursery->blocks = bd; // might have gone just under, by freeing a large block, so make // up the difference. if (nursery_blocks < blocks) { nursery->blocks = allocNursery(node, nursery->blocks, blocks-nursery_blocks); } } nursery->n_blocks = blocks; ASSERT(countBlocks(nursery->blocks) == nursery->n_blocks); } }
/* * Open the floppy image file */ static void openFloppy() { fimage = fopen("floppy.bin", "rw"); if (fimage == NULL) { fprintf(stderr, "Can't find 'floppy.bin'\n"); debugTrace(); exit(1); } }
void interruptWorkerTask (Task *task) { ASSERT(osThreadId() != task->id); // seppuku not allowed ASSERT(task->incall->suspended_tso); // use this only for FFI calls interruptOSThread(task->id); debugTrace(DEBUG_sched, "interrupted worker task %p", taskId(task)); }
failure(char *msg) { debugTrace(DEBUG_hpc,"hpc failure: %s\n",msg); fprintf(stderr,"Hpc failure: %s\n",msg); if (tixFilename) { fprintf(stderr,"(perhaps remove %s file?)\n",tixFilename); } else { fprintf(stderr,"(perhaps remove .tix file?)\n"); } stg_exit(1); }
void GInputPool::putToPool(const GInputData & inputData) { if(this->pool->isFull()) { debugTrace("Input pool is full!!!"); return; } this->pool->requireNext() = inputData; }
void sendTo(char* message, int to, int from){ char* buf; int size = strlen((char*)message)+MAX_USR_LENGTH + 20; char tmp[size]; memset(tmp,0,size); strcat(tmp,usrDatas[from].name); strcat(tmp," : "); strcat(tmp,(char*)message); buf = parseMessage(tmp,strlen(tmp)); printf("Envoie au client : %d\n",to); if (Writeline(ctx.socketFd[to], buf, strlen(buf)+1) < 0){ debugTrace("Message issue"); } else { debugTrace("Message sent\n"); } free(buf); }
void gcStablePtrTable( void ) { snEntry *p, *end_stable_ptr_table; StgPtr q; end_stable_ptr_table = &stable_ptr_table[SPT_size]; // NOTE: _starting_ at index 1; index 0 is unused. for (p = stable_ptr_table + 1; p < end_stable_ptr_table; p++) { // Update the pointer to the StableName object, if there is one if (p->sn_obj != NULL) { p->sn_obj = isAlive(p->sn_obj); } // Internal pointers are free slots. If q == NULL, it's a // stable name where the object has been GC'd, but the // StableName object (sn_obj) is still alive. q = p->addr; if (q && (q < (P_)stable_ptr_table || q >= (P_)end_stable_ptr_table)) { // StableNames only: if (p->ref == 0) { if (p->sn_obj == NULL) { // StableName object is dead freeStableName(p); debugTrace(DEBUG_stable, "GC'd Stable name %ld", (long)(p - stable_ptr_table)); continue; } else { p->addr = (StgPtr)isAlive((StgClosure *)p->addr); debugTrace(DEBUG_stable, "stable name %ld still alive at %p, ref %ld\n", (long)(p - stable_ptr_table), p->addr, p->ref); } } } } }
static void resizeNursery (nursery *nursery, W_ blocks) { bdescr *bd; W_ nursery_blocks; nursery_blocks = nursery->n_blocks; if (nursery_blocks == blocks) return; if (nursery_blocks < blocks) { debugTrace(DEBUG_gc, "increasing size of nursery to %d blocks", blocks); nursery->blocks = allocNursery(nursery->blocks, blocks-nursery_blocks); } else { bdescr *next_bd; debugTrace(DEBUG_gc, "decreasing size of nursery to %d blocks", blocks); bd = nursery->blocks; while (nursery_blocks > blocks) { next_bd = bd->link; next_bd->u.back = NULL; nursery_blocks -= bd->blocks; // might be a large block freeGroup(bd); bd = next_bd; } nursery->blocks = bd; // might have gone just under, by freeing a large block, so make // up the difference. if (nursery_blocks < blocks) { nursery->blocks = allocNursery(nursery->blocks, blocks-nursery_blocks); } } nursery->n_blocks = blocks; ASSERT(countBlocks(nursery->blocks) == nursery->n_blocks); }
/* * Execute the MONITOREXIT instruction */ void op_monitorexit() { // assume the current thread owns the monitor // assume lock was created when monitorenter was called Ref object = popRef(); Ref lock = getRef(object, OBJECT_LOCK); if (lock == NULL) { printf("Illegal State, no lock found\n"); debugTrace(); exit(1); } unlockLock(lock); pc++; }
// ------------------------------------------------------------------------------- CInformationCollection* XMLPersister::createInformationCollection( QString xmlString ) // ------------------------------------------------------------------------------- { debugTrace( "[XMLPersister::createInformationCollection] xmlString = " + xmlString ); QDomDocument* xmlDocument = createDomDocumentFromString(xmlString); if ( NULLPTR != xmlDocument ) { return createInformationCollection( *xmlDocument ); } return NULLPTR; }
void startupHpc(void) { char *hpc_tixdir; char *hpc_tixfile; if (moduleHash == NULL) { // no modules were registered with hs_hpc_module, so don't bother // creating the .tix file. return; } if (hpc_inited != 0) { return; } hpc_inited = 1; hpc_pid = getpid(); hpc_tixdir = getenv("HPCTIXDIR"); hpc_tixfile = getenv("HPCTIXFILE"); debugTrace(DEBUG_hpc,"startupHpc"); /* XXX Check results of mallocs/strdups, and check we are requesting enough bytes */ if (hpc_tixfile != NULL) { tixFilename = strdup(hpc_tixfile); } else if (hpc_tixdir != NULL) { /* Make sure the directory is present; * conditional code for mkdir lifted from lndir.c */ #ifdef WIN32 mkdir(hpc_tixdir); #else mkdir(hpc_tixdir,0777); #endif /* Then, try open the file */ tixFilename = (char *) stgMallocBytes(strlen(hpc_tixdir) + strlen(prog_name) + 12, "Hpc.startupHpc"); sprintf(tixFilename,"%s/%s-%d.tix",hpc_tixdir,prog_name,(int)hpc_pid); } else { tixFilename = (char *) stgMallocBytes(strlen(prog_name) + 6, "Hpc.startupHpc"); sprintf(tixFilename, "%s.tix", prog_name); } if (init_open(fopen(tixFilename,"r"))) { readTix(); } }
void HttpUpdateDownloader::on(Data, HttpConnection*, const uint8_t* buffer, size_t length) throw(){ #ifdef _DEBUG debugTrace("onData: %d bytes\n", length); #endif if (file == INVALID_HANDLE_VALUE) { if (fileError) { // TODO лучше при ошибке просто закрыть сокет. return; } FileUtils::ensureDirectory(targetPath); DWORD flags = FILE_ATTRIBUTE_NOT_CONTENT_INDEXED; if (m_hidden) { flags |= FILE_ATTRIBUTE_HIDDEN; } file = CreateFile(getTempFile().c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, flags, NULL); if (file == INVALID_HANDLE_VALUE) { #ifdef _DEBUG DWORD errorCode = GetLastError(); debugTrace("Error %d creating file\n", SystemUtils::describeError(errorCode).c_str()); #endif fileError = true; return; } } DWORD written; if (!WriteFile(file, buffer, length, &written, NULL) || written != length) { #ifdef _DEBUG debugTrace("Error %d writing file\n", GetLastError()); #endif CloseHandle(file); DeleteFile(targetPath.c_str()); fileError = true; return; } m_currentSize += length; m_digest.update(buffer, length); }
StgPtr alloc_todo_block (gen_workspace *ws, nat size) { bdescr *bd/*, *hd, *tl */; // Grab a part block if we have one, and it has enough room bd = ws->part_list; if (bd != NULL && bd->start + bd->blocks * BLOCK_SIZE_W - bd->free > (int)size) { ws->part_list = bd->link; ws->n_part_blocks -= bd->blocks; } else { // blocks in to-space get the BF_EVACUATED flag. // allocBlocks_sync(16, &hd, &tl, // ws->step->gen_no, ws->step, BF_EVACUATED); // // tl->link = ws->part_list; // ws->part_list = hd->link; // ws->n_part_blocks += 15; // // bd = hd; if (size > BLOCK_SIZE_W) { bd = allocGroup_sync((W_)BLOCK_ROUND_UP(size*sizeof(W_)) / BLOCK_SIZE); } else { bd = allocBlock_sync(); } initBdescr(bd, ws->gen, ws->gen->to); bd->flags = BF_EVACUATED; bd->u.scan = bd->free = bd->start; } bd->link = NULL; ws->todo_bd = bd; ws->todo_free = bd->free; ws->todo_lim = stg_min(bd->start + bd->blocks * BLOCK_SIZE_W, bd->free + stg_max(WORK_UNIT_WORDS,size)); debugTrace(DEBUG_gc, "alloc new todo block %p for gen %d", bd->free, ws->gen->no); return ws->todo_free; }
static void writeTix(FILE *f) { HpcModuleInfo *tmpModule; unsigned int i, inner_comma, outer_comma; outer_comma = 0; if (f == 0) { return; } fprintf(f,"Tix ["); tmpModule = modules; for(;tmpModule != 0;tmpModule = tmpModule->next) { if (outer_comma) { fprintf(f,","); } else { outer_comma = 1; } fprintf(f," TixModule \"%s\" %u %u [", tmpModule->modName, (uint32_t)tmpModule->hashNo, (uint32_t)tmpModule->tickCount); debugTrace(DEBUG_hpc,"%s: %u (hash=%u)\n", tmpModule->modName, (uint32_t)tmpModule->tickCount, (uint32_t)tmpModule->hashNo); inner_comma = 0; for(i = 0;i < tmpModule->tickCount;i++) { if (inner_comma) { fprintf(f,","); } else { inner_comma = 1; } if (tmpModule->tixArr) { fprintf(f,"%" FMT_Word64,tmpModule->tixArr[i]); } else { fprintf(f,"0"); } } fprintf(f,"]"); } fprintf(f,"]\n"); fclose(f); }
StgPtr alloc_todo_block (gen_workspace *ws, uint32_t size) { bdescr *bd/*, *hd, *tl */; // Grab a part block if we have one, and it has enough room bd = ws->part_list; if (bd != NULL && bd->start + bd->blocks * BLOCK_SIZE_W - bd->free > (int)size) { ws->part_list = bd->link; ws->n_part_blocks -= bd->blocks; ws->n_part_words -= bd->free - bd->start; } else { if (size > BLOCK_SIZE_W) { bd = allocGroup_sync((W_)BLOCK_ROUND_UP(size*sizeof(W_)) / BLOCK_SIZE); } else { if (gct->free_blocks) { bd = gct->free_blocks; gct->free_blocks = bd->link; } else { allocBlocks_sync(16, &bd); gct->free_blocks = bd->link; } } // blocks in to-space get the BF_EVACUATED flag. bd->flags = BF_EVACUATED; bd->u.scan = bd->start; initBdescr(bd, ws->gen, ws->gen->to); } bd->link = NULL; ws->todo_bd = bd; ws->todo_free = bd->free; ws->todo_lim = stg_min(bd->start + bd->blocks * BLOCK_SIZE_W, bd->free + stg_max(WORK_UNIT_WORDS,size)); // See Note [big objects] debugTrace(DEBUG_gc, "alloc new todo block %p for gen %d", bd->free, ws->gen->no); return ws->todo_free; }
static void scavengeTSO (StgTSO *tso) { rtsBool saved_eager; debugTrace(DEBUG_gc,"scavenging thread %d",(int)tso->id); // update the pointer from the Task. if (tso->bound != NULL) { tso->bound->tso = tso; } saved_eager = gct->eager_promotion; gct->eager_promotion = rtsFalse; evacuate((StgClosure **)&tso->blocked_exceptions); evacuate((StgClosure **)&tso->bq); // scavange current transaction record evacuate((StgClosure **)&tso->trec); evacuate((StgClosure **)&tso->stackobj); evacuate((StgClosure **)&tso->_link); if ( tso->why_blocked == BlockedOnMVar || tso->why_blocked == BlockedOnBlackHole || tso->why_blocked == BlockedOnMsgThrowTo || tso->why_blocked == NotBlocked ) { evacuate(&tso->block_info.closure); } #ifdef THREADED_RTS // in the THREADED_RTS, block_info.closure must always point to a // valid closure, because we assume this in throwTo(). In the // non-threaded RTS it might be a FD (for // BlockedOnRead/BlockedOnWrite) or a time value (BlockedOnDelay) else { tso->block_info.closure = (StgClosure *)END_TSO_QUEUE; } #endif tso->dirty = gct->failed_to_evac; gct->eager_promotion = saved_eager; }
/* --------------------------------------------------------------------------- * Function: initCapabilities() * * Purpose: set up the Capability handling. For the THREADED_RTS build, * we keep a table of them, the size of which is * controlled by the user via the RTS flag -N. * * ------------------------------------------------------------------------- */ void initCapabilities( void ) { #if defined(THREADED_RTS) nat i; #ifndef REG_Base // We can't support multiple CPUs if BaseReg is not a register if (RtsFlags.ParFlags.nNodes > 1) { errorBelch("warning: multiple CPUs not supported in this build, reverting to 1"); RtsFlags.ParFlags.nNodes = 1; } #endif n_capabilities = RtsFlags.ParFlags.nNodes; if (n_capabilities == 1) { capabilities = &MainCapability; // THREADED_RTS must work on builds that don't have a mutable // BaseReg (eg. unregisterised), so in this case // capabilities[0] must coincide with &MainCapability. } else { capabilities = stgMallocBytes(n_capabilities * sizeof(Capability), "initCapabilities"); } for (i = 0; i < n_capabilities; i++) { initCapability(&capabilities[i], i); } debugTrace(DEBUG_sched, "allocated %d capabilities", n_capabilities); #else /* !THREADED_RTS */ n_capabilities = 1; capabilities = &MainCapability; initCapability(&MainCapability, 0); #endif // There are no free capabilities to begin with. We will start // a worker Task to each Capability, which will quickly put the // Capability on the free list when it finds nothing to do. last_free_capability = &capabilities[0]; }
void discardTasksExcept (Task *keep) { Task *task, *next; // Wipe the task list, except the current Task. ACQUIRE_LOCK(&all_tasks_mutex); for (task = all_tasks; task != NULL; task=next) { next = task->all_next; if (task != keep) { debugTrace(DEBUG_sched, "discarding task %ld", (long)TASK_ID(task)); freeTask(task); } } all_tasks = keep; keep->all_next = NULL; keep->all_prev = NULL; RELEASE_LOCK(&all_tasks_mutex); }
Task * newBoundTask (void) { Task *task; if (!tasksInitialized) { errorBelch("newBoundTask: RTS is not initialised; call hs_init() first"); stg_exit(EXIT_FAILURE); } task = allocTask(); task->stopped = rtsFalse; newInCall(task); debugTrace(DEBUG_sched, "new task (taskCount: %d)", taskCount); return task; }
StgWord lookupStableName (StgPtr p) { StgWord sn; const void* sn_tmp; stableLock(); if (stable_name_free == NULL) { enlargeStableNameTable(); } /* removing indirections increases the likelihood * of finding a match in the stable name hash table. */ p = (StgPtr)removeIndirections((StgClosure*)p); // register the untagged pointer. This just makes things simpler. p = (StgPtr)UNTAG_CLOSURE((StgClosure*)p); sn_tmp = lookupHashTable(addrToStableHash,(W_)p); sn = (StgWord)sn_tmp; if (sn != 0) { ASSERT(stable_name_table[sn].addr == p); debugTrace(DEBUG_stable, "cached stable name %ld at %p",sn,p); stableUnlock(); return sn; } sn = stable_name_free - stable_name_table; stable_name_free = (snEntry*)(stable_name_free->addr); stable_name_table[sn].addr = p; stable_name_table[sn].sn_obj = NULL; /* debugTrace(DEBUG_stable, "new stable name %d at %p\n",sn,p); */ /* add the new stable name to the hash table */ insertHashTable(addrToStableHash, (W_)p, (void *)sn); stableUnlock(); return sn; }
void boundTaskExiting (Task *task) { #if defined(THREADED_RTS) ASSERT(osThreadId() == task->id); #endif ASSERT(myTask() == task); endInCall(task); // Set task->stopped, but only if this is the last call (#4850). // Remember that we might have a worker Task that makes a foreign // call and then a callback, so it can transform into a bound // Task for the duration of the callback. if (task->incall == NULL) { task->stopped = rtsTrue; } debugTrace(DEBUG_sched, "task exiting"); }