rm unused pthread files
This commit is contained in:
parent
17eda91773
commit
6c03b632fd
|
|
@ -1,40 +0,0 @@
|
|||
// OpenSTA, Static Timing Analyzer
|
||||
// Copyright (c) 2019, Parallax Software, Inc.
|
||||
//
|
||||
// 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 3 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, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "Machine.hh"
|
||||
#include "Mutex.hh"
|
||||
|
||||
namespace sta {
|
||||
|
||||
Mutex::Mutex()
|
||||
{
|
||||
int error = pthread_mutex_init(&mutex_, NULL);
|
||||
CheckThreadError(error);
|
||||
}
|
||||
|
||||
Mutex::Mutex(const Mutex&)
|
||||
{
|
||||
int error = pthread_mutex_init(&mutex_, NULL);
|
||||
CheckThreadError(error);
|
||||
}
|
||||
|
||||
|
||||
Mutex::~Mutex()
|
||||
{
|
||||
pthread_mutex_destroy(&mutex_);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
149
util/Pthread.cc
149
util/Pthread.cc
|
|
@ -1,149 +0,0 @@
|
|||
// OpenSTA, Static Timing Analyzer
|
||||
// Copyright (c) 2019, Parallax Software, Inc.
|
||||
//
|
||||
// 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 3 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, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "StaConfig.hh"
|
||||
|
||||
#if !PTHREADS
|
||||
|
||||
#include "Pthread.hh"
|
||||
|
||||
namespace sta {
|
||||
|
||||
int
|
||||
pthread_create(pthread_t *,
|
||||
const pthread_attr_t *,
|
||||
void *(*) (void *),
|
||||
void *)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pthread_join(pthread_t,
|
||||
void **)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pthread_attr_init(pthread_attr_t *)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pthread_attr_setscope(pthread_attr_t *,
|
||||
int)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pthread_cond_init(pthread_cond_t *,
|
||||
const pthread_condattr_t *)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pthread_cond_destroy(pthread_cond_t *)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pthread_cond_signal(pthread_cond_t *)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pthread_cond_broadcast(pthread_cond_t *)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pthread_cond_wait(pthread_cond_t *,
|
||||
pthread_mutex_t *)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutex_init(pthread_mutex_t *,
|
||||
const pthread_mutexattr_t *)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutex_destroy(pthread_mutex_t *)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutex_lock(pthread_mutex_t *)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutex_trylock(pthread_mutex_t *)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutex_unlock(pthread_mutex_t *)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pthread_rwlock_init(pthread_rwlock_t *,
|
||||
const pthread_rwlockattr_t *)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pthread_rwlock_destroy(pthread_rwlock_t *)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pthread_rwlock_rdlock(pthread_rwlock_t *)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pthread_rwlock_wrlock(pthread_rwlock_t *)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pthread_rwlock_unlock(pthread_rwlock_t *)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
#endif
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
// OpenSTA, Static Timing Analyzer
|
||||
// Copyright (c) 2019, Parallax Software, Inc.
|
||||
//
|
||||
// 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 3 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, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef STA_PTHREAD_H
|
||||
#define STA_PTHREAD_H
|
||||
|
||||
#include "StaConfig.hh"
|
||||
|
||||
#if PTHREADS
|
||||
#include <pthread.h>
|
||||
#define STA_PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_SYSTEM
|
||||
#else
|
||||
|
||||
// Define standins for pthread API.
|
||||
|
||||
namespace sta {
|
||||
|
||||
#define STA_PTHREAD_SCOPE_SYSTEM 0
|
||||
|
||||
typedef int pthread_cond_t;
|
||||
typedef int pthread_condattr_t;
|
||||
typedef int pthread_mutex_t;
|
||||
typedef int pthread_mutexattr_t;
|
||||
typedef int pthread_rwlock_t;
|
||||
typedef int pthread_rwlockattr_t;
|
||||
typedef int pthread_t;
|
||||
typedef int pthread_attr_t;
|
||||
|
||||
int
|
||||
pthread_create(pthread_t *,
|
||||
const pthread_attr_t *,
|
||||
void *(*) (void *), void *);
|
||||
int
|
||||
pthread_join(pthread_t, void **);
|
||||
int
|
||||
pthread_attr_init(pthread_attr_t *);
|
||||
int
|
||||
pthread_attr_setscope(pthread_attr_t *, int);
|
||||
|
||||
int
|
||||
pthread_cond_init(pthread_cond_t *,
|
||||
const pthread_condattr_t *);
|
||||
int
|
||||
pthread_cond_destroy(pthread_cond_t *);
|
||||
int
|
||||
pthread_cond_signal(pthread_cond_t *);
|
||||
int
|
||||
pthread_cond_broadcast(pthread_cond_t *);
|
||||
int
|
||||
pthread_cond_wait(pthread_cond_t *,
|
||||
pthread_mutex_t *);
|
||||
|
||||
int
|
||||
pthread_mutex_init(pthread_mutex_t *,
|
||||
const pthread_mutexattr_t *);
|
||||
int
|
||||
pthread_mutex_destroy(pthread_mutex_t *);
|
||||
int
|
||||
pthread_mutex_lock(pthread_mutex_t *);
|
||||
int
|
||||
pthread_mutex_trylock(pthread_mutex_t *);
|
||||
int
|
||||
pthread_mutex_unlock(pthread_mutex_t *);
|
||||
|
||||
int
|
||||
pthread_rwlock_init(pthread_rwlock_t *,
|
||||
const pthread_rwlockattr_t *);
|
||||
int
|
||||
pthread_rwlock_destroy(pthread_rwlock_t *);
|
||||
int
|
||||
pthread_rwlock_rdlock(pthread_rwlock_t *);
|
||||
int
|
||||
pthread_rwlock_wrlock(pthread_rwlock_t *);
|
||||
int
|
||||
pthread_rwlock_unlock(pthread_rwlock_t *);
|
||||
|
||||
} // namespace
|
||||
#endif // PTHREAD
|
||||
#endif // STA_PTHREAD_H
|
||||
|
|
@ -1,134 +0,0 @@
|
|||
// OpenSTA, Static Timing Analyzer
|
||||
// Copyright (c) 2019, Parallax Software, Inc.
|
||||
//
|
||||
// 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 3 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, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <cstdio>
|
||||
#include "Machine.hh"
|
||||
#include "Error.hh"
|
||||
#include "Error.hh"
|
||||
#include "ThreadException.hh"
|
||||
#include "ThreadWorker.hh"
|
||||
|
||||
namespace sta {
|
||||
|
||||
bool ThreadWorker::default_attr_inited_ = false;
|
||||
pthread_attr_t ThreadWorker::default_attr_;
|
||||
|
||||
ThreadWorker::ThreadWorker() :
|
||||
state_(state_ready),
|
||||
func_(NULL),
|
||||
arg_(NULL)
|
||||
{
|
||||
int error = pthread_create(&thread_, defaultAttr(), threadBegin, this);
|
||||
CheckThreadError(error);
|
||||
}
|
||||
|
||||
ThreadWorker::~ThreadWorker()
|
||||
{
|
||||
// Stop the pthread function.
|
||||
lock_.lock();
|
||||
state_ = state_stop;
|
||||
condition_.signal();
|
||||
lock_.unlock();
|
||||
pthread_join(thread_, NULL);
|
||||
}
|
||||
|
||||
pthread_attr_t *
|
||||
ThreadWorker::defaultAttr()
|
||||
{
|
||||
if (!default_attr_inited_) {
|
||||
int error;
|
||||
|
||||
error = pthread_attr_init(&default_attr_);
|
||||
CheckThreadError(error);
|
||||
|
||||
// Make sure the thread contends for CPU time with threads
|
||||
// in other processes.
|
||||
error = pthread_attr_setscope(&default_attr_, STA_PTHREAD_SCOPE_SYSTEM);
|
||||
CheckThreadError(error);
|
||||
|
||||
// Set stack size to 1MB.
|
||||
// error = pthread_attr_setstacksize(&default_attr_, (1 << 20));
|
||||
CheckThreadError(error);
|
||||
|
||||
default_attr_inited_ = true;
|
||||
}
|
||||
return &default_attr_;
|
||||
}
|
||||
|
||||
void
|
||||
ThreadWorker::beginTask(ThreadFunc func,
|
||||
void *arg)
|
||||
{
|
||||
lock_.lock();
|
||||
while (state_ != state_ready)
|
||||
condition_.wait(lock_);
|
||||
|
||||
func_ = func;
|
||||
arg_ = arg;
|
||||
state_ = state_run;
|
||||
// Use broadcast instead of signal as start(), wait(), threadStart()
|
||||
// may all be in different threads.
|
||||
condition_.broadcast();
|
||||
lock_.unlock();
|
||||
}
|
||||
|
||||
void
|
||||
ThreadWorker::wait()
|
||||
{
|
||||
lock_.lock();
|
||||
while (state_ != state_ready)
|
||||
condition_.wait(lock_);
|
||||
lock_.unlock();
|
||||
}
|
||||
|
||||
// Evaluate tasks as they are assigned by and then wait for another
|
||||
// task.
|
||||
// This function is stopped by the ThreadWorker destructor.
|
||||
void *
|
||||
ThreadWorker::threadBegin(void *arg)
|
||||
{
|
||||
ThreadWorker *worker = reinterpret_cast<ThreadWorker*>(arg);
|
||||
while (true) {
|
||||
worker->lock_.lock();
|
||||
while (worker->state_ != state_run &&
|
||||
worker->state_ != state_stop)
|
||||
worker->condition_.wait(worker->lock_);
|
||||
|
||||
if (worker->state_ == state_stop) {
|
||||
// Stop the thread.
|
||||
worker->lock_.unlock();
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
(*worker->func_)(worker->arg_);
|
||||
}
|
||||
// Keep the thread worker alive even after an exception.
|
||||
catch (StaException &except) {
|
||||
printf("Caught %s exception.", except.what());
|
||||
}
|
||||
catch (...) {
|
||||
printf("Caught ... exception.");
|
||||
}
|
||||
|
||||
worker->state_ = state_ready;
|
||||
worker->condition_.broadcast();
|
||||
worker->lock_.unlock();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
// OpenSTA, Static Timing Analyzer
|
||||
// Copyright (c) 2019, Parallax Software, Inc.
|
||||
//
|
||||
// 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 3 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, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef STA_THREAD_WORKER_H
|
||||
#define STA_THREAD_WORKER_H
|
||||
|
||||
#include "Pthread.hh"
|
||||
#include "DisallowCopyAssign.hh"
|
||||
#include "Mutex.hh"
|
||||
#include "Condition.hh"
|
||||
|
||||
namespace sta {
|
||||
|
||||
typedef void (*ThreadFunc)(void*);
|
||||
|
||||
class ThreadWorker
|
||||
{
|
||||
public:
|
||||
ThreadWorker();
|
||||
~ThreadWorker();
|
||||
// beginTask() caller must call wait(), or deadlock will happen.
|
||||
void beginTask(ThreadFunc func,
|
||||
void *arg);
|
||||
void wait();
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(ThreadWorker);
|
||||
|
||||
static pthread_attr_t *defaultAttr();
|
||||
static void *threadBegin(void *arg);
|
||||
|
||||
typedef enum {
|
||||
state_ready = 0,
|
||||
state_run,
|
||||
state_done,
|
||||
state_stop
|
||||
} TaskState;
|
||||
|
||||
pthread_t thread_;
|
||||
Mutex lock_;
|
||||
Condition condition_;
|
||||
TaskState state_;
|
||||
ThreadFunc func_;
|
||||
void *arg_;
|
||||
|
||||
static bool default_attr_inited_;
|
||||
static pthread_attr_t default_attr_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
#endif
|
||||
Loading…
Reference in New Issue