Skip to content

Commit

Permalink
restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
vityaman committed Nov 21, 2024
1 parent 789f1f3 commit 15af55e
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 17 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ CFLAGS += $(SANITIZERS)

LDFLAGS = $(CFLAGS)

SRCS := $(wildcard $(SRC_DIR)/*.c) $(wildcard $(SRC_DIR)/*.S)
SRCS := $(shell find source -iname '*.c') $(shell find source -iname '*.S')

OBJS := $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRCS))
OBJS := $(patsubst $(SRC_DIR)/%.S, $(OBJ_DIR)/%.o, $(OBJS))
Expand All @@ -37,9 +37,11 @@ $(BIN_DIR)/$(TARGET): $(BIN_DIR) $(OBJ_DIR) $(OBJS)
$(CC) $(OBJS) -o $@ $(LDFLAGS)

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
mkdir -p $(shell dirname $@)
$(CC) $(CFLAGS) -c $< -o $@

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.S
mkdir -p $(shell dirname $@)
$(CC) $(CFLAGS) -c $< -o $@

$(OBJ_DIR): $(BUILD_DIR)
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion source/log.c → source/coroed/api/log.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "log.h"

#include "spinlock.h"
#include "coroed/core/spinlock.h"

struct spinlock log_lock;

Expand Down
2 changes: 1 addition & 1 deletion source/log.h → source/coroed/api/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <stdio.h> // NOLINT

#include "spinlock.h"
#include "coroed/core/spinlock.h"

#define LOG_INFO(message, ...) \
do { \
Expand Down
27 changes: 27 additions & 0 deletions source/coroed/api/task.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "task.h"

#include "coroed/sched/schedy.h"

void tasks_init() {
sched_init();
}

void tasks_submit(task_body body, void* argument) {
sched_submit(body, argument);
}

void tasks_start() {
sched_start();
}

void tasks_wait() {
sched_wait();
}

void tasks_print_statistics() {
sched_print_statistics();
}

void tasks_destroy() {
sched_destroy();
}
11 changes: 10 additions & 1 deletion source/task.h → source/coroed/api/task.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "uthread.h"
#include "coroed/sched/uthread.h"

#define YIELD \
do { \
Expand All @@ -14,6 +14,15 @@

struct task;

typedef uthread_routine task_body;

void tasks_init();
void tasks_submit(task_body body, void* argument);
void tasks_start();
void tasks_wait();
void tasks_print_statistics();
void tasks_destroy();

void task_yield(struct task* task);
void task_exit(struct task* task);
void task_submit(struct task* parent, uthread_routine entry, void* argument);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions source/schedy.c → source/coroed/sched/schedy.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#include <time.h>
#include <unistd.h>

#include "coroed/api/task.h"
#include "coroed/core/spinlock.h"
#include "kthread.h"
#include "spinlock.h"
#include "task.h"
#include "uthread.h"

enum {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 10 additions & 11 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
#include <stdlib.h>
#include <string.h>

#include "clock.h"
#include "log.h"
#include "schedy.h"
#include "task.h"
#include "coroed/api/clock.h"
#include "coroed/api/log.h"
#include "coroed/api/task.h"

enum {
DELAY = 50,
Expand Down Expand Up @@ -65,7 +64,7 @@ TASK_DEFINE(spammer, void, ignored) {

void add(int64_t value) {
expected_count += value;
sched_submit(&adder, (void*)(value));
tasks_submit(&adder, (void*)(value));
}

int randint() {
Expand All @@ -74,11 +73,11 @@ int randint() {

int main() {
log_init();
sched_init();
tasks_init();

srand(231); // NOLINT

sched_submit(&spammer, NULL);
tasks_submit(&spammer, NULL);
add(randint());
add(randint());
add(randint());
Expand All @@ -88,15 +87,15 @@ int main() {
add(randint());
add(randint());

sched_start();
tasks_start();

sched_wait();
tasks_wait();

sched_print_statistics();
tasks_print_statistics();

assert(atomic_load(&actual_count) == expected_count);

sched_destroy();
tasks_destroy();

return 0;
}

0 comments on commit 15af55e

Please sign in to comment.