diff options
author | Alex Auvolat <alex.auvolat@ens.fr> | 2014-12-16 22:35:09 +0100 |
---|---|---|
committer | Alex Auvolat <alex.auvolat@ens.fr> | 2014-12-16 22:35:09 +0100 |
commit | 8c247352543c50204314efeb988f9f59d84f5019 (patch) | |
tree | ef7d8775c9c51eddbc1e14e57e0e654b350efe7c /kernel/include | |
parent | 0cafda1270f765e98c6ab5b298d28fd820b0e68c (diff) | |
download | macroscope-8c247352543c50204314efeb988f9f59d84f5019.tar.gz macroscope-8c247352543c50204314efeb988f9f59d84f5019.zip |
Add simple reference counted buffer structure.
Diffstat (limited to 'kernel/include')
-rw-r--r-- | kernel/include/buffer.h | 38 | ||||
-rw-r--r-- | kernel/include/thread.h | 3 |
2 files changed, 40 insertions, 1 deletions
diff --git a/kernel/include/buffer.h b/kernel/include/buffer.h new file mode 100644 index 0000000..577ceae --- /dev/null +++ b/kernel/include/buffer.h @@ -0,0 +1,38 @@ +#pragma once + +#include <stdint.h> +#include <stddef.h> + +// The buffer_t type is a simple reference-counted buffer type +// enabling the creation, sharing, slicing and concatenation of buffers +// without having to copy everything each time + +// Once a buffer is allocated, its contents is immutable + +// Encoding and decoding functions for buffer contents are provided in +// a separate file (encode.h) + +struct buffer; +typedef struct buffer buffer_t; + +void buffer_ref(buffer_t*); // increase reference counter +void buffer_unref(buffer_t*); // decrease reference counter + +size_t buffer_len(buffer_t* buf); +size_t read_buffer(buffer_t* buf, char* to, size_t begin, size_t n); // returns num of bytes read + +buffer_t* buffer_from_bytes(const char* data, size_t n); // bytes are COPIED +buffer_t* buffer_from_bytes_nocopy(const char* data, size_t n); // bytes are NOT COPIED + +// these functions GIVE the buffer in order to create the new buffer, ie they do not increase RC +// the buffer is NOT GIVED if the new buffer could not be created (ie retval == 0) +buffer_t* buffer_slice(buffer_t* b, size_t begin, size_t n); +buffer_t* buffer_concat(buffer_t* a, buffer_t* b); + +// these functions KEEP a reference on the buffer (ie RC is incremented) +// the RC is NOT INCREMENTED if the new buffer cannot be created +buffer_t* buffer_slice_k(buffer_t* b, size_t begin, size_t n); +buffer_t* buffer_concat_k(buffer_t* a, buffer_t* b); + + +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/kernel/include/thread.h b/kernel/include/thread.h index 4c5f337..757ba00 100644 --- a/kernel/include/thread.h +++ b/kernel/include/thread.h @@ -17,6 +17,7 @@ typedef struct saved_context { void (*eip)(); } saved_context_t; +struct process; typedef struct thread { saved_context_t ctx; pagedir_t *current_pd_d; @@ -25,7 +26,7 @@ typedef struct thread { region_info_t *stack_region; - void* more_data; + struct process *proc; // process : L1 data structure struct thread *next_in_queue; } thread_t; |