}
//Display the inventory list
- public String inventory(){
- HashMapIterator i = new HashMapIterator(map, 0);// Gets key from the hashmap= name of item
- HashMapIterator j = new HashMapIterator(map, 1);//Gets the value from hashmap
- StringBuffer sb = new StringBuffer("");
+ //Display the inventory list
+ public synchronized void inventory(Socket s){
+ HashMapIterator i = new HashMapIterator(map, 0);// Gets key from the hashmap= name of item
+ HashMapIterator j = new HashMapIterator(map, 1);//Gets the value from hashmap
int totalvalue=balance;
- while (i.hasNext() == true) {
- Object o = i.next();
- String name = o.toString();
- ItemInfo oo = (ItemInfo) j.next();
- sb.append(name);
- sb.append(" ");
- Integer q = new Integer(oo.quantity);
- sb.append(q.toString());
- sb.append(" ");
- Integer p = new Integer(oo.price);
- sb.append(p.toString());
- sb.append("\n");
- totalvalue+=oo.quantity*oo.price;
- }
- sb.append("Total value: ");
- sb.append((new Integer(totalvalue)).toString());
- sb.append("\n");
- return sb.toString();
- }
+ while (i.hasNext() == true) {
+ StringBuffer sb = new StringBuffer("");
+ Object o = i.next();
+ String name = o.toString();
+ ItemInfo oo = (ItemInfo) j.next();
+ sb.append(name);
+ sb.append(" ");
+ Integer q = new Integer(oo.quantity);
+ sb.append(q.toString());
+ sb.append(" ");
+ Integer p = new Integer(oo.price);
+ sb.append(p.toString());
+ sb.append("\n");
+ totalvalue+=oo.quantity*oo.price;
+ s.write(sb.toString().getBytes());
+ }
+ StringBuffer sb=new StringBuffer("");
+ sb.append("Total value: ");
+ sb.append((new Integer(totalvalue)).toString());
+ sb.append("\n");
+ s.write(sb.toString().getBytes());
+ }
}
void restorecheckpoint(int numparams, void ** original, void ** checkpoint, struct RuntimeHash *forward, struct RuntimeHash * reverse) {
struct RuntimeHash *todo=allocateRuntimeHash(100);
+ struct RuntimeHash *visited=allocateRuntimeHash(100);
int i;
for(i=0;i<numparams;i++) {
- RuntimeHashadd(todo, (int) checkpoint[i], (int) checkpoint[i]);
+ if (checkpoint[i]!=NULL) {
+ RuntimeHashadd(todo, (int) checkpoint[i], (int) checkpoint[i]);
+ RuntimeHashadd(visited, (int) checkpoint[i], (int) checkpoint[i]);
+ }
}
-
+
while(RuntimeHashcountset(todo)!=0) {
void * ptr=(void *) RuntimeHashfirstkey(todo);
int type=((int *)ptr)[0];
RuntimeHashremove(todo, (int) ptr, (int) ptr);
+
{
void *cpy;
int *pointer;
void *objptr=((void **)(((char *)& ao->___length___)+sizeof(int)))[i];
if (objptr==NULL)
((void **)(((char *)& ao_cpy->___length___)+sizeof(int)))[i]=NULL;
- else
+ else {
+ if (!RuntimeHashcontainskey(visited, (int) objptr)) {
+ RuntimeHashadd(visited, (int) objptr, (int) objptr);
+ RuntimeHashadd(todo, (int) objptr, (int) objptr);
+ }
RuntimeHashget(reverse, (int) objptr, (int *) &((void **)(((char *)& ao_cpy->___length___)+sizeof(int)))[i]);
+ }
}
} else {
int numptr=pointer[0];
void * objptr=*((void **)(((int)ptr)+offset));
if (objptr==NULL)
*((void **) (((int)cpy)+offset))=NULL;
- else
+ else {
+ if (!RuntimeHashcontainskey(visited, (int) objptr)) {
+ RuntimeHashadd(visited, (int) objptr, (int) objptr);
+ RuntimeHashadd(todo, (int) objptr, (int) objptr);
+ }
RuntimeHashget(reverse, (int) objptr, (int *) &(((char *)cpy)[offset]));
+ }
}
if (hasflags[type]) {
(((void **)cpy)[2])=flagptr;
}
}
freeRuntimeHash(todo);
+ freeRuntimeHash(visited);
}
extern struct Queue * activetasks;
extern struct parameterwrapper * objectqueues[NUMCLASSES];
extern struct genhashtable * failedtasks;
+extern struct taskparamdescriptor *currtpd;
extern struct RuntimeHash *forward;
extern struct RuntimeHash *reverse;
extern struct RuntimeHash *fdtoobject;
}
}
+ {
+ /* Update current task descriptor */
+ int i;
+ for(i=0;i<currtpd->numParameters;i++) {
+ void *orig=currtpd->parameterArray[i];
+ void *copy;
+ if (gc_createcopy(orig, ©))
+ enqueue(orig);
+ currtpd->parameterArray[i]=copy;
+ }
+
+ }
{
/* Update active tasks */
struct genpointerlist * ptr=failedtasks->list;
while(ptr!=NULL) {
struct taskparamdescriptor *tpd=ptr->src;
- void *orig;
- void *copy;
int i;
for(i=0;i<tpd->numParameters;i++) {
- orig=tpd->parameterArray[i];
+ void * orig=tpd->parameterArray[i];
+ void * copy;
if (gc_createcopy(orig, ©))
enqueue(orig);
tpd->parameterArray[i]=copy;
struct Queue * activetasks;
struct parameterwrapper * objectqueues[NUMCLASSES];
struct genhashtable * failedtasks;
+struct taskparamdescriptor * currtpd;
struct RuntimeHash * forward;
struct RuntimeHash * reverse;
with the or mask and and's it with the andmask. */
void flagorand(void * ptr, int ormask, int andmask) {
- int flag=((int *)ptr)[1];
+ int oldflag=((int *)ptr)[1];
struct RuntimeHash *flagptr=(struct RuntimeHash *)(((int*)ptr)[2]);
- flag|=ormask;
+ int flag=ormask|oldflag;
flag&=andmask;
+ if (flag==oldflag) /* Don't do anything */
+ return;
((int*)ptr)[1]=flag;
/*Remove object from all queues */
/* Queue task */
if (!gencontains(failedtasks, tpd))
addNewItem(activetasks, tpd);
-
+ else {
+ RUNFREE(tpd->parameterArray);
+ RUNFREE(tpd);
+ }
+
/* This loop iterates to the next parameter combination */
for(j=0;j<numparams;j++) {
if (j==newindex) {
sigaction(SIGBUS,&sig,0);
sigaction(SIGSEGV,&sig,0);
sigaction(SIGFPE,&sig,0);
+ sigaction(SIGPIPE,&sig,0);
/* Zero fd set */
FD_ZERO(&readfds);
if (!isEmpty(activetasks)) {
int i;
struct QueueItem * qi=(struct QueueItem *) getTail(activetasks);
- struct taskparamdescriptor *tpd=(struct taskparamdescriptor *) qi->objectptr;
+ currtpd=(struct taskparamdescriptor *) qi->objectptr;
removeItem(activetasks, qi);
/* Check if this task has failed */
- if (gencontains(failedtasks, tpd))
+ if (gencontains(failedtasks, currtpd)) {
+ // Free up task parameter descriptor
+ RUNFREE(currtpd->parameterArray);
+ RUNFREE(currtpd);
goto newtask;
+ }
/* Make sure that the parameters are still in the queues */
- for(i=0;i<tpd->task->numParameters;i++) {
- void * parameter=tpd->parameterArray[i];
- struct parameterdescriptor * pd=tpd->task->descriptorarray[i];
+ for(i=0;i<currtpd->task->numParameters;i++) {
+ void * parameter=currtpd->parameterArray[i];
+ struct parameterdescriptor * pd=currtpd->task->descriptorarray[i];
struct parameterwrapper *pw=(struct parameterwrapper *) pd->queue;
- if (!RuntimeHashcontainskey(pw->objectset, (int) parameter))
+ if (!RuntimeHashcontainskey(pw->objectset, (int) parameter)) {
+ RUNFREE(currtpd->parameterArray);
+ RUNFREE(currtpd);
goto newtask;
+ }
taskpointerarray[i+OFFSET]=parameter;
}
{
/* Checkpoint the state */
forward=allocateRuntimeHash(100);
reverse=allocateRuntimeHash(100);
- void ** checkpoint=makecheckpoint(tpd->task->numParameters, &taskpointerarray[OFFSET], forward, reverse);
+ void ** checkpoint=makecheckpoint(currtpd->task->numParameters, currtpd->parameterArray, forward, reverse);
int x;
if (x=setjmp(error_handler)) {
/* Recover */
#ifdef DEBUG
printf("Fatal Error=%d, Recovering!\n",x);
#endif
- genputtable(failedtasks,tpd,tpd);
- restorecheckpoint(tpd->task->numParameters, &taskpointerarray[OFFSET], checkpoint, forward, reverse);
+ genputtable(failedtasks,currtpd,currtpd);
+ restorecheckpoint(currtpd->task->numParameters, currtpd->parameterArray, checkpoint, forward, reverse);
freeRuntimeHash(forward);
freeRuntimeHash(reverse);
freemalloc();
} else {
if (injectfailures) {
if ((((double)random())/RAND_MAX)<failurechance) {
- printf("\nINJECTING TASK FAILURE to %s\n", tpd->task->name);
+ printf("\nINJECTING TASK FAILURE to %s\n", currtpd->task->name);
longjmp(error_handler,10);
}
}
/* Actually call task */
#ifdef PRECISE_GC
- ((int *)taskpointerarray)[0]=tpd->task->numParameters;
+ ((int *)taskpointerarray)[0]=currtpd->task->numParameters;
taskpointerarray[1]=NULL;
#endif
if (debugtask) {
- printf("ENTER %s count=%d\n",tpd->task->name, (instaccum-instructioncount));
- ((void (*) (void **)) tpd->task->taskptr)(taskpointerarray);
- printf("EXIT %s count=%d\n",tpd->task->name, (instaccum-instructioncount));
+ printf("ENTER %s count=%d\n",currtpd->task->name, (instaccum-instructioncount));
+ ((void (*) (void **)) currtpd->task->taskptr)(taskpointerarray);
+ printf("EXIT %s count=%d\n",currtpd->task->name, (instaccum-instructioncount));
} else
- ((void (*) (void **)) tpd->task->taskptr)(taskpointerarray);
+ ((void (*) (void **)) currtpd->task->taskptr)(taskpointerarray);
freeRuntimeHash(forward);
freeRuntimeHash(reverse);
freemalloc();
+ // Free up task parameter descriptor
+ RUNFREE(currtpd->parameterArray);
+ RUNFREE(currtpd);
forward=NULL;
reverse=NULL;
}