- if ((type == SILC_TASK_GENERIC) && queue->task) {
- SilcTask task;
-
- task = queue->task;
- while(1) {
- if ((task->callback == cb) && (task->context == context)) {
- SILC_LOG_DEBUG(("Found matching generic task, using the match"));
-
- /* Add the fd to be listened, the task found now applies to this
- fd as well. */
- silc_schedule_set_listen_fd(queue->schedule,
- fd, (1L << SILC_TASK_READ));
- return task;
+ if (type == SILC_TASK_GENERIC) {
+ silc_mutex_lock(queue->lock);
+
+ if (queue->task) {
+ SilcTask task = queue->task;
+ while(1) {
+ if ((task->callback == cb) && (task->context == context)) {
+ SILC_LOG_DEBUG(("Found matching generic task, using the match"));
+
+ silc_mutex_unlock(queue->lock);
+
+ /* Add the fd to be listened, the task found now applies to this
+ fd as well. */
+ silc_schedule_set_listen_fd(queue->schedule,
+ fd, (1L << SILC_TASK_READ));
+ return task;
+ }
+
+ if (queue->task == task->next)
+ break;
+
+ task = task->next;