Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
This change is about the refactoring of the source code of the objects use int the...
[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 #ifndef WIN32 /* HAVE_SEMAPHOR_H */
18 #include <semaphore.h>
19 #endif
20
21
22 SG_BEGIN_DECL()
23
24 /** @addtogroup XBT_thread
25  *  @brief Thread portability layer
26  * 
27  *  This section describes the thread portability layer. It defines types and 
28  *  functions very close to the pthread API, but it's portable to windows too.
29  * 
30  *  @{
31  */
32
33   /** \brief Thread data type (opaque structure) */
34   typedef struct xbt_os_thread_       *xbt_os_thread_t;
35
36   XBT_PUBLIC(xbt_os_thread_t) xbt_os_thread_create(const char *name,pvoid_f_pvoid_t start_routine,void* param);
37   XBT_PUBLIC(void) xbt_os_thread_exit(int *retcode);
38   XBT_PUBLIC(xbt_os_thread_t) xbt_os_thread_self(void);
39   XBT_PUBLIC(const char*) xbt_os_thread_self_name(void);
40   XBT_PUBLIC(const char*) xbt_os_thread_name(xbt_os_thread_t);
41   /* xbt_os_thread_join frees the joined thread (ie the XBT wrapper around it, the OS frees the rest) */
42   XBT_PUBLIC(void) xbt_os_thread_join(xbt_os_thread_t thread,void ** thread_return);
43   XBT_PUBLIC(void) xbt_os_thread_yield(void);
44   XBT_PUBLIC(void) xbt_os_thread_cancel(xbt_os_thread_t thread);
45   XBT_PUBLIC(void*) xbt_os_thread_getparam(void);
46
47
48   /** \brief Thread mutex data type (opaque structure) */
49   typedef struct xbt_os_mutex_ *xbt_os_mutex_t;
50
51   XBT_PUBLIC(xbt_os_mutex_t) xbt_os_mutex_init(void);
52   XBT_PUBLIC(void)           xbt_os_mutex_acquire(xbt_os_mutex_t mutex);
53   XBT_PUBLIC(void)           xbt_os_mutex_release(xbt_os_mutex_t mutex);
54   XBT_PUBLIC(void)           xbt_os_mutex_destroy(xbt_os_mutex_t mutex);
55
56
57   /** \brief Thread condition data type (opaque structure) */
58   typedef struct xbt_os_cond_  *xbt_os_cond_t;
59
60   XBT_PUBLIC(xbt_os_cond_t) xbt_os_cond_init(void);
61   XBT_PUBLIC(void)          xbt_os_cond_wait(xbt_os_cond_t cond,
62                                              xbt_os_mutex_t mutex);
63   XBT_PUBLIC(void)          xbt_os_cond_timedwait(xbt_os_cond_t cond,
64                                                   xbt_os_mutex_t mutex,
65                                                   double delay);
66   XBT_PUBLIC(void)          xbt_os_cond_signal(xbt_os_cond_t cond);
67   XBT_PUBLIC(void)          xbt_os_cond_broadcast(xbt_os_cond_t cond);
68   XBT_PUBLIC(void)          xbt_os_cond_destroy(xbt_os_cond_t cond);
69   
70    /** \brief Semaphore data type (opaque structure) */
71   typedef struct xbt_os_sem_* xbt_os_sem_t;
72
73   XBT_PUBLIC(xbt_os_sem_t) xbt_os_sem_init(unsigned int value);
74   XBT_PUBLIC(void) xbt_os_sem_acquire(xbt_os_sem_t sem);
75   XBT_PUBLIC(void) xbt_os_sem_timedacquire(xbt_os_sem_t sem,double timeout);
76   XBT_PUBLIC(void) xbt_os_sem_release(xbt_os_sem_t sem);
77   XBT_PUBLIC(void) xbt_os_sem_destroy(xbt_os_sem_t sem);
78   XBT_PUBLIC(void) xbt_os_sem_get_value(xbt_os_sem_t sem, int* svalue);
79  
80
81 /** @} */
82
83 SG_END_DECL()
84
85 #endif /* _XBT_OS_THREAD_H */