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

« back to all changes in this revision

Viewing changes to erts/emulator/beam/erl_drv_thread.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
1
/*
2
2
 * %CopyrightBegin%
3
 
 * 
4
 
 * Copyright Ericsson AB 2007-2009. All Rights Reserved.
5
 
 * 
 
3
 *
 
4
 * Copyright Ericsson AB 2007-2011. All Rights Reserved.
 
5
 *
6
6
 * The contents of this file are subject to the Erlang Public License,
7
7
 * Version 1.1, (the "License"); you may not use this file except in
8
8
 * compliance with the License. You should have received a copy of the
9
9
 * Erlang Public License along with this software. If not, it can be
10
10
 * retrieved online at http://www.erlang.org/.
11
 
 * 
 
11
 *
12
12
 * Software distributed under the License is distributed on an "AS IS"
13
13
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
14
 * the License for the specific language governing rights and limitations
15
15
 * under the License.
16
 
 * 
 
16
 *
17
17
 * %CopyrightEnd%
18
18
 */
19
19
 
24
24
#include "global.h"
25
25
#include <string.h>
26
26
 
 
27
#if defined(__APPLE__) && defined(__MACH__) && !defined(__DARWIN__)
 
28
#define __DARWIN__ 1
 
29
#endif
 
30
 
27
31
#define ERL_DRV_THR_OPTS_SIZE(LAST_FIELD) \
28
32
  (((size_t) &((ErlDrvThreadOpts *) 0)->LAST_FIELD) \
29
33
   + sizeof(((ErlDrvThreadOpts *) 0)->LAST_FIELD))
186
190
erl_drv_mutex_trylock(ErlDrvMutex *dmtx)
187
191
{
188
192
#ifdef USE_THREADS
189
 
    int res = dmtx ? ethr_mutex_trylock(&dmtx->mtx) : EINVAL;
190
 
    if (res != 0 && res != EBUSY)
191
 
        fatal_error(res, "erl_drv_mutex_trylock()");
192
 
    return res;
 
193
    if (!dmtx)
 
194
        fatal_error(EINVAL, "erl_drv_mutex_trylock()");
 
195
    return ethr_mutex_trylock(&dmtx->mtx);
193
196
#else
194
197
    return 0;
195
198
#endif
199
202
erl_drv_mutex_lock(ErlDrvMutex *dmtx)
200
203
{
201
204
#ifdef USE_THREADS
202
 
    int res = dmtx ? ethr_mutex_lock(&dmtx->mtx) : EINVAL;
203
 
    if (res != 0)
204
 
        fatal_error(res, "erl_drv_mutex_lock()");
 
205
    if (!dmtx)
 
206
        fatal_error(EINVAL, "erl_drv_mutex_lock()");
 
207
    ethr_mutex_lock(&dmtx->mtx);
205
208
#endif
206
209
}
207
210
 
209
212
erl_drv_mutex_unlock(ErlDrvMutex *dmtx)
210
213
{
211
214
#ifdef USE_THREADS
212
 
    int res = dmtx ? ethr_mutex_unlock(&dmtx->mtx) : EINVAL;
213
 
    if (res != 0)
214
 
        fatal_error(res, "erl_drv_mutex_unlock()");
 
215
    if (!dmtx)
 
216
        fatal_error(EINVAL, "erl_drv_mutex_unlock()");
 
217
    ethr_mutex_unlock(&dmtx->mtx);
215
218
#endif
216
219
}
217
220
 
256
259
erl_drv_cond_signal(ErlDrvCond *dcnd)
257
260
{
258
261
#ifdef USE_THREADS
259
 
    int res = dcnd ? ethr_cond_signal(&dcnd->cnd) : EINVAL;
260
 
    if (res != 0)
261
 
        fatal_error(res, "erl_drv_cond_signal()");
 
262
    if (!dcnd)
 
263
        fatal_error(EINVAL, "erl_drv_cond_signal()");
 
264
    ethr_cond_signal(&dcnd->cnd);
262
265
#endif
263
266
}
264
267
 
266
269
erl_drv_cond_broadcast(ErlDrvCond *dcnd)
267
270
{
268
271
#ifdef USE_THREADS
269
 
    int res = dcnd ? ethr_cond_broadcast(&dcnd->cnd) : EINVAL;
270
 
    if (res != 0)
271
 
        fatal_error(res, "erl_drv_cond_broadcast()");
 
272
    if (!dcnd)
 
273
        fatal_error(EINVAL, "erl_drv_cond_broadcast()");
 
274
    ethr_cond_broadcast(&dcnd->cnd);
272
275
#endif
273
276
}
274
277
 
277
280
erl_drv_cond_wait(ErlDrvCond *dcnd, ErlDrvMutex *dmtx)
278
281
{
279
282
#ifdef USE_THREADS
280
 
    int res;
281
283
    if (!dcnd || !dmtx) {
282
 
        res = EINVAL;
283
 
    error:
284
 
        fatal_error(res, "erl_drv_cond_wait()");
 
284
        fatal_error(EINVAL, "erl_drv_cond_wait()");
285
285
    }
286
286
    while (1) {
287
 
        res = ethr_cond_wait(&dcnd->cnd, &dmtx->mtx);
 
287
        int res = ethr_cond_wait(&dcnd->cnd, &dmtx->mtx);
288
288
        if (res == 0)
289
289
            break;
290
 
        if (res != EINTR)
291
 
            goto error;
292
290
    }
293
291
#endif
294
292
}
333
331
erl_drv_rwlock_tryrlock(ErlDrvRWLock *drwlck)
334
332
{
335
333
#ifdef USE_THREADS
336
 
    int res = drwlck ? ethr_rwmutex_tryrlock(&drwlck->rwmtx) : EINVAL;
337
 
    if (res != 0 && res != EBUSY)
338
 
        fatal_error(res, "erl_drv_rwlock_tryrlock()");
339
 
    return res;
 
334
    if (!drwlck)
 
335
        fatal_error(EINVAL, "erl_drv_rwlock_tryrlock()");
 
336
    return ethr_rwmutex_tryrlock(&drwlck->rwmtx);
340
337
#else
341
338
    return 0;
342
339
#endif
346
343
erl_drv_rwlock_rlock(ErlDrvRWLock *drwlck)
347
344
{
348
345
#ifdef USE_THREADS
349
 
    int res = drwlck ? ethr_rwmutex_rlock(&drwlck->rwmtx) : EINVAL;
350
 
    if (res != 0)
351
 
        fatal_error(res, "erl_drv_rwlock_rlock()");
 
346
    if (!drwlck)
 
347
        fatal_error(EINVAL, "erl_drv_rwlock_rlock()");
 
348
    ethr_rwmutex_rlock(&drwlck->rwmtx);
352
349
#endif
353
350
}
354
351
 
356
353
erl_drv_rwlock_runlock(ErlDrvRWLock *drwlck)
357
354
{
358
355
#ifdef USE_THREADS
359
 
    int res = drwlck ? ethr_rwmutex_runlock(&drwlck->rwmtx) : EINVAL;
360
 
    if (res != 0)
361
 
        fatal_error(res, "erl_drv_rwlock_runlock()");
 
356
    if (!drwlck)
 
357
        fatal_error(EINVAL, "erl_drv_rwlock_runlock()");
 
358
    ethr_rwmutex_runlock(&drwlck->rwmtx);
362
359
#endif
363
360
}
364
361
 
366
363
erl_drv_rwlock_tryrwlock(ErlDrvRWLock *drwlck)
367
364
{
368
365
#ifdef USE_THREADS
369
 
    int res = drwlck ? ethr_rwmutex_tryrwlock(&drwlck->rwmtx) : EINVAL;
370
 
    if (res != 0 && res != EBUSY)
371
 
        fatal_error(res, "erl_drv_rwlock_tryrwlock()");
372
 
    return res;
 
366
    if (!drwlck)
 
367
        fatal_error(EINVAL, "erl_drv_rwlock_tryrwlock()");
 
368
    return ethr_rwmutex_tryrwlock(&drwlck->rwmtx);
373
369
#else
374
370
    return 0;
375
371
#endif
379
375
erl_drv_rwlock_rwlock(ErlDrvRWLock *drwlck)
380
376
{
381
377
#ifdef USE_THREADS
382
 
    int res = drwlck ? ethr_rwmutex_rwlock(&drwlck->rwmtx) : EINVAL;
383
 
    if (res != 0)
384
 
        fatal_error(res, "erl_drv_rwlock_rwlock()");
 
378
    if (!drwlck)
 
379
        fatal_error(EINVAL, "erl_drv_rwlock_rwlock()");
 
380
    ethr_rwmutex_rwlock(&drwlck->rwmtx);
385
381
#endif
386
382
}
387
383
 
389
385
erl_drv_rwlock_rwunlock(ErlDrvRWLock *drwlck)
390
386
{
391
387
#ifdef USE_THREADS
392
 
    int res = drwlck ? ethr_rwmutex_rwunlock(&drwlck->rwmtx) : EINVAL;
393
 
    if (res != 0)
394
 
        fatal_error(res, "erl_drv_rwlock_rwunlock()");
 
388
    if (!drwlck)
 
389
        fatal_error(EINVAL, "erl_drv_rwlock_rwunlock()");
 
390
    ethr_rwmutex_rwunlock(&drwlck->rwmtx);
395
391
#endif
396
392
}
397
393
 
536
532
    if (!dtid)
537
533
        return NULL;
538
534
#endif
539
 
    if (ERL_DRV_TSD_LEN__ < key)
 
535
    if (ERL_DRV_TSD_LEN__ <= key)
540
536
        return NULL;
541
537
    return ERL_DRV_TSD__[key];
542
538
}
603
599
        dtid->name = ((char *) dtid) + sizeof(struct ErlDrvTid_);
604
600
        sys_strcpy(dtid->name, name);
605
601
    }
606
 
#ifdef ERTS_ENABLE_LOCK_COUNT
607
 
    res = erts_lcnt_thr_create(&dtid->tid, erl_drv_thread_wrapper, dtid, use_opts);
608
 
#else
609
602
    res = ethr_thr_create(&dtid->tid, erl_drv_thread_wrapper, dtid, use_opts);
610
 
#endif
611
603
 
612
604
    if (res != 0) {
613
605
        erts_free(ERTS_ALC_T_DRV_TID, dtid);
704
696
#endif
705
697
}
706
698
 
 
699
#if defined(__DARWIN__) && defined(USE_THREADS) && defined(ERTS_SMP)
 
700
extern int erts_darwin_main_thread_pipe[2];
 
701
extern int erts_darwin_main_thread_result_pipe[2];
 
702
 
 
703
 
 
704
int
 
705
erl_drv_stolen_main_thread_join(ErlDrvTid tid, void **respp)
 
706
{
 
707
    void *dummy;
 
708
    void **x;
 
709
    if (respp == NULL)
 
710
        x = &dummy;
 
711
    else
 
712
        x = respp;
 
713
    read(erts_darwin_main_thread_result_pipe[0],x,sizeof(void *));
 
714
    return 0;
 
715
}
 
716
 
 
717
int
 
718
erl_drv_steal_main_thread(char *name,
 
719
                          ErlDrvTid *tid,
 
720
                          void* (*func)(void*),
 
721
                          void* arg,
 
722
                          ErlDrvThreadOpts *opts)
 
723
{
 
724
    char buff[sizeof(void* (*)(void*)) + sizeof(void *)];
 
725
    int buff_sz = sizeof(void* (*)(void*)) + sizeof(void *);
 
726
    /*struct ErlDrvTid_ *dtid;
 
727
 
 
728
    dtid = erts_alloc_fnf(ERTS_ALC_T_DRV_TID,
 
729
                          (sizeof(struct ErlDrvTid_)
 
730
                           + (name ? sys_strlen(name) + 1 : 0)));
 
731
    if (!dtid)
 
732
        return ENOMEM;
 
733
    memset(dtid,0,sizeof(ErlDrvTid_));
 
734
    dtid->tid = (void * ) -1;
 
735
    dtid->drv_thr = 1;
 
736
    dtid->func = func;
 
737
    dtid->arg = arg;
 
738
    dtid->tsd = NULL;
 
739
    dtid->tsd_len = 0;
 
740
    dtid->name = no_name;
 
741
    *tid = (ErlDrvTid) dtid;
 
742
    */
 
743
    *tid = NULL;
 
744
    /* Ignore options and name... */
 
745
    
 
746
    memcpy(buff,&func,sizeof(void* (*)(void*)));
 
747
    memcpy(buff + sizeof(void* (*)(void*)),&arg,sizeof(void *));
 
748
    write(erts_darwin_main_thread_pipe[1],buff,buff_sz);
 
749
    return 0;
 
750
}
 
751
 
 
752
#endif