diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-10-10 13:06:10 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-10-10 13:06:10 +0000 |
commit | 48d42fc2f77879dc1541d8ad3c6cfcba644dbb1b (patch) | |
tree | 4886a7c4c025e54b5a4734958f3c08c10c8b7487 /src/util | |
parent | 1f004891c6d37c7c99896a6e59fc80880c78079f (diff) | |
download | gnunet-48d42fc2f77879dc1541d8ad3c6cfcba644dbb1b.tar.gz gnunet-48d42fc2f77879dc1541d8ad3c6cfcba644dbb1b.zip |
use log from
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/scheduler.c | 857 |
1 files changed, 440 insertions, 417 deletions
diff --git a/src/util/scheduler.c b/src/util/scheduler.c index dad924c32..b7860650e 100644 --- a/src/util/scheduler.c +++ b/src/util/scheduler.c | |||
@@ -265,7 +265,7 @@ static void *scheduler_select_cls; | |||
265 | */ | 265 | */ |
266 | void | 266 | void |
267 | GNUNET_SCHEDULER_set_select (GNUNET_SCHEDULER_select new_select, | 267 | GNUNET_SCHEDULER_set_select (GNUNET_SCHEDULER_select new_select, |
268 | void *new_select_cls) | 268 | void *new_select_cls) |
269 | { | 269 | { |
270 | scheduler_select = new_select; | 270 | scheduler_select = new_select; |
271 | scheduler_select_cls = new_select_cls; | 271 | scheduler_select_cls = new_select_cls; |
@@ -284,7 +284,7 @@ check_priority (enum GNUNET_SCHEDULER_Priority p) | |||
284 | if ((p >= 0) && (p < GNUNET_SCHEDULER_PRIORITY_COUNT)) | 284 | if ((p >= 0) && (p < GNUNET_SCHEDULER_PRIORITY_COUNT)) |
285 | return p; | 285 | return p; |
286 | GNUNET_assert (0); | 286 | GNUNET_assert (0); |
287 | return 0; /* make compiler happy */ | 287 | return 0; /* make compiler happy */ |
288 | } | 288 | } |
289 | 289 | ||
290 | 290 | ||
@@ -306,37 +306,37 @@ is_pending (GNUNET_SCHEDULER_TaskIdentifier id) | |||
306 | 306 | ||
307 | if (id < lowest_pending_id) | 307 | if (id < lowest_pending_id) |
308 | return GNUNET_NO; | 308 | return GNUNET_NO; |
309 | min = -1; /* maximum value */ | 309 | min = -1; /* maximum value */ |
310 | pos = pending; | 310 | pos = pending; |
311 | while (pos != NULL) | 311 | while (pos != NULL) |
312 | { | 312 | { |
313 | if (pos->id == id) | 313 | if (pos->id == id) |
314 | return GNUNET_YES; | 314 | return GNUNET_YES; |
315 | if (pos->id < min) | 315 | if (pos->id < min) |
316 | min = pos->id; | 316 | min = pos->id; |
317 | pos = pos->next; | 317 | pos = pos->next; |
318 | } | 318 | } |
319 | pos = pending_timeout; | 319 | pos = pending_timeout; |
320 | while (pos != NULL) | 320 | while (pos != NULL) |
321 | { | ||
322 | if (pos->id == id) | ||
323 | return GNUNET_YES; | ||
324 | if (pos->id < min) | ||
325 | min = pos->id; | ||
326 | pos = pos->next; | ||
327 | } | ||
328 | for (p = 0; p < GNUNET_SCHEDULER_PRIORITY_COUNT; p++) | ||
329 | { | ||
330 | pos = ready[p]; | ||
331 | while (pos != NULL) | ||
332 | { | 321 | { |
333 | if (pos->id == id) | 322 | if (pos->id == id) |
334 | return GNUNET_YES; | 323 | return GNUNET_YES; |
335 | if (pos->id < min) | 324 | if (pos->id < min) |
336 | min = pos->id; | 325 | min = pos->id; |
337 | pos = pos->next; | 326 | pos = pos->next; |
338 | } | 327 | } |
339 | } | 328 | for (p = 0; p < GNUNET_SCHEDULER_PRIORITY_COUNT; p++) |
329 | { | ||
330 | pos = ready[p]; | ||
331 | while (pos != NULL) | ||
332 | { | ||
333 | if (pos->id == id) | ||
334 | return GNUNET_YES; | ||
335 | if (pos->id < min) | ||
336 | min = pos->id; | ||
337 | pos = pos->next; | ||
338 | } | ||
339 | } | ||
340 | lowest_pending_id = min; | 340 | lowest_pending_id = min; |
341 | return GNUNET_NO; | 341 | return GNUNET_NO; |
342 | } | 342 | } |
@@ -351,7 +351,7 @@ is_pending (GNUNET_SCHEDULER_TaskIdentifier id) | |||
351 | */ | 351 | */ |
352 | static void | 352 | static void |
353 | update_sets (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws, | 353 | update_sets (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws, |
354 | struct GNUNET_TIME_Relative *timeout) | 354 | struct GNUNET_TIME_Relative *timeout) |
355 | { | 355 | { |
356 | struct Task *pos; | 356 | struct Task *pos; |
357 | struct GNUNET_TIME_Absolute now; | 357 | struct GNUNET_TIME_Absolute now; |
@@ -360,40 +360,40 @@ update_sets (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws, | |||
360 | now = GNUNET_TIME_absolute_get (); | 360 | now = GNUNET_TIME_absolute_get (); |
361 | pos = pending_timeout; | 361 | pos = pending_timeout; |
362 | if (pos != NULL) | 362 | if (pos != NULL) |
363 | { | 363 | { |
364 | to = GNUNET_TIME_absolute_get_difference (now, pos->timeout); | 364 | to = GNUNET_TIME_absolute_get_difference (now, pos->timeout); |
365 | if (timeout->rel_value > to.rel_value) | 365 | if (timeout->rel_value > to.rel_value) |
366 | *timeout = to; | 366 | *timeout = to; |
367 | if (pos->reason != 0) | 367 | if (pos->reason != 0) |
368 | *timeout = GNUNET_TIME_UNIT_ZERO; | 368 | *timeout = GNUNET_TIME_UNIT_ZERO; |
369 | } | 369 | } |
370 | pos = pending; | 370 | pos = pending; |
371 | while (pos != NULL) | 371 | while (pos != NULL) |
372 | { | ||
373 | if ((pos->prereq_id != GNUNET_SCHEDULER_NO_TASK) && | ||
374 | (GNUNET_YES == is_pending (pos->prereq_id))) | ||
375 | { | 372 | { |
373 | if ((pos->prereq_id != GNUNET_SCHEDULER_NO_TASK) && | ||
374 | (GNUNET_YES == is_pending (pos->prereq_id))) | ||
375 | { | ||
376 | pos = pos->next; | ||
377 | continue; | ||
378 | } | ||
379 | if (pos->timeout.abs_value != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value) | ||
380 | { | ||
381 | to = GNUNET_TIME_absolute_get_difference (now, pos->timeout); | ||
382 | if (timeout->rel_value > to.rel_value) | ||
383 | *timeout = to; | ||
384 | } | ||
385 | if (pos->read_fd != -1) | ||
386 | GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd); | ||
387 | if (pos->write_fd != -1) | ||
388 | GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd); | ||
389 | if (pos->read_set != NULL) | ||
390 | GNUNET_NETWORK_fdset_add (rs, pos->read_set); | ||
391 | if (pos->write_set != NULL) | ||
392 | GNUNET_NETWORK_fdset_add (ws, pos->write_set); | ||
393 | if (pos->reason != 0) | ||
394 | *timeout = GNUNET_TIME_UNIT_ZERO; | ||
376 | pos = pos->next; | 395 | pos = pos->next; |
377 | continue; | ||
378 | } | 396 | } |
379 | if (pos->timeout.abs_value != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value) | ||
380 | { | ||
381 | to = GNUNET_TIME_absolute_get_difference (now, pos->timeout); | ||
382 | if (timeout->rel_value > to.rel_value) | ||
383 | *timeout = to; | ||
384 | } | ||
385 | if (pos->read_fd != -1) | ||
386 | GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd); | ||
387 | if (pos->write_fd != -1) | ||
388 | GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd); | ||
389 | if (pos->read_set != NULL) | ||
390 | GNUNET_NETWORK_fdset_add (rs, pos->read_set); | ||
391 | if (pos->write_set != NULL) | ||
392 | GNUNET_NETWORK_fdset_add (ws, pos->write_set); | ||
393 | if (pos->reason != 0) | ||
394 | *timeout = GNUNET_TIME_UNIT_ZERO; | ||
395 | pos = pos->next; | ||
396 | } | ||
397 | } | 397 | } |
398 | 398 | ||
399 | 399 | ||
@@ -408,17 +408,17 @@ update_sets (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws, | |||
408 | */ | 408 | */ |
409 | static int | 409 | static int |
410 | set_overlaps (const struct GNUNET_NETWORK_FDSet *ready, | 410 | set_overlaps (const struct GNUNET_NETWORK_FDSet *ready, |
411 | struct GNUNET_NETWORK_FDSet *want) | 411 | struct GNUNET_NETWORK_FDSet *want) |
412 | { | 412 | { |
413 | if ((NULL == want) || (NULL == ready)) | 413 | if ((NULL == want) || (NULL == ready)) |
414 | return GNUNET_NO; | 414 | return GNUNET_NO; |
415 | if (GNUNET_NETWORK_fdset_overlap (ready, want)) | 415 | if (GNUNET_NETWORK_fdset_overlap (ready, want)) |
416 | { | 416 | { |
417 | /* copy all over (yes, there maybe unrelated bits, | 417 | /* copy all over (yes, there maybe unrelated bits, |
418 | * but this should not hurt well-written clients) */ | 418 | * but this should not hurt well-written clients) */ |
419 | GNUNET_NETWORK_fdset_copy (want, ready); | 419 | GNUNET_NETWORK_fdset_copy (want, ready); |
420 | return GNUNET_YES; | 420 | return GNUNET_YES; |
421 | } | 421 | } |
422 | return GNUNET_NO; | 422 | return GNUNET_NO; |
423 | } | 423 | } |
424 | 424 | ||
@@ -435,8 +435,8 @@ set_overlaps (const struct GNUNET_NETWORK_FDSet *ready, | |||
435 | */ | 435 | */ |
436 | static int | 436 | static int |
437 | is_ready (struct Task *task, struct GNUNET_TIME_Absolute now, | 437 | is_ready (struct Task *task, struct GNUNET_TIME_Absolute now, |
438 | const struct GNUNET_NETWORK_FDSet *rs, | 438 | const struct GNUNET_NETWORK_FDSet *rs, |
439 | const struct GNUNET_NETWORK_FDSet *ws) | 439 | const struct GNUNET_NETWORK_FDSet *ws) |
440 | { | 440 | { |
441 | enum GNUNET_SCHEDULER_Reason reason; | 441 | enum GNUNET_SCHEDULER_Reason reason; |
442 | 442 | ||
@@ -445,25 +445,25 @@ is_ready (struct Task *task, struct GNUNET_TIME_Absolute now, | |||
445 | reason |= GNUNET_SCHEDULER_REASON_TIMEOUT; | 445 | reason |= GNUNET_SCHEDULER_REASON_TIMEOUT; |
446 | if ((0 == (reason & GNUNET_SCHEDULER_REASON_READ_READY)) && | 446 | if ((0 == (reason & GNUNET_SCHEDULER_REASON_READ_READY)) && |
447 | (((task->read_fd != -1) && | 447 | (((task->read_fd != -1) && |
448 | (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (rs, task->read_fd))) || | 448 | (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (rs, task->read_fd))) |
449 | (set_overlaps (rs, task->read_set)))) | 449 | || (set_overlaps (rs, task->read_set)))) |
450 | reason |= GNUNET_SCHEDULER_REASON_READ_READY; | 450 | reason |= GNUNET_SCHEDULER_REASON_READ_READY; |
451 | if ((0 == (reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) && | 451 | if ((0 == (reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) && |
452 | (((task->write_fd != -1) && | 452 | (((task->write_fd != -1) && |
453 | (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (ws, task->write_fd))) | 453 | (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (ws, task->write_fd))) |
454 | || (set_overlaps (ws, task->write_set)))) | 454 | || (set_overlaps (ws, task->write_set)))) |
455 | reason |= GNUNET_SCHEDULER_REASON_WRITE_READY; | 455 | reason |= GNUNET_SCHEDULER_REASON_WRITE_READY; |
456 | if (reason == 0) | 456 | if (reason == 0) |
457 | return GNUNET_NO; /* not ready */ | 457 | return GNUNET_NO; /* not ready */ |
458 | if (task->prereq_id != GNUNET_SCHEDULER_NO_TASK) | 458 | if (task->prereq_id != GNUNET_SCHEDULER_NO_TASK) |
459 | { | ||
460 | if (GNUNET_YES == is_pending (task->prereq_id)) | ||
461 | { | 459 | { |
462 | task->reason = reason; | 460 | if (GNUNET_YES == is_pending (task->prereq_id)) |
463 | return GNUNET_NO; /* prereq waiting */ | 461 | { |
462 | task->reason = reason; | ||
463 | return GNUNET_NO; /* prereq waiting */ | ||
464 | } | ||
465 | reason |= GNUNET_SCHEDULER_REASON_PREREQ_DONE; | ||
464 | } | 466 | } |
465 | reason |= GNUNET_SCHEDULER_REASON_PREREQ_DONE; | ||
466 | } | ||
467 | task->reason = reason; | 467 | task->reason = reason; |
468 | return GNUNET_YES; | 468 | return GNUNET_YES; |
469 | } | 469 | } |
@@ -496,7 +496,7 @@ queue_ready_task (struct Task *task) | |||
496 | */ | 496 | */ |
497 | static void | 497 | static void |
498 | check_ready (const struct GNUNET_NETWORK_FDSet *rs, | 498 | check_ready (const struct GNUNET_NETWORK_FDSet *rs, |
499 | const struct GNUNET_NETWORK_FDSet *ws) | 499 | const struct GNUNET_NETWORK_FDSet *ws) |
500 | { | 500 | { |
501 | struct Task *pos; | 501 | struct Task *pos; |
502 | struct Task *prev; | 502 | struct Task *prev; |
@@ -507,40 +507,41 @@ check_ready (const struct GNUNET_NETWORK_FDSet *rs, | |||
507 | prev = NULL; | 507 | prev = NULL; |
508 | pos = pending_timeout; | 508 | pos = pending_timeout; |
509 | while (pos != NULL) | 509 | while (pos != NULL) |
510 | { | 510 | { |
511 | next = pos->next; | 511 | next = pos->next; |
512 | if (now.abs_value >= pos->timeout.abs_value) | 512 | if (now.abs_value >= pos->timeout.abs_value) |
513 | pos->reason |= GNUNET_SCHEDULER_REASON_TIMEOUT; | 513 | pos->reason |= GNUNET_SCHEDULER_REASON_TIMEOUT; |
514 | if (0 == pos->reason) | 514 | if (0 == pos->reason) |
515 | break; | 515 | break; |
516 | pending_timeout = next; | 516 | pending_timeout = next; |
517 | if (pending_timeout_last == pos) | 517 | if (pending_timeout_last == pos) |
518 | pending_timeout_last = NULL; | 518 | pending_timeout_last = NULL; |
519 | queue_ready_task (pos); | 519 | queue_ready_task (pos); |
520 | pos = next; | 520 | pos = next; |
521 | } | 521 | } |
522 | pos = pending; | 522 | pos = pending; |
523 | while (pos != NULL) | 523 | while (pos != NULL) |
524 | { | 524 | { |
525 | #if DEBUG_TASKS | 525 | #if DEBUG_TASKS |
526 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 526 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
527 | "Checking readiness of task: %llu / %p\n", pos->id, | 527 | "util", |
528 | pos->callback_cls); | 528 | "Checking readiness of task: %llu / %p\n", pos->id, |
529 | pos->callback_cls); | ||
529 | #endif | 530 | #endif |
530 | next = pos->next; | 531 | next = pos->next; |
531 | if (GNUNET_YES == is_ready (pos, now, rs, ws)) | 532 | if (GNUNET_YES == is_ready (pos, now, rs, ws)) |
532 | { | 533 | { |
533 | if (prev == NULL) | 534 | if (prev == NULL) |
534 | pending = next; | 535 | pending = next; |
535 | else | 536 | else |
536 | prev->next = next; | 537 | prev->next = next; |
537 | queue_ready_task (pos); | 538 | queue_ready_task (pos); |
539 | pos = next; | ||
540 | continue; | ||
541 | } | ||
542 | prev = pos; | ||
538 | pos = next; | 543 | pos = next; |
539 | continue; | ||
540 | } | 544 | } |
541 | prev = pos; | ||
542 | pos = next; | ||
543 | } | ||
544 | } | 545 | } |
545 | 546 | ||
546 | 547 | ||
@@ -559,26 +560,15 @@ GNUNET_SCHEDULER_shutdown () | |||
559 | 560 | ||
560 | pos = pending_timeout; | 561 | pos = pending_timeout; |
561 | while (pos != NULL) | 562 | while (pos != NULL) |
562 | { | 563 | { |
563 | pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; | 564 | pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; |
564 | /* we don't move the task into the ready queue yet; check_ready | 565 | /* we don't move the task into the ready queue yet; check_ready |
565 | * will do that later, possibly adding additional | 566 | * will do that later, possibly adding additional |
566 | * readiness-factors */ | 567 | * readiness-factors */ |
567 | pos = pos->next; | 568 | pos = pos->next; |
568 | } | 569 | } |
569 | pos = pending; | 570 | pos = pending; |
570 | while (pos != NULL) | 571 | while (pos != NULL) |
571 | { | ||
572 | pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; | ||
573 | /* we don't move the task into the ready queue yet; check_ready | ||
574 | * will do that later, possibly adding additional | ||
575 | * readiness-factors */ | ||
576 | pos = pos->next; | ||
577 | } | ||
578 | for (i = 0; i < GNUNET_SCHEDULER_PRIORITY_COUNT; i++) | ||
579 | { | ||
580 | pos = ready[i]; | ||
581 | while (pos != NULL) | ||
582 | { | 572 | { |
583 | pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; | 573 | pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; |
584 | /* we don't move the task into the ready queue yet; check_ready | 574 | /* we don't move the task into the ready queue yet; check_ready |
@@ -586,7 +576,18 @@ GNUNET_SCHEDULER_shutdown () | |||
586 | * readiness-factors */ | 576 | * readiness-factors */ |
587 | pos = pos->next; | 577 | pos = pos->next; |
588 | } | 578 | } |
589 | } | 579 | for (i = 0; i < GNUNET_SCHEDULER_PRIORITY_COUNT; i++) |
580 | { | ||
581 | pos = ready[i]; | ||
582 | while (pos != NULL) | ||
583 | { | ||
584 | pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; | ||
585 | /* we don't move the task into the ready queue yet; check_ready | ||
586 | * will do that later, possibly adding additional | ||
587 | * readiness-factors */ | ||
588 | pos = pos->next; | ||
589 | } | ||
590 | } | ||
590 | } | 591 | } |
591 | 592 | ||
592 | 593 | ||
@@ -628,69 +629,74 @@ run_ready (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws) | |||
628 | 629 | ||
629 | max_priority_added = GNUNET_SCHEDULER_PRIORITY_KEEP; | 630 | max_priority_added = GNUNET_SCHEDULER_PRIORITY_KEEP; |
630 | do | 631 | do |
631 | { | ||
632 | if (ready_count == 0) | ||
633 | return; | ||
634 | GNUNET_assert (ready[GNUNET_SCHEDULER_PRIORITY_KEEP] == NULL); | ||
635 | /* yes, p>0 is correct, 0 is "KEEP" which should | ||
636 | * always be an empty queue (see assertion)! */ | ||
637 | for (p = GNUNET_SCHEDULER_PRIORITY_COUNT - 1; p > 0; p--) | ||
638 | { | 632 | { |
639 | pos = ready[p]; | 633 | if (ready_count == 0) |
640 | if (pos != NULL) | 634 | return; |
641 | break; | 635 | GNUNET_assert (ready[GNUNET_SCHEDULER_PRIORITY_KEEP] == NULL); |
642 | } | 636 | /* yes, p>0 is correct, 0 is "KEEP" which should |
643 | GNUNET_assert (pos != NULL); /* ready_count wrong? */ | 637 | * always be an empty queue (see assertion)! */ |
644 | ready[p] = pos->next; | 638 | for (p = GNUNET_SCHEDULER_PRIORITY_COUNT - 1; p > 0; p--) |
645 | ready_count--; | 639 | { |
646 | if (current_priority != pos->priority) | 640 | pos = ready[p]; |
647 | { | 641 | if (pos != NULL) |
648 | current_priority = pos->priority; | 642 | break; |
649 | (void) GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), | 643 | } |
650 | pos->priority); | 644 | GNUNET_assert (pos != NULL); /* ready_count wrong? */ |
651 | } | 645 | ready[p] = pos->next; |
652 | current_lifeness = pos->lifeness; | 646 | ready_count--; |
653 | active_task = pos; | 647 | if (current_priority != pos->priority) |
648 | { | ||
649 | current_priority = pos->priority; | ||
650 | (void) GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), | ||
651 | pos->priority); | ||
652 | } | ||
653 | current_lifeness = pos->lifeness; | ||
654 | active_task = pos; | ||
654 | #if PROFILE_DELAYS | 655 | #if PROFILE_DELAYS |
655 | if (GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value > | 656 | if (GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value > |
656 | DELAY_THRESHOLD.rel_value) | 657 | DELAY_THRESHOLD.rel_value) |
657 | { | 658 | { |
658 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 659 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, |
659 | "Task %llu took %llums to be scheduled\n", pos->id, | 660 | "util", |
660 | (unsigned long long) | 661 | "Task %llu took %llums to be scheduled\n", pos->id, |
661 | GNUNET_TIME_absolute_get_duration | 662 | (unsigned long long) |
662 | (pos->start_time).rel_value); | 663 | GNUNET_TIME_absolute_get_duration |
663 | } | 664 | (pos->start_time).rel_value); |
665 | } | ||
664 | #endif | 666 | #endif |
665 | tc.reason = pos->reason; | 667 | tc.reason = pos->reason; |
666 | tc.read_ready = (pos->read_set == NULL) ? rs : pos->read_set; | 668 | tc.read_ready = (pos->read_set == NULL) ? rs : pos->read_set; |
667 | if ((pos->read_fd != -1) && | 669 | if ((pos->read_fd != -1) && |
668 | (0 != (pos->reason & GNUNET_SCHEDULER_REASON_READ_READY))) | 670 | (0 != (pos->reason & GNUNET_SCHEDULER_REASON_READ_READY))) |
669 | GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd); | 671 | GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd); |
670 | tc.write_ready = (pos->write_set == NULL) ? ws : pos->write_set; | 672 | tc.write_ready = (pos->write_set == NULL) ? ws : pos->write_set; |
671 | if ((pos->write_fd != -1) && | 673 | if ((pos->write_fd != -1) && |
672 | (0 != (pos->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))) | 674 | (0 != (pos->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))) |
673 | GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd); | 675 | GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd); |
674 | if (((tc.reason & GNUNET_SCHEDULER_REASON_WRITE_READY) != 0) && | 676 | if (((tc.reason & GNUNET_SCHEDULER_REASON_WRITE_READY) != 0) && |
675 | (pos->write_fd != -1) && | 677 | (pos->write_fd != -1) && |
676 | (!GNUNET_NETWORK_fdset_test_native (ws, pos->write_fd))) | 678 | (!GNUNET_NETWORK_fdset_test_native (ws, pos->write_fd))) |
677 | abort (); // added to ready in previous select loop! | 679 | abort (); // added to ready in previous select loop! |
678 | #if DEBUG_TASKS | 680 | #if DEBUG_TASKS |
679 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running task: %llu / %p\n", pos->id, | 681 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
680 | pos->callback_cls); | 682 | "util", |
683 | "Running task: %llu / %p\n", pos->id, | ||
684 | pos->callback_cls); | ||
681 | #endif | 685 | #endif |
682 | pos->callback (pos->callback_cls, &tc); | 686 | pos->callback (pos->callback_cls, &tc); |
683 | #if EXECINFO | 687 | #if EXECINFO |
684 | int i; | 688 | int i; |
685 | 689 | ||
686 | for (i = 0; i < pos->num_backtrace_strings; i++) | 690 | for (i = 0; i < pos->num_backtrace_strings; i++) |
687 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Task %llu trace %d: %s\n", pos->id, | 691 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, |
688 | i, pos->backtrace_strings[i]); | 692 | "util", |
693 | "Task %llu trace %d: %s\n", pos->id, | ||
694 | i, pos->backtrace_strings[i]); | ||
689 | #endif | 695 | #endif |
690 | active_task = NULL; | 696 | active_task = NULL; |
691 | destroy_task (pos); | 697 | destroy_task (pos); |
692 | tasks_run++; | 698 | tasks_run++; |
693 | } | 699 | } |
694 | while ((pending == NULL) || (p >= max_priority_added)); | 700 | while ((pending == NULL) || (p >= max_priority_added)); |
695 | } | 701 | } |
696 | 702 | ||
@@ -716,11 +722,11 @@ static void | |||
716 | sighandler_shutdown () | 722 | sighandler_shutdown () |
717 | { | 723 | { |
718 | static char c; | 724 | static char c; |
719 | int old_errno = errno; /* backup errno */ | 725 | int old_errno = errno; /* backup errno */ |
720 | 726 | ||
721 | GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle | 727 | GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle |
722 | (shutdown_pipe_handle, GNUNET_DISK_PIPE_END_WRITE), | 728 | (shutdown_pipe_handle, GNUNET_DISK_PIPE_END_WRITE), |
723 | &c, sizeof (c)); | 729 | &c, sizeof (c)); |
724 | errno = old_errno; | 730 | errno = old_errno; |
725 | } | 731 | } |
726 | 732 | ||
@@ -746,10 +752,10 @@ check_lifeness () | |||
746 | if (t->lifeness == GNUNET_YES) | 752 | if (t->lifeness == GNUNET_YES) |
747 | return GNUNET_OK; | 753 | return GNUNET_OK; |
748 | if ((NULL != pending) || (NULL != pending_timeout)) | 754 | if ((NULL != pending) || (NULL != pending_timeout)) |
749 | { | 755 | { |
750 | GNUNET_SCHEDULER_shutdown (); | 756 | GNUNET_SCHEDULER_shutdown (); |
751 | return GNUNET_OK; | 757 | return GNUNET_OK; |
752 | } | 758 | } |
753 | return GNUNET_NO; | 759 | return GNUNET_NO; |
754 | } | 760 | } |
755 | 761 | ||
@@ -795,7 +801,7 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls) | |||
795 | shutdown_pipe_handle = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO); | 801 | shutdown_pipe_handle = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO); |
796 | GNUNET_assert (shutdown_pipe_handle != NULL); | 802 | GNUNET_assert (shutdown_pipe_handle != NULL); |
797 | pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle, | 803 | pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle, |
798 | GNUNET_DISK_PIPE_END_READ); | 804 | GNUNET_DISK_PIPE_END_READ); |
799 | GNUNET_assert (pr != NULL); | 805 | GNUNET_assert (pr != NULL); |
800 | shc_int = GNUNET_SIGNAL_handler_install (SIGINT, &sighandler_shutdown); | 806 | shc_int = GNUNET_SIGNAL_handler_install (SIGINT, &sighandler_shutdown); |
801 | shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, &sighandler_shutdown); | 807 | shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, &sighandler_shutdown); |
@@ -807,77 +813,79 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls) | |||
807 | current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT; | 813 | current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT; |
808 | current_lifeness = GNUNET_YES; | 814 | current_lifeness = GNUNET_YES; |
809 | GNUNET_SCHEDULER_add_continuation (task, task_cls, | 815 | GNUNET_SCHEDULER_add_continuation (task, task_cls, |
810 | GNUNET_SCHEDULER_REASON_STARTUP); | 816 | GNUNET_SCHEDULER_REASON_STARTUP); |
811 | #if ENABLE_WINDOWS_WORKAROUNDS | 817 | #if ENABLE_WINDOWS_WORKAROUNDS |
812 | active_task = (void *) (long) -1; /* force passing of sanity check */ | 818 | active_task = (void *) (long) -1; /* force passing of sanity check */ |
813 | GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO, | 819 | GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO, |
814 | &GNUNET_OS_install_parent_control_handler, | 820 | &GNUNET_OS_install_parent_control_handler, |
815 | NULL); | 821 | NULL); |
816 | active_task = NULL; | 822 | active_task = NULL; |
817 | #endif | 823 | #endif |
818 | last_tr = 0; | 824 | last_tr = 0; |
819 | busy_wait_warning = 0; | 825 | busy_wait_warning = 0; |
820 | while (GNUNET_OK == check_lifeness ()) | 826 | while (GNUNET_OK == check_lifeness ()) |
821 | { | ||
822 | GNUNET_NETWORK_fdset_zero (rs); | ||
823 | GNUNET_NETWORK_fdset_zero (ws); | ||
824 | timeout = GNUNET_TIME_UNIT_FOREVER_REL; | ||
825 | update_sets (rs, ws, &timeout); | ||
826 | GNUNET_NETWORK_fdset_handle_set (rs, pr); | ||
827 | if (ready_count > 0) | ||
828 | { | ||
829 | /* no blocking, more work already ready! */ | ||
830 | timeout = GNUNET_TIME_UNIT_ZERO; | ||
831 | } | ||
832 | if (NULL == scheduler_select) | ||
833 | ret = GNUNET_NETWORK_socket_select (rs, ws, NULL, timeout); | ||
834 | else | ||
835 | ret = scheduler_select (scheduler_select_cls, rs, ws, NULL, timeout); | ||
836 | if (ret == GNUNET_SYSERR) | ||
837 | { | 827 | { |
838 | if (errno == EINTR) | 828 | GNUNET_NETWORK_fdset_zero (rs); |
839 | continue; | 829 | GNUNET_NETWORK_fdset_zero (ws); |
840 | 830 | timeout = GNUNET_TIME_UNIT_FOREVER_REL; | |
841 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "select"); | 831 | update_sets (rs, ws, &timeout); |
832 | GNUNET_NETWORK_fdset_handle_set (rs, pr); | ||
833 | if (ready_count > 0) | ||
834 | { | ||
835 | /* no blocking, more work already ready! */ | ||
836 | timeout = GNUNET_TIME_UNIT_ZERO; | ||
837 | } | ||
838 | if (NULL == scheduler_select) | ||
839 | ret = GNUNET_NETWORK_socket_select (rs, ws, NULL, timeout); | ||
840 | else | ||
841 | ret = scheduler_select (scheduler_select_cls, rs, ws, NULL, timeout); | ||
842 | if (ret == GNUNET_SYSERR) | ||
843 | { | ||
844 | if (errno == EINTR) | ||
845 | continue; | ||
846 | |||
847 | GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_ERROR, "util", | ||
848 | "select"); | ||
842 | #ifndef MINGW | 849 | #ifndef MINGW |
843 | #if USE_LSOF | 850 | #if USE_LSOF |
844 | char lsof[512]; | 851 | char lsof[512]; |
845 | 852 | ||
846 | snprintf (lsof, sizeof (lsof), "lsof -p %d", getpid ()); | 853 | snprintf (lsof, sizeof (lsof), "lsof -p %d", getpid ()); |
847 | (void) close (1); | 854 | (void) close (1); |
848 | (void) dup2 (2, 1); | 855 | (void) dup2 (2, 1); |
849 | if (0 != system (lsof)) | 856 | if (0 != system (lsof)) |
850 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "system"); | 857 | GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, "util", |
858 | "system"); | ||
851 | #endif | 859 | #endif |
852 | #endif | 860 | #endif |
853 | abort (); | 861 | abort (); |
854 | break; | 862 | break; |
855 | } | 863 | } |
856 | if ((ret == 0) && (timeout.rel_value == 0) && (busy_wait_warning > 16)) | 864 | if ((ret == 0) && (timeout.rel_value == 0) && (busy_wait_warning > 16)) |
857 | { | 865 | { |
858 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 866 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, |
859 | _("Looks like we're busy waiting...\n")); | 867 | "util", _("Looks like we're busy waiting...\n")); |
860 | sleep (1); /* mitigate */ | 868 | sleep (1); /* mitigate */ |
861 | } | 869 | } |
862 | check_ready (rs, ws); | 870 | check_ready (rs, ws); |
863 | run_ready (rs, ws); | 871 | run_ready (rs, ws); |
864 | if (GNUNET_NETWORK_fdset_handle_isset (rs, pr)) | 872 | if (GNUNET_NETWORK_fdset_handle_isset (rs, pr)) |
865 | { | 873 | { |
866 | /* consume the signal */ | 874 | /* consume the signal */ |
867 | GNUNET_DISK_file_read (pr, &c, sizeof (c)); | 875 | GNUNET_DISK_file_read (pr, &c, sizeof (c)); |
868 | /* mark all active tasks as ready due to shutdown */ | 876 | /* mark all active tasks as ready due to shutdown */ |
869 | GNUNET_SCHEDULER_shutdown (); | 877 | GNUNET_SCHEDULER_shutdown (); |
870 | } | 878 | } |
871 | if (last_tr == tasks_run) | 879 | if (last_tr == tasks_run) |
872 | { | 880 | { |
873 | busy_wait_warning++; | 881 | busy_wait_warning++; |
874 | } | 882 | } |
875 | else | 883 | else |
876 | { | 884 | { |
877 | last_tr = tasks_run; | 885 | last_tr = tasks_run; |
878 | busy_wait_warning = 0; | 886 | busy_wait_warning = 0; |
887 | } | ||
879 | } | 888 | } |
880 | } | ||
881 | GNUNET_SIGNAL_handler_uninstall (shc_int); | 889 | GNUNET_SIGNAL_handler_uninstall (shc_int); |
882 | GNUNET_SIGNAL_handler_uninstall (shc_term); | 890 | GNUNET_SIGNAL_handler_uninstall (shc_term); |
883 | #ifndef MINGW | 891 | #ifndef MINGW |
@@ -930,10 +938,10 @@ GNUNET_SCHEDULER_get_load (enum GNUNET_SCHEDULER_Priority p) | |||
930 | ret = 0; | 938 | ret = 0; |
931 | pos = ready[check_priority (p)]; | 939 | pos = ready[check_priority (p)]; |
932 | while (pos != NULL) | 940 | while (pos != NULL) |
933 | { | 941 | { |
934 | pos = pos->next; | 942 | pos = pos->next; |
935 | ret++; | 943 | ret++; |
936 | } | 944 | } |
937 | return ret; | 945 | return ret; |
938 | } | 946 | } |
939 | 947 | ||
@@ -959,77 +967,79 @@ GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_TaskIdentifier task) | |||
959 | prev = NULL; | 967 | prev = NULL; |
960 | t = pending; | 968 | t = pending; |
961 | while (t != NULL) | 969 | while (t != NULL) |
962 | { | ||
963 | if (t->id == task) | ||
964 | break; | ||
965 | prev = t; | ||
966 | t = t->next; | ||
967 | } | ||
968 | if (t == NULL) | ||
969 | { | ||
970 | prev = NULL; | ||
971 | to = 1; | ||
972 | t = pending_timeout; | ||
973 | while (t != NULL) | ||
974 | { | 970 | { |
975 | if (t->id == task) | 971 | if (t->id == task) |
976 | break; | 972 | break; |
977 | prev = t; | 973 | prev = t; |
978 | t = t->next; | 974 | t = t->next; |
979 | } | 975 | } |
980 | if (pending_timeout_last == t) | 976 | if (t == NULL) |
981 | pending_timeout_last = NULL; | ||
982 | } | ||
983 | p = 0; | ||
984 | while (t == NULL) | ||
985 | { | ||
986 | p++; | ||
987 | if (p >= GNUNET_SCHEDULER_PRIORITY_COUNT) | ||
988 | { | 977 | { |
989 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 978 | prev = NULL; |
990 | _("Attempt to cancel dead task %llu!\n"), | 979 | to = 1; |
991 | (unsigned long long) task); | 980 | t = pending_timeout; |
992 | GNUNET_assert (0); | 981 | while (t != NULL) |
982 | { | ||
983 | if (t->id == task) | ||
984 | break; | ||
985 | prev = t; | ||
986 | t = t->next; | ||
987 | } | ||
988 | if (pending_timeout_last == t) | ||
989 | pending_timeout_last = NULL; | ||
993 | } | 990 | } |
994 | prev = NULL; | 991 | p = 0; |
995 | t = ready[p]; | 992 | while (t == NULL) |
996 | while (t != NULL) | ||
997 | { | 993 | { |
998 | if (t->id == task) | 994 | p++; |
999 | { | 995 | if (p >= GNUNET_SCHEDULER_PRIORITY_COUNT) |
1000 | ready_count--; | 996 | { |
1001 | break; | 997 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, |
1002 | } | 998 | "util", |
1003 | prev = t; | 999 | _("Attempt to cancel dead task %llu!\n"), |
1004 | t = t->next; | 1000 | (unsigned long long) task); |
1001 | GNUNET_assert (0); | ||
1002 | } | ||
1003 | prev = NULL; | ||
1004 | t = ready[p]; | ||
1005 | while (t != NULL) | ||
1006 | { | ||
1007 | if (t->id == task) | ||
1008 | { | ||
1009 | ready_count--; | ||
1010 | break; | ||
1011 | } | ||
1012 | prev = t; | ||
1013 | t = t->next; | ||
1014 | } | ||
1005 | } | 1015 | } |
1006 | } | ||
1007 | if (prev == NULL) | 1016 | if (prev == NULL) |
1008 | { | ||
1009 | if (p == 0) | ||
1010 | { | 1017 | { |
1011 | if (to == 0) | 1018 | if (p == 0) |
1012 | { | 1019 | { |
1013 | pending = t->next; | 1020 | if (to == 0) |
1014 | } | 1021 | { |
1022 | pending = t->next; | ||
1023 | } | ||
1024 | else | ||
1025 | { | ||
1026 | pending_timeout = t->next; | ||
1027 | } | ||
1028 | } | ||
1015 | else | 1029 | else |
1016 | { | 1030 | { |
1017 | pending_timeout = t->next; | 1031 | ready[p] = t->next; |
1018 | } | 1032 | } |
1019 | } | 1033 | } |
1020 | else | 1034 | else |
1021 | { | 1035 | { |
1022 | ready[p] = t->next; | 1036 | prev->next = t->next; |
1023 | } | 1037 | } |
1024 | } | ||
1025 | else | ||
1026 | { | ||
1027 | prev->next = t->next; | ||
1028 | } | ||
1029 | ret = t->callback_cls; | 1038 | ret = t->callback_cls; |
1030 | #if DEBUG_TASKS | 1039 | #if DEBUG_TASKS |
1031 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Canceling task: %llu / %p\n", task, | 1040 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1032 | t->callback_cls); | 1041 | "util", |
1042 | "Canceling task: %llu / %p\n", task, t->callback_cls); | ||
1033 | #endif | 1043 | #endif |
1034 | destroy_task (t); | 1044 | destroy_task (t); |
1035 | return ret; | 1045 | return ret; |
@@ -1047,7 +1057,7 @@ GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_TaskIdentifier task) | |||
1047 | */ | 1057 | */ |
1048 | void | 1058 | void |
1049 | GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls, | 1059 | GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls, |
1050 | enum GNUNET_SCHEDULER_Reason reason) | 1060 | enum GNUNET_SCHEDULER_Reason reason) |
1051 | { | 1061 | { |
1052 | struct Task *t; | 1062 | struct Task *t; |
1053 | 1063 | ||
@@ -1057,12 +1067,12 @@ GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls, | |||
1057 | 1067 | ||
1058 | GNUNET_assert (NULL != task); | 1068 | GNUNET_assert (NULL != task); |
1059 | GNUNET_assert ((active_task != NULL) || | 1069 | GNUNET_assert ((active_task != NULL) || |
1060 | (reason == GNUNET_SCHEDULER_REASON_STARTUP)); | 1070 | (reason == GNUNET_SCHEDULER_REASON_STARTUP)); |
1061 | t = GNUNET_malloc (sizeof (struct Task)); | 1071 | t = GNUNET_malloc (sizeof (struct Task)); |
1062 | #if EXECINFO | 1072 | #if EXECINFO |
1063 | t->num_backtrace_strings = backtrace (backtrace_array, 50); | 1073 | t->num_backtrace_strings = backtrace (backtrace_array, 50); |
1064 | t->backtrace_strings = | 1074 | t->backtrace_strings = |
1065 | backtrace_symbols (backtrace_array, t->num_backtrace_strings); | 1075 | backtrace_symbols (backtrace_array, t->num_backtrace_strings); |
1066 | #endif | 1076 | #endif |
1067 | t->read_fd = -1; | 1077 | t->read_fd = -1; |
1068 | t->write_fd = -1; | 1078 | t->write_fd = -1; |
@@ -1076,8 +1086,10 @@ GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls, | |||
1076 | t->priority = current_priority; | 1086 | t->priority = current_priority; |
1077 | t->lifeness = current_lifeness; | 1087 | t->lifeness = current_lifeness; |
1078 | #if DEBUG_TASKS | 1088 | #if DEBUG_TASKS |
1079 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding continuation task: %llu / %p\n", | 1089 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1080 | t->id, t->callback_cls); | 1090 | "util", |
1091 | "Adding continuation task: %llu / %p\n", | ||
1092 | t->id, t->callback_cls); | ||
1081 | #endif | 1093 | #endif |
1082 | queue_ready_task (t); | 1094 | queue_ready_task (t); |
1083 | } | 1095 | } |
@@ -1102,11 +1114,12 @@ GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls, | |||
1102 | */ | 1114 | */ |
1103 | GNUNET_SCHEDULER_TaskIdentifier | 1115 | GNUNET_SCHEDULER_TaskIdentifier |
1104 | GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, | 1116 | GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, |
1105 | GNUNET_SCHEDULER_Task task, void *task_cls) | 1117 | GNUNET_SCHEDULER_Task task, void *task_cls) |
1106 | { | 1118 | { |
1107 | return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, | 1119 | return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, |
1108 | prerequisite_task, GNUNET_TIME_UNIT_ZERO, | 1120 | prerequisite_task, |
1109 | NULL, NULL, task, task_cls); | 1121 | GNUNET_TIME_UNIT_ZERO, NULL, NULL, task, |
1122 | task_cls); | ||
1110 | } | 1123 | } |
1111 | 1124 | ||
1112 | 1125 | ||
@@ -1121,11 +1134,12 @@ GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, | |||
1121 | */ | 1134 | */ |
1122 | GNUNET_SCHEDULER_TaskIdentifier | 1135 | GNUNET_SCHEDULER_TaskIdentifier |
1123 | GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio, | 1136 | GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio, |
1124 | GNUNET_SCHEDULER_Task task, void *task_cls) | 1137 | GNUNET_SCHEDULER_Task task, |
1138 | void *task_cls) | ||
1125 | { | 1139 | { |
1126 | return GNUNET_SCHEDULER_add_select (prio, GNUNET_SCHEDULER_NO_TASK, | 1140 | return GNUNET_SCHEDULER_add_select (prio, GNUNET_SCHEDULER_NO_TASK, |
1127 | GNUNET_TIME_UNIT_ZERO, NULL, NULL, task, | 1141 | GNUNET_TIME_UNIT_ZERO, NULL, NULL, task, |
1128 | task_cls); | 1142 | task_cls); |
1129 | } | 1143 | } |
1130 | 1144 | ||
1131 | 1145 | ||
@@ -1144,7 +1158,7 @@ GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio, | |||
1144 | */ | 1158 | */ |
1145 | GNUNET_SCHEDULER_TaskIdentifier | 1159 | GNUNET_SCHEDULER_TaskIdentifier |
1146 | GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay, | 1160 | GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay, |
1147 | GNUNET_SCHEDULER_Task task, void *task_cls) | 1161 | GNUNET_SCHEDULER_Task task, void *task_cls) |
1148 | { | 1162 | { |
1149 | #if 1 | 1163 | #if 1 |
1150 | /* new, optimized version */ | 1164 | /* new, optimized version */ |
@@ -1164,7 +1178,7 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay, | |||
1164 | #if EXECINFO | 1178 | #if EXECINFO |
1165 | t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH); | 1179 | t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH); |
1166 | t->backtrace_strings = | 1180 | t->backtrace_strings = |
1167 | backtrace_symbols (backtrace_array, t->num_backtrace_strings); | 1181 | backtrace_symbols (backtrace_array, t->num_backtrace_strings); |
1168 | #endif | 1182 | #endif |
1169 | t->read_fd = -1; | 1183 | t->read_fd = -1; |
1170 | t->write_fd = -1; | 1184 | t->write_fd = -1; |
@@ -1179,24 +1193,24 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay, | |||
1179 | * appending to a long list of tasks with timeouts) */ | 1193 | * appending to a long list of tasks with timeouts) */ |
1180 | prev = pending_timeout_last; | 1194 | prev = pending_timeout_last; |
1181 | if (prev != NULL) | 1195 | if (prev != NULL) |
1182 | { | 1196 | { |
1183 | if (prev->timeout.abs_value > t->timeout.abs_value) | 1197 | if (prev->timeout.abs_value > t->timeout.abs_value) |
1184 | prev = NULL; | 1198 | prev = NULL; |
1185 | else | 1199 | else |
1186 | pos = prev->next; /* heuristic success! */ | 1200 | pos = prev->next; /* heuristic success! */ |
1187 | } | 1201 | } |
1188 | if (prev == NULL) | 1202 | if (prev == NULL) |
1189 | { | 1203 | { |
1190 | /* heuristic failed, do traversal of timeout list */ | 1204 | /* heuristic failed, do traversal of timeout list */ |
1191 | pos = pending_timeout; | 1205 | pos = pending_timeout; |
1192 | } | 1206 | } |
1193 | while ((pos != NULL) && | 1207 | while ((pos != NULL) && |
1194 | ((pos->timeout.abs_value <= t->timeout.abs_value) || | 1208 | ((pos->timeout.abs_value <= t->timeout.abs_value) || |
1195 | (pos->reason != 0))) | 1209 | (pos->reason != 0))) |
1196 | { | 1210 | { |
1197 | prev = pos; | 1211 | prev = pos; |
1198 | pos = pos->next; | 1212 | pos = pos->next; |
1199 | } | 1213 | } |
1200 | if (prev == NULL) | 1214 | if (prev == NULL) |
1201 | pending_timeout = t; | 1215 | pending_timeout = t; |
1202 | else | 1216 | else |
@@ -1206,23 +1220,26 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay, | |||
1206 | pending_timeout_last = t; | 1220 | pending_timeout_last = t; |
1207 | 1221 | ||
1208 | #if DEBUG_TASKS | 1222 | #if DEBUG_TASKS |
1209 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding task: %llu / %p\n", t->id, | 1223 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1210 | t->callback_cls); | 1224 | "util", |
1225 | "Adding task: %llu / %p\n", t->id, t->callback_cls); | ||
1211 | #endif | 1226 | #endif |
1212 | #if EXECINFO | 1227 | #if EXECINFO |
1213 | int i; | 1228 | int i; |
1214 | 1229 | ||
1215 | for (i = 0; i < t->num_backtrace_strings; i++) | 1230 | for (i = 0; i < t->num_backtrace_strings; i++) |
1216 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Task %llu trace %d: %s\n", t->id, i, | 1231 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1217 | t->backtrace_strings[i]); | 1232 | "util", |
1233 | "Task %llu trace %d: %s\n", t->id, i, | ||
1234 | t->backtrace_strings[i]); | ||
1218 | #endif | 1235 | #endif |
1219 | return t->id; | 1236 | return t->id; |
1220 | 1237 | ||
1221 | #else | 1238 | #else |
1222 | /* unoptimized version */ | 1239 | /* unoptimized version */ |
1223 | return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, | 1240 | return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, |
1224 | GNUNET_SCHEDULER_NO_TASK, delay, NULL, | 1241 | GNUNET_SCHEDULER_NO_TASK, delay, NULL, |
1225 | NULL, task, task_cls); | 1242 | NULL, task, task_cls); |
1226 | #endif | 1243 | #endif |
1227 | } | 1244 | } |
1228 | 1245 | ||
@@ -1241,9 +1258,9 @@ GNUNET_SCHEDULER_TaskIdentifier | |||
1241 | GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task, void *task_cls) | 1258 | GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task, void *task_cls) |
1242 | { | 1259 | { |
1243 | return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, | 1260 | return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, |
1244 | GNUNET_SCHEDULER_NO_TASK, | 1261 | GNUNET_SCHEDULER_NO_TASK, |
1245 | GNUNET_TIME_UNIT_ZERO, NULL, NULL, task, | 1262 | GNUNET_TIME_UNIT_ZERO, NULL, NULL, task, |
1246 | task_cls); | 1263 | task_cls); |
1247 | } | 1264 | } |
1248 | 1265 | ||
1249 | 1266 | ||
@@ -1263,16 +1280,16 @@ GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task, void *task_cls) | |||
1263 | */ | 1280 | */ |
1264 | GNUNET_SCHEDULER_TaskIdentifier | 1281 | GNUNET_SCHEDULER_TaskIdentifier |
1265 | GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness, | 1282 | GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness, |
1266 | GNUNET_SCHEDULER_Task task, | 1283 | GNUNET_SCHEDULER_Task task, |
1267 | void *task_cls) | 1284 | void *task_cls) |
1268 | { | 1285 | { |
1269 | GNUNET_SCHEDULER_TaskIdentifier ret; | 1286 | GNUNET_SCHEDULER_TaskIdentifier ret; |
1270 | 1287 | ||
1271 | ret = | 1288 | ret = |
1272 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, | 1289 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, |
1273 | GNUNET_SCHEDULER_NO_TASK, | 1290 | GNUNET_SCHEDULER_NO_TASK, |
1274 | GNUNET_TIME_UNIT_ZERO, NULL, NULL, task, | 1291 | GNUNET_TIME_UNIT_ZERO, NULL, NULL, task, |
1275 | task_cls); | 1292 | task_cls); |
1276 | GNUNET_assert (pending->id == ret); | 1293 | GNUNET_assert (pending->id == ret); |
1277 | pending->lifeness = lifeness; | 1294 | pending->lifeness = lifeness; |
1278 | return ret; | 1295 | return ret; |
@@ -1310,7 +1327,7 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness, | |||
1310 | #ifndef MINGW | 1327 | #ifndef MINGW |
1311 | GNUNET_SCHEDULER_TaskIdentifier | 1328 | GNUNET_SCHEDULER_TaskIdentifier |
1312 | add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd, | 1329 | add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd, |
1313 | GNUNET_SCHEDULER_Task task, void *task_cls) | 1330 | GNUNET_SCHEDULER_Task task, void *task_cls) |
1314 | { | 1331 | { |
1315 | struct Task *t; | 1332 | struct Task *t; |
1316 | 1333 | ||
@@ -1326,45 +1343,45 @@ add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd, | |||
1326 | #if EXECINFO | 1343 | #if EXECINFO |
1327 | t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH); | 1344 | t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH); |
1328 | t->backtrace_strings = | 1345 | t->backtrace_strings = |
1329 | backtrace_symbols (backtrace_array, t->num_backtrace_strings); | 1346 | backtrace_symbols (backtrace_array, t->num_backtrace_strings); |
1330 | #endif | 1347 | #endif |
1331 | #if DEBUG_FDS | 1348 | #if DEBUG_FDS |
1332 | if (-1 != rfd) | 1349 | if (-1 != rfd) |
1333 | { | ||
1334 | int flags = fcntl (rfd, F_GETFD); | ||
1335 | |||
1336 | if (flags == -1 && errno == EBADF) | ||
1337 | { | 1350 | { |
1338 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got invalid file descriptor %d!\n", | 1351 | int flags = fcntl (rfd, F_GETFD); |
1339 | rfd); | 1352 | |
1353 | if ((flags == -1) && (errno == EBADF)) | ||
1354 | { | ||
1355 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | ||
1356 | "util", "Got invalid file descriptor %d!\n", rfd); | ||
1340 | #if EXECINFO | 1357 | #if EXECINFO |
1341 | int i; | 1358 | int i; |
1342 | 1359 | ||
1343 | for (i = 0; i < t->num_backtrace_strings; i++) | 1360 | for (i = 0; i < t->num_backtrace_strings; i++) |
1344 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trace: %s\n", | 1361 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1345 | t->backtrace_strings[i]); | 1362 | "util", "Trace: %s\n", t->backtrace_strings[i]); |
1346 | #endif | 1363 | #endif |
1347 | GNUNET_assert (0); | 1364 | GNUNET_assert (0); |
1365 | } | ||
1348 | } | 1366 | } |
1349 | } | ||
1350 | if (-1 != wfd) | 1367 | if (-1 != wfd) |
1351 | { | ||
1352 | int flags = fcntl (wfd, F_GETFD); | ||
1353 | |||
1354 | if (flags == -1 && errno == EBADF) | ||
1355 | { | 1368 | { |
1356 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got invalid file descriptor %d!\n", | 1369 | int flags = fcntl (wfd, F_GETFD); |
1357 | wfd); | 1370 | |
1371 | if (flags == -1 && errno == EBADF) | ||
1372 | { | ||
1373 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | ||
1374 | "util", "Got invalid file descriptor %d!\n", wfd); | ||
1358 | #if EXECINFO | 1375 | #if EXECINFO |
1359 | int i; | 1376 | int i; |
1360 | 1377 | ||
1361 | for (i = 0; i < t->num_backtrace_strings; i++) | 1378 | for (i = 0; i < t->num_backtrace_strings; i++) |
1362 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trace: %s\n", | 1379 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1363 | t->backtrace_strings[i]); | 1380 | "util", "Trace: %s\n", t->backtrace_strings[i]); |
1364 | #endif | 1381 | #endif |
1365 | GNUNET_assert (0); | 1382 | GNUNET_assert (0); |
1383 | } | ||
1366 | } | 1384 | } |
1367 | } | ||
1368 | #endif | 1385 | #endif |
1369 | t->read_fd = rfd; | 1386 | t->read_fd = rfd; |
1370 | GNUNET_assert (wfd >= -1); | 1387 | GNUNET_assert (wfd >= -1); |
@@ -1381,15 +1398,17 @@ add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd, | |||
1381 | pending = t; | 1398 | pending = t; |
1382 | max_priority_added = GNUNET_MAX (max_priority_added, t->priority); | 1399 | max_priority_added = GNUNET_MAX (max_priority_added, t->priority); |
1383 | #if DEBUG_TASKS | 1400 | #if DEBUG_TASKS |
1384 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding task: %llu / %p\n", t->id, | 1401 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1385 | t->callback_cls); | 1402 | "util", |
1403 | "Adding task: %llu / %p\n", t->id, t->callback_cls); | ||
1386 | #endif | 1404 | #endif |
1387 | #if EXECINFO | 1405 | #if EXECINFO |
1388 | int i; | 1406 | int i; |
1389 | 1407 | ||
1390 | for (i = 0; i < t->num_backtrace_strings; i++) | 1408 | for (i = 0; i < t->num_backtrace_strings; i++) |
1391 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Task %llu trace %d: %s\n", t->id, i, | 1409 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "util", |
1392 | t->backtrace_strings[i]); | 1410 | "Task %llu trace %d: %s\n", t->id, i, |
1411 | t->backtrace_strings[i]); | ||
1393 | #endif | 1412 | #endif |
1394 | return t->id; | 1413 | return t->id; |
1395 | } | 1414 | } |
@@ -1415,8 +1434,8 @@ add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd, | |||
1415 | */ | 1434 | */ |
1416 | GNUNET_SCHEDULER_TaskIdentifier | 1435 | GNUNET_SCHEDULER_TaskIdentifier |
1417 | GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay, | 1436 | GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay, |
1418 | struct GNUNET_NETWORK_Handle *rfd, | 1437 | struct GNUNET_NETWORK_Handle * rfd, |
1419 | GNUNET_SCHEDULER_Task task, void *task_cls) | 1438 | GNUNET_SCHEDULER_Task task, void *task_cls) |
1420 | { | 1439 | { |
1421 | #if MINGW | 1440 | #if MINGW |
1422 | struct GNUNET_NETWORK_FDSet *rs; | 1441 | struct GNUNET_NETWORK_FDSet *rs; |
@@ -1426,14 +1445,14 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay, | |||
1426 | rs = GNUNET_NETWORK_fdset_create (); | 1445 | rs = GNUNET_NETWORK_fdset_create (); |
1427 | GNUNET_NETWORK_fdset_set (rs, rfd); | 1446 | GNUNET_NETWORK_fdset_set (rs, rfd); |
1428 | ret = | 1447 | ret = |
1429 | GNUNET_SCHEDULER_add_select (check_priority (current_priority), | 1448 | GNUNET_SCHEDULER_add_select (check_priority (current_priority), |
1430 | GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL, | 1449 | GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL, |
1431 | task, task_cls); | 1450 | task, task_cls); |
1432 | GNUNET_NETWORK_fdset_destroy (rs); | 1451 | GNUNET_NETWORK_fdset_destroy (rs); |
1433 | return ret; | 1452 | return ret; |
1434 | #else | 1453 | #else |
1435 | return add_without_sets (delay, GNUNET_NETWORK_get_fd (rfd), -1, task, | 1454 | return add_without_sets (delay, GNUNET_NETWORK_get_fd (rfd), -1, task, |
1436 | task_cls); | 1455 | task_cls); |
1437 | #endif | 1456 | #endif |
1438 | } | 1457 | } |
1439 | 1458 | ||
@@ -1456,8 +1475,8 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay, | |||
1456 | */ | 1475 | */ |
1457 | GNUNET_SCHEDULER_TaskIdentifier | 1476 | GNUNET_SCHEDULER_TaskIdentifier |
1458 | GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay, | 1477 | GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay, |
1459 | struct GNUNET_NETWORK_Handle *wfd, | 1478 | struct GNUNET_NETWORK_Handle * wfd, |
1460 | GNUNET_SCHEDULER_Task task, void *task_cls) | 1479 | GNUNET_SCHEDULER_Task task, void *task_cls) |
1461 | { | 1480 | { |
1462 | #if MINGW | 1481 | #if MINGW |
1463 | struct GNUNET_NETWORK_FDSet *ws; | 1482 | struct GNUNET_NETWORK_FDSet *ws; |
@@ -1467,15 +1486,15 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay, | |||
1467 | ws = GNUNET_NETWORK_fdset_create (); | 1486 | ws = GNUNET_NETWORK_fdset_create (); |
1468 | GNUNET_NETWORK_fdset_set (ws, wfd); | 1487 | GNUNET_NETWORK_fdset_set (ws, wfd); |
1469 | ret = | 1488 | ret = |
1470 | GNUNET_SCHEDULER_add_select (check_priority (current_priority), | 1489 | GNUNET_SCHEDULER_add_select (check_priority (current_priority), |
1471 | GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws, | 1490 | GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws, |
1472 | task, task_cls); | 1491 | task, task_cls); |
1473 | GNUNET_NETWORK_fdset_destroy (ws); | 1492 | GNUNET_NETWORK_fdset_destroy (ws); |
1474 | return ret; | 1493 | return ret; |
1475 | #else | 1494 | #else |
1476 | GNUNET_assert (GNUNET_NETWORK_get_fd (wfd) >= 0); | 1495 | GNUNET_assert (GNUNET_NETWORK_get_fd (wfd) >= 0); |
1477 | return add_without_sets (delay, -1, GNUNET_NETWORK_get_fd (wfd), task, | 1496 | return add_without_sets (delay, -1, GNUNET_NETWORK_get_fd (wfd), task, |
1478 | task_cls); | 1497 | task_cls); |
1479 | #endif | 1498 | #endif |
1480 | } | 1499 | } |
1481 | 1500 | ||
@@ -1498,8 +1517,8 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay, | |||
1498 | */ | 1517 | */ |
1499 | GNUNET_SCHEDULER_TaskIdentifier | 1518 | GNUNET_SCHEDULER_TaskIdentifier |
1500 | GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay, | 1519 | GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay, |
1501 | const struct GNUNET_DISK_FileHandle *rfd, | 1520 | const struct GNUNET_DISK_FileHandle * rfd, |
1502 | GNUNET_SCHEDULER_Task task, void *task_cls) | 1521 | GNUNET_SCHEDULER_Task task, void *task_cls) |
1503 | { | 1522 | { |
1504 | #if MINGW | 1523 | #if MINGW |
1505 | struct GNUNET_NETWORK_FDSet *rs; | 1524 | struct GNUNET_NETWORK_FDSet *rs; |
@@ -1509,9 +1528,9 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay, | |||
1509 | rs = GNUNET_NETWORK_fdset_create (); | 1528 | rs = GNUNET_NETWORK_fdset_create (); |
1510 | GNUNET_NETWORK_fdset_handle_set (rs, rfd); | 1529 | GNUNET_NETWORK_fdset_handle_set (rs, rfd); |
1511 | ret = | 1530 | ret = |
1512 | GNUNET_SCHEDULER_add_select (check_priority (current_priority), | 1531 | GNUNET_SCHEDULER_add_select (check_priority (current_priority), |
1513 | GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL, | 1532 | GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL, |
1514 | task, task_cls); | 1533 | task, task_cls); |
1515 | GNUNET_NETWORK_fdset_destroy (rs); | 1534 | GNUNET_NETWORK_fdset_destroy (rs); |
1516 | return ret; | 1535 | return ret; |
1517 | #else | 1536 | #else |
@@ -1542,8 +1561,8 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay, | |||
1542 | */ | 1561 | */ |
1543 | GNUNET_SCHEDULER_TaskIdentifier | 1562 | GNUNET_SCHEDULER_TaskIdentifier |
1544 | GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, | 1563 | GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, |
1545 | const struct GNUNET_DISK_FileHandle *wfd, | 1564 | const struct GNUNET_DISK_FileHandle * wfd, |
1546 | GNUNET_SCHEDULER_Task task, void *task_cls) | 1565 | GNUNET_SCHEDULER_Task task, void *task_cls) |
1547 | { | 1566 | { |
1548 | #if MINGW | 1567 | #if MINGW |
1549 | struct GNUNET_NETWORK_FDSet *ws; | 1568 | struct GNUNET_NETWORK_FDSet *ws; |
@@ -1553,9 +1572,9 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, | |||
1553 | ws = GNUNET_NETWORK_fdset_create (); | 1572 | ws = GNUNET_NETWORK_fdset_create (); |
1554 | GNUNET_NETWORK_fdset_handle_set (ws, wfd); | 1573 | GNUNET_NETWORK_fdset_handle_set (ws, wfd); |
1555 | ret = | 1574 | ret = |
1556 | GNUNET_SCHEDULER_add_select (check_priority (current_priority), | 1575 | GNUNET_SCHEDULER_add_select (check_priority (current_priority), |
1557 | GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws, | 1576 | GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws, |
1558 | task, task_cls); | 1577 | task, task_cls); |
1559 | GNUNET_NETWORK_fdset_destroy (ws); | 1578 | GNUNET_NETWORK_fdset_destroy (ws); |
1560 | return ret; | 1579 | return ret; |
1561 | #else | 1580 | #else |
@@ -1604,11 +1623,12 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, | |||
1604 | */ | 1623 | */ |
1605 | GNUNET_SCHEDULER_TaskIdentifier | 1624 | GNUNET_SCHEDULER_TaskIdentifier |
1606 | GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, | 1625 | GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, |
1607 | GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, | 1626 | GNUNET_SCHEDULER_TaskIdentifier |
1608 | struct GNUNET_TIME_Relative delay, | 1627 | prerequisite_task, |
1609 | const struct GNUNET_NETWORK_FDSet *rs, | 1628 | struct GNUNET_TIME_Relative delay, |
1610 | const struct GNUNET_NETWORK_FDSet *ws, | 1629 | const struct GNUNET_NETWORK_FDSet * rs, |
1611 | GNUNET_SCHEDULER_Task task, void *task_cls) | 1630 | const struct GNUNET_NETWORK_FDSet * ws, |
1631 | GNUNET_SCHEDULER_Task task, void *task_cls) | ||
1612 | { | 1632 | { |
1613 | struct Task *t; | 1633 | struct Task *t; |
1614 | 1634 | ||
@@ -1624,20 +1644,20 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, | |||
1624 | #if EXECINFO | 1644 | #if EXECINFO |
1625 | t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH); | 1645 | t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH); |
1626 | t->backtrace_strings = | 1646 | t->backtrace_strings = |
1627 | backtrace_symbols (backtrace_array, t->num_backtrace_strings); | 1647 | backtrace_symbols (backtrace_array, t->num_backtrace_strings); |
1628 | #endif | 1648 | #endif |
1629 | t->read_fd = -1; | 1649 | t->read_fd = -1; |
1630 | t->write_fd = -1; | 1650 | t->write_fd = -1; |
1631 | if (rs != NULL) | 1651 | if (rs != NULL) |
1632 | { | 1652 | { |
1633 | t->read_set = GNUNET_NETWORK_fdset_create (); | 1653 | t->read_set = GNUNET_NETWORK_fdset_create (); |
1634 | GNUNET_NETWORK_fdset_copy (t->read_set, rs); | 1654 | GNUNET_NETWORK_fdset_copy (t->read_set, rs); |
1635 | } | 1655 | } |
1636 | if (ws != NULL) | 1656 | if (ws != NULL) |
1637 | { | 1657 | { |
1638 | t->write_set = GNUNET_NETWORK_fdset_create (); | 1658 | t->write_set = GNUNET_NETWORK_fdset_create (); |
1639 | GNUNET_NETWORK_fdset_copy (t->write_set, ws); | 1659 | GNUNET_NETWORK_fdset_copy (t->write_set, ws); |
1640 | } | 1660 | } |
1641 | t->id = ++last_id; | 1661 | t->id = ++last_id; |
1642 | #if PROFILE_DELAYS | 1662 | #if PROFILE_DELAYS |
1643 | t->start_time = GNUNET_TIME_absolute_get (); | 1663 | t->start_time = GNUNET_TIME_absolute_get (); |
@@ -1645,23 +1665,26 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, | |||
1645 | t->prereq_id = prerequisite_task; | 1665 | t->prereq_id = prerequisite_task; |
1646 | t->timeout = GNUNET_TIME_relative_to_absolute (delay); | 1666 | t->timeout = GNUNET_TIME_relative_to_absolute (delay); |
1647 | t->priority = | 1667 | t->priority = |
1648 | check_priority ((prio == | 1668 | check_priority ((prio == |
1649 | GNUNET_SCHEDULER_PRIORITY_KEEP) ? current_priority : | 1669 | GNUNET_SCHEDULER_PRIORITY_KEEP) ? current_priority : |
1650 | prio); | 1670 | prio); |
1651 | t->lifeness = current_lifeness; | 1671 | t->lifeness = current_lifeness; |
1652 | t->next = pending; | 1672 | t->next = pending; |
1653 | pending = t; | 1673 | pending = t; |
1654 | max_priority_added = GNUNET_MAX (max_priority_added, t->priority); | 1674 | max_priority_added = GNUNET_MAX (max_priority_added, t->priority); |
1655 | #if DEBUG_TASKS | 1675 | #if DEBUG_TASKS |
1656 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding task: %llu / %p\n", t->id, | 1676 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1657 | t->callback_cls); | 1677 | "util", |
1678 | "Adding task: %llu / %p\n", t->id, t->callback_cls); | ||
1658 | #endif | 1679 | #endif |
1659 | #if EXECINFO | 1680 | #if EXECINFO |
1660 | int i; | 1681 | int i; |
1661 | 1682 | ||
1662 | for (i = 0; i < t->num_backtrace_strings; i++) | 1683 | for (i = 0; i < t->num_backtrace_strings; i++) |
1663 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Task %llu trace %d: %s\n", t->id, i, | 1684 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1664 | t->backtrace_strings[i]); | 1685 | "util", |
1686 | "Task %llu trace %d: %s\n", t->id, i, | ||
1687 | t->backtrace_strings[i]); | ||
1665 | #endif | 1688 | #endif |
1666 | return t->id; | 1689 | return t->id; |
1667 | } | 1690 | } |