* Makefile.in (BUILDTOP, LIBNAME, XTRA, OBJFILE): Define for Windows.
authorKen Raeburn <raeburn@mit.edu>
Fri, 18 Jun 2004 22:49:55 +0000 (22:49 +0000)
committerKen Raeburn <raeburn@mit.edu>
Fri, 18 Jun 2004 22:49:55 +0000 (22:49 +0000)
(LIBOBJS): Define.
($(BUILDTOP)/include/krb5/autoconf.h): Disable rule on Windows.

* threads.c (tls_idx, key_lock, destructors, destructors_set): New variables
for Windows.
(krb5int_thread_support_init, krb5int_thread_support_fini, k5_key_register,
k5_getspecific, k5_setspecific, k5_key_delete, krb5int_thread_detach_hook):
New functions for Windows.  Some are just placeholders.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16482 dc483132-0cff-0310-8789-dd5450dbe970

src/util/support/ChangeLog
src/util/support/Makefile.in
src/util/support/threads.c

index f4019c0a3b32b5bc9d8c98e616b3bf88d80ed837..15d2eff1a70dfa1cadf99f0148ac0c2cecee4fcb 100644 (file)
@@ -1,3 +1,17 @@
+2004-06-17  Ken Raeburn  <raeburn@mit.edu>
+
+       * Makefile.in (BUILDTOP, LIBNAME, XTRA, OBJFILE): Define for
+       Windows.
+       (LIBOBJS): Define.
+       ($(BUILDTOP)/include/krb5/autoconf.h): Disable rule on Windows.
+
+       * threads.c (tls_idx, key_lock, destructors, destructors_set): New
+       variables for Windows.
+       (krb5int_thread_support_init, krb5int_thread_support_fini,
+       k5_key_register, k5_getspecific, k5_setspecific, k5_key_delete,
+       krb5int_thread_detach_hook): New functions for Windows.  Some are
+       just placeholders.
+
 2004-06-14  Ken Raeburn  <raeburn@mit.edu>
 
        * libkrb5support.exports: Drop krb5int_foreach_localaddr.
index 618c01f46635e66b2ca5f9da3e677dfccc81a159..6ce7bdaba847140160471167e053f7991c15db5f 100644 (file)
@@ -4,6 +4,11 @@ mydir=util/support
 BUILDTOP=$(REL)..$(S)..
 RELDIR=../util/support
 
+##DOS##BUILDTOP = ..\..
+##DOS##LIBNAME=$(OUTPRE)krb5support_32.lib
+##DOS##XTRA=
+##DOS##OBJFILE=$(OUTPRE)krb5support_32.lst
+
 SED = sed
 
 KRB5_RUN_ENV= @KRB5_RUN_ENV@
@@ -20,6 +25,9 @@ LIBFINIFUNC=krb5int_thread_support_fini
 STLIBOBJS= \
        threads.o
 
+LIBOBJS= \
+       $(OUTPRE)threads.$(OBJEXT)
+
 STOBJLISTS=OBJS.ST
 
 INSTALLFILE = cp
@@ -42,9 +50,10 @@ install-unix:: install-libs
 
 clean-unix:: clean-liblinks clean-libs clean-libobjs
 
+##DOS##!if 0
 $(BUILDTOP)/include/krb5/autoconf.h: $(SRCTOP)/include/krb5/autoconf.h.in
        (cd $(BUILDTOP)/include; $(MAKE) krb5/autoconf.h)
-
+##DOS##!endif
 
 # @lib_frag@
 # @libobj_frag@
index 1b5d1723ed52e5a017908f2ca4653fc2b0e69749..13a2e420f54f0cc3892bb7177306ba1c1d4861fe 100644 (file)
 MAKE_INIT_FUNCTION(krb5int_thread_support_init);
 MAKE_FINI_FUNCTION(krb5int_thread_support_fini);
 
+\f
 #ifdef ENABLE_THREADS
 
 #ifdef _WIN32
 
-#error "need WIN32 thread support code written"
+static DWORD tls_idx;
+CRITICAL_SECTION key_lock;
+static void (*destructors[K5_KEY_MAX])(void *);
+static unsigned char destructors_set[K5_KEY_MAX];
+
+int krb5int_thread_support_init (void)
+{
+    tls_idx = TlsAlloc();
+    /* XXX This can raise an exception if memory is low!  */
+    InitializeCriticalSection(&key_lock);
+    return 0;
+}
+
+void krb5int_thread_support_fini (void)
+{
+    if (! INITIALIZER_RAN (krb5int_thread_support_init))
+       return;
+    /* ... free stuff ... */
+    TlsFree(tls_idx);
+    DeleteCriticalSection(&key_lock);
+}
+
+int k5_key_register (k5_key_t keynum, void (*destructor)(void *))
+{
+    DWORD wait_result;
+
+    assert(keynum >= 0 && keynum < K5_KEY_MAX);
+    /* XXX: This can raise EXCEPTION_POSSIBLE_DEADLOCK.  */
+    EnterCriticalSection(&key_lock);
+    assert(destructors_set[keynum] == 0);
+    destructors_set[keynum] = 1;
+    destructors[keynum] = destructor;
+    LeaveCriticalSection(&key_lock);
+    return 0;
+}
+
+void *k5_getspecific (k5_key_t keynum)
+{
+    struct tsd_block *t;
+
+    err = CALL_INIT_FUNCTION(krb5int_thread_support_init);
+    if (err)
+       return NULL;
+
+    assert(keynum >= 0 && keynum < K5_KEY_MAX);
+
+    t = TlsGetValue(tls_idx);
+    if (t == NULL)
+       return NULL;
+    return t->values[keynum];
+}
+
+int k5_setspecific (k5_key_t keynum, void *value)
+{
+    struct tsd_block *t;
+
+    err = CALL_INIT_FUNCTION(krb5int_thread_support_init);
+    if (err)
+       return NULL;
+
+    assert(keynum >= 0 && keynum < K5_KEY_MAX);
+
+    t = TlsGetValue(tls_idx);
+    if (t == NULL) {
+       int i;
+       t = malloc(sizeof(*t));
+       if (t == NULL)
+           return errno;
+       for (i = 0; i < K5_KEY_MAX; i++)
+           t->values[i] = 0;
+       /* add to global linked list */
+       t->next = 0;
+       err = TlsSetValue(key, t);
+       if (err) {
+           free(t);
+           return err;
+       }
+    }
+    t->values[keynum] = value;
+    return 0;
+}
+
+int k5_key_delete (k5_key_t keynum)
+{
+    assert(keynum >= 0 && keynum < K5_KEY_MAX);
+    /* XXX: This can raise EXCEPTION_POSSIBLE_DEADLOCK.  */
+    EnterCriticalSection(&key_lock);
+    abort();
+    LeaveCriticalSection(&key_lock);
+    return 0;
+}
+
+void krb5int_thread_detach_hook (void)
+{
+    /* XXX Memory leak here!
+       Need to destroy all TLS objects we know about for this thread.  */
+}
 
+\f
 #else
 
 /* POSIX */
@@ -79,6 +177,7 @@ int krb5int_thread_support_init(void)
 
 void krb5int_thread_support_fini(void)
 {
+    /* ... delete stuff ... */
     if (INITIALIZER_RAN(krb5int_thread_support_init))
        pthread_key_delete(key);
 }
@@ -188,7 +287,9 @@ int k5_key_delete (k5_key_t keynum)
 
 #endif /* Win32 vs POSIX */
 
+\f
 #else
+/* no thread support */
 
 static void (*destructors[K5_KEY_MAX])(void *);
 static void *tsd_values[K5_KEY_MAX];