diff options
author | Matt Strapp <strap012@umn.edu> | 2020-11-22 16:07:31 -0600 |
---|---|---|
committer | Matt Strapp <strap012@umn.edu> | 2020-11-22 16:07:31 -0600 |
commit | 173c9eed8c21994d9c7c9cf41acda6b8ec56ecc9 (patch) | |
tree | b93b0a6890bbcfcc2ee301cc345774c08a2bd841 /P3 | |
parent | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa (diff) | |
download | csci4061-173c9eed8c21994d9c7c9cf41acda6b8ec56ecc9.tar csci4061-173c9eed8c21994d9c7c9cf41acda6b8ec56ecc9.tar.gz csci4061-173c9eed8c21994d9c7c9cf41acda6b8ec56ecc9.tar.bz2 csci4061-173c9eed8c21994d9c7c9cf41acda6b8ec56ecc9.tar.lz csci4061-173c9eed8c21994d9c7c9cf41acda6b8ec56ecc9.tar.xz csci4061-173c9eed8c21994d9c7c9cf41acda6b8ec56ecc9.tar.zst csci4061-173c9eed8c21994d9c7c9cf41acda6b8ec56ecc9.zip |
change a thing or seven
Diffstat (limited to 'P3')
-rw-r--r-- | P3/.vscode/launch.json | 9 | ||||
-rw-r--r-- | P3/server.c | 28 |
2 files changed, 17 insertions, 20 deletions
diff --git a/P3/.vscode/launch.json b/P3/.vscode/launch.json index f529d06..6c97570 100644 --- a/P3/.vscode/launch.json +++ b/P3/.vscode/launch.json @@ -9,7 +9,7 @@ "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/web_server", - "args": ["9000", "testing", "100", "100", "1", "100", "100"], + "args": ["9000", "testing", "100", "100", "0", "100", "100"], "stopAtEntry": false, "cwd": "${workspaceFolder}", @@ -23,13 +23,6 @@ "ignoreFailures": true }, ], - // "customLaunchSetupCommands": [ - // { - // "description": "PLEASE WORK", - // "text": "set detach-on-fork off", - // "ignoreFailures": false - // } - //], "preLaunchTask": "Make", }, ] diff --git a/P3/server.c b/P3/server.c index 5164a91..f4fc06c 100644 --- a/P3/server.c +++ b/P3/server.c @@ -21,11 +21,12 @@ #define BUFF_SIZE 1024 // Global variables -int port, workers, dispatchers, dynFlag, qLen, cSiz, cacheLength, wIndex = 0; +int port, workers, dispatchers, dynFlag, maxQlen, maxCSiz, curQSiz, cacheLength, wIndex; int tempNodeCounter = 0, counter2 = 0; pthread_t *wID; char *path; pthread_mutex_t Qlock, logLock, cacheLock; +pthread_cond_t QisFull; clock_t start_t, end_t, total_t = 600; void *worker(void *arg); @@ -67,7 +68,7 @@ void *dynamic_pool_size_update(void *arg) if (total_t > 3000) { // Threads must be detachable - wID = (pthread_t *) realloc(wID, (++wIndex * sizeof(pthread_t))); + pthread_t * newwID = (pthread_t *) realloc(wID, (++wIndex * sizeof(pthread_t))); pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); @@ -77,13 +78,15 @@ void *dynamic_pool_size_update(void *arg) char threadName[16]; sprintf(threadName, "Worker %d", wIndex); pthread_setname_np(wID[wIndex - 1], threadName); + printf("Created a new thread\n"); } else if (total_t < 500) { //TODO: Make sure thread isn't doing anything before killing it pthread_cancel(wID[wIndex--]); // Need dynamically allocated array of thread ID's so we can cancel the necessary threads - wID = realloc(wID, wIndex * sizeof(pthread_t)); + pthread_t* newwID = realloc(wID, wIndex * sizeof(pthread_t)); + printf("Deleting a thread\n"); } } } @@ -139,7 +142,7 @@ void addIntoCache(char *mybuf, char *memory, int memory_size) bool fullCache = false; while (traverse->next != NULL) { - if (cacheLength >= cSiz) + if (cacheLength >= maxCSiz) { fullCache = true; break; @@ -213,7 +216,8 @@ void deleteCache() void initCache() { // Allocating memory and initializing the cache array - dynQ = (cache_entry_t *)malloc(sizeof(cache_entry_t)); + // dynQ = (cache_entry_t *)malloc(sizeof(cache_entry_t)); + wIndex = 0; cacheLength = 0; } @@ -299,9 +303,9 @@ void *dispatch(void *arg) pthread_mutex_lock(&Qlock); request_t *traverse = Q; - // Get request from the client - // Add the request into the queue - for (int i = 0; i < qLen - 1; i++) + + int i; + for (i = 0; i < maxQlen - 1; i++) { if (traverse == NULL || traverse->next == NULL) @@ -475,9 +479,9 @@ int main(int argc, char **argv) //Dynamic worker flag dynFlag = atoi(argv[5]); //Queue Length - qLen = atoi(argv[6]); + maxQlen = atoi(argv[6]); //Max cache size - cSiz = atoi(argv[7]); + maxCSiz = atoi(argv[7]); /* -- ERROR CHECKING -- */ if (port < 1025 || port > 65535) @@ -495,7 +499,7 @@ int main(int argc, char **argv) printf("Number of dispatchers is invalid. It must be greater than 1 or less than %d (inclusive).\n", MAX_THREADS); return -1; } - if (qLen > MAX_queue_len || qLen < 1) + if (maxQlen > MAX_queue_len || maxQlen < 1) { printf("Queue length is invalid It must be greater than 1 or less than %d (inclusive).\n", MAX_queue_len); return -1; @@ -569,7 +573,7 @@ int main(int argc, char **argv) printf("\nSIGINT caught, exiting now.\n"); // Print the number of pending requests in the request queue int pendReqs; - for (pendReqs = 0; pendReqs < qLen; pendReqs++) + for (pendReqs = 0; pendReqs < maxQlen; pendReqs++) { if (Q == NULL || Q->next == NULL) break; |