Skip to content
Snippets Groups Projects
Commit ea3779e7 authored by Aidan Chalk's avatar Aidan Chalk
Browse files

getting thread ID is now just a simple call that doesn't require the user to...

getting thread ID is now just a simple call that doesn't require the user to pass any values. Its slightly complex and relies on pthread_getspecific returning NULL when not called from a pthread - however this is what the pthread specification says so I think its fine
parent 3f951d23
No related branches found
No related tags found
1 merge request!8[WIP] Fortran bindings
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
void runner(int type, void* data) void runner(int type, void* data)
{ {
printf("%i\n", qsched_get_tid(&s)); printf("%i\n", qsched_get_tid());
} }
......
...@@ -25,10 +25,9 @@ Module quicksched ...@@ -25,10 +25,9 @@ Module quicksched
Interface Interface
Integer(Kind=C_INT) Function qsched_get_tid(s) BIND(C) Integer(Kind=C_INT) Function qsched_get_tid() BIND(C)
Use, Intrinsic :: ISO_C_BINDING Use, Intrinsic :: ISO_C_BINDING
Implicit None Implicit None
Type(C_PTR), VALUE :: s
End Function End Function
Type(C_PTR) Function f_qsched_create() BIND(C) Type(C_PTR) Function f_qsched_create() BIND(C)
......
...@@ -50,6 +50,9 @@ ...@@ -50,6 +50,9 @@
char *qsched_timer_names[ qsched_timer_count ] = char *qsched_timer_names[ qsched_timer_count ] =
{ "queue" , "qlock" , "lock" , "gettask" , "done" , "prepare" }; { "queue" , "qlock" , "lock" , "gettask" , "done" , "prepare" };
#if defined( HAVE_PTHREAD )
pthread_key_t qsched_pointer;
#endif
/** /**
* @brief Change the owner of a resource. * @brief Change the owner of a resource.
...@@ -412,6 +415,7 @@ void *qsched_pthread_run ( void *in ) { ...@@ -412,6 +415,7 @@ void *qsched_pthread_run ( void *in ) {
struct task *t; struct task *t;
#if defined ( HAVE_PTHREAD ) #if defined ( HAVE_PTHREAD )
pthread_setspecific(s->thread_id_key, &r->tid); pthread_setspecific(s->thread_id_key, &r->tid);
pthread_setspecific(qsched_pointer, r->s);
#endif #endif
/* Main loop. */ /* Main loop. */
while ( 1 ) { while ( 1 ) {
...@@ -529,8 +533,12 @@ void qsched_run ( struct qsched *s , int nr_threads , qsched_funtype fun ) { ...@@ -529,8 +533,12 @@ void qsched_run ( struct qsched *s , int nr_threads , qsched_funtype fun ) {
} }
int qsched_get_tid(struct qsched *s) { int qsched_get_tid() {
if( !HAVE_OPENMP || s->flags & (qsched_flag_yield | qsched_flag_pthread ) ) struct qsched *s = NULL;
#if defined( HAVE_PTHREAD )
s = (struct qsched *)pthread_getspecific(qsched_pointer);
#endif
if( s != NULL )
return *(int*)pthread_getspecific(s->thread_id_key); return *(int*)pthread_getspecific(s->thread_id_key);
else else
return omp_get_thread_num(); return omp_get_thread_num();
...@@ -1557,6 +1565,7 @@ void qsched_free ( struct qsched *s ) { ...@@ -1557,6 +1565,7 @@ void qsched_free ( struct qsched *s ) {
s->runners_count = 0; s->runners_count = 0;
} }
pthread_key_delete(s->thread_id_key); pthread_key_delete(s->thread_id_key);
pthread_key_delete(qsched_pointer);
#endif #endif
/* Clear the flags. */ /* Clear the flags. */
...@@ -1646,6 +1655,7 @@ void qsched_init ( struct qsched *s , int nr_queues , int flags ) { ...@@ -1646,6 +1655,7 @@ void qsched_init ( struct qsched *s , int nr_queues , int flags ) {
error( "Failed to lock barrier mutex." ); error( "Failed to lock barrier mutex." );
} }
pthread_key_create(&s->thread_id_key, NULL); pthread_key_create(&s->thread_id_key, NULL);
pthread_key_create(&qsched_pointer, NULL);
#endif #endif
/* Clear the timers. */ /* Clear the timers. */
......
...@@ -212,7 +212,7 @@ void qsched_reset ( struct qsched *s ); ...@@ -212,7 +212,7 @@ void qsched_reset ( struct qsched *s );
void qsched_addtask_dynamic ( struct qsched *s , int type , unsigned int flags , void *data , int data_size , int cost , qsched_res_t *locks , int nr_locks , qsched_res_t *uses , int nr_uses ); void qsched_addtask_dynamic ( struct qsched *s , int type , unsigned int flags , void *data , int data_size , int cost , qsched_res_t *locks , int nr_locks , qsched_res_t *uses , int nr_uses );
void qsched_ensure ( struct qsched *s , int nr_tasks , int nr_res , int nr_deps , int nr_locks , int nr_uses , int size_data ); void qsched_ensure ( struct qsched *s , int nr_tasks , int nr_res , int nr_deps , int nr_locks , int nr_uses , int size_data );
void qsched_res_own ( struct qsched *s , qsched_res_t res , int owner ); void qsched_res_own ( struct qsched *s , qsched_res_t res , int owner );
int qsched_get_tid(struct qsched *s); int qsched_get_tid();
struct qsched * f_qsched_create(); struct qsched * f_qsched_create();
void f_qsched_destroy( struct qsched *s); void f_qsched_destroy( struct qsched *s);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment