summaryrefslogtreecommitdiff
path: root/libcult/cult/sched
diff options
context:
space:
mode:
Diffstat (limited to 'libcult/cult/sched')
-rw-r--r--libcult/cult/sched/condition.cxx49
-rw-r--r--libcult/cult/sched/condition.hxx42
-rw-r--r--libcult/cult/sched/exception.hxx30
-rw-r--r--libcult/cult/sched/lock.cxx13
-rw-r--r--libcult/cult/sched/lock.hxx58
-rw-r--r--libcult/cult/sched/mutex.cxx54
-rw-r--r--libcult/cult/sched/mutex.hxx41
-rw-r--r--libcult/cult/sched/spin.cxx28
-rw-r--r--libcult/cult/sched/spin.hxx41
-rw-r--r--libcult/cult/sched/spin.ixx43
-rw-r--r--libcult/cult/sched/thread.cxx211
-rw-r--r--libcult/cult/sched/thread.hxx86
12 files changed, 0 insertions, 696 deletions
diff --git a/libcult/cult/sched/condition.cxx b/libcult/cult/sched/condition.cxx
deleted file mode 100644
index 5f547c8..0000000
--- a/libcult/cult/sched/condition.cxx
+++ /dev/null
@@ -1,49 +0,0 @@
-// file : cult/sched/condition.cxx
-// author : Boris Kolpackov <boris@kolpackov.net>
-// copyright : Copyright (c) 2005-2010 Boris Kolpackov
-// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
-
-#include <cult/sched/condition.hxx>
-#include <cult/sched/exception.hxx>
-
-namespace Cult
-{
- namespace Sched
- {
- Condition::
- ~Condition ()
- {
- if (Int e = pthread_cond_destroy (&cond_))
- throw Implementation (e);
- }
-
- Condition::
- Condition (Mutex& mutex)
- : mutex_ (mutex)
- {
- if (Int e = pthread_cond_init (&cond_, 0))
- throw Implementation (e);
- }
-
- Void Condition::
- signal ()
- {
- if (Int e = pthread_cond_signal (&cond_))
- throw Implementation (e);
- }
-
- Void Condition::
- broadcast ()
- {
- if (Int e = pthread_cond_broadcast (&cond_))
- throw Implementation (e);
- }
-
- Void Condition::
- wait ()
- {
- if (Int e = pthread_cond_wait (&cond_, &mutex_.mutex_))
- throw Implementation (e);
- }
- }
-}
diff --git a/libcult/cult/sched/condition.hxx b/libcult/cult/sched/condition.hxx
deleted file mode 100644
index b1a0f30..0000000
--- a/libcult/cult/sched/condition.hxx
+++ /dev/null
@@ -1,42 +0,0 @@
-// file : cult/sched/condition.hxx
-// author : Boris Kolpackov <boris@kolpackov.net>
-// copyright : Copyright (c) 2005-2010 Boris Kolpackov
-// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
-
-#ifndef CULT_SCHED_CONDITION_HXX
-#define CULT_SCHED_CONDITION_HXX
-
-#include <cult/types/fundamental.hxx>
-
-#include <cult/sched/mutex.hxx>
-
-#include <pthread.h>
-
-namespace Cult
-{
- namespace Sched
- {
- class Condition: public NonCopyable
- {
- public:
- ~Condition ();
-
- Condition (Mutex& mutex);
-
- Void
- signal ();
-
- Void
- broadcast ();
-
- Void
- wait ();
-
- private:
- Mutex& mutex_;
- pthread_cond_t cond_;
- };
- }
-}
-
-#endif // CULT_SCHED_CONDITION_HXX
diff --git a/libcult/cult/sched/exception.hxx b/libcult/cult/sched/exception.hxx
deleted file mode 100644
index 3fa6e5f..0000000
--- a/libcult/cult/sched/exception.hxx
+++ /dev/null
@@ -1,30 +0,0 @@
-// file : cult/sched/exception.hxx
-// author : Boris Kolpackov <boris@kolpackov.net>
-// copyright : Copyright (c) 2005-2010 Boris Kolpackov
-// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
-
-#ifndef CULT_SCHED_EXCEPTION_HXX
-#define CULT_SCHED_EXCEPTION_HXX
-
-#include <cult/types/fundamental.hxx>
-
-#include <cult/eh/exception.hxx>
-#include <cult/os/exception.hxx>
-
-namespace Cult
-{
- namespace Sched
- {
- struct Exception: virtual EH::Exception {};
-
- struct Implementation: virtual Exception, virtual OS::Exception
- {
- Implementation (Int code) throw ()
- : OS::Exception (code)
- {
- }
- };
- }
-}
-
-#endif // CULT_SCHED_EXCEPTION_HXX
diff --git a/libcult/cult/sched/lock.cxx b/libcult/cult/sched/lock.cxx
deleted file mode 100644
index 853d9b0..0000000
--- a/libcult/cult/sched/lock.cxx
+++ /dev/null
@@ -1,13 +0,0 @@
-// file : cult/sched/lock.cxx
-// author : Boris Kolpackov <boris@kolpackov.net>
-// copyright : Copyright (c) 2005-2010 Boris Kolpackov
-// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
-
-#include <cult/sched/lock.hxx>
-
-namespace Cult
-{
- namespace Sched
- {
- }
-}
diff --git a/libcult/cult/sched/lock.hxx b/libcult/cult/sched/lock.hxx
deleted file mode 100644
index 1ecf3fb..0000000
--- a/libcult/cult/sched/lock.hxx
+++ /dev/null
@@ -1,58 +0,0 @@
-// file : cult/sched/lock.hxx
-// author : Boris Kolpackov <boris@kolpackov.net>
-// copyright : Copyright (c) 2005-2010 Boris Kolpackov
-// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
-
-#ifndef CULT_SCHED_LOCK_HXX
-#define CULT_SCHED_LOCK_HXX
-
-#include <cult/types/fundamental.hxx>
-
-namespace Cult
-{
- namespace Sched
- {
- class Lock: public NonCopyable
- {
- public:
- ~Lock ()
- {
- unlock ();
- }
-
- template <typename X>
- Lock (X& x)
- : x_ (reinterpret_cast<Void*>(&x)),
- unlock_ (&unlock<X>),
- locked_ (true)
- {
- x.lock ();
- }
-
- Void
- unlock ()
- {
- if (locked_)
- {
- unlock_ (x_);
- locked_ = false;
- }
- }
-
- private:
- template <typename X>
- static Void
- unlock (Void* p)
- {
- reinterpret_cast<X*> (p)->unlock ();
- }
-
- private:
- Void* x_;
- Void (*unlock_) (Void*);
- Boolean locked_;
- };
- }
-}
-
-#endif // CULT_SCHED_LOCK_HXX
diff --git a/libcult/cult/sched/mutex.cxx b/libcult/cult/sched/mutex.cxx
deleted file mode 100644
index 9667a67..0000000
--- a/libcult/cult/sched/mutex.cxx
+++ /dev/null
@@ -1,54 +0,0 @@
-// file : cult/sched/mutex.cxx
-// author : Boris Kolpackov <boris@kolpackov.net>
-// copyright : Copyright (c) 2005-2010 Boris Kolpackov
-// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
-
-#include <cult/sched/mutex.hxx>
-#include <cult/sched/exception.hxx>
-
-namespace Cult
-{
- namespace Sched
- {
- Mutex::
- ~Mutex ()
- {
- if (Int e = pthread_mutex_destroy (&mutex_))
- throw Implementation (e);
- }
-
- Mutex::
- Mutex ()
- {
- if (Int e = pthread_mutex_init (&mutex_, 0))
- throw Implementation (e);
- }
-
- Void Mutex::
- lock ()
- {
- if (Int e = pthread_mutex_lock (&mutex_))
- throw Implementation (e);
- }
-
- Boolean Mutex::
- try_lock ()
- {
- Int e (pthread_mutex_trylock (&mutex_));
-
- switch (e)
- {
- case 0: return true;
- case EBUSY: return false;
- default: throw Implementation (e);
- }
- }
-
- Void Mutex::
- unlock ()
- {
- if (Int e = pthread_mutex_unlock (&mutex_))
- throw Implementation (e);
- }
- }
-}
diff --git a/libcult/cult/sched/mutex.hxx b/libcult/cult/sched/mutex.hxx
deleted file mode 100644
index 0c6daee..0000000
--- a/libcult/cult/sched/mutex.hxx
+++ /dev/null
@@ -1,41 +0,0 @@
-// file : cult/sched/mutex.hxx
-// author : Boris Kolpackov <boris@kolpackov.net>
-// copyright : Copyright (c) 2005-2010 Boris Kolpackov
-// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
-
-#ifndef CULT_SCHED_MUTEX_HXX
-#define CULT_SCHED_MUTEX_HXX
-
-#include <cult/types/fundamental.hxx>
-
-#include <pthread.h>
-
-namespace Cult
-{
- namespace Sched
- {
- class Mutex: public NonCopyable
- {
- public:
- ~Mutex ();
-
- Mutex ();
-
- Void
- lock ();
-
- Boolean
- try_lock ();
-
- Void
- unlock ();
-
- private:
- friend class Condition;
-
- pthread_mutex_t mutex_;
- };
- }
-}
-
-#endif // CULT_SCHED_MUTEX_HXX
diff --git a/libcult/cult/sched/spin.cxx b/libcult/cult/sched/spin.cxx
deleted file mode 100644
index 54df7ce..0000000
--- a/libcult/cult/sched/spin.cxx
+++ /dev/null
@@ -1,28 +0,0 @@
-// file : cult/sched/spin.cxx
-// author : Boris Kolpackov <boris@kolpackov.net>
-// copyright : Copyright (c) 2005-2010 Boris Kolpackov
-// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
-
-#include <cult/sched/spin.hxx>
-#include <cult/sched/exception.hxx>
-
-namespace Cult
-{
- namespace Sched
- {
- Spin::
- ~Spin ()
- {
- if (Int e = pthread_spin_destroy (&spin_))
- throw Implementation (e);
- }
-
- Spin::
- Spin ()
- {
- if (Int e = pthread_spin_init (&spin_, PTHREAD_PROCESS_PRIVATE))
- throw Implementation (e);
- }
- }
-}
-
diff --git a/libcult/cult/sched/spin.hxx b/libcult/cult/sched/spin.hxx
deleted file mode 100644
index c32e836..0000000
--- a/libcult/cult/sched/spin.hxx
+++ /dev/null
@@ -1,41 +0,0 @@
-// file : cult/sched/spin.hxx
-// author : Boris Kolpackov <boris@kolpackov.net>
-// copyright : Copyright (c) 2005-2010 Boris Kolpackov
-// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
-
-#ifndef CULT_SCHED_SPIN_HXX
-#define CULT_SCHED_SPIN_HXX
-
-#include <cult/types/fundamental.hxx>
-
-#include <pthread.h>
-
-namespace Cult
-{
- namespace Sched
- {
- class Spin: public NonCopyable
- {
- public:
- ~Spin ();
-
- Spin ();
-
- Void
- lock ();
-
- Boolean
- try_lock ();
-
- Void
- unlock ();
-
- private:
- pthread_spinlock_t spin_;
- };
- }
-}
-
-#include <cult/sched/spin.ixx>
-
-#endif // CULT_SCHED_SPIN_HXX
diff --git a/libcult/cult/sched/spin.ixx b/libcult/cult/sched/spin.ixx
deleted file mode 100644
index 2accdde..0000000
--- a/libcult/cult/sched/spin.ixx
+++ /dev/null
@@ -1,43 +0,0 @@
-// file : cult/sched/spin.ixx
-// author : Boris Kolpackov <boris@kolpackov.net>
-// copyright : Copyright (c) 2005-2010 Boris Kolpackov
-// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
-
-#include <cult/sched/exception.hxx>
-
-namespace Cult
-{
- namespace Sched
- {
- inline
- Void Spin::
- lock ()
- {
- if (Int e = pthread_spin_lock (&spin_))
- throw Implementation (e);
- }
-
- inline
- Boolean Spin::
- try_lock ()
- {
- Int e (pthread_spin_trylock (&spin_));
-
- switch (e)
- {
- case 0: return true;
- case EBUSY: return false;
- default: throw Implementation (e);
- }
- }
-
- inline
- Void Spin::
- unlock ()
- {
- if (Int e = pthread_spin_unlock (&spin_))
- throw Implementation (e);
- }
- }
-}
-
diff --git a/libcult/cult/sched/thread.cxx b/libcult/cult/sched/thread.cxx
deleted file mode 100644
index 89368b6..0000000
--- a/libcult/cult/sched/thread.cxx
+++ /dev/null
@@ -1,211 +0,0 @@
-// file : cult/sched/thread.cxx
-// author : Boris Kolpackov <boris@kolpackov.net>
-// copyright : Copyright (c) 2005-2010 Boris Kolpackov
-// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
-
-#include <cult/sched/thread.hxx>
-#include <cult/sched/lock.hxx>
-#include <cult/sched/exception.hxx>
-
-#include <cult/mm/counter.hxx> // MM::inc_ref
-
-#include <cult/trace/stream.hxx>
-
-namespace Cult
-{
- namespace Sched
- {
- namespace
- {
- Trace::Stream tout ("Cult::Sched::Thread", 7);
- }
-
- namespace Bits
- {
- typedef Void* (*Routine) (Void*);
-
- struct StartData
- {
- StartData (Shptr<Thread> const& thread, Routine routine, void* arg)
- : thread_ (thread), routine_ (routine), arg_ (arg)
- {
- }
-
- ~StartData ()
- {
- tout << 8 << "start data is being destroyed.";
- }
-
- Shptr<Thread> thread_;
- Routine routine_;
- Void* arg_;
- };
-
- static pthread_key_t key;
- static pthread_once_t key_once = PTHREAD_ONCE_INIT;
-
- extern "C" Void
- cult_thread_dtor (Void* p)
- {
- // Exception in this function will result in the call
- // to std::terminate().
- //
-
- tout << "cult_thread_dtor is being executed.";
-
- Shptr<Thread> self (reinterpret_cast<Thread*> (p));
- }
-
- extern "C" Void
- cult_thread_make_key ()
- {
- if (Int e = pthread_key_create (&key, &cult_thread_dtor))
- throw Implementation (e);
- }
-
- extern "C" Void*
- cult_thread_trampoline (Void* arg)
- {
- // Any failure in this function will result in the call
- // to std::terminate().
- //
-
- Routine routine;
-
- {
- Shptr<StartData> data (reinterpret_cast<StartData*> (arg));
-
- Thread* p (data->thread_.get ());
-
- if (Int e = pthread_setspecific (key, p))
- throw Implementation (e);
- else
- MM::inc_ref (p);
-
- routine = data->routine_;
- arg = data->arg_;
- }
-
- return routine (arg);
- }
- }
-
- Thread::
- Thread (Void* (*routine) (Void*), Void* arg)
- : detached_ (false)
- {
- using Bits::StartData;
-
- tout << "thread is being constructed.";
-
- pthread_once (&Bits::key_once, &Bits::cult_thread_make_key);
-
- Shptr<Thread> self (MM::inc_ref (this));
-
- Shptr<StartData> data (new StartData (self, routine, arg));
-
- if (Int e = pthread_create (&id_,
- 0,
- &Bits::cult_thread_trampoline,
- data.get ()))
- {
- throw Implementation (e);
- }
- else
- {
- // If pthread_create did not fail then thread_trampoline
- // will release the data.
- //
- data.release ();
- }
- }
-
- Thread::
- Thread ()
- : id_ (pthread_self ()), detached_ (false) //@@ We can't be sure
- // the it is detached.
- {
- tout << "thread is being adopted.";
-
- pthread_once (&Bits::key_once, &Bits::cult_thread_make_key);
-
- if (pthread_getspecific (Bits::key) != 0)
- throw Adopted ();
-
- Shptr<Thread> self (MM::inc_ref (this));
-
- if(Int e = pthread_setspecific (Bits::key, this))
- {
- throw Implementation (e);
- }
- else
- {
- // TSD slot has the reference now.
- //
- self.release ();
- }
- }
-
- Void* Thread::
- join ()
- {
- Lock lock (mutex_);
-
- if (detached_)
- throw Joined ();
-
- Void* r;
-
- if (Int e = pthread_join (id_, &r))
- throw Implementation (e);
-
- detached_ = true;
-
- return r;
- }
-
- Void Thread::
- cancel ()
- {
- if (Int e = pthread_cancel (id_))
- throw Implementation (e);
- }
-
- Void Thread::
- exit (Void* ret)
- {
- pthread_exit (ret);
- }
-
- Shptr<Thread> Thread::
- self ()
- {
- Thread* p (reinterpret_cast<Thread*> (pthread_getspecific (Bits::key)));
-
- if (p != 0)
- return Shptr<Thread> (MM::inc_ref (p));
- else
- throw Foreign ();
- }
-
- Void Thread::
- test_cancel ()
- {
- pthread_testcancel ();
- }
-
- Thread::
- ~Thread ()
- {
- tout << "thread is being destroyed.";
-
- Lock lock (mutex_);
-
- if (!detached_)
- {
- if (Int e = pthread_detach (id_))
- throw Implementation (e);
- }
- }
- }
-}
diff --git a/libcult/cult/sched/thread.hxx b/libcult/cult/sched/thread.hxx
deleted file mode 100644
index 49d6225..0000000
--- a/libcult/cult/sched/thread.hxx
+++ /dev/null
@@ -1,86 +0,0 @@
-// file : cult/sched/thread.hxx
-// author : Boris Kolpackov <boris@kolpackov.net>
-// copyright : Copyright (c) 2005-2010 Boris Kolpackov
-// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
-
-#ifndef CULT_SCHED_THREAD_HXX
-#define CULT_SCHED_THREAD_HXX
-
-#include <cult/types/fundamental.hxx>
-#include <cult/types/shptr.hxx>
-
-#include <cult/sched/mutex.hxx>
-#include <cult/sched/exception.hxx>
-
-#include <cult/mm/new.hxx>
-
-#include <pthread.h>
-
-namespace Cult
-{
- namespace Sched
- {
- // Instantiating an automatic variable of type Thread results
- // in undefined behavior (read core dump).
- //
- class Thread: public MM::ServiceAwareObject
- {
- public:
- struct Exception: virtual Sched::Exception {};
-
- public:
- virtual
- ~Thread ();
-
- Thread (Void* (*StartRoutine) (Void*), Void* arg = 0);
-
- // Adopt an existing thread. Adoption of a detached thread
- // results in undefined behavior. Adoption of an already
- // adopted thread results in Adopted exception.
- //
-
- struct Adopted: virtual Exception {};
-
- Thread ();
-
- public:
- // Joining an already joined thread results in Joined exception.
- //
-
- struct Joined: virtual Exception {};
-
- //@@ Need to work out the cancelled case.
- //
- Void*
- join ();
-
- Void
- cancel ();
-
- public:
- static Void
- exit (Void* ret);
-
- // self() may not be called in TSD destructors. Call to self() from
- // a foreign thread (i.e., one that is neither native nor adopted)
- // results in Foreign exception.
- //
-
- struct Foreign: virtual Exception {};
-
- static Shptr<Thread>
- self ();
-
- static Void
- test_cancel ();
-
- private:
- pthread_t id_;
-
- Boolean detached_;
- Mutex mutex_;
- };
- }
-}
-
-#endif // CULT_SCHED_THREAD_HXX