~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to erts/include/internal/pthread/ethr_event.h

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * %CopyrightBegin%
 
3
 *
 
4
 * Copyright Ericsson AB 2009-2011. All Rights Reserved.
 
5
 *
 
6
 * The contents of this file are subject to the Erlang Public License,
 
7
 * Version 1.1, (the "License"); you may not use this file except in
 
8
 * compliance with the License. You should have received a copy of the
 
9
 * Erlang Public License along with this software. If not, it can be
 
10
 * retrieved online at http://www.erlang.org/.
 
11
 *
 
12
 * Software distributed under the License is distributed on an "AS IS"
 
13
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
14
 * the License for the specific language governing rights and limitations
 
15
 * under the License.
 
16
 *
 
17
 * %CopyrightEnd%
 
18
 */
 
19
 
 
20
/*
 
21
 * Author: Rickard Green
 
22
 */
 
23
 
 
24
#if defined(ETHR_HAVE_LINUX_FUTEX) && defined(ETHR_HAVE_NATIVE_ATOMICS)
 
25
/* --- Linux futex implementation of ethread events ------------------------- */
 
26
#define ETHR_LINUX_FUTEX_IMPL__
 
27
 
 
28
#include <sys/syscall.h>
 
29
#include <unistd.h>
 
30
#include <linux/futex.h>
 
31
#include <sys/time.h>
 
32
 
 
33
#define ETHR_EVENT_OFF_WAITER__         ((ethr_sint32_t) -1)
 
34
#define ETHR_EVENT_OFF__                ((ethr_sint32_t) 1)
 
35
#define ETHR_EVENT_ON__                 ((ethr_sint32_t) 0)
 
36
 
 
37
#if defined(FUTEX_WAIT_PRIVATE) && defined(FUTEX_WAKE_PRIVATE)
 
38
#  define ETHR_FUTEX_WAIT__ FUTEX_WAIT_PRIVATE
 
39
#  define ETHR_FUTEX_WAKE__ FUTEX_WAKE_PRIVATE
 
40
#else
 
41
#  define ETHR_FUTEX_WAIT__ FUTEX_WAIT
 
42
#  define ETHR_FUTEX_WAKE__ FUTEX_WAKE
 
43
#endif
 
44
 
 
45
typedef struct {
 
46
    ethr_atomic32_t futex;
 
47
} ethr_event;
 
48
 
 
49
#define ETHR_FUTEX__(FTX, OP, VAL)                      \
 
50
  (-1 == syscall(__NR_futex,                            \
 
51
                 (void *) ethr_atomic32_addr((FTX)),    \
 
52
                 (OP),                                  \
 
53
                 (int) (VAL),                           \
 
54
                 NULL,                                  \
 
55
                 NULL,                                  \
 
56
                 0)                                     \
 
57
   ? errno : 0)
 
58
 
 
59
#if defined(ETHR_TRY_INLINE_FUNCS) || defined(ETHR_EVENT_IMPL__)
 
60
 
 
61
static void ETHR_INLINE
 
62
ETHR_INLINE_FUNC_NAME_(ethr_event_set)(ethr_event *e)
 
63
{
 
64
    ethr_sint32_t val;
 
65
    ETHR_MEMORY_BARRIER;
 
66
    val = ethr_atomic32_xchg(&e->futex, ETHR_EVENT_ON__);
 
67
    if (val == ETHR_EVENT_OFF_WAITER__) {
 
68
        int res = ETHR_FUTEX__(&e->futex, ETHR_FUTEX_WAKE__, 1);
 
69
        if (res != 0)
 
70
            ETHR_FATAL_ERROR__(res);
 
71
    }
 
72
}
 
73
 
 
74
static void ETHR_INLINE
 
75
ETHR_INLINE_FUNC_NAME_(ethr_event_reset)(ethr_event *e)
 
76
{
 
77
    ethr_atomic32_set(&e->futex, ETHR_EVENT_OFF__);
 
78
    ETHR_MEMORY_BARRIER;
 
79
}
 
80
 
 
81
#endif
 
82
 
 
83
#elif defined(ETHR_PTHREADS)
 
84
/* --- Posix mutex/cond implementation of events ---------------------------- */
 
85
 
 
86
typedef struct {
 
87
    ethr_atomic32_t state;
 
88
    pthread_mutex_t mtx;
 
89
    pthread_cond_t cnd;
 
90
} ethr_event;
 
91
 
 
92
#define ETHR_EVENT_OFF_WAITER__         -1L
 
93
#define ETHR_EVENT_OFF__                1L
 
94
#define ETHR_EVENT_ON__                 0L
 
95
 
 
96
#if defined(ETHR_TRY_INLINE_FUNCS) || defined(ETHR_EVENT_IMPL__)
 
97
 
 
98
static void ETHR_INLINE
 
99
ETHR_INLINE_FUNC_NAME_(ethr_event_set)(ethr_event *e)
 
100
{
 
101
    ethr_sint32_t val;
 
102
    ETHR_MEMORY_BARRIER;
 
103
    val = ethr_atomic32_xchg(&e->state, ETHR_EVENT_ON__);
 
104
    if (val == ETHR_EVENT_OFF_WAITER__) {
 
105
        int res = pthread_mutex_lock(&e->mtx);
 
106
        if (res != 0)
 
107
            ETHR_FATAL_ERROR__(res);
 
108
        res = pthread_cond_signal(&e->cnd);
 
109
        if (res != 0)
 
110
            ETHR_FATAL_ERROR__(res);
 
111
        res = pthread_mutex_unlock(&e->mtx);
 
112
        if (res != 0)
 
113
            ETHR_FATAL_ERROR__(res);
 
114
    }
 
115
}
 
116
 
 
117
static void ETHR_INLINE
 
118
ETHR_INLINE_FUNC_NAME_(ethr_event_reset)(ethr_event *e)
 
119
{
 
120
    ethr_atomic32_set(&e->state, ETHR_EVENT_OFF__);
 
121
    ETHR_MEMORY_BARRIER;
 
122
}
 
123
 
 
124
#endif
 
125
 
 
126
#endif
 
127
 
 
128
int ethr_event_init(ethr_event *e);
 
129
int ethr_event_destroy(ethr_event *e);
 
130
int ethr_event_wait(ethr_event *e);
 
131
int ethr_event_swait(ethr_event *e, int spincount);
 
132
#if !defined(ETHR_TRY_INLINE_FUNCS) || defined(ETHR_EVENT_IMPL__)
 
133
void ethr_event_set(ethr_event *e);
 
134
void ethr_event_reset(ethr_event *e);
 
135
#endif