aboutsummaryrefslogtreecommitdiffstats
path: root/P3
diff options
context:
space:
mode:
authorMatt Strapp <strap012@umn.edu>2020-11-17 22:11:08 -0600
committerMatt Strapp <strap012@umn.edu>2020-11-17 22:11:08 -0600
commit1b3fe24365bc3a2d1200553918abb5db2c4bc134 (patch)
treef8a51e0cc60999d20d7cc32496644fab6552a0ec /P3
parentFinish prelim? (diff)
downloadcsci4061-1b3fe24365bc3a2d1200553918abb5db2c4bc134.tar
csci4061-1b3fe24365bc3a2d1200553918abb5db2c4bc134.tar.gz
csci4061-1b3fe24365bc3a2d1200553918abb5db2c4bc134.tar.bz2
csci4061-1b3fe24365bc3a2d1200553918abb5db2c4bc134.tar.lz
csci4061-1b3fe24365bc3a2d1200553918abb5db2c4bc134.tar.xz
csci4061-1b3fe24365bc3a2d1200553918abb5db2c4bc134.tar.zst
csci4061-1b3fe24365bc3a2d1200553918abb5db2c4bc134.zip
?
Diffstat (limited to 'P3')
-rw-r--r--P3/server.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/P3/server.c b/P3/server.c
index 65ccc15..a760903 100644
--- a/P3/server.c
+++ b/P3/server.c
@@ -40,9 +40,9 @@ typedef struct cache_entry {
int len;
char *request;
char *content;
+ struct cache_entry* next;
} cache_entry_t;
-
-
+cache_entry_t *dynQ = NULL; //The cache queue
/* ******************** Dynamic Pool Code [Extra Credit A] **********************/
// Extra Credit: This function implements the policy to change the worker thread pool dynamically
@@ -76,6 +76,12 @@ void deleteCache(){
// Function to initialize the cache
void initCache(){
+ dynQ = (cache_entry_t *)calloc(sizeof(cache_entry_t), cSiz);
+ if (dynQ == NULL)
+ {
+ printf("malloc cannot allocate the initial requested memory.\n");
+ exit(-2);
+ }
// Allocating memory and initializing the cache array
}
@@ -303,15 +309,8 @@ int main(int argc, char **argv) {
return -2;
}
// Initialize cache (extra credit B)
- cache_entry_t *dynQ;
- if (cSiz != 0) {
- //Should the queue start this large?
- dynQ = (cache_entry_t*) calloc(sizeof(cache_entry_t), cSiz);
- if (dynQ == NULL) {
- printf("malloc cannot allocate the initial requested memory.\n");
- exit(-2);
- }
- }
+ initCache();
+
//Make sure threads are all detached
pthread_attr_t attr;
pthread_attr_init(&attr);