1 /* System thread definitions
2 Copyright (C) 2012 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
27 #ifdef HAVE_SYS_PRCTL_H
28 #include <sys/prctl.h>
32 sys_mutex_init (sys_mutex_t
*mutex
)
34 pthread_mutex_init (mutex
, NULL
);
38 sys_mutex_lock (sys_mutex_t
*mutex
)
40 pthread_mutex_lock (mutex
);
44 sys_mutex_unlock (sys_mutex_t
*mutex
)
46 pthread_mutex_unlock (mutex
);
50 sys_mutex_destroy (sys_mutex_t
*mutex
)
52 pthread_mutex_destroy (mutex
);
56 sys_cond_init (sys_cond_t
*cond
)
58 pthread_cond_init (cond
, NULL
);
62 sys_cond_wait (sys_cond_t
*cond
, sys_mutex_t
*mutex
)
64 pthread_cond_wait (cond
, mutex
);
68 sys_cond_signal (sys_cond_t
*cond
)
70 pthread_cond_signal (cond
);
74 sys_cond_broadcast (sys_cond_t
*cond
)
76 pthread_cond_broadcast (cond
);
80 sys_cond_destroy (sys_cond_t
*cond
)
82 pthread_cond_destroy (cond
);
86 sys_thread_self (void)
88 return pthread_self ();
92 sys_thread_equal (sys_thread_t one
, sys_thread_t two
)
94 return pthread_equal (one
, two
);
98 sys_thread_create (sys_thread_t
*thread_ptr
, const char *name
,
99 thread_creation_function
*func
, void *arg
)
104 if (pthread_attr_init (&attr
))
107 if (!pthread_attr_setdetachstate (&attr
, PTHREAD_CREATE_DETACHED
))
109 result
= pthread_create (thread_ptr
, &attr
, func
, arg
) == 0;
110 #if defined (HAVE_SYS_PRCTL_H) && defined (HAVE_PRCTL) && defined (PR_SET_NAME)
111 if (result
&& name
!= NULL
)
112 prctl (PR_SET_NAME
, name
);
116 pthread_attr_destroy (&attr
);
122 sys_thread_yield (void)