Skip to content

Commit

Permalink
Add p_uthread_current_id() to get thread's current ID
Browse files Browse the repository at this point in the history
  • Loading branch information
saprykin committed Apr 29, 2016
1 parent 52172e1 commit 4b338d6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/puthread-none.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,9 @@ p_uthread_set_priority (PUThread *thread,

return -1;
}

P_LIB_API P_HANDLE
p_uthread_current_id (void)
{
return (P_HANDLE) 0;
}
6 changes: 6 additions & 0 deletions src/puthread-posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,9 @@ p_uthread_set_priority (PUThread *thread,
thread->prio = prio;
return 0;
}

P_LIB_API P_HANDLE
p_uthread_current_id (void)
{
return (P_HANDLE) pthread_self ();
}
6 changes: 6 additions & 0 deletions src/puthread-solaris.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,9 @@ p_uthread_set_priority (PUThread *thread,

return 0;
}

P_LIB_API P_HANDLE
p_uthread_current_id (void)
{
return (P_HANDLE) thr_self ();
}
6 changes: 6 additions & 0 deletions src/puthread-win.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,9 @@ p_uthread_set_priority (PUThread *thread,

return 0;
}

P_LIB_API P_HANDLE
p_uthread_current_id (void)
{
return (P_HANDLE) GetCurrentThreadId ();
}
15 changes: 13 additions & 2 deletions src/puthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,23 @@ P_LIB_API pint p_uthread_set_priority (PUThread *thread,

/**
* @brief Tells scheduler to skip the current (caller) thread in the current
* planning stage. In other words, scheduler shouldn't give time ticks for the
* current thread during the current period.
* planning stage.
* @since 0.0.1
*
* Scheduler shouldn't give time ticks for the current thread during the current
* period, but it may ignore this call.
*/
P_LIB_API void p_uthread_yield (void);

/**
* @brief Gets an ID of the current (caller) thread.
* @since 0.0.1
*
* This is a platform-dependent type. You shouldn't treat it as a number, it
* only gives you a uniquer ID of the thread accross the system.
*/
P_LIB_API P_HANDLE p_uthread_current_id (void);

P_END_DECLS

#endif /* __PUTHREAD_H__ */

0 comments on commit 4b338d6

Please sign in to comment.