Added SILC Rand API, SILC Global Variables API and silcruntime.h.in
[runtime.git] / lib / silcutil / silcthread_i.h
1 /*
2
3   silcthread_i.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2007 - 2008 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 #ifndef SILCTHREAD_I_H
21 #define SILCTHREAD_I_H
22
23 #ifndef SILCTHREAD_H
24 #error "Do not include this header directly"
25 #endif
26
27 /* Thread-local storage structure.  This structure is saved to each thread's
28    Tls if the SILC Tls API is used.  This structure must be allocatable
29    with silc_calloc and freeable with silc_free, and must also be able to
30    pre-allocate from stack. */
31 typedef struct SilcTlsObject {
32   SilcMutex lock;                           /* Global lock, shared */
33   SilcHashTable variables;                  /* Global variables, shared */
34   SilcHashTable tls_variables;              /* Tls variables */
35   SilcStack stack;                          /* Thread's stack */
36   SilcSchedule schedule;                    /* Thread's scheduler */
37   void *thread_context;                     /* Context set with SILC Tls API */
38   void *platform_context;                   /* Platform specific context */
39   char error_reason[256];                   /* Reason for the error */
40   SilcResult error;                         /* Errno, last error */
41   unsigned int shared_data     : 1;         /* Set when shares data with other
42                                                threads in the Tls. */
43 } *SilcTls, SilcTlsStruct;
44
45 /* The internal Tls API.  Implementation is platform specific. */
46
47 /* Initializes Tls for current thread.  Must be called for each thread to
48    allocate Tls for the thread, including the main thread. */
49 SilcTls silc_thread_tls_init(void);
50
51 /* Return current thread's Tls structure. */
52 SilcTls silc_thread_get_tls(void);
53
54 /* Uninitialize whole Tls system (free shared data), called only once per
55    process. */
56 void silc_thread_tls_uninit(void);
57
58 #endif /* SILCTHREAD_I_H */