| 97 | } |
| 98 | |
| 99 | void |
| 100 | taskset_cycle( taskset_t *ts ) |
| 101 | { |
| 102 | int i; |
| 103 | if ( !ts->task_thread_started ) { |
| 104 | for ( i = 0; i < ts->thread_count; i++ ) { |
| 105 | taskset_thread_t *thread = taskset_thread( ts, i ); |
| 106 | thread->thread = hb_thread_init( ts->task_descr, taskset_thread_f, |
| 107 | taskset_thread_args( ts, i ), |
| 108 | HB_NORMAL_PRIORITY ); |
| 109 | } |
| 110 | ts->task_thread_started = 1; |
| 111 | } |
| 112 | |
| 113 | /* |
| 114 | * Signal all threads that their work is available. |
| 115 | */ |
| 116 | for (i = 0; i < ts->thread_count; i++) { |
| 117 | taskset_thread_t *thread = taskset_thread( ts, i ); |
| 118 | hb_lock( thread->lock ); |
| 119 | thread->begin = 1; |
| 120 | hb_cond_signal( thread->begin_cond ); |
| 121 | hb_unlock( thread->lock ); |
| 122 | } |
| 123 | |
| 124 | /* |
| 125 | * Wait until all threads have completed. Note that we must |
| 126 | * loop here as hb_cond_wait() on some platforms (e.g pthread_cond_wait) |
| 127 | * may unblock prematurely. |
| 128 | */ |
| 129 | for ( i = 0; i < ts->thread_count; i++ ) |
| 130 | { |
| 131 | taskset_thread_t *thread = taskset_thread( ts, i ); |
| 132 | hb_lock( thread->lock ); |
| 133 | while (!thread->complete) { |
| 134 | hb_cond_wait( thread->complete_cond, thread->lock); |
| 135 | } |
| 136 | thread->complete = 0; |
| 137 | hb_unlock( thread->lock ); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | /* |
| 142 | * Block current thread until work is available for it. |
no test coverage detected