diff options
| author | Ken Raeburn <raeburn@mit.edu> | 2004-07-07 06:17:28 +0000 |
|---|---|---|
| committer | Ken Raeburn <raeburn@mit.edu> | 2004-07-07 06:17:28 +0000 |
| commit | 4d7c3d1c1cd88396ff19e9f808d9a2394d54575d (patch) | |
| tree | 4b059a8399e31cb9bad380dc247b5ea8786327dd /src/include | |
| parent | aa2e82af675d2436e8f4347940d27a272ed1ba8f (diff) | |
| download | krb5-4d7c3d1c1cd88396ff19e9f808d9a2394d54575d.tar.gz krb5-4d7c3d1c1cd88396ff19e9f808d9a2394d54575d.tar.xz krb5-4d7c3d1c1cd88396ff19e9f808d9a2394d54575d.zip | |
* k5-thread.h [! HAVE_PTHREAD_H]: Don't explicitly disable thread support when
pthread.h is missing.
(k5_os_mutex, K5_OS_MUTEX_PARTIAL_INITIALIZER, k5_os_mutex_finish_init,
k5_os_mutex_init, k5_os_mutex_destroy, k5_os_mutex_lock, k5_os_mutex_unlock,
k5_os_mutex_assert_unlocked, k5_os_mutex_assert_locked) [_WIN32]: Define
Windows versions; still not enabled by default.
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16552 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/ChangeLog | 10 | ||||
| -rw-r--r-- | src/include/k5-thread.h | 45 |
2 files changed, 50 insertions, 5 deletions
diff --git a/src/include/ChangeLog b/src/include/ChangeLog index 4bee9f7afe..97a3785eeb 100644 --- a/src/include/ChangeLog +++ b/src/include/ChangeLog @@ -1,3 +1,13 @@ +2004-07-07 Ken Raeburn <raeburn@mit.edu> + + * k5-thread.h [! HAVE_PTHREAD_H]: Don't explicitly disable thread + support when pthread.h is missing. + (k5_os_mutex, K5_OS_MUTEX_PARTIAL_INITIALIZER, + k5_os_mutex_finish_init, k5_os_mutex_init, k5_os_mutex_destroy, + k5_os_mutex_lock, k5_os_mutex_unlock, k5_os_mutex_assert_unlocked, + k5_os_mutex_assert_locked) [_WIN32]: Define Windows versions; + still not enabled by default. + 2004-07-06 Ken Raeburn <raeburn@mit.edu> * k5-thread.h: Use K5_THREAD_H for multiple inclusion protection. diff --git a/src/include/k5-thread.h b/src/include/k5-thread.h index 07dae107d8..9229f94371 100644 --- a/src/include/k5-thread.h +++ b/src/include/k5-thread.h @@ -137,10 +137,6 @@ More to be added, perhaps. */ -#ifndef HAVE_PTHREAD_H -# undef ENABLE_THREADS -#endif - #define DEBUG_THREADS #define DEBUG_THREADS_LOC #undef DEBUG_THREADS_STATS @@ -464,7 +460,46 @@ typedef struct { #elif defined _WIN32 -# error "Windows thread support not implemented yet" +typedef struct { + HANDLE h; + int is_locked; +} k5_os_mutex; + +# define K5_OS_MUTEX_PARTIAL_INITIALIZER { INVALID_HANDLE_VALUE, 0 } + +# define k5_os_mutex_finish_init(M) \ + (assert((M)->h == INVALID_HANDLE_VALUE), \ + ((M)->h = CreateMutex(NULL, FALSE, NULL)) ? 0 : GetLastError()) +# define k5_os_mutex_init(M) \ + ((M)->is_locked = 0, \ + ((M)->h = CreateMutex(NULL, FALSE, NULL)) ? 0 : GetLastError()) +# define k5_os_mutex_destroy(M) \ + (CloseHandle((M)->h) ? ((M)->h = 0, 0) : GetLastError()) + +static inline int k5_os_mutex_lock(k5_os_mutex *m) +{ + DWORD res; + res = WaitForSingleObject(m->h, INFINITE); + if (res == WAIT_FAILED) + return GetLastError(); + /* Eventually these should be turned into some reasonable error + code. */ + assert(res != WAIT_TIMEOUT); + assert(res != WAIT_ABANDONED); + assert(res == WAIT_OBJECT_0); + /* Avoid locking twice. */ + assert(m->is_locked == 0); + m->is_locked = 1; + return 0; +} + +# define k5_os_mutex_unlock(M) \ + (assert((M)->is_locked == 1), \ + (M)->is_locked = 0, \ + ReleaseMutex((M)->h) ? 0 : GetLastError()) + +# define k5_os_mutex_assert_unlocked(M) (0) +# define k5_os_mutex_assert_locked(M) (0) #else |
