Skip to content

Commit

Permalink
implement some more apis
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Mar 1, 2022
1 parent b877bed commit 4fb242e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
26 changes: 19 additions & 7 deletions include/re_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ typedef int thread_once_flag;
/**
* Creates a new thread
*
* @param thr Pointer to new thread
* @param func Function to execute
* @param arg Argument to pass to the function
* @param thr Pointer to new thread
* @param func Function to execute
* @param arg Argument to pass to the function
*
* @return 0 if success, otherwise errorcode
*/
Expand All @@ -44,7 +44,7 @@ int thread_create(thread *thr, thread_h func, void *arg);
int thread_equal(thread lhs, thread rhs);

/**
* @return the identifier of the calling thread.
* Return the identifier of the calling thread.
*/
thread thread_current(void);

Expand All @@ -59,14 +59,26 @@ int thread_detach(thread thr);
* Blocks the current thread until the thread identified by thr finishes
* execution
*
* @param thr Thread
* @param res Result code location
* @param thr Thread
* @param res Result code location
*
* @return 0 if success, otherwise errorcode
*/
int thread_join(thread thr, int *res);

int thread_once(thread_once_flag *flag, void (*func)(void));
/**
* Calls a function exactly once
*
* @param flag Pointer to object initialized by THREAD_ONCE_FLAG_INIT
* @param func The function to execute only once
*/
void thread_once(thread_once_flag *flag, void (*func)(void));

/**
* Terminates the calling thread
*
* @param res
*/
void thread_exit(int res);

int thread_cond_init(thread_cond *cond);
Expand Down
16 changes: 13 additions & 3 deletions src/thread/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ static void *thread_handler(void *p)

mem_deref(p);

th.func(th.arg);

return NULL;
return (void *)(intptr_t)th.func(th.arg);
}


Expand Down Expand Up @@ -81,3 +79,15 @@ int thread_join(thread thr, int *res)

return err;
}


void thread_once(thread_once_flag *flag, void (*func)(void))
{
pthread_once(flag, func);
}


void thread_exit(int res)
{
pthread_exit((void *)(intptr_t)res);
}

0 comments on commit 4fb242e

Please sign in to comment.