1886 } 1887 1888 return 0; 1889 } 1890 1891 int os::get_last_error() { 1892 DWORD error = GetLastError(); 1893 if (error == 0) { 1894 error = errno; 1895 } 1896 return (int)error; 1897 } 1898 1899 WindowsSemaphore::WindowsSemaphore(uint value) { 1900 _semaphore = ::CreateSemaphore(NULL, value, LONG_MAX, NULL); 1901 1902 guarantee(_semaphore != NULL, err_msg("CreateSemaphore failed with error code: %lu", GetLastError())); 1903 } 1904 1905 WindowsSemaphore::~WindowsSemaphore() { 1906 if (_semaphore != NULL) { 1907 ::CloseHandle(_semaphore); 1908 } 1909 } 1910 1911 void WindowsSemaphore::signal(uint count) { 1912 if (count > 0) { 1913 BOOL ret = ::ReleaseSemaphore(_semaphore, count, NULL); 1914 1915 assert(ret != 0, err_msg("ReleaseSemaphore failed with error code: %lu", GetLastError())); 1916 } 1917 } 1918 1919 void WindowsSemaphore::wait() { 1920 DWORD ret = ::WaitForSingleObject(_semaphore, INFINITE); 1921 assert(ret != WAIT_FAILED, err_msg("WaitForSingleObject failed with error code: %lu", GetLastError())); 1922 assert(ret == WAIT_OBJECT_0, err_msg("WaitForSingleObject failed with return value: %lu", ret)); 1923 } 1924 1925 // sun.misc.Signal 1926 // NOTE that this is a workaround for an apparent kernel bug where if 1927 // a signal handler for SIGBREAK is installed then that signal handler 1928 // takes priority over the console control handler for CTRL_CLOSE_EVENT. | 1886 } 1887 1888 return 0; 1889 } 1890 1891 int os::get_last_error() { 1892 DWORD error = GetLastError(); 1893 if (error == 0) { 1894 error = errno; 1895 } 1896 return (int)error; 1897 } 1898 1899 WindowsSemaphore::WindowsSemaphore(uint value) { 1900 _semaphore = ::CreateSemaphore(NULL, value, LONG_MAX, NULL); 1901 1902 guarantee(_semaphore != NULL, err_msg("CreateSemaphore failed with error code: %lu", GetLastError())); 1903 } 1904 1905 WindowsSemaphore::~WindowsSemaphore() { 1906 ::CloseHandle(_semaphore); 1907 } 1908 1909 void WindowsSemaphore::signal(uint count) { 1910 if (count > 0) { 1911 BOOL ret = ::ReleaseSemaphore(_semaphore, count, NULL); 1912 1913 assert(ret != 0, err_msg("ReleaseSemaphore failed with error code: %lu", GetLastError())); 1914 } 1915 } 1916 1917 void WindowsSemaphore::wait() { 1918 DWORD ret = ::WaitForSingleObject(_semaphore, INFINITE); 1919 assert(ret != WAIT_FAILED, err_msg("WaitForSingleObject failed with error code: %lu", GetLastError())); 1920 assert(ret == WAIT_OBJECT_0, err_msg("WaitForSingleObject failed with return value: %lu", ret)); 1921 } 1922 1923 // sun.misc.Signal 1924 // NOTE that this is a workaround for an apparent kernel bug where if 1925 // a signal handler for SIGBREAK is installed then that signal handler 1926 // takes priority over the console control handler for CTRL_CLOSE_EVENT. |