Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
merge conflict resolved
[simgrid.git] / src / include / xbt / xbt_os_thread.h
1 /* xbt/xbt_thread.h -- Thread portability layer                             */
2
3 /* Copyright (c) 2007, 2009, 2010. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9
10 #ifndef _XBT_OS_THREAD_H
11 #define _XBT_OS_THREAD_H
12
13 #include "gras_config.h"
14 #include "xbt/misc.h"           /* SG_BEGIN_DECL */
15 #include "xbt/function_types.h"
16
17 SG_BEGIN_DECL()
18
19 /** @addtogroup XBT_thread
20  *  @brief Thread portability layer
21  * 
22  *  This section describes the thread portability layer. It defines types and 
23  *  functions very close to the pthread API, but it's portable to windows too.
24  * 
25  *  @{
26  */
27   /** \brief Thread data type (opaque structure) */
28 typedef struct xbt_os_thread_ *xbt_os_thread_t;
29
30 #ifdef HAVE_PTHREAD_H
31 #include <pthread.h>
32 typedef pthread_key_t xbt_os_thread_key_t;
33 #elif defined(_XBT_WIN32)
34 #include <WinDef.h>
35 typedef DWORD xbt_os_thread_key_t;
36 #endif
37
38 /* Calls pthread_atfork() if present, and else does nothing.
39  * The only known user of this wrapper is mmalloc_preinit(); This function may disapear in the near future.
40  */
41 XBT_PUBLIC(int) xbt_os_thread_atfork(void (*prepare)(void),
42                                      void (*parent)(void),
43                                      void (*child)(void));
44
45 XBT_PUBLIC(int) xbt_os_get_numcores(void);
46
47 XBT_PUBLIC(xbt_os_thread_t) xbt_os_thread_create(const char *name,
48                                                  pvoid_f_pvoid_t start_routine,
49                                                  void *param,
50                                                  void *data);
51
52 XBT_PUBLIC(void) xbt_os_thread_exit(int *retcode);
53 XBT_PUBLIC(void) xbt_os_thread_detach(xbt_os_thread_t thread);
54 XBT_PUBLIC(xbt_os_thread_t) xbt_os_thread_self(void);
55 XBT_PUBLIC(const char *) xbt_os_thread_self_name(void);
56 XBT_PUBLIC(const char *) xbt_os_thread_name(xbt_os_thread_t);
57 XBT_PUBLIC(void) xbt_os_thread_set_extra_data(void *data);
58 XBT_PUBLIC(void *) xbt_os_thread_get_extra_data(void);
59 XBT_PUBLIC(void) xbt_os_thread_key_create(xbt_os_thread_key_t* key);
60 XBT_PUBLIC(void) xbt_os_thread_set_specific(xbt_os_thread_key_t key, void* value);
61 XBT_PUBLIC(void*) xbt_os_thread_get_specific(xbt_os_thread_key_t key);
62   /* xbt_os_thread_join frees the joined thread (ie the XBT wrapper around it, the OS frees the rest) */
63 XBT_PUBLIC(void) xbt_os_thread_join(xbt_os_thread_t thread,
64                                     void **thread_return);
65 XBT_PUBLIC(void) xbt_os_thread_yield(void);
66 XBT_PUBLIC(void) xbt_os_thread_cancel(xbt_os_thread_t thread);
67 XBT_PUBLIC(void *) xbt_os_thread_getparam(void);
68
69
70   /** \brief Thread mutex data type (opaque structure) */
71 typedef struct xbt_os_mutex_ *xbt_os_mutex_t;
72
73 XBT_PUBLIC(xbt_os_mutex_t) xbt_os_mutex_init(void);
74 XBT_PUBLIC(void) xbt_os_mutex_acquire(xbt_os_mutex_t mutex);
75 XBT_PUBLIC(void) xbt_os_mutex_timedacquire(xbt_os_mutex_t mutex,
76                                            double delay);
77 XBT_PUBLIC(void) xbt_os_mutex_release(xbt_os_mutex_t mutex);
78 XBT_PUBLIC(void) xbt_os_mutex_destroy(xbt_os_mutex_t mutex);
79
80 /** \brief Thread reentrant mutex data type (opaque structure) */
81 typedef struct xbt_os_rmutex_ *xbt_os_rmutex_t;
82
83 XBT_PUBLIC(xbt_os_rmutex_t) xbt_os_rmutex_init(void);
84 XBT_PUBLIC(void) xbt_os_rmutex_acquire(xbt_os_rmutex_t rmutex);
85 XBT_PUBLIC(void) xbt_os_rmutex_release(xbt_os_rmutex_t rmutex);
86 XBT_PUBLIC(void) xbt_os_rmutex_destroy(xbt_os_rmutex_t rmutex);
87
88
89   /** \brief Thread condition data type (opaque structure) */
90 typedef struct xbt_os_cond_ *xbt_os_cond_t;
91
92 XBT_PUBLIC(xbt_os_cond_t) xbt_os_cond_init(void);
93 XBT_PUBLIC(void) xbt_os_cond_wait(xbt_os_cond_t cond,
94                                   xbt_os_mutex_t mutex);
95 XBT_PUBLIC(void) xbt_os_cond_timedwait(xbt_os_cond_t cond,
96                                        xbt_os_mutex_t mutex, double delay);
97 XBT_PUBLIC(void) xbt_os_cond_signal(xbt_os_cond_t cond);
98 XBT_PUBLIC(void) xbt_os_cond_broadcast(xbt_os_cond_t cond);
99 XBT_PUBLIC(void) xbt_os_cond_destroy(xbt_os_cond_t cond);
100
101    /** \brief Semaphore data type (opaque structure) */
102 typedef struct xbt_os_sem_ *xbt_os_sem_t;
103
104 XBT_PUBLIC(xbt_os_sem_t) xbt_os_sem_init(unsigned int value);
105 XBT_PUBLIC(void) xbt_os_sem_acquire(xbt_os_sem_t sem);
106 XBT_PUBLIC(void) xbt_os_sem_timedacquire(xbt_os_sem_t sem, double timeout);
107 XBT_PUBLIC(void) xbt_os_sem_release(xbt_os_sem_t sem);
108 XBT_PUBLIC(void) xbt_os_sem_destroy(xbt_os_sem_t sem);
109 XBT_PUBLIC(void) xbt_os_sem_get_value(xbt_os_sem_t sem, int *svalue);
110
111
112 /** @} */
113
114 SG_END_DECL()
115 #endif                          /* _XBT_OS_THREAD_H */