1505d05c7Sgtb /*
2*5e01956fSGlenn Barry  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
3505d05c7Sgtb  */
4505d05c7Sgtb 
5505d05c7Sgtb /*
6505d05c7Sgtb  * include/k5-thread.h
7505d05c7Sgtb  *
854925bf6Swillf  * Copyright 2004,2005,2006 by the Massachusetts Institute of Technology.
9505d05c7Sgtb  * All Rights Reserved.
10505d05c7Sgtb  *
11505d05c7Sgtb  * Export of this software from the United States of America may
12505d05c7Sgtb  *   require a specific license from the United States Government.
13505d05c7Sgtb  *   It is the responsibility of any person or organization contemplating
14505d05c7Sgtb  *   export to obtain such a license before exporting.
15505d05c7Sgtb  *
16505d05c7Sgtb  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
17505d05c7Sgtb  * distribute this software and its documentation for any purpose and
18505d05c7Sgtb  * without fee is hereby granted, provided that the above copyright
19505d05c7Sgtb  * notice appear in all copies and that both that copyright notice and
20505d05c7Sgtb  * this permission notice appear in supporting documentation, and that
21505d05c7Sgtb  * the name of M.I.T. not be used in advertising or publicity pertaining
22505d05c7Sgtb  * to distribution of the software without specific, written prior
23505d05c7Sgtb  * permission.  Furthermore if you modify this software you must label
24505d05c7Sgtb  * your software as modified software and not distribute it in such a
25505d05c7Sgtb  * fashion that it might be confused with the original M.I.T. software.
26505d05c7Sgtb  * M.I.T. makes no representations about the suitability of
27505d05c7Sgtb  * this software for any purpose.  It is provided "as is" without express
28505d05c7Sgtb  * or implied warranty.
29505d05c7Sgtb  *
30505d05c7Sgtb  *
31505d05c7Sgtb  * Preliminary thread support.
32505d05c7Sgtb  */
33505d05c7Sgtb 
34505d05c7Sgtb #ifndef K5_THREAD_H
35505d05c7Sgtb #define K5_THREAD_H
36505d05c7Sgtb 
37ab9b2e15Sgtb #ifdef _KERNEL
38ab9b2e15Sgtb 
39ab9b2e15Sgtb #include <sys/ksynch.h>
40ab9b2e15Sgtb 
41ab9b2e15Sgtb typedef kmutex_t k5_mutex_t;
42ab9b2e15Sgtb 
43ab9b2e15Sgtb #define K5_MUTEX_PARTIAL_INITIALIZER {0}
44ab9b2e15Sgtb 
45ab9b2e15Sgtb /* ARGSUSED */
k5_mutex_assert_locked(k5_mutex_t * m)46ab9b2e15Sgtb static void k5_mutex_assert_locked(k5_mutex_t *m) { }
47ab9b2e15Sgtb 
48ab9b2e15Sgtb static int
k5_mutex_lock(k5_mutex_t * m)49ab9b2e15Sgtb k5_mutex_lock(k5_mutex_t *m)
50ab9b2e15Sgtb {
51ab9b2e15Sgtb   mutex_enter(m);
52ab9b2e15Sgtb   return (0);
53ab9b2e15Sgtb }
54ab9b2e15Sgtb 
55ab9b2e15Sgtb static int
k5_mutex_unlock(k5_mutex_t * m)56ab9b2e15Sgtb k5_mutex_unlock(k5_mutex_t *m)
57ab9b2e15Sgtb {
58ab9b2e15Sgtb   mutex_exit(m);
59ab9b2e15Sgtb   return(0);
60ab9b2e15Sgtb }
61ab9b2e15Sgtb 
62ab9b2e15Sgtb 
63ab9b2e15Sgtb #else /* _KERNEL */
64ab9b2e15Sgtb 
65505d05c7Sgtb #include "autoconf.h"
6654925bf6Swillf #ifndef KRB5_CALLCONV
6754925bf6Swillf # define KRB5_CALLCONV
6854925bf6Swillf #endif
6954925bf6Swillf #ifndef KRB5_CALLCONV_C
7054925bf6Swillf # define KRB5_CALLCONV_C
7154925bf6Swillf #endif
7254925bf6Swillf 
73505d05c7Sgtb /* Interface (tentative):
74505d05c7Sgtb 
75505d05c7Sgtb    Mutex support:
76505d05c7Sgtb 
77505d05c7Sgtb    // Between these two, we should be able to do pure compile-time
78505d05c7Sgtb    // and pure run-time initialization.
79505d05c7Sgtb    //   POSIX:   partial initializer is PTHREAD_MUTEX_INITIALIZER,
80505d05c7Sgtb    //            finish does nothing
81505d05c7Sgtb    //   Windows: partial initializer is an invalid handle,
82505d05c7Sgtb    //            finish does the real initialization work
83505d05c7Sgtb    //   debug:   partial initializer sets one magic value,
84505d05c7Sgtb    //            finish verifies and sets a new magic value for
85505d05c7Sgtb    //              lock/unlock to check
86505d05c7Sgtb    k5_mutex_t foo_mutex = K5_MUTEX_PARTIAL_INITIALIZER;
87505d05c7Sgtb    int k5_mutex_finish_init(k5_mutex_t *);
88505d05c7Sgtb    // for dynamic allocation
89505d05c7Sgtb    int k5_mutex_init(k5_mutex_t *);
90505d05c7Sgtb    // Must work for both kinds of alloc, even if it means adding flags.
91505d05c7Sgtb    int k5_mutex_destroy(k5_mutex_t *);
92505d05c7Sgtb 
93505d05c7Sgtb    // As before.
94