void* ResourceObj::operator new(size_t size){ char* r = (bootstrapping || allocatePersistent) ? (char *) selfs_malloc(size) : allocateResource(size); # if GENERATE_DEBUGGING_AIDS if (CheckAssertions && size && r == (char*) catchThisOne) breakpoint(); # endif return r; }
// Sets a value of the object to string int UIOperationEvent::setString(const char* pString) { if (stringValue) releaseAllResources(); stringValue = (char*) allocateResource (sizeof (char), (int)strlen(pString) + 1); if (!stringValue) { valueType = UI_STRING; return setError(ERR_MEMORY_ALLOC, SETTING_OPERATION_EVENT); } strcpy (stringValue, pString); length = (int)strlen(stringValue); set_value(); return setSuccess(); }
void genericThreadLaunch(UINT level, UINT type, void* (*f)(void*)) { pthread_t* thread = (pthread_t *)malloc(num_threads * sizeof(pthread_t)); ThreadParam** thArray = (ThreadParam**)malloc(num_threads * sizeof(ThreadParam*)); pthread_attr_t attr; UINT rc; void *status; /* Initialize and set thread detached attribute */ pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); UINT numCand = numCandidates; UINT tnumCandidates = numCand/num_threads; if (numCand % num_threads != 0) tnumCandidates++; UINT toffset = 0; UINT thread_count = 0; for(UINT t = 0; t < num_threads; t++) { //printf("Main: creating thread %ld\n", t); if (numCand < tnumCandidates) tnumCandidates = numCand; if (tnumCandidates > 0) { thArray[t] = (ThreadParam*)malloc(sizeof(ThreadParam)); ThreadParam* th = thArray[t]; th->level = level; th->numCandidates = tnumCandidates; th->offset = toffset; allocateResource(tnumCandidates, level, th, type); rc = pthread_create(&thread[t], &attr, f, th); thread_count ++; } else break; if (rc) { printf("ERROR; return code from pthread_create() is %d\n", rc); exit(-1); } toffset += tnumCandidates; numCand -= tnumCandidates; } /* Free attribute and wait for the other threads */ pthread_attr_destroy(&attr); for(UINT t = 0; t < thread_count; t++) { rc = pthread_join(thread[t], &status); if (rc) { printf("ERROR; return code from pthread_join() is %d\n", rc); exit(-1); } //printf("Main: completed join with thread %ld having a status of %ld\n",t,(long)status); } for(UINT t = 0; t < thread_count; t++) { freeResource(thArray[t]); free(thArray[t]); thArray[t] = NULL; } //printf("Main: program completed. Exiting.\n"); free(thArray); free(thread); }