mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-03-01 16:31:13 +00:00
Revision of Brian's threading support library to be a bit more generic and
platform independent. This code is completely untested (but never used), and needs autoconf support for detecting pthreads, but it's a start, and deletes two emails from my inbox. :) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10906 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
64811a3e18
commit
440f87eea2
34
include/Support/ThreadSupport-NoSupport.h
Normal file
34
include/Support/ThreadSupport-NoSupport.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
//===-- Support/ThreadSupport-NoSupport.h - Generic impl --------*- C++ -*-===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file was developed by the LLVM research group and is distributed under
|
||||||
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// This file defines a generic ThreadSupport implementation used when there is
|
||||||
|
// no supported threading mechanism on the current system. Users should never
|
||||||
|
// #include this file directly!
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// Users should never #include this file directly! As such, no include guards
|
||||||
|
// are needed.
|
||||||
|
|
||||||
|
#ifndef SUPPORT_THREADSUPPORT_H
|
||||||
|
#error "Code should not #include Support/ThreadSupport-NoSupport.h directly!"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace llvm {
|
||||||
|
/// Mutex - This class allows user code to protect variables shared between
|
||||||
|
/// threads. It implements a "recursive" mutex, to simplify user code.
|
||||||
|
///
|
||||||
|
/// Since there is no platform support for _creating threads_, the non-thread
|
||||||
|
/// implementation of this class is a noop.
|
||||||
|
///
|
||||||
|
struct Mutex {
|
||||||
|
void acquire () {}
|
||||||
|
void release () {}
|
||||||
|
};
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
//===-- Support/Lock.h - Platform-agnostic mutual exclusion -----*- C++ -*-===//
|
//===-- Support/ThreadSupport-PThreads.h - PThreads support -----*- C++ -*-===//
|
||||||
//
|
//
|
||||||
// The LLVM Compiler Infrastructure
|
// The LLVM Compiler Infrastructure
|
||||||
//
|
//
|
||||||
@ -7,63 +7,36 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
//
|
//
|
||||||
// This file contains classes that implement locks (mutual exclusion
|
// This file defines pthreads implementations of the generic threading
|
||||||
// variables) in a platform-agnostic way. Basically the user should
|
// mechanisms. Users should never #include this file directly!
|
||||||
// just call Lock::create() to get a Lock object of the correct sort
|
|
||||||
// for the current platform, and use its acquire() and release()
|
|
||||||
// methods, or a LockHolder, to protect critical sections of code for
|
|
||||||
// thread-safety.
|
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#ifndef SUPPORT_LOCK_H
|
// Users should never #include this file directly! As such, no include guards
|
||||||
#define SUPPORT_LOCK_H
|
// are needed.
|
||||||
|
|
||||||
|
#ifndef SUPPORT_THREADSUPPORT_H
|
||||||
|
#error "Code should not #include Support/ThreadSupport/PThreads.h directly!"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
/// Lock - Abstract class that provides mutual exclusion (also known
|
/// Mutex - This class allows user code to protect variables shared between
|
||||||
/// as a mutex.)
|
/// threads. It implements a "recursive" mutex, to simplify user code.
|
||||||
///
|
|
||||||
class Lock {
|
|
||||||
protected:
|
|
||||||
virtual ~Lock() {} // Derive from me
|
|
||||||
public:
|
|
||||||
virtual void acquire () { abort (); }
|
|
||||||
virtual void release () { abort (); }
|
|
||||||
|
|
||||||
/// create - Static method that returns a Lock of the correct class
|
|
||||||
/// for the current host OS.
|
|
||||||
///
|
///
|
||||||
static Lock create ();
|
class Mutex {
|
||||||
};
|
|
||||||
|
|
||||||
/// POSIXLock - Specialization of Lock class implemented using
|
|
||||||
/// pthread_mutex_t objects.
|
|
||||||
///
|
|
||||||
class POSIXLock : public Lock {
|
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
public:
|
Mutex(const Mutex &); // DO NOT IMPLEMENT
|
||||||
POSIXLock () { pthread_mutex_init (&mutex, 0); }
|
void operator=(const Mutex &); // DO NOT IMPLEMENT
|
||||||
virtual ~POSIXLock () { pthread_mutex_destroy (&mutex); }
|
public:
|
||||||
virtual void acquire () { pthread_mutex_lock (&mutex); }
|
Mutex() {
|
||||||
virtual void release () { pthread_mutex_unlock (&mutex); }
|
pthread_mutexattr_t Attr;
|
||||||
};
|
pthread_mutex_init(&mutex, &Attr);
|
||||||
|
}
|
||||||
/// LockHolder - Instances of this class acquire a given Lock when
|
~Mutex() { pthread_mutex_destroy(&mutex); }
|
||||||
/// constructed and hold that lock until destruction. Uncle Bjarne
|
void acquire () { pthread_mutex_lock (&mutex); }
|
||||||
/// says, "Resource acquisition is allocation." Or is it the other way
|
void release () { pthread_mutex_unlock (&mutex); }
|
||||||
/// around? I never can remember.
|
};
|
||||||
///
|
|
||||||
class LockHolder {
|
|
||||||
Lock &L;
|
|
||||||
public:
|
|
||||||
LockHolder (Lock &_L) : L (_L) { L.acquire (); }
|
|
||||||
~LockHolder () { L.release (); }
|
|
||||||
};
|
|
||||||
|
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
|
||||||
#endif // SUPPORT_LOCK_H
|
|
||||||
|
41
include/Support/ThreadSupport.h
Normal file
41
include/Support/ThreadSupport.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
//===-- Support/ThreadSupport.h - Generic threading support -----*- C++ -*-===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file was developed by the LLVM research group and is distributed under
|
||||||
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// This file defines platform-agnostic interfaces that can be used to write
|
||||||
|
// multi-threaded programs. Autoconf is used to chose the correct
|
||||||
|
// implementation of these interfaces, or default to a non-thread-capable system
|
||||||
|
// if no matching system support is available.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef SUPPORT_THREADSUPPORT_H
|
||||||
|
#define SUPPORT_THREADSUPPORT_H
|
||||||
|
|
||||||
|
// FIXME: We need autoconf support to detect pthreads!
|
||||||
|
#if 0
|
||||||
|
#include "Support/ThreadSupport-PThreads.h"
|
||||||
|
#else
|
||||||
|
#include "Support/ThreadSupport-NoSupport.h"
|
||||||
|
#endif // If no system support is available
|
||||||
|
|
||||||
|
namespace llvm {
|
||||||
|
/// LockHolder - Instances of this class acquire a given Lock when constructed
|
||||||
|
/// and hold that lock until destruction.
|
||||||
|
///
|
||||||
|
class MutexLocker {
|
||||||
|
Mutex &M;
|
||||||
|
MutexLocker(const LockHolder &); // DO NOT IMPLEMENT
|
||||||
|
void operator=(const MutexLocker&); // DO NOT IMPLEMENT
|
||||||
|
public:
|
||||||
|
MutexLocker(Mutex &m) : M(m) { M.acquire(); }
|
||||||
|
~MutexLocker() { M.release(); }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SUPPORT_THREADSUPPORT_H
|
34
include/llvm/Support/ThreadSupport-NoSupport.h
Normal file
34
include/llvm/Support/ThreadSupport-NoSupport.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
//===-- Support/ThreadSupport-NoSupport.h - Generic impl --------*- C++ -*-===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file was developed by the LLVM research group and is distributed under
|
||||||
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// This file defines a generic ThreadSupport implementation used when there is
|
||||||
|
// no supported threading mechanism on the current system. Users should never
|
||||||
|
// #include this file directly!
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// Users should never #include this file directly! As such, no include guards
|
||||||
|
// are needed.
|
||||||
|
|
||||||
|
#ifndef SUPPORT_THREADSUPPORT_H
|
||||||
|
#error "Code should not #include Support/ThreadSupport-NoSupport.h directly!"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace llvm {
|
||||||
|
/// Mutex - This class allows user code to protect variables shared between
|
||||||
|
/// threads. It implements a "recursive" mutex, to simplify user code.
|
||||||
|
///
|
||||||
|
/// Since there is no platform support for _creating threads_, the non-thread
|
||||||
|
/// implementation of this class is a noop.
|
||||||
|
///
|
||||||
|
struct Mutex {
|
||||||
|
void acquire () {}
|
||||||
|
void release () {}
|
||||||
|
};
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
//===-- Support/Lock.h - Platform-agnostic mutual exclusion -----*- C++ -*-===//
|
//===-- Support/ThreadSupport-PThreads.h - PThreads support -----*- C++ -*-===//
|
||||||
//
|
//
|
||||||
// The LLVM Compiler Infrastructure
|
// The LLVM Compiler Infrastructure
|
||||||
//
|
//
|
||||||
@ -7,63 +7,36 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
//
|
//
|
||||||
// This file contains classes that implement locks (mutual exclusion
|
// This file defines pthreads implementations of the generic threading
|
||||||
// variables) in a platform-agnostic way. Basically the user should
|
// mechanisms. Users should never #include this file directly!
|
||||||
// just call Lock::create() to get a Lock object of the correct sort
|
|
||||||
// for the current platform, and use its acquire() and release()
|
|
||||||
// methods, or a LockHolder, to protect critical sections of code for
|
|
||||||
// thread-safety.
|
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#ifndef SUPPORT_LOCK_H
|
// Users should never #include this file directly! As such, no include guards
|
||||||
#define SUPPORT_LOCK_H
|
// are needed.
|
||||||
|
|
||||||
|
#ifndef SUPPORT_THREADSUPPORT_H
|
||||||
|
#error "Code should not #include Support/ThreadSupport/PThreads.h directly!"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
/// Lock - Abstract class that provides mutual exclusion (also known
|
/// Mutex - This class allows user code to protect variables shared between
|
||||||
/// as a mutex.)
|
/// threads. It implements a "recursive" mutex, to simplify user code.
|
||||||
///
|
|
||||||
class Lock {
|
|
||||||
protected:
|
|
||||||
virtual ~Lock() {} // Derive from me
|
|
||||||
public:
|
|
||||||
virtual void acquire () { abort (); }
|
|
||||||
virtual void release () { abort (); }
|
|
||||||
|
|
||||||
/// create - Static method that returns a Lock of the correct class
|
|
||||||
/// for the current host OS.
|
|
||||||
///
|
///
|
||||||
static Lock create ();
|
class Mutex {
|
||||||
};
|
|
||||||
|
|
||||||
/// POSIXLock - Specialization of Lock class implemented using
|
|
||||||
/// pthread_mutex_t objects.
|
|
||||||
///
|
|
||||||
class POSIXLock : public Lock {
|
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
public:
|
Mutex(const Mutex &); // DO NOT IMPLEMENT
|
||||||
POSIXLock () { pthread_mutex_init (&mutex, 0); }
|
void operator=(const Mutex &); // DO NOT IMPLEMENT
|
||||||
virtual ~POSIXLock () { pthread_mutex_destroy (&mutex); }
|
public:
|
||||||
virtual void acquire () { pthread_mutex_lock (&mutex); }
|
Mutex() {
|
||||||
virtual void release () { pthread_mutex_unlock (&mutex); }
|
pthread_mutexattr_t Attr;
|
||||||
};
|
pthread_mutex_init(&mutex, &Attr);
|
||||||
|
}
|
||||||
/// LockHolder - Instances of this class acquire a given Lock when
|
~Mutex() { pthread_mutex_destroy(&mutex); }
|
||||||
/// constructed and hold that lock until destruction. Uncle Bjarne
|
void acquire () { pthread_mutex_lock (&mutex); }
|
||||||
/// says, "Resource acquisition is allocation." Or is it the other way
|
void release () { pthread_mutex_unlock (&mutex); }
|
||||||
/// around? I never can remember.
|
};
|
||||||
///
|
|
||||||
class LockHolder {
|
|
||||||
Lock &L;
|
|
||||||
public:
|
|
||||||
LockHolder (Lock &_L) : L (_L) { L.acquire (); }
|
|
||||||
~LockHolder () { L.release (); }
|
|
||||||
};
|
|
||||||
|
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
|
||||||
#endif // SUPPORT_LOCK_H
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user