t->initial_log = 0;
t->event_fd_released = 0;
t->allocmem = 0;
+
+ t->target_condition_happens = 0;
pthread_mutex_init(&t->target_mtx, NULL);
pthread_cond_init(&t->target_cv, NULL);
target_array_unlock();
}
+/* TODO move all condition work to separate file. */
+void target_thread_cond(struct target *target)
+{
+ pthread_mutex_lock(&target->target_mtx);
+ target->target_condition_happens = true;
+ pthread_cond_broadcast(&target->target_cv);
+ pthread_mutex_unlock(&target->target_mtx);
+}
+
static void wait_for_acknowledge_or_timeout(struct target *t, int timeout)
{
struct timespec timeToWait;
timeToWait.tv_nsec = now.tv_usec;
pthread_mutex_lock(&t->target_mtx);
- pthread_cond_timedwait(&t->target_cv, &t->target_mtx, &timeToWait);
+ if (!t->target_condition_happens)
+ pthread_cond_timedwait(&t->target_cv, &t->target_mtx, &timeToWait);
+
pthread_mutex_unlock(&t->target_mtx);
}
pthread_mutex_t target_mtx;
pthread_cond_t target_cv;
+ int target_condition_happens;
+
struct thread *thread;
};
void target_wait_all(void);
void target_stop_all(void);
uint64_t target_get_total_alloc(pid_t pid);
+void target_thread_cond(struct target *target);
#endif /* _TARGER_H_ */
if (msg->type == APP_MSG_STOP) {
LOGI("APP_MSG_STOP arrived\n");
- pthread_cond_broadcast(&target->target_cv);
+ target_thread_cond(target);
continue;
}
msg->data[msg->length] = '\0';
pass = 1;
}
+ target_thread_cond(target);
free(msg);
LOGI("thread finished %u:%u\n", target->pid, target->ppid);
return NULL;