リビジョン | 21285dae9b58ab00e79c8c25fc86267fd95b8d88 (tree) |
---|---|
日時 | 2020-09-06 06:51:47 |
作者 | Starg <starg@user...> |
コミッター | Starg |
Merge dev41
@@ -5601,19 +5601,33 @@ static struct | ||
5601 | 5601 | } rc_queue[RC_QUEUE_SIZE]; |
5602 | 5602 | static volatile int rc_queue_len, rc_queue_beg, rc_queue_end; |
5603 | 5603 | |
5604 | +#define TIMW32G_USE_USERMODE_LOCKS | |
5605 | +#ifdef TIMW32G_USE_USERMODE_LOCKS | |
5606 | +static SRWLOCK w32g_lock_srwlock = SRWLOCK_INIT; | |
5607 | +static CONDITION_VARIABLE w32g_lock_cv = CONDITION_VARIABLE_INIT; | |
5608 | +#else | |
5604 | 5609 | static HANDLE w32g_lock_sem = NULL; |
5605 | 5610 | static HANDLE w32g_empty_sem = NULL; |
5611 | +#endif | |
5606 | 5612 | |
5607 | 5613 | void w32g_lock(void) |
5608 | 5614 | { |
5615 | +#ifdef TIMW32G_USE_USERMODE_LOCKS | |
5616 | + AcquireSRWLockExclusive(&w32g_lock_srwlock); | |
5617 | +#else | |
5609 | 5618 | if(w32g_lock_sem) |
5610 | 5619 | WaitForSingleObject(w32g_lock_sem, INFINITE); |
5620 | +#endif | |
5611 | 5621 | } |
5612 | 5622 | |
5613 | 5623 | void w32g_unlock(void) |
5614 | 5624 | { |
5625 | +#ifdef TIMW32G_USE_USERMODE_LOCKS | |
5626 | + ReleaseSRWLockExclusive(&w32g_lock_srwlock); | |
5627 | +#else | |
5615 | 5628 | if(w32g_lock_sem) |
5616 | 5629 | ReleaseSemaphore(w32g_lock_sem, 1, NULL); |
5630 | +#endif | |
5617 | 5631 | } |
5618 | 5632 | |
5619 | 5633 | void w32g_send_rc(int rc, ptr_size_t value) |
@@ -5631,26 +5645,45 @@ void w32g_send_rc(int rc, ptr_size_t value) | ||
5631 | 5645 | rc_queue[rc_queue_end].rc = rc; |
5632 | 5646 | rc_queue[rc_queue_end].value = value; |
5633 | 5647 | rc_queue_end = (rc_queue_end + 1) % RC_QUEUE_SIZE; |
5648 | +#ifdef TIMW32G_USE_USERMODE_LOCKS | |
5649 | + w32g_unlock(); | |
5650 | + WakeConditionVariable(&w32g_lock_cv); | |
5651 | +#else | |
5634 | 5652 | if(w32g_empty_sem) |
5635 | 5653 | ReleaseSemaphore(w32g_empty_sem, 1, NULL); |
5636 | 5654 | w32g_unlock(); |
5655 | +#endif | |
5637 | 5656 | } |
5638 | 5657 | |
5639 | 5658 | int w32g_get_rc(ptr_size_t *value, int wait_if_empty) |
5640 | 5659 | { |
5641 | 5660 | int rc; |
5661 | +#ifdef TIMW32G_USE_USERMODE_LOCKS | |
5662 | + w32g_lock(); | |
5663 | +#endif | |
5642 | 5664 | |
5643 | 5665 | while(rc_queue_len == 0) |
5644 | 5666 | { |
5645 | 5667 | if(!wait_if_empty) |
5646 | - return RC_NONE; | |
5668 | + { | |
5669 | +#ifdef TIMW32G_USE_USERMODE_LOCKS | |
5670 | + w32g_unlock(); | |
5671 | +#endif | |
5672 | + return RC_NONE; | |
5673 | + } | |
5674 | +#ifdef TIMW32G_USE_USERMODE_LOCKS | |
5675 | + SleepConditionVariableSRW(&w32g_lock_cv, &w32g_lock_srwlock, INFINITE, 0); | |
5676 | +#else | |
5647 | 5677 | if(w32g_empty_sem) |
5648 | 5678 | WaitForSingleObject(w32g_empty_sem, INFINITE); |
5679 | +#endif | |
5649 | 5680 | VOLATILE_TOUCH(rc_queue_len); |
5650 | 5681 | } |
5651 | 5682 | |
5652 | - w32g_lock(); | |
5653 | - rc = rc_queue[rc_queue_beg].rc; | |
5683 | +#ifndef TIMW32G_USE_USERMODE_LOCKS | |
5684 | + w32g_lock(); | |
5685 | +#endif | |
5686 | + rc = rc_queue[rc_queue_beg].rc; | |
5654 | 5687 | *value = rc_queue[rc_queue_beg].value; |
5655 | 5688 | rc_queue_len--; |
5656 | 5689 | rc_queue_beg = (rc_queue_beg + 1) % RC_QUEUE_SIZE; |
@@ -5664,8 +5697,10 @@ int w32g_open(void) | ||
5664 | 5697 | SaveSettingTiMidity(st_current); |
5665 | 5698 | memcpy(st_temp, st_current, sizeof(SETTING_TIMIDITY)); |
5666 | 5699 | |
5700 | +#ifndef TIMW32G_USE_USERMODE_LOCKS | |
5667 | 5701 | w32g_lock_sem = CreateSemaphore(NULL, 1, 1, _T("TiMidity Mutex Lock")); |
5668 | 5702 | w32g_empty_sem = CreateSemaphore(NULL, 0, 8, _T("TiMidity Empty Lock")); |
5703 | +#endif | |
5669 | 5704 | |
5670 | 5705 | hPlayerThread = GetCurrentThread(); |
5671 | 5706 | w32g_wait_for_init = 1; |
@@ -5703,6 +5738,7 @@ static void terminate_main_thread(void) | ||
5703 | 5738 | void w32g_close(void) |
5704 | 5739 | { |
5705 | 5740 | terminate_main_thread(); |
5741 | +#ifndef TIMW32G_USE_USERMODE_LOCKS | |
5706 | 5742 | if(w32g_lock_sem){ |
5707 | 5743 | CloseHandle(w32g_lock_sem); |
5708 | 5744 | w32g_lock_sem = NULL; |
@@ -5711,6 +5747,7 @@ void w32g_close(void) | ||
5711 | 5747 | CloseHandle(w32g_empty_sem); |
5712 | 5748 | w32g_empty_sem = NULL; |
5713 | 5749 | } |
5750 | +#endif | |
5714 | 5751 | } |
5715 | 5752 | |
5716 | 5753 | void w32g_restart(void) |
@@ -5718,6 +5755,7 @@ void w32g_restart(void) | ||
5718 | 5755 | w32g_restart_gui_flag = 1; |
5719 | 5756 | |
5720 | 5757 | terminate_main_thread(); |
5758 | +#ifndef TIMW32G_USE_USERMODE_LOCKS | |
5721 | 5759 | if(w32g_lock_sem){ |
5722 | 5760 | CloseHandle(w32g_lock_sem); |
5723 | 5761 | w32g_lock_sem = NULL; |
@@ -5726,6 +5764,7 @@ void w32g_restart(void) | ||
5726 | 5764 | CloseHandle(w32g_empty_sem); |
5727 | 5765 | w32g_empty_sem = NULL; |
5728 | 5766 | } |
5767 | +#endif | |
5729 | 5768 | |
5730 | 5769 | /* Reset variable */ |
5731 | 5770 | hDebugEditWnd = 0; |
@@ -1646,6 +1646,7 @@ private: | ||
1646 | 1646 | |
1647 | 1647 | // TODO: support trigger=release |
1648 | 1648 | case TriggerKind::Release: |
1649 | + if (i == 0) | |
1649 | 1650 | { |
1650 | 1651 | auto loc = flatSection.GetLocationForOpCode(OpCodeKind::Trigger); |
1651 | 1652 | ctl->cmsg( |
@@ -1668,6 +1669,7 @@ private: | ||
1668 | 1669 | case TriggerKind::First: |
1669 | 1670 | case TriggerKind::Legato: |
1670 | 1671 | default: |
1672 | + if (i == 0) | |
1671 | 1673 | { |
1672 | 1674 | auto loc = flatSection.GetLocationForOpCode(OpCodeKind::Trigger); |
1673 | 1675 | ctl->cmsg( |
@@ -1729,39 +1731,48 @@ private: | ||
1729 | 1731 | |
1730 | 1732 | if (s.seq_length < s.seq_position) |
1731 | 1733 | { |
1732 | - auto loc = flatSection.GetLocationForOpCode(OpCodeKind::SequencePosition); | |
1734 | + if (i == 0) | |
1735 | + { | |
1736 | + auto loc = flatSection.GetLocationForOpCode(OpCodeKind::SequencePosition); | |
1737 | + ctl->cmsg( | |
1738 | + CMSG_WARNING, | |
1739 | + VERB_VERBOSE, | |
1740 | + "%s(%u): 'seq_position' is larger than 'seq_length'; this region will never be played", | |
1741 | + std::string(m_Parser.GetPreprocessor().GetFileNameFromID(loc.FileID)).c_str(), | |
1742 | + static_cast<std::uint32_t>(loc.Line) | |
1743 | + ); | |
1744 | + } | |
1745 | + } | |
1746 | + } | |
1747 | + else | |
1748 | + { | |
1749 | + if (i == 0) | |
1750 | + { | |
1751 | + auto loc = flatSection.GetLocationForOpCode(OpCodeKind::SequenceLength); | |
1733 | 1752 | ctl->cmsg( |
1734 | 1753 | CMSG_WARNING, |
1735 | 1754 | VERB_VERBOSE, |
1736 | - "%s(%u): 'seq_position' is larger than 'seq_length'; this region will never be played", | |
1755 | + "%s(%u): 'seq_length' was specified but 'seq_position' was not; this region will never be played", | |
1737 | 1756 | std::string(m_Parser.GetPreprocessor().GetFileNameFromID(loc.FileID)).c_str(), |
1738 | 1757 | static_cast<std::uint32_t>(loc.Line) |
1739 | 1758 | ); |
1740 | 1759 | } |
1741 | 1760 | } |
1742 | - else | |
1761 | + } | |
1762 | + else if (auto seqPos = flatSection.GetAs<double>(OpCodeKind::SequencePosition)) | |
1763 | + { | |
1764 | + if (i == 0) | |
1743 | 1765 | { |
1744 | - auto loc = flatSection.GetLocationForOpCode(OpCodeKind::SequenceLength); | |
1766 | + auto loc = flatSection.GetLocationForOpCode(OpCodeKind::SequencePosition); | |
1745 | 1767 | ctl->cmsg( |
1746 | 1768 | CMSG_WARNING, |
1747 | 1769 | VERB_VERBOSE, |
1748 | - "%s(%u): 'seq_length' was specified but 'seq_position' was not; this region will never be played", | |
1770 | + "%s(%u): 'seq_position' was specified but 'seq_length' was not", | |
1749 | 1771 | std::string(m_Parser.GetPreprocessor().GetFileNameFromID(loc.FileID)).c_str(), |
1750 | 1772 | static_cast<std::uint32_t>(loc.Line) |
1751 | 1773 | ); |
1752 | 1774 | } |
1753 | 1775 | } |
1754 | - else if (auto seqPos = flatSection.GetAs<double>(OpCodeKind::SequencePosition)) | |
1755 | - { | |
1756 | - auto loc = flatSection.GetLocationForOpCode(OpCodeKind::SequencePosition); | |
1757 | - ctl->cmsg( | |
1758 | - CMSG_WARNING, | |
1759 | - VERB_VERBOSE, | |
1760 | - "%s(%u): 'seq_position' was specified but 'seq_length' was not", | |
1761 | - std::string(m_Parser.GetPreprocessor().GetFileNameFromID(loc.FileID)).c_str(), | |
1762 | - static_cast<std::uint32_t>(loc.Line) | |
1763 | - ); | |
1764 | - } | |
1765 | 1776 | |
1766 | 1777 | if (auto loRand = flatSection.GetAs<double>(OpCodeKind::LoRand)) |
1767 | 1778 | { |
@@ -1859,15 +1870,18 @@ private: | ||
1859 | 1870 | // sw_down is invalid; disable it |
1860 | 1871 | s.sw_down = -1; |
1861 | 1872 | |
1862 | - auto loc = flatSection.GetLocationForOpCode(OpCodeKind::SwDown); | |
1863 | - | |
1864 | - ctl->cmsg( | |
1865 | - CMSG_WARNING, | |
1866 | - VERB_VERBOSE, | |
1867 | - "%s(%u): 'sw_down' was specified but it is outside the range specified by 'sw_lokey' and 'sw_hikey'", | |
1868 | - std::string(m_Parser.GetPreprocessor().GetFileNameFromID(loc.FileID)).c_str(), | |
1869 | - static_cast<std::uint32_t>(loc.Line) | |
1870 | - ); | |
1873 | + if (i == 0) | |
1874 | + { | |
1875 | + auto loc = flatSection.GetLocationForOpCode(OpCodeKind::SwDown); | |
1876 | + | |
1877 | + ctl->cmsg( | |
1878 | + CMSG_WARNING, | |
1879 | + VERB_VERBOSE, | |
1880 | + "%s(%u): 'sw_down' was specified but it is outside the range specified by 'sw_lokey' and 'sw_hikey'", | |
1881 | + std::string(m_Parser.GetPreprocessor().GetFileNameFromID(loc.FileID)).c_str(), | |
1882 | + static_cast<std::uint32_t>(loc.Line) | |
1883 | + ); | |
1884 | + } | |
1871 | 1885 | } |
1872 | 1886 | } |
1873 | 1887 | else |
@@ -1884,15 +1898,18 @@ private: | ||
1884 | 1898 | // sw_up is invalid; disable it |
1885 | 1899 | s.sw_up = -1; |
1886 | 1900 | |
1887 | - auto loc = flatSection.GetLocationForOpCode(OpCodeKind::SwUp); | |
1888 | - | |
1889 | - ctl->cmsg( | |
1890 | - CMSG_WARNING, | |
1891 | - VERB_VERBOSE, | |
1892 | - "%s(%u): 'sw_up' was specified but it is outside the range specified by 'sw_lokey' and 'sw_hikey'", | |
1893 | - std::string(m_Parser.GetPreprocessor().GetFileNameFromID(loc.FileID)).c_str(), | |
1894 | - static_cast<std::uint32_t>(loc.Line) | |
1895 | - ); | |
1901 | + if (i == 0) | |
1902 | + { | |
1903 | + auto loc = flatSection.GetLocationForOpCode(OpCodeKind::SwUp); | |
1904 | + | |
1905 | + ctl->cmsg( | |
1906 | + CMSG_WARNING, | |
1907 | + VERB_VERBOSE, | |
1908 | + "%s(%u): 'sw_up' was specified but it is outside the range specified by 'sw_lokey' and 'sw_hikey'", | |
1909 | + std::string(m_Parser.GetPreprocessor().GetFileNameFromID(loc.FileID)).c_str(), | |
1910 | + static_cast<std::uint32_t>(loc.Line) | |
1911 | + ); | |
1912 | + } | |
1896 | 1913 | } |
1897 | 1914 | } |
1898 | 1915 | else |