Skip to content

Commit

Permalink
More MSVC++ fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
slembcke committed Oct 4, 2023
1 parent c6d565a commit 0e57681
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
4 changes: 3 additions & 1 deletion extras/CMakeLists.txt
Expand Up @@ -2,13 +2,15 @@ cmake_minimum_required(VERSION 3.8)

project(tina-extras)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 20)

include_directories(. ..)

set(COMMON common/common.c common/libs/tinycthread.c )
set(COMMON common/common.c common/libs/tinycthread.c)

add_executable(test-jobs-throughput test/jobs-throughput.c ${COMMON})
add_executable(test-jobs-wait test/jobs-wait.c ${COMMON})
add_executable(cpp-test test/cpp-test.cc common/libs/tinycthread.c)

add_executable(examples-coro-simple examples/coro-simple.c ${COMMON})
add_executable(examples-coro-symmetric examples/coro-symmetric.c ${COMMON})
7 changes: 4 additions & 3 deletions tina.h
Expand Up @@ -144,20 +144,21 @@ tina* tina_init(void* buffer, size_t size, tina_func* body, void* user_data){
*(uint32_t*)stack_end = TINA_EMPTY._canary;

tina* coro = (tina*)aligned;
(*coro) = (tina){
tina coro_value = {
.body = body, .user_data = user_data, .name = "<no name>",
.buffer = buffer, .size = size, .completed = false,
._caller = NULL, ._stack_pointer = NULL,
._canary_end = (uint32_t*)stack_end,
._canary = TINA_EMPTY._canary,
};
(*coro) = coro_value;

// Empty coroutine for the init function to use for a return location.
tina dummy = TINA_EMPTY;
coro->_caller = &dummy;

typedef tina* init_func(tina* coro, tina_func* body, void** sp_loc, void* sp);
return ((init_func*)_tina_init_stack)(coro, body, &dummy._stack_pointer, stack_end);
return ((init_func*)(void*)_tina_init_stack)(coro, body, &dummy._stack_pointer, stack_end);
}

void _tina_context(tina* coro); // Can this be static and still referenced by the inline asm?!
Expand All @@ -182,7 +183,7 @@ void* tina_swap(tina* from, tina* to, void* value){
_TINA_ASSERT(from->_canary == TINA_EMPTY._canary, "Tina Error: Bad canary value. Coroutine has likely had a stack overflow.");
_TINA_ASSERT(*from->_canary_end == TINA_EMPTY._canary, "Tina Error: Bad canary value. Coroutine has likely had a stack underflow.");
typedef void* swap(void** sp_from, void** sp_to, void* value);
return ((swap*)_tina_swap)(&from->_stack_pointer, &to->_stack_pointer, value);
return ((swap*)(void*)_tina_swap)(&from->_stack_pointer, &to->_stack_pointer, value);
}

void* tina_resume(tina* coro, void* value){
Expand Down
12 changes: 8 additions & 4 deletions tina_jobs.h
Expand Up @@ -241,9 +241,11 @@ static tina_scheduler* _tina_scheduler_init2(void* buffer, unsigned job_count, u
cursor += _tina_jobs_align(sizeof(tina_scheduler));
sched->_queues = (_tina_queue*)cursor;
cursor += _tina_jobs_align(queue_count*sizeof(_tina_queue));
sched->_fibers = (_tina_stack){.arr = (void**)cursor, .count = 0};
_tina_stack fibers = {.arr = (void**)cursor, .count = 0};
sched->_fibers = fibers;
cursor += _tina_jobs_align(fiber_count*sizeof(void*));
sched->_job_pool = (_tina_stack){.arr = (void**)cursor, .count = 0};
_tina_stack job_pool = {.arr = (void**)cursor, .count = 0};
sched->_job_pool = job_pool;
cursor += _tina_jobs_align(job_count*sizeof(void*));

// Initialize the queues arrays.
Expand Down Expand Up @@ -453,7 +455,8 @@ unsigned tina_scheduler_enqueue_batch(tina_scheduler* sched, const tina_job_desc

// Pop a job from the pool.
tina_job* job = (tina_job*)sched->_job_pool.arr[--sched->_job_pool.count];
(*job) = (tina_job){.desc = list[i], .user_data = NULL, .fiber = NULL, .group = group, .wait_next = NULL, .wait_threshold = 0};
tina_job job_value = {.desc = list[i], .user_data = NULL, .fiber = NULL, .group = group, .wait_next = NULL, .wait_threshold = 0};
(*job) = job_value;

// Push it to the proper queue.
_tina_queue* queue = _tina_get_queue(sched, list[i].queue_idx);
Expand All @@ -471,7 +474,8 @@ void tina_scheduler_enqueue_n(tina_scheduler* sched, tina_job_func* func, void*

for(unsigned i = 0; i < count; i++){
// Push description
desc[cursor++] = (tina_job_description){.name = NULL, .func = func, .user_data = user_data, .user_idx = i, .queue_idx = queue_idx};
tina_job_description description = {.name = NULL, .func = func, .user_data = user_data, .user_idx = i, .queue_idx = queue_idx};
desc[cursor++] = description;

// Check if the buffer is full.
if(cursor == 256){
Expand Down

0 comments on commit 0e57681

Please sign in to comment.