Commit 43bd93b2 authored by Marek Vavrusa's avatar Marek Vavrusa

Updated DThreads dt_stop() to support all/single threads.

parent 20d115c5
......@@ -564,7 +564,7 @@ int dt_join (dt_unit_t *unit)
return 0;
}
int dt_stop (dthread_t *thread)
int dt_stop_id (dthread_t *thread)
{
// Signalize active thread to stop
lock_thread_rw(thread);
......@@ -585,6 +585,37 @@ int dt_stop (dthread_t *thread)
return 0;
}
int dt_stop (dt_unit_t *unit)
{
// Lock unit
lock_unit_rw(unit);
// Signalize all threads to stop
for (int i = 0; i < unit->size; ++i) {
// Lock thread
dthread_t *thread = unit->threads[i];
lock_thread_rw(thread);
if(thread->state > ThreadDead) {
thread->state = ThreadDead | ThreadCancelled;
dt_signalize(thread, SIGALRM);
}
unlock_thread_rw(thread);
}
// Unlock unit
unlock_unit_rw(unit);
// Broadcast notification
if(unit != 0) {
pthread_mutex_lock(&unit->_notify_mx);
pthread_cond_broadcast(&unit->_notify);
pthread_mutex_unlock(&unit->_notify_mx);
}
return 0;
}
int dt_setprio (dthread_t* thread, int prio)
{
// Clamp priority
......
......@@ -173,7 +173,17 @@ int dt_join (dt_unit_t *unit);
*
* \return On success: 0, else <0
*/
int dt_stop (dthread_t* thread);
int dt_stop_id (dthread_t* thread);
/*!
* \brief Stop all threads in unit.
*
* Active threads are interrupted at the nearest
* runnable cancellation point.
*
* \return On success: 0, else <0
*/
int dt_stop (dt_unit_t *unit);
/*!
* \brief Modify thread priority.
......
......@@ -215,11 +215,7 @@ static inline int dt_test_start(dt_unit_t *unit)
/*! \brief Stop unit. */
static inline int dt_test_stop(dt_unit_t *unit)
{
int ret = 0;
for (int i = 0; i < unit->size; ++i)
ret += dt_stop(unit->threads[i]);
return ret;
return dt_stop(unit);
}
/*! \brief Join unit. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment