Skip to content

Commit

Permalink
Added: pt: co-routine: added option to run thread from an set id.
Browse files Browse the repository at this point in the history
  • Loading branch information
zakarouf committed Nov 20, 2021
1 parent 668d722 commit aa41fde
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/proc/pt/coroutine.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,23 @@ z__u32 z__pt_coroutine_run_raw(z__u32 *id, z__pt_Thread_Attr *attr, void *(*fn)
z__pt(create, &z__Arr_getTop(_g_threads).thread, attr, fn, arg);
z__pt(mutex_unlock, &thread_counter_lock);

return *id;
}

void z__pt_coroutine_run_setid_raw(
z__u32 inp_id, z__u32 *id
, z__pt_Thread_Attr *attr, void *(*fn)(void *), void *arg
, const char *name, z__u32 name_size)
{
z__pt(mutex_lock, &thread_counter_lock);
*id = inp_id;
if(inp_id > z__Arr_getLen(_g_threads)){
z__Arr_resize(&_g_threads, inp_id);
}
_z__pt_coroutine_thread_enable(&z__Arr_getVal(_g_threads, inp_id), inp_id, name, name_size);
z__pt(create, &z__Arr_getTop(_g_threads).thread, attr, fn, arg);
z__pt(mutex_unlock, &thread_counter_lock);

return *id;
}

void z__pt_coroutine_join_raw(z__u32 id)
Expand Down
22 changes: 21 additions & 1 deletion src/proc/pt/coroutine.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,25 @@ void z__pt_coroutine_start(void);
*/
void z__pt_coroutine_end(void);

/**
*/
z__u32 z__pt_coroutine_run_raw(z__u32 *id, z__pt_Thread_Attr *attr, void *(*fn) (void *), void *arg, char const *name, z__u32 name_size);

/**
*/
void z__pt_coroutine_run_setid_raw(
z__u32 inp_id, z__u32 *id
, z__pt_Thread_Attr *attr, void *(*fn)(void *), void *arg
, const char *name, z__u32 name_size);

/**
*/
void z__pt_coroutine_join_raw(z__u32 id);


char *z__pt_coroutine_get_name_of_tid(z__u32 tid);


z__u32 z__pt_coroutine_tstatus_is_done(z__u32 id);
void z__pt_coroutine_set_tstatus_done(z__u32 id);
z__bool z__pt_coroutine_is_thread_active(z__u32 id);
Expand All @@ -31,7 +45,13 @@ z__bool z__pt_coroutine_is_thread_active(z__u32 id);
z__pt_coroutine_run_raw( \
&(arg)->unique.id \
, attr, fn, arg \
, #fn, sizeof(#fn));
, #fn, sizeof(#fn))

#define z__pt_coroutine_run_setid(id, fn, arg, attr)\
z__pt_coroutine_run_setid_raw( \
id, &(arg)->unique.id \
, attr, fn, arg \
, #fn, sizeof(#fn))

#define z__pt_coroutine_join(id)\
z__pt_coroutine_join_raw(id);
Expand Down

0 comments on commit aa41fde

Please sign in to comment.