~ubuntu-branches/ubuntu/trusty/gnustep-base/trusty

« back to all changes in this revision

Viewing changes to Source/GSPThread.h

Tags: upstream-1.20.0
ImportĀ upstreamĀ versionĀ 1.20.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GSPThread.h
 
2
   Copyright (C) 2010 Free Software Foundation, Inc.
 
3
 
 
4
   Written by:  Niels Grewe <niels.grewe@halbordnung.de>
 
5
   
 
6
   This file is part of the GNUstep Base Library.
 
7
 
 
8
   This library is free software; you can redistribute it and/or
 
9
   modify it under the terms of the GNU Lesser General Public
 
10
   License as published by the Free Software Foundation; either
 
11
   version 2 of the License, or (at your option) any later version.
 
12
   
 
13
   This library is distributed in the hope that it will be useful,
 
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
   Library General Public License for more details.
 
17
   
 
18
   You should have received a copy of the GNU Lesser General Public
 
19
   License along with this library; if not, write to the Free
 
20
   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
21
   MA 02111 USA.
 
22
*/ 
 
23
#ifndef _GSPThread_h_
 
24
#define _GSPThread_h_
 
25
 
 
26
/*
 
27
 * Since glibc does not enable Unix98 extensions by default, we need to tell it
 
28
 * to do so explicitly. That support is switched on by _XOPEN_SOURCE and
 
29
 * __USE_UNIX98 is an internal flag which can cause trouble if enabled alone.
 
30
 * For safety we enable this only on linux and hurd where glibc is likely.
 
31
 * We include features.h explicitely to avoid weird problems.
 
32
 */
 
33
#if defined __linux__ || defined __GNU__
 
34
#  ifndef _XOPEN_SOURCE
 
35
#    define _XOPEN_SOURCE 600
 
36
#  endif
 
37
#endif
 
38
 
 
39
#include <pthread.h>
 
40
 
 
41
/*
 
42
 * Macro to initialize recursive mutexes in a portable way. Adopted from
 
43
 * libobjc2 (lock.h).
 
44
 */
 
45
#       ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
 
46
#               define GS_INIT_RECURSIVE_MUTEX(x) x = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
 
47
#       elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
 
48
#               define GS_INIT_RECURSIVE_MUTEX(x) x = PTHREAD_RECURSIVE_MUTEX_INITIALIZER
 
49
#       else
 
50
#               define GS_INIT_RECURSIVE_MUTEX(x) GSPThreadInitRecursiveMutex(&(x))
 
51
 
 
52
static inline void GSPThreadInitRecursiveMutex(pthread_mutex_t *x)
 
53
{
 
54
        pthread_mutexattr_t recursiveAttributes;
 
55
        pthread_mutexattr_init(&recursiveAttributes);
 
56
        pthread_mutexattr_settype(&recursiveAttributes, PTHREAD_MUTEX_RECURSIVE);
 
57
        pthread_mutex_init(x, &recursiveAttributes);
 
58
        pthread_mutexattr_destroy(&recursiveAttributes);
 
59
}
 
60
#       endif // PTHREAD_RECURSIVE_MUTEX_INITIALIZER(_NP)
 
61
 
 
62
#endif // _GSPThread_h_