The NewOS Operating System
by Travis K. Geiselbrecht

Listing One
proc_id proc_create_proc(const char *path, const char *name, int priority);
int proc_kill_proc(proc_id id);
int proc_wait_on_proc(proc_id id, int *retcode);
thread_id thread_create_user_thread(char *name, proc_id pid, int priority, addr entry);
thread_id thread_create_kernel_thread(const char *name, int (*func)(void), int priority);
int thread_suspend_thread(thread_id id);
int thread_resume_thread(thread_id id);
void thread_snooze(time_t time);
void thread_exit(int retcode);
thread_id thread_get_current_thread_id();
int thread_wait_on_thread(thread_id id, int *retcode);

Listing Two
typedef int (*timer_callback)(void *);
typedef enum {
    TIMER_MODE_ONESHOT = 0,
    TIMER_MODE_PERIODIC
} timer_mode;
typedef struct timer_event {
    struct timer_event *next;
    timer_mode mode;
    time_t sched_time;
    time_t periodic_time;
    timer_callback func;
    void *data;
} timer_event;
// caller provides the timer structure
void timer_setup_timer(timer_callback func, void *data, timer_event *event);
int timer_set_event(time_t relative_time, timer_mode mode, timer_event *event);
int timer_cancel_event(timer_event *event);

Listing Three
#define SEM_FLAG_NO_RESCHED 1 // force sem_release_etc to not reschedule
#define SEM_FLAG_TIMEOUT 2
sem_id sem_create(int count, const char *name);
int sem_delete(sem_id id);
int sem_delete_etc(sem_id id, int return_code);
int sem_acquire(sem_id id, int count);
int sem_acquire_etc(sem_id id, int count, int flags, time_t timeout, int *deleted_retcode);
int sem_release(sem_id id, int count);
int sem_release_etc(sem_id id, int count, int flags);

Listing Four
// lock must be pre-initialized to 0
void acquire_spinlock(int *lock);
void release_spinlock(int *lock);

Listing Five
typedef enum {
    STREAM_TYPE_NULL = 0,
    STREAM_TYPE_FILE,
    STREAM_TYPE_DIR,
    STREAM_TYPE_DEVICE,
    STREAM_TYPE_STRING
} stream_type;
typedef enum {
    SEEK_SET = 0,
    SEEK_CUR,
    SEEK_END
} seek_type;
int open(const char *path, const char *stream, stream_type type);
int seek(int fd, off_t pos, seek_type seek_type);
int read(int fd, void *buf, off_t pos, size_t *len);
int write(int fd, const void *buf, off_t pos, size_t *len);
int ioctl(int fd, int op, void *buf, size_t len);
int close(int fd);
int create(const char *path, const char *stream, stream_type type);
// not complete, needs facility to unlink files among others





2

