/usr/include/d2/4.6/gcc/threadsem.d is in libphobos2-4.6-dev 0.29.1-4.6.3-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | /* GDC -- D front-end for GCC
Copyright (C) 2004 David Friedman
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
module gcc.threadsem;
version (GNU_Semaphore_POSIX)
{
private import core.sys.posix.semaphore;
struct Semaphore {
sem_t sem;
bool create() { return sem_init(& sem, 0, 0) == 0; }
void wait() { sem_wait(& sem); }
void signal() { sem_post(& sem); }
}
}
else version (GNU_Semaphore_Mach)
{
private import core.sys.osx.mach.semaphore;
struct Semaphore {
semaphore_t sem;
bool create() {
return semaphore_create(mach_task_self(), & sem,
SYNC_POLICY_FIFO, 0) == KERN_SUCCESS; }
void wait() { semaphore_wait(sem); }
void signal() { semaphore_signal(sem); }
}
}
else version (GNU_Sempahore_Pthreads)
{
private import core.sys.posix.semaphore;
struct Semaphore {
pthread_mutex_t lock;
pthread_cond_t cond;
int count; // boehm-gc only calls lock once -- outside the loop
bool create() {
count = 0;
return pthread_mutex_init(& lock, null) == 0 &&
pthread_cond_init(& cond, null) == 0;
}
void wait() {
// boehm-gc only calls lock once -- outside the loop
pthread_mutex_lock(& lock);
if (--count < 0) {
while (count < 0) { // shouldn't be needed
pthread_cond_wait(& cond, & lock);
}
}
pthread_mutex_unlock(& lock);
}
void signal() {
pthread_mutex_lock(& lock);
if (++count >= 0) {
pthread_cond_signal(& cond);
}
pthread_mutex_unlock(& lock);
}
}
}
else version (GNU_Semaphore_SysV)
{
// TODO
}
|