trunk/src/osd/sdl/sdlwork.c
| r242652 | r242653 | |
| 139 | 139 | static int effective_num_processors(void); |
| 140 | 140 | static void * worker_thread_entry(void *param); |
| 141 | 141 | static void worker_thread_process(osd_work_queue *queue, work_thread_info *thread); |
| 142 | static bool queue_has_list_items(osd_work_queue *queue); |
| 142 | 143 | |
| 143 | 144 | |
| 144 | 145 | //============================================================ |
| r242652 | r242653 | |
| 617 | 618 | if (queue->exiting) |
| 618 | 619 | break; |
| 619 | 620 | |
| 621 | if (!queue_has_list_items(queue)) |
| 620 | 622 | { |
| 621 | | INT32 lockslot = osd_scalable_lock_acquire(queue->lock); |
| 622 | | bool wait_for_event = (queue->list == NULL); |
| 623 | | osd_scalable_lock_release(queue->lock, lockslot); |
| 624 | | |
| 625 | | if (wait_for_event) |
| 626 | | { |
| 627 | | begin_timing(thread->waittime); |
| 628 | | osd_event_wait(thread->wakeevent, INFINITE); |
| 629 | | end_timing(thread->waittime); |
| 630 | | } |
| 623 | begin_timing(thread->waittime); |
| 624 | osd_event_wait(thread->wakeevent, INFINITE); |
| 625 | end_timing(thread->waittime); |
| 631 | 626 | } |
| 632 | 627 | |
| 633 | 628 | if (queue->exiting) |
| r242652 | r242653 | |
| 661 | 656 | } |
| 662 | 657 | |
| 663 | 658 | // if nothing more, release the processor |
| 664 | | if (queue->list == NULL) |
| 659 | if (!queue_has_list_items(queue)) |
| 665 | 660 | break; |
| 666 | 661 | add_to_stat(&queue->spinloops, 1); |
| 667 | 662 | } |
| r242652 | r242653 | |
| 694 | 689 | { |
| 695 | 690 | osd_work_item *item; |
| 696 | 691 | |
| 692 | bool end_loop = false; |
| 693 | |
| 697 | 694 | // use a critical section to synchronize the removal of items |
| 698 | | INT32 lockslot = osd_scalable_lock_acquire(queue->lock); |
| 699 | 695 | { |
| 696 | INT32 lockslot = osd_scalable_lock_acquire(queue->lock); |
| 700 | 697 | if (queue->list == NULL) |
| 701 | 698 | { |
| 702 | | osd_scalable_lock_release(queue->lock, lockslot); |
| 703 | | break; |
| 699 | end_loop = true; |
| 704 | 700 | } |
| 705 | | |
| 706 | | |
| 707 | | // pull the item from the queue |
| 708 | | item = (osd_work_item *)queue->list; |
| 709 | | if (item != NULL) |
| 701 | else |
| 710 | 702 | { |
| 711 | | queue->list = item->next; |
| 712 | | if (queue->list == NULL) |
| 713 | | queue->tailptr = (osd_work_item **)&queue->list; |
| 703 | // pull the item from the queue |
| 704 | item = (osd_work_item *)queue->list; |
| 705 | if (item != NULL) |
| 706 | { |
| 707 | queue->list = item->next; |
| 708 | if (queue->list == NULL) |
| 709 | queue->tailptr = (osd_work_item **)&queue->list; |
| 710 | } |
| 714 | 711 | } |
| 712 | osd_scalable_lock_release(queue->lock, lockslot); |
| 715 | 713 | } |
| 716 | | osd_scalable_lock_release(queue->lock, lockslot); |
| 717 | 714 | |
| 715 | if (end_loop) |
| 716 | break; |
| 717 | |
| 718 | 718 | // process non-NULL items |
| 719 | 719 | if (item != NULL) |
| 720 | 720 | { |
| r242652 | r242653 | |
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | // if we removed an item and there's still work to do, bump the stats |
| 748 | | // TODO: data race |
| 749 | | if (queue->list != NULL) |
| 748 | if (queue_has_list_items(queue)) |
| 750 | 749 | add_to_stat(&queue->extraitems, 1); |
| 751 | 750 | } |
| 752 | 751 | } |
| r242652 | r242653 | |
| 761 | 760 | end_timing(thread->runtime); |
| 762 | 761 | } |
| 763 | 762 | |
| 764 | | #endif // SDLMAME_NOASM |
| 763 | bool queue_has_list_items(osd_work_queue *queue) |
| 764 | { |
| 765 | INT32 lockslot = osd_scalable_lock_acquire(queue->lock); |
| 766 | bool has_list_items = (queue->list != NULL); |
| 767 | osd_scalable_lock_release(queue->lock, lockslot); |
| 768 | return has_list_items; |
| 769 | } |
| 770 | #endif // SDLMAME_NOASM |
| | No newline at end of file |
trunk/src/osd/windows/winwork.c
| r242652 | r242653 | |
| 149 | 149 | static int effective_num_processors(void); |
| 150 | 150 | static void * worker_thread_entry(void *param); |
| 151 | 151 | static void worker_thread_process(osd_work_queue *queue, work_thread_info *thread); |
| 152 | static bool queue_has_list_items(osd_work_queue *queue); |
| 152 | 153 | |
| 153 | 154 | |
| 154 | 155 | //============================================================ |
| r242652 | r242653 | |
| 450 | 451 | item->callback = callback; |
| 451 | 452 | item->param = parambase; |
| 452 | 453 | item->result = NULL; |
| 453 | | item->flags = flags; |
| 454 | item->flags = flags; |
| 454 | 455 | |
| 455 | 456 | // advance to the next |
| 456 | 457 | lastitem = item; |
| r242652 | r242653 | |
| 617 | 618 | if (queue->exiting) |
| 618 | 619 | break; |
| 619 | 620 | |
| 621 | if (!queue_has_list_items(queue)) |
| 620 | 622 | { |
| 621 | | INT32 lockslot = osd_scalable_lock_acquire(queue->lock); |
| 622 | | bool wait_for_event = (queue->list == NULL); |
| 623 | | osd_scalable_lock_release(queue->lock, lockslot); |
| 624 | | |
| 625 | | if (wait_for_event) |
| 626 | | { |
| 627 | | begin_timing(thread->waittime); |
| 628 | | osd_event_wait(thread->wakeevent, INFINITE); |
| 629 | | end_timing(thread->waittime); |
| 630 | | } |
| 623 | begin_timing(thread->waittime); |
| 624 | osd_event_wait(thread->wakeevent, INFINITE); |
| 625 | end_timing(thread->waittime); |
| 631 | 626 | } |
| 632 | 627 | |
| 633 | 628 | if (queue->exiting) |
| r242652 | r242653 | |
| 657 | 652 | } |
| 658 | 653 | |
| 659 | 654 | // if nothing more, release the processor |
| 660 | | if (queue->list == NULL) |
| 655 | if (!queue_has_list_items(queue)) |
| 661 | 656 | break; |
| 662 | 657 | add_to_stat(&queue->spinloops, 1); |
| 663 | 658 | } |
| r242652 | r242653 | |
| 685 | 680 | { |
| 686 | 681 | osd_work_item *item; |
| 687 | 682 | |
| 683 | bool end_loop = false; |
| 684 | |
| 688 | 685 | // use a critical section to synchronize the removal of items |
| 689 | | INT32 lockslot = osd_scalable_lock_acquire(queue->lock); |
| 690 | 686 | { |
| 687 | INT32 lockslot = osd_scalable_lock_acquire(queue->lock); |
| 691 | 688 | if (queue->list == NULL) |
| 692 | 689 | { |
| 693 | | osd_scalable_lock_release(queue->lock, lockslot); |
| 694 | | break; |
| 690 | end_loop = true; |
| 695 | 691 | } |
| 696 | | |
| 697 | | |
| 698 | | // pull the item from the queue |
| 699 | | item = (osd_work_item *)queue->list; |
| 700 | | if (item != NULL) |
| 692 | else |
| 701 | 693 | { |
| 702 | | queue->list = item->next; |
| 703 | | if (queue->list == NULL) |
| 704 | | queue->tailptr = (osd_work_item **)&queue->list; |
| 694 | // pull the item from the queue |
| 695 | item = (osd_work_item *)queue->list; |
| 696 | if (item != NULL) |
| 697 | { |
| 698 | queue->list = item->next; |
| 699 | if (queue->list == NULL) |
| 700 | queue->tailptr = (osd_work_item **)&queue->list; |
| 701 | } |
| 705 | 702 | } |
| 703 | osd_scalable_lock_release(queue->lock, lockslot); |
| 706 | 704 | } |
| 707 | | osd_scalable_lock_release(queue->lock, lockslot); |
| 708 | 705 | |
| 706 | if (end_loop) |
| 707 | break; |
| 708 | |
| 709 | 709 | // process non-NULL items |
| 710 | 710 | if (item != NULL) |
| 711 | 711 | { |
| r242652 | r242653 | |
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | // if we removed an item and there's still work to do, bump the stats |
| 739 | | // TODO: data race |
| 740 | | if (queue->list != NULL) |
| 739 | if (queue_has_list_items(queue)) |
| 741 | 740 | add_to_stat(&queue->extraitems, 1); |
| 742 | 741 | } |
| 743 | 742 | } |
| r242652 | r242653 | |
| 751 | 750 | |
| 752 | 751 | end_timing(thread->runtime); |
| 753 | 752 | } |
| 753 | |
| 754 | bool queue_has_list_items(osd_work_queue *queue) |
| 755 | { |
| 756 | INT32 lockslot = osd_scalable_lock_acquire(queue->lock); |
| 757 | bool has_list_items = (queue->list != NULL); |
| 758 | osd_scalable_lock_release(queue->lock, lockslot); |
| 759 | return has_list_items; |
| 760 | } |