]> git.pond.sub.org Git - empserver/blobdiff - src/lib/empthread/ntthread.c
Fix trailing whitespace
[empserver] / src / lib / empthread / ntthread.c
index 9b05f7d97730d456389b4119316aeb669e4469df..68bd3ffb1945e5403ce457cd9d41c72500b92d55 100644 (file)
@@ -26,7 +26,7 @@
  *  ---
  *
  *  ntthread.c: Interface from Empire threads to Windows NT threads
- * 
+ *
  *  Known contributors to this file:
  *     Doug Hay, 1998
  *     Steve McClure, 1998
@@ -73,7 +73,7 @@
 struct loc_Thread {
 
     /* The thread name, passed in at create time. */
-    char szName[17];
+    char *szName;
 
     /* True if this is the main line, and not a real thread. */
     BOOL bMainThread;
@@ -135,7 +135,7 @@ struct loc_Thread {
  *
  */
 struct loc_RWLock {
-    char name[17];     /* The thread name, passed in at create time. */
+    char *name;                /* The lock name, passed in at create time. */
     HANDLE can_read;   /* Manual event -- allows read locks */
     HANDLE can_write;  /* Auto-reset event -- allows write locks */
     int nread;         /* number of active readers */
@@ -224,6 +224,8 @@ loc_FreeThreadInfo(empth_t *pThread)
     if (pThread) {
        if (pThread->hThreadEvent)
            CloseHandle(pThread->hThreadEvent);
+       if (pThread->szName != NULL)
+           free(pThread->szName);
        memset(pThread, 0, sizeof(*pThread));
        free(pThread);
     }
@@ -302,12 +304,12 @@ loc_BlockThisThread(void)
 static BOOL WINAPI
 loc_Exit_Handler(DWORD fdwCtrlType)
 {
-    switch (fdwCtrlType) { 
+    switch (fdwCtrlType) {
         case CTRL_C_EVENT:
         case CTRL_CLOSE_EVENT:
-        case CTRL_BREAK_EVENT: 
-        case CTRL_LOGOFF_EVENT: 
-        case CTRL_SHUTDOWN_EVENT: 
+        case CTRL_BREAK_EVENT:
+        case CTRL_LOGOFF_EVENT:
+        case CTRL_SHUTDOWN_EVENT:
            empth_request_shutdown();
             return TRUE;
         default:
@@ -403,7 +405,7 @@ empth_init(void **ctx_ptr, int flags)
     }
     memset(pThread, 0, sizeof(*pThread));
 
-    strncpy(pThread->szName, "Main", sizeof(pThread->szName) - 1);
+    pThread->szName = strdup("Main");
     pThread->ulThreadID = GetCurrentThreadId();
     pThread->bMainThread = TRUE;
 
@@ -446,7 +448,7 @@ empth_create(void (*entry)(void *), int size, int flags,
     }
     memset(pThread, 0, sizeof(*pThread));
 
-    strncpy(pThread->szName, name, sizeof(pThread->szName) - 1);
+    pThread->szName = strdup(name);
     pThread->pvUserData = ud;
     pThread->pfnEntry = entry;
     pThread->bMainThread = FALSE;
@@ -458,7 +460,7 @@ empth_create(void (*entry)(void *), int size, int flags,
        size = loc_MIN_THREAD_STACK;
 
     pThread->ulThreadID = _beginthread(empth_threadMain, size, pThread);
-    if (pThread->ulThreadID == 1L) {
+    if (pThread->ulThreadID == 1L || pThread->ulThreadID == 0L) {
        logerror("can not create thread: %s: %s", name, strerror(errno));
        goto bad;
     }
@@ -502,7 +504,9 @@ empth_name(empth_t *thread)
 void
 empth_set_name(empth_t *thread, char *name)
 {
-    strncpy(thread->szName, name, sizeof(thread->szName) - 1);
+    if (thread->szName != NULL)
+       free(thread->szName);
+    thread->szName = strdup(name);
 }
 
 /************************
@@ -662,11 +666,12 @@ empth_rwlock_create(char *name)
        return NULL;
 
     memset(rwlock, 0, sizeof(*rwlock));
-    strncpy(rwlock->name, name, sizeof(rwlock->name) - 1);
+    rwlock->name = strdup(name);
 
     if ((rwlock->can_read = CreateEvent(NULL, TRUE, TRUE, NULL)) == NULL) {
        logerror("rwlock_create: failed to create reader event %s at %s:%d",
            name, __FILE__, __LINE__);
+       free(rwlock->name);
        free(rwlock);
        return NULL;
     }
@@ -674,6 +679,7 @@ empth_rwlock_create(char *name)
     if ((rwlock->can_write = CreateEvent(NULL, FALSE, TRUE, NULL)) == NULL) {
        logerror("rwlock_create: failed to create writer event %s at %s:%d",
            name, __FILE__, __LINE__);
+       free(rwlock->name);
        CloseHandle(rwlock->can_read);
        free(rwlock);
        return NULL;
@@ -686,6 +692,8 @@ empth_rwlock_destroy(empth_rwlock_t *rwlock)
 {
     if (CANT_HAPPEN(rwlock->nread || rwlock->nwrite))
        return;
+    if (rwlock->name != NULL)
+       free(rwlock->name);
     CloseHandle(rwlock->can_read);
     CloseHandle(rwlock->can_write);
     free(rwlock);