< prev index next >

src/os/windows/vm/os_windows.cpp

Print this page




1882     if (n >= len) n = len - 1;
1883     strncpy(buf, s, n);
1884     buf[n] = '\0';
1885     return n;
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 Semaphore::Semaphore(uint value, uint max) {
1900   _semaphore = ::CreateSemaphore(NULL, value, max, NULL);
1901 
1902   guarantee(_semaphore != NULL, err_msg("CreateSemaphore failed: %ld", GetLastError()));
1903 }
1904 
1905 Semaphore::~Semaphore() {
1906   if (_semaphore != NULL) {
1907     ::CloseHandle(_semaphore);
1908   }
1909 }
1910 
1911 void Semaphore::signal(uint count) {
1912   BOOL ret = ::ReleaseSemaphore(_semaphore, count, NULL);
1913 
1914   guarantee(ret != 0, err_msg("ReleaseSemaphore failed: %d", GetLastError()));
1915 }
1916 
1917 void Semaphore::signal() {
1918   signal(1);
1919 }
1920 
1921 void Semaphore::wait() {
1922   DWORD ret = ::WaitForSingleObject(_semaphore, INFINITE);
1923   guarantee(ret == WAIT_OBJECT_0, err_msg("WaitForSingleObject failed: %d", GetLastError()));
1924 }
1925 
1926 bool Semaphore::trywait() {
1927   Unimplemented();
1928   return false;
1929 }
1930 
1931 bool Semaphore::timedwait(unsigned int sec, int nsec) {
1932   Unimplemented();
1933   return false;
1934 }
1935 
1936 // sun.misc.Signal
1937 // NOTE that this is a workaround for an apparent kernel bug where if
1938 // a signal handler for SIGBREAK is installed then that signal handler
1939 // takes priority over the console control handler for CTRL_CLOSE_EVENT.
1940 // See bug 4416763.
1941 static void (*sigbreakHandler)(int) = NULL;
1942 
1943 static void UserHandler(int sig, void *siginfo, void *context) {
1944   os::signal_notify(sig);
1945   // We need to reinstate the signal handler each time...
1946   os::signal(sig, (void*)UserHandler);
1947 }
1948 
1949 void* os::user_handler() {
1950   return (void*) UserHandler;
1951 }
1952 
1953 void* os::signal(int signal_number, void* handler) {




1882     if (n >= len) n = len - 1;
1883     strncpy(buf, s, n);
1884     buf[n] = '\0';
1885     return n;
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 Semaphore::Semaphore(uint value, uint max) {
1900   _semaphore = ::CreateSemaphore(NULL, value, max, NULL);
1901 
1902   assert(_semaphore != NULL, err_msg("CreateSemaphore failed: %ld", GetLastError()));
1903 }
1904 
1905 Semaphore::~Semaphore() {
1906   if (_semaphore != NULL) {
1907     ::CloseHandle(_semaphore);
1908   }
1909 }
1910 
1911 void Semaphore::signal(uint count) {
1912   BOOL ret = ::ReleaseSemaphore(_semaphore, count, NULL);
1913 
1914   assert(ret != 0, err_msg("ReleaseSemaphore failed: %d", GetLastError()));
1915 }
1916 
1917 void Semaphore::signal() {
1918   signal(1);
1919 }
1920 
1921 void Semaphore::wait() {
1922   DWORD ret = ::WaitForSingleObject(_semaphore, INFINITE);
1923   assert(ret == WAIT_OBJECT_0, err_msg("WaitForSingleObject failed: %d", GetLastError()));










1924 }
1925 
1926 // sun.misc.Signal
1927 // NOTE that this is a workaround for an apparent kernel bug where if
1928 // a signal handler for SIGBREAK is installed then that signal handler
1929 // takes priority over the console control handler for CTRL_CLOSE_EVENT.
1930 // See bug 4416763.
1931 static void (*sigbreakHandler)(int) = NULL;
1932 
1933 static void UserHandler(int sig, void *siginfo, void *context) {
1934   os::signal_notify(sig);
1935   // We need to reinstate the signal handler each time...
1936   os::signal(sig, (void*)UserHandler);
1937 }
1938 
1939 void* os::user_handler() {
1940   return (void*) UserHandler;
1941 }
1942 
1943 void* os::signal(int signal_number, void* handler) {


< prev index next >