Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fc62d0da35eb22d86797a1a74c326e686815de52
[simgrid.git] / src / include / xbt / xbt_os_thread.h
1 /* $Id$ */
2
3 /* xbt/xbt_thread.h -- Thread portability layer                             */
4
5 /* Copyright (c) 2007 Martin Quinson. All rights reserved.                  */
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9
10
11 #ifndef _XBT_OS_THREAD_H
12 #define _XBT_OS_THREAD_H
13
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 XBT_PUBLIC(xbt_os_thread_t) xbt_os_thread_create(const char *name,
31                                                  pvoid_f_pvoid_t
32                                                  start_routine, void *param);
33 XBT_PUBLIC(void) xbt_os_thread_exit(int *retcode);
34 XBT_PUBLIC(xbt_os_thread_t) xbt_os_thread_self(void);
35 XBT_PUBLIC(const char *) xbt_os_thread_self_name(void);
36 XBT_PUBLIC(const char *) xbt_os_thread_name(xbt_os_thread_t);
37   /* xbt_os_thread_join frees the joined thread (ie the XBT wrapper around it, the OS frees the rest) */
38 XBT_PUBLIC(void) xbt_os_thread_join(xbt_os_thread_t thread,
39                                     void **thread_return);
40 XBT_PUBLIC(void) xbt_os_thread_yield(void);
41 XBT_PUBLIC(void) xbt_os_thread_cancel(xbt_os_thread_t thread);
42 XBT_PUBLIC(void *) xbt_os_thread_getparam(void);
43
44
45   /** \brief Thread mutex data type (opaque structure) */
46      typedef struct xbt_os_mutex_ *xbt_os_mutex_t;
47
48 XBT_PUBLIC(xbt_os_mutex_t) xbt_os_mutex_init(void);
49 XBT_PUBLIC(void) xbt_os_mutex_acquire(xbt_os_mutex_t mutex);
50 XBT_PUBLIC(void) xbt_os_mutex_timedacquire(xbt_os_mutex_t mutex,
51                                            double delay);
52 XBT_PUBLIC(void) xbt_os_mutex_release(xbt_os_mutex_t mutex);
53 XBT_PUBLIC(void) xbt_os_mutex_destroy(xbt_os_mutex_t mutex);
54
55
56   /** \brief Thread condition data type (opaque structure) */
57      typedef struct xbt_os_cond_ *xbt_os_cond_t;
58
59 XBT_PUBLIC(xbt_os_cond_t) xbt_os_cond_init(void);
60 XBT_PUBLIC(void) xbt_os_cond_wait(xbt_os_cond_t cond, xbt_os_mutex_t mutex);
61 XBT_PUBLIC(void) xbt_os_cond_timedwait(xbt_os_cond_t cond,
62                                        xbt_os_mutex_t mutex, double delay);
63 XBT_PUBLIC(void) xbt_os_cond_signal(xbt_os_cond_t cond);
64 XBT_PUBLIC(void) xbt_os_cond_broadcast(xbt_os_cond_t cond);
65 XBT_PUBLIC(void) xbt_os_cond_destroy(xbt_os_cond_t cond);
66
67    /** \brief Semaphore data type (opaque structure) */
68      typedef struct xbt_os_sem_ *xbt_os_sem_t;
69
70 XBT_PUBLIC(xbt_os_sem_t) xbt_os_sem_init(unsigned int value);
71 XBT_PUBLIC(void) xbt_os_sem_acquire(xbt_os_sem_t sem);
72 XBT_PUBLIC(void) xbt_os_sem_timedacquire(xbt_os_sem_t sem, double timeout);
73 XBT_PUBLIC(void) xbt_os_sem_release(xbt_os_sem_t sem);
74 XBT_PUBLIC(void) xbt_os_sem_destroy(xbt_os_sem_t sem);
75 XBT_PUBLIC(void) xbt_os_sem_get_value(xbt_os_sem_t sem, int *svalue);
76
77
78 /** @} */
79
80 SG_END_DECL()
81 #endif /* _XBT_OS_THREAD_H */