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

« back to all changes in this revision

Viewing changes to erts/lib_src/win/ethr_event.c

  • 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-2010. 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
#define ETHR_INLINE_FUNC_NAME_(X) X ## __
 
25
#define ETHR_EVENT_IMPL__
 
26
 
 
27
#include "ethread.h"
 
28
 
 
29
/* --- Windows implementation of thread events ------------------------------ */
 
30
 
 
31
#pragma intrinsic(_InterlockedExchangeAdd)
 
32
#pragma intrinsic(_InterlockedCompareExchange)
 
33
 
 
34
int
 
35
ethr_event_init(ethr_event *e)
 
36
{
 
37
    e->state = ETHR_EVENT_OFF__;
 
38
    e->handle = CreateEvent(NULL, FALSE, FALSE, NULL);
 
39
    if (e->handle == INVALID_HANDLE_VALUE)
 
40
        return ethr_win_get_errno__();
 
41
    return 0;
 
42
}
 
43
 
 
44
int
 
45
ethr_event_destroy(ethr_event *e)
 
46
{
 
47
    BOOL res = CloseHandle(e->handle);
 
48
    return res == 0 ? ethr_win_get_errno__() : 0;
 
49
}
 
50
 
 
51
void
 
52
ethr_event_set(ethr_event *e)
 
53
{
 
54
    ethr_event_set__(e);
 
55
}
 
56
 
 
57
void
 
58
ethr_event_reset(ethr_event *e)
 
59
{
 
60
    ethr_event_reset__(e);
 
61
}
 
62
 
 
63
static ETHR_INLINE int
 
64
wait(ethr_event *e, int spincount)
 
65
{
 
66
    LONG state;
 
67
    DWORD code;
 
68
    int sc, res, until_yield = ETHR_YIELD_AFTER_BUSY_LOOPS;
 
69
 
 
70
    if (spincount < 0)
 
71
        ETHR_FATAL_ERROR__(EINVAL);
 
72
 
 
73
    sc = spincount;
 
74
 
 
75
    while (1) {
 
76
        long on;
 
77
        while (1) {
 
78
#if ETHR_READ_AND_SET_WITHOUT_INTERLOCKED_OP__
 
79
            state = e->state;
 
80
#else
 
81
            state = _InterlockedExchangeAdd(&e->state, (LONG) 0);
 
82
#endif
 
83
            if (state == ETHR_EVENT_ON__)
 
84
                return 0;
 
85
            if (sc == 0)
 
86
                break;
 
87
            sc--;
 
88
            ETHR_SPIN_BODY;
 
89
            if (--until_yield == 0) {
 
90
                until_yield = ETHR_YIELD_AFTER_BUSY_LOOPS;
 
91
                res = ETHR_YIELD();
 
92
                if (res != 0)
 
93
                    ETHR_FATAL_ERROR__(res);
 
94
            }
 
95
        }
 
96
 
 
97
        if (state != ETHR_EVENT_OFF_WAITER__) {
 
98
            state = _InterlockedCompareExchange(&e->state,
 
99
                                                ETHR_EVENT_OFF_WAITER__,
 
100
                                                ETHR_EVENT_OFF__);
 
101
            if (state == ETHR_EVENT_ON__)
 
102
                return 0;
 
103
            ETHR_ASSERT(state == ETHR_EVENT_OFF__);
 
104
        }
 
105
 
 
106
        code = WaitForSingleObject(e->handle, INFINITE);
 
107
        if (code != WAIT_OBJECT_0)
 
108
            ETHR_FATAL_ERROR__(ethr_win_get_errno__());
 
109
    }
 
110
 
 
111
}
 
112
 
 
113
int
 
114
ethr_event_wait(ethr_event *e)
 
115
{
 
116
    return wait(e, 0);
 
117
}
 
118
 
 
119
int
 
120
ethr_event_swait(ethr_event *e, int spincount)
 
121
{
 
122
    return wait(e, spincount);
 
123
}