| 875 | { |
| 876 | public: |
| 877 | explicit GlobalPortLock(int id) |
| 878 | : handle(INVALID_HANDLE_VALUE) |
| 879 | { |
| 880 | if (id) |
| 881 | { |
| 882 | TEXT mutex_name[MAXPATHLEN]; |
| 883 | fb_utils::snprintf(mutex_name, sizeof(mutex_name), "FirebirdPortMutex%d", id); |
| 884 | fb_utils::prefix_kernel_object_name(mutex_name, sizeof(mutex_name)); |
| 885 | |
| 886 | if (!(handle = CreateMutex(ISC_get_security_desc(), FALSE, mutex_name))) |
| 887 | { |
| 888 | // MSDN: if the caller has limited access rights, the function will fail with |
| 889 | // ERROR_ACCESS_DENIED and the caller should use the OpenMutex function. |
| 890 | if (GetLastError() == ERROR_ACCESS_DENIED) |
| 891 | system_call_failed::raise("CreateMutex - cannot open existing mutex"); |
| 892 | else |
| 893 | system_call_failed::raise("CreateMutex"); |
| 894 | } |
| 895 | |
| 896 | if (WaitForSingleObject(handle, INFINITE) == WAIT_FAILED) |
| 897 | { |
| 898 | system_call_failed::raise("WaitForSingleObject"); |
| 899 | } |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | ~GlobalPortLock() |
| 904 | { |
nothing calls this directly
no test coverage detected