Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix win64 compilation.
[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 "xbt/misc.h"           /* SG_BEGIN_DECL */
14 #include "xbt/function_types.h"
15
16 SG_BEGIN_DECL()
17
18 /** @addtogroup XBT_thread
19  *  @brief Thread portability layer
20  * 
21  *  This section describes the thread portability layer. It defines types and 
22  *  functions very close to the pthread API, but it's portable to windows too.
23  * 
24  *  @{
25  */
26   /** \brief Thread data type (opaque structure) */
27 typedef struct xbt_os_thread_ *xbt_os_thread_t;
28
29 /* Calls pthread_atfork() if present, and else does nothing.
30  * The only known user of this wrapper is mmalloc_preinit().
31  */
32 XBT_PUBLIC(int) xbt_os_thread_atfork(void (*prepare)(void),
33                                      void (*parent)(void),
34                                      void (*child)(void));
35
36
37 XBT_PUBLIC(xbt_os_thread_t) xbt_os_thread_create(const char *name,
38                                                  pvoid_f_pvoid_t start_routine,
39                                                  void *param,
40                                                  void *data);
41
42 XBT_PUBLIC(void) xbt_os_thread_exit(int *retcode);
43 XBT_PUBLIC(void) xbt_os_thread_detach(xbt_os_thread_t thread);
44 XBT_PUBLIC(xbt_os_thread_t) xbt_os_thread_self(void);
45 XBT_PUBLIC(const char *) xbt_os_thread_self_name(void);
46 XBT_PUBLIC(const char *) xbt_os_thread_name(xbt_os_thread_t);
47 XBT_PUBLIC(void) xbt_os_thread_set_extra_data(void *data);
48 XBT_PUBLIC(void *) xbt_os_thread_get_extra_data(void);
49   /* xbt_os_thread_join frees the joined thread (ie the XBT wrapper around it, the OS frees the rest) */
50 XBT_PUBLIC(void) xbt_os_thread_join(xbt_os_thread_t thread,
51                                     void **thread_return);
52 XBT_PUBLIC(void) xbt_os_thread_yield(void);
53 XBT_PUBLIC(void) xbt_os_thread_cancel(xbt_os_thread_t thread);
54 XBT_PUBLIC(void *) xbt_os_thread_getparam(void);
55
56
57   /** \brief Thread mutex data type (opaque structure) */
58 typedef struct xbt_os_mutex_ *xbt_os_mutex_t;
59
60 XBT_PUBLIC(xbt_os_mutex_t) xbt_os_mutex_init(void);
61 XBT_PUBLIC(void) xbt_os_mutex_acquire(xbt_os_mutex_t mutex);
62 XBT_PUBLIC(void) xbt_os_mutex_timedacquire(xbt_os_mutex_t mutex,
63                                            double delay);
64 XBT_PUBLIC(void) xbt_os_mutex_release(xbt_os_mutex_t mutex);
65 XBT_PUBLIC(void) xbt_os_mutex_destroy(xbt_os_mutex_t mutex);
66
67 /** \brief Thread reentrant mutex data type (opaque structure) */
68 typedef struct xbt_os_rmutex_ *xbt_os_rmutex_t;
69
70 XBT_PUBLIC(xbt_os_rmutex_t) xbt_os_rmutex_init(void);
71 XBT_PUBLIC(void) xbt_os_rmutex_acquire(xbt_os_rmutex_t rmutex);
72 XBT_PUBLIC(void) xbt_os_rmutex_release(xbt_os_rmutex_t rmutex);
73 XBT_PUBLIC(void) xbt_os_rmutex_destroy(xbt_os_rmutex_t rmutex);
74
75
76   /** \brief Thread condition data type (opaque structure) */
77 typedef struct xbt_os_cond_ *xbt_os_cond_t;
78
79 XBT_PUBLIC(xbt_os_cond_t) xbt_os_cond_init(void);
80 XBT_PUBLIC(void) xbt_os_cond_wait(xbt_os_cond_t cond,
81                                   xbt_os_mutex_t mutex);
82 XBT_PUBLIC(void) xbt_os_cond_timedwait(xbt_os_cond_t cond,
83                                        xbt_os_mutex_t mutex, double delay);
84 XBT_PUBLIC(void) xbt_os_cond_signal(xbt_os_cond_t cond);
85 XBT_PUBLIC(void) xbt_os_cond_broadcast(xbt_os_cond_t cond);
86 XBT_PUBLIC(void) xbt_os_cond_destroy(xbt_os_cond_t cond);
87
88    /** \brief Semaphore data type (opaque structure) */
89 typedef struct xbt_os_sem_ *xbt_os_sem_t;
90
91 XBT_PUBLIC(xbt_os_sem_t) xbt_os_sem_init(unsigned int value);
92 XBT_PUBLIC(void) xbt_os_sem_acquire(xbt_os_sem_t sem);
93 XBT_PUBLIC(void) xbt_os_sem_timedacquire(xbt_os_sem_t sem, double timeout);
94 XBT_PUBLIC(void) xbt_os_sem_release(xbt_os_sem_t sem);
95 XBT_PUBLIC(void) xbt_os_sem_destroy(xbt_os_sem_t sem);
96 XBT_PUBLIC(void) xbt_os_sem_get_value(xbt_os_sem_t sem, int *svalue);
97
98
99 /** @} */
100
101 SG_END_DECL()
102 #endif                          /* _XBT_OS_THREAD_H */