//TODO check that the right path is pointed to by the below #include\r
#include "RuntimeConflictResolver.h"\r
\r
-#define NOT_AT_FRONT = 3;\r
-#define TRAVERSER_FINISHED = 2;\r
-\r
//Note: is global to all processes\r
WaitingQueueBinVector * freeBinVectors;\r
\r
}\r
\r
//NOTE: allocSiteID is NOT the same as allocsite, rather it's an ID generated by the traverser for an alloc site for a traversal.\r
-void putWaitingQueue(int allocSiteID, WaitingQueueBin * queue, int effectType, void * resumePtr, int traverserID) {\r
+void putIntoWaitingQueue(int allocSiteID, WaitingQueueBin * queue, int effectType, void * resumePtr, int traverserID) {\r
//lock bin\r
WaitingQueueBinVector * currentVector;\r
TraverserResumeDataFromWaitingQ * b;\r
\r
//completely empty case\r
if (queue[allocSiteID].tail == NULL) {\r
- currentVector = getUsableVector();\r
+ currentVector = getUsableWaitingQueueBinVector();\r
head = currentVector;\r
queue[allocSiteID].tail = currentVector; //We do not set the head here because we need lock\r
}\r
//Tail bin full\r
else if (queue[allocSiteID].tail->tailIndex == NUMITEMS_WQ) {\r
- currentVector = getUsableVector();\r
+ currentVector = getUsableWaitingQueueBinVector();\r
queue[allocSiteID].tail->next = currentVector;\r
queue[allocSiteID].tail = currentVector;\r
} else { //the bin not full case\r
\r
//This method should be called by the SESE block\r
//Return is how many things are removed. -1 would indicate error\r
-int removeFromQueue(WaitingQueueBin * wQueue, int allocSiteID, int TraverserID) {\r
+int removeFromWaitingQueue(WaitingQueueBin * wQueue, int allocSiteID, int TraverserID) {\r
TraverserResumeDataFromWaitingQ * td;\r
WaitingQueueBin * be = &(wQueue[allocSiteID]);\r
int count = 0;\r
return count;\r
}\r
\r
- //TODo replace 2 with #define\r
- if(traverse(td->resumePtr, td->traverserID) == 2) {\r
+ if(traverse(td->resumePtr, td->traverserID) == TRAVERSER_FINISHED) {\r
count++; // means we at least got rid of 1 item in the traverser\r
be->size--;\r
\r
}\r
else if(++(be->head->headIndex) == be->head->tailIndex){\r
//Note: be->head->next CANNOT be NULL since that would imply be->size == 0\r
- be->head = returnVectorToFreePool(be->head);\r
+ be->head = returnWaitingQueueBinVectorToFreePool(be->head);\r
}\r
}\r
else\r
} while(1);\r
}\r
\r
-WaitingQueueBinVector * returnVectorToFreePool(WaitingQueueBinVector *ptr) {\r
+WaitingQueueBinVector * returnWaitingQueueBinVectorToFreePool(WaitingQueueBinVector *ptr) {\r
WaitingQueueBinVector * freeHead;\r
WaitingQueueBinVector * ptrNext;\r
do {\r
freeHead = (WaitingQueueBinVector *) 0x1;\r
- //TODO check if this cuts off part of the mem addr or not.\r
freeHead = LOCKXCHG(&freeBinVectors, freeHead);\r
} while (freeHead == (WaitingQueueBinVector *) 0x1);\r
//free bins locked\r
return ptrNext;\r
}\r
\r
-WaitingQueueBinVector * getUsableVector() {\r
+WaitingQueueBinVector * getUsableWaitingQueueBinVector() {\r
//Attempt to take one from the free bin first\r
WaitingQueueBinVector * ptr;\r
do {\r
\r
if (ptr == NULL) {\r
freeBinVectors = NULL; //lock released\r
- return mallocNewVector();\r
+ return mallocNewWaitingQueueBinVector();\r
} else {\r
freeBinVectors = ptr->next; //lock released\r
ptr->next = NULL;\r
}\r
}\r
\r
-WaitingQueueBinVector * mallocNewVector() {\r
+WaitingQueueBinVector * mallocNewWaitingQueueBinVector() {\r
WaitingQueueBinVector * retval = (WaitingQueueBinVector *) malloc(\r
sizeof(WaitingQueueBinVector));\r
retval->next = NULL;\r
#ifndef WAITINGQUEUE_H_\r
#define WAITINGQUEUE_H_\r
\r
-#define NOT_AT_FRONT = 3;\r
-#define TRAVERSER_FINISHED = 2;\r
#define NUMITEMS_WQ 20\r
\r
/* print header */\r
int size;\r
} WaitingQueueBin;\r
\r
-\r
-//TODO in the future, remove this struct all together\r
-//struct WaitingQueue {\r
-// struct BinElement_wq * array;\r
-//};\r
-\r
-void putWaitingQueue(int allocSiteID, WaitingQueueBin * queue, int effectType, void * resumePtr, int traverserID);\r
+void putIntoWaitingQueue(int allocSiteID, WaitingQueueBin * queue, int effectType, void * resumePtr, int traverserID);\r
int isEmptyForWaitingQ(WaitingQueueBin * queue, int allocSiteID);\r
WaitingQueueBin * mallocWaitingQueue(int size);\r
-WaitingQueueBinVector * returnVectorToFreePool(struct BinVector_wq *ptr);\r
-int removeFromQueue(WaitingQueueBin * queue, int allocSiteID, int TraverserID);\r
-//int resolveWaitingQueueChain(struct WaitingQueue * queue, int allocSiteID, int traverserID);\r
-WaitingQueueBinVector * mallocNewVector();\r
-WaitingQueueBinVector * getUsableVector();\r
+WaitingQueueBinVector * returnWaitingQueueBinVectorToFreePool(struct BinVector_wq *ptr);\r
+int removeFromWaitingQueue(WaitingQueueBin * queue, int allocSiteID, int TraverserID);\r
+WaitingQueueBinVector * mallocNewWaitingQueueBinVector();\r
+WaitingQueueBinVector * getUsableWaitingQueueBinVector();\r
\r
//TODO this only a debug method GET RID OF IT WHEN DONE!!\r
WaitingQueueBinVector * debug_GetTheFreeBinsPtr();\r
//P.S. make sure this is the FIRST and ONLY thing to run if you want to test this.
void testWaitingQueueFreeBinsSingleTest() {
- WaitingQueueBinVector * ptr = getUsableVector();
+ WaitingQueueBinVector * ptr = getUsableWaitingQueueBinVector();
if(ptr == NULL) {
printf("waitingQueueBinVector didn't work ><\n");
printf("either testWaitingQueueFreeBins wasn't called first or somehow it's not null....");
}
- if(returnVectorToFreePool(ptr) != NULL) {
+ if(returnWaitingQueueBinVectorToFreePool(ptr) != NULL) {
printf("Returning the .next in the waiting queue didn't quite work...");
}
}
//void putWaintingQueue(int allocSiteID, WaitingQueueBin * queue, int effectType, void * resumePtr, int traverserID);
- putWaitingQueue(100, waitingQueue, 1, 2, 3);
+ putIntoWaitingQueue(100, waitingQueue, 1, 2, 3);
if(isEmptyForWaitingQ(waitingQueue, 100)) {
printf("The one item added at location %u did not actually get put there according to isEmpty\n", 100);
}
//int removeFromQueue(WaitingQueueBin * wQueue, int allocSiteID, int TraverserID)
- if(removeFromQueue(waitingQueue, 100, 3) != 1) {
+ if(removeFromWaitingQueue(waitingQueue, 100, 3) != 1) {
printf("it appears that removing doens't remove the correct # of items\n");
}
//add 2 more
//void putWaintingQueue(int allocSiteID, WaitingQueueBin * queue, int effectType, void * resumePtr, int traverserID);
- putWaitingQueue(100, waitingQueue, 1, 2, 4);
- putWaitingQueue(100, waitingQueue, 1, 2, 4);
- putWaitingQueue(100, waitingQueue, 1, 2, 5);
+ putIntoWaitingQueue(100, waitingQueue, 1, 2, 4);
+ putIntoWaitingQueue(100, waitingQueue, 1, 2, 4);
+ putIntoWaitingQueue(100, waitingQueue, 1, 2, 5);
for(i = 0; i < 200; i++) {
if(i != 100) {
// //Return is how many things are removed. -1 would indicate error
// int removeFromQueue(WaitingQueueBin * wQueue, int allocSiteID, int TraverserID)
- if(removeFromQueue(waitingQueue, 101,0) != -1) {
+ if(removeFromWaitingQueue(waitingQueue, 101,0) != -1) {
printf("failsafe does not work in removeFromQueue\n");
}
- if(removeFromQueue(waitingQueue, 100, 29038) != 0 || removeFromQueue(waitingQueue, 100, 5) != 0) {
+ if(removeFromWaitingQueue(waitingQueue, 100, 29038) != 0 || removeFromWaitingQueue(waitingQueue, 100, 5) != 0) {
printf("removeFromQueue does not check element's traverserID before removing");
}
- if(removeFromQueue(waitingQueue, 100, 4) != 1 || waitingQueue[100].size != 1) {
+ if(removeFromWaitingQueue(waitingQueue, 100, 4) != 1 || waitingQueue[100].size != 1) {
printf("removeFromQueue didn't remove items and/or didn't decrement counter correctly 1\n");
}
- if(removeFromQueue(waitingQueue, 100, 4) != 0 || waitingQueue[100].size != 1) {
+ if(removeFromWaitingQueue(waitingQueue, 100, 4) != 0 || waitingQueue[100].size != 1) {
printf("removeFromQueue didn't remove items and/or didn't decrement counter correctly 2\n");
}
- if(removeFromQueue(waitingQueue, 99, 5) != -1 || waitingQueue[99].size != 0) {
+ if(removeFromWaitingQueue(waitingQueue, 99, 5) != -1 || waitingQueue[99].size != 0) {
printf("failsafe in remove does not work correctly\n");
}
- if(removeFromQueue(waitingQueue, 100, 5) != 1 || waitingQueue[100].size != 0 || !isEmptyForWaitingQ(waitingQueue, 100)) {
+ if(removeFromWaitingQueue(waitingQueue, 100, 5) != 1 || waitingQueue[100].size != 0 || !isEmptyForWaitingQ(waitingQueue, 100)) {
printf("removeFromQueue didn't remove items and/or didn't decrement counter correctly 3\n");
}
//next try adding 10,000 items
for(i = 0; i < 10000; i++) {
- putWaitingQueue(100, waitingQueue, 1, 2, i);
+ putIntoWaitingQueue(100, waitingQueue, 1, 2, i);
}
if(isEmptyForWaitingQ(waitingQueue, 100)) {
}
for(i = 0; i <10000; i++) {
- if(removeFromQueue(waitingQueue, 100, i) != 1) {
+ if(removeFromWaitingQueue(waitingQueue, 100, i) != 1) {
printf("remove from 10000 didn't properly just remove ONE item");
}
int i;
for(i = 0; i < size; i++) {
- ptrs[i] = getUsableVector();
+ ptrs[i] = getUsableWaitingQueueBinVector();
ptrs[i]->tailIndex = 293847; //this is to make sure we don't get a segmentation fault
if(ptrs[i]->next != NULL || ptrs[i]->tailIndex != 293847) {
}
for(i = 0; i < size; i++) {
- returnVectorToFreePool(ptrs[i]);
+ returnWaitingQueueBinVectorToFreePool(ptrs[i]);
if(debug_GetTheFreeBinsPtr() != ptrs[i]) {
printf("it appears that the returnVectorToFreePool didn't put the vector at the front at index %u\n", i);
}
}
for(i = size-1; i>= 0; i--) {
- if(getUsableVector() != ptrs[i]) {
+ if(getUsableWaitingQueueBinVector() != ptrs[i]) {
printf("getUsableVector does not get the correct one at index %u\n", i);
}
}
}
int main() {
- waitingQueuePutAndRemoveTestMulti();
+ testWaitingQueueFreeBinsMultipleTest(1000);
return 1;
}