forked from open-education-hub/operating-systems
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
arg/parallel-graph: Update skeleton implementation
Synchronize skeleton implementation with the official soluion. The official solution is a redesign of the thread pool, together with the use of a generic list implementation (inspired from the Linux kernel). Signed-off-by: Razvan Deaconescu <[email protected]>
- Loading branch information
Showing
8 changed files
with
270 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,34 @@ | ||
BUILD_DIR := build | ||
CC := gcc | ||
CFLAGS := -c -Wall -g | ||
LD := ld | ||
LDFLAGS := | ||
LDLIBS := -lpthread | ||
|
||
SERIAL_SRCS := serial.c os_graph.c | ||
PARALLEL_SRCS:= parallel.c os_graph.c os_list.c os_threadpool.c | ||
SERIAL_OBJS := $(patsubst $(SRC)/%.c,$(BUILD_DIR)/%.o,$(SERIAL_SRCS)) | ||
PARALLEL_OBJS := $(patsubst $(SRC)/%.c,$(BUILD_DIR)/%.o,$(PARALLEL_SRCS)) | ||
UTILS_PATH ?= ../utils | ||
CPPFLAGS := -I$(UTILS_PATH) | ||
CFLAGS := -Wall -Wextra | ||
# Remove the line below to disable debugging support. | ||
CFLAGS += -g -O0 | ||
PARALLEL_LDLIBS := -lpthread | ||
|
||
SERIAL_SRCS := serial.c os_graph.c $(UTILS_PATH)/log/log.c | ||
PARALLEL_SRCS:= parallel.c os_graph.c os_threadpool.c $(UTILS_PATH)/log/log.c | ||
SERIAL_OBJS := $(patsubst %.c,%.o,$(SERIAL_SRCS)) | ||
PARALLEL_OBJS := $(patsubst %.c,%.o,$(PARALLEL_SRCS)) | ||
|
||
.PHONY: all pack clean always | ||
|
||
all: serial parallel | ||
|
||
always: | ||
mkdir -p build | ||
|
||
serial: always $(SERIAL_OBJS) | ||
$(CC) $(LDFLAGS) -o serial $(SERIAL_OBJS) | ||
serial: $(SERIAL_OBJS) | ||
$(CC) -o $@ $^ | ||
|
||
parallel: always $(PARALLEL_OBJS) | ||
$(CC) $(LDFLAGS) -o parallel $(PARALLEL_OBJS) $(LDLIBS) | ||
parallel: $(PARALLEL_OBJS) | ||
$(CC) -o $@ $^ $(PARALLEL_LDLIBS) | ||
|
||
$(BUILD_DIR)/%.o: %.c | ||
$(CC) $(CFLAGS) -o $@ $< | ||
$(UTILS_PATH)/log/log.o: $(UTILS_PATH)/log/log.c $(UTILS_PATH)/log/log.h | ||
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< | ||
|
||
pack: clean | ||
-rm -f ../src.zip | ||
zip -r ../src.zip * | ||
|
||
clean: | ||
-rm -f ../src.zip | ||
-rm -rf build | ||
-rm -f $(SERIAL_OBJS) $(PARALLEL_OBJS) | ||
-rm -f serial parallel | ||
-rm -f *~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,64 @@ | ||
/* SPDX-License-Identifier: BSD-3-Clause */ | ||
|
||
/* | ||
* Heavily inspired for Linux kernel code: | ||
* https://github.com/torvalds/linux/blob/master/include/linux/list.h | ||
*/ | ||
|
||
#ifndef __OS_LIST_H__ | ||
#define __OS_LIST_H__ 1 | ||
|
||
#include <pthread.h> | ||
#include <stddef.h> | ||
|
||
typedef struct os_list_node_t { | ||
void *info; | ||
struct os_list_node_t *next; | ||
struct os_list_node_t *prev, *next; | ||
} os_list_node_t; | ||
|
||
typedef struct { | ||
struct os_list_node_t *first; | ||
struct os_list_node_t *last; | ||
pthread_mutex_t lock; | ||
} os_queue_t; | ||
static inline void list_init(os_list_node_t *head) | ||
{ | ||
head->prev = head; | ||
head->next = head; | ||
} | ||
|
||
static inline void list_add(os_list_node_t *head, os_list_node_t *node) | ||
{ | ||
node->next = head->next; | ||
node->prev = head; | ||
head->next->prev = node; | ||
head->next = node; | ||
} | ||
|
||
static inline void list_add_tail(os_list_node_t *head, os_list_node_t *node) | ||
{ | ||
node->prev = head->prev; | ||
node->next = head; | ||
head->prev->next = node; | ||
head->prev = node; | ||
} | ||
|
||
static inline void list_del(os_list_node_t *node) | ||
{ | ||
node->prev->next = node->next; | ||
node->next->prev = node->prev; | ||
node->next = node; | ||
node->prev = node; | ||
} | ||
|
||
static inline int list_empty(os_list_node_t *head) | ||
{ | ||
return (head->next == head); | ||
} | ||
|
||
#define list_entry(ptr, type, member) ({ \ | ||
void *tmp = (void *)(ptr); \ | ||
(type *) (tmp - offsetof(type, member)); \ | ||
}) | ||
|
||
#define list_for_each(pos, head) \ | ||
for (pos = (head)->next; pos != (head); pos = pos->next) | ||
|
||
os_queue_t *queue_create(void); | ||
void queue_add(os_queue_t *queue, void *info); | ||
os_list_node_t *queue_get(os_queue_t *queue); | ||
#define list_for_each_safe(pos, tmp, head) \ | ||
for (pos = (head)->next, tmp = pos->next; pos != (head); \ | ||
pos = tmp, tmp = pos->next) | ||
|
||
#endif |
Oops, something went wrong.