| 13 | |
| 14 | |
| 15 | cEvent::cEvent(void) |
| 16 | { |
| 17 | #ifdef _WIN32 |
| 18 | m_Event = CreateEvent(NULL, FALSE, FALSE, NULL); |
| 19 | if (m_Event == NULL) |
| 20 | { |
| 21 | LOGERROR("cEvent: cannot create event, GLE = %d. Aborting server.", GetLastError()); |
| 22 | abort(); |
| 23 | } |
| 24 | #else // *nix |
| 25 | m_bIsNamed = false; |
| 26 | m_Event = new sem_t; |
| 27 | if (sem_init(m_Event, 0, 0)) |
| 28 | { |
| 29 | // This path is used by MacOS, because it doesn't support unnamed semaphores. |
| 30 | delete m_Event; |
| 31 | m_bIsNamed = true; |
| 32 | |
| 33 | AString EventName; |
| 34 | Printf(EventName, "cEvent%p", this); |
| 35 | m_Event = sem_open(EventName.c_str(), O_CREAT, 777, 0 ); |
| 36 | if (m_Event == SEM_FAILED) |
| 37 | { |
| 38 | AString error = GetOSErrorString(errno); |
| 39 | LOGERROR("cEvent: Cannot create event, err = %s. Aborting server.", error.c_str()); |
| 40 | abort(); |
| 41 | } |
| 42 | // Unlink the semaphore immediately - it will continue to function but will not pollute the namespace |
| 43 | // We don't store the name, so can't call this in the destructor |
| 44 | if (sem_unlink(EventName.c_str()) != 0) |
| 45 | { |
| 46 | AString error = GetOSErrorString(errno); |
| 47 | LOGWARN("ERROR: Could not unlink cEvent. (%s)", error.c_str()); |
| 48 | } |
| 49 | } |
| 50 | #endif // *nix |
| 51 | } |
| 52 | |
| 53 | |
| 54 |
nothing calls this directly
no test coverage detected