From 56314894fff50d67f7d761077fee1754a07048b5 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Fri, 20 May 2022 19:57:20 +0200 Subject: [PATCH 01/15] codechange - TCP listener: replaced pthread with STL thread --- source/server/listener.cpp | 91 ++++++++++++++++--------------------- source/server/listener.h | 32 +++++++------ source/server/rorserver.cpp | 6 +-- 3 files changed, 57 insertions(+), 72 deletions(-) diff --git a/source/server/listener.cpp b/source/server/listener.cpp index d4ff146f..a5d8de8b 100644 --- a/source/server/listener.cpp +++ b/source/server/listener.cpp @@ -39,79 +39,60 @@ along with Foobar. If not, see . #endif -void *s_lsthreadstart(void *arg) { - Listener *listener = static_cast(arg); - listener->threadstart(); - return nullptr; -} - -Listener::Listener(Sequencer *sequencer, int port) : - m_listen_port(port), - m_sequencer(sequencer), - m_thread_shutdown(false) { +Listener::Listener(Sequencer *sequencer) : + m_sequencer(sequencer) { } -Listener::~Listener(void) { - if (!m_thread_shutdown) { - this->Shutdown(); +bool Listener::Initialize() { + // Make sure it's not started twice + std::lock_guard lock(m_mutex); + if (m_thread_state != ThreadState::NOT_RUNNING) + { + return true; } -} -bool Listener::Initialize() { - if (!m_ready_cond.Initialize()) { + // Start listening on the socket + SWBaseSocket::SWBaseError error; + m_listen_socket.bind(Config::getListenPort(), &error); + if (error != SWBaseSocket::ok) { + Logger::Log(LOG_ERROR, "FATAL Listerer: %s", error.get_error().c_str()); return false; } - return (0 == pthread_create(&m_thread, NULL, s_lsthreadstart, this)); + m_listen_socket.listen(); + + // Start the thread + m_thread = std::thread(&Listener::ThreadMain, this); + m_thread_state = ThreadState::RUNNING; + + return true; } void Listener::Shutdown() { + // Make sure it's not shut down twice + std::lock_guard lock(m_mutex); + if (m_thread_state != ThreadState::RUNNING) + { + return; + } + Logger::Log(LOG_VERBOSE, "Stopping listener thread..."); - m_thread_shutdown = true; - m_listen_socket.disconnect(); - pthread_join(m_thread, nullptr); + m_thread_state = ThreadState::STOP_REQUESTED; + m_thread.join(); Logger::Log(LOG_VERBOSE, "Listener thread stopped"); } -bool Listener::WaitUntilReady() { - int result = 0; - if (!m_ready_cond.Wait(&result)) { - Logger::Log(LOG_ERROR, "Internal: Error while starting listener thread"); - return false; - } - if (result < 0) { - Logger::Log(LOG_ERROR, "Internal: Listerer thread failed to start"); - return false; - } - return true; -} - -void Listener::threadstart() { +void Listener::ThreadMain() { Logger::Log(LOG_DEBUG, "Listerer thread starting"); - //here we start - SWBaseSocket::SWBaseError error; - - //manage the listening socket - m_listen_socket.bind(m_listen_port, &error); - if (error != SWBaseSocket::ok) { - //this is an error! - Logger::Log(LOG_ERROR, "FATAL Listerer: %s", error.get_error().c_str()); - //there is nothing we can do here - return; - // exit(1); - } - m_listen_socket.listen(); - Logger::Log(LOG_VERBOSE, "Listener ready"); - m_ready_cond.Signal(1); + SWBaseSocket::SWBaseError error; //await connections - while (!m_thread_shutdown) { + while (GetThreadState() == ThreadState::RUNNING) { Logger::Log(LOG_VERBOSE, "Listener awaiting connections"); SWInetSocket *ts = (SWInetSocket *) m_listen_socket.accept(&error); - if (error != SWBaseSocket::ok) { - if (m_thread_shutdown) { + if (GetThreadState() == ThreadState::STOP_REQUESTED) { Logger::Log(LOG_ERROR, "INFO Listener shutting down"); } else { Logger::Log(LOG_ERROR, "ERROR Listener: %s", error.get_error().c_str()); @@ -237,3 +218,9 @@ void Listener::threadstart() { } } } + +Listener::ThreadState Listener::GetThreadState() +{ + std::lock_guard lock(m_mutex); + return m_thread_state; +} diff --git a/source/server/listener.h b/source/server/listener.h index 47f1e466..1a8a4f65 100644 --- a/source/server/listener.h +++ b/source/server/listener.h @@ -21,31 +21,33 @@ #pragma once #include "SocketW.h" -#include "mutexutils.h" #include "prerequisites.h" -#include -#include +#include +#include class Listener { private: - pthread_t m_thread; + enum class ThreadState + { + NOT_RUNNING, + RUNNING, + STOP_REQUESTED + }; + SWInetSocket m_listen_socket; - int m_listen_port; - Threading::SimpleCond m_ready_cond; - Sequencer *m_sequencer; - std::atomic_bool m_thread_shutdown; -public: - Listener(Sequencer *sequencer, int port); + ThreadState m_thread_state = ThreadState::NOT_RUNNING; + std::mutex m_mutex; + std::thread m_thread; + Sequencer* m_sequencer = nullptr; - ~Listener(void); + void ThreadMain(); + ThreadState GetThreadState(); - void threadstart(); +public: + Listener(Sequencer *sequencer); bool Initialize(); - - bool WaitUntilReady(); - void Shutdown(); }; diff --git a/source/server/rorserver.cpp b/source/server/rorserver.cpp index 8d592adf..62de763f 100644 --- a/source/server/rorserver.cpp +++ b/source/server/rorserver.cpp @@ -309,16 +309,12 @@ int main(int argc, char *argv[]) { #endif // ! _WIN32 - Listener listener(&s_sequencer, Config::getListenPort()); + Listener listener(&s_sequencer); if (!listener.Initialize()) { return -1; } s_sequencer.Initialize(); - if (!listener.WaitUntilReady()) { - return -1; // Error already logged - } - // Listener is ready, let's register ourselves on serverlist (which will contact us back to check). if (server_mode != SERVER_LAN) { bool registered = s_master_server.Register(); From 4e5f7d5a208198e9fcfb4827eec13692daecd18a Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Fri, 20 May 2022 20:05:14 +0200 Subject: [PATCH 02/15] codechange - Sequencer(Clients): replaced pthread with STL thread --- source/server/sequencer.cpp | 20 +++++++++----------- source/server/sequencer.h | 4 ++-- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/source/server/sequencer.cpp b/source/server/sequencer.cpp index 0d8ab479..e323bef8 100644 --- a/source/server/sequencer.cpp +++ b/source/server/sequencer.cpp @@ -147,7 +147,6 @@ void *LaunchKillerThread(void *data) { Sequencer::Sequencer() : m_script_engine(nullptr), m_auth_resolver(nullptr), - m_clients_mutex(/*recursive=*/ true), m_num_disconnects_total(0), m_num_disconnects_crash(0), m_blacklist(this), @@ -247,7 +246,7 @@ void Sequencer::createClient(SWInetSocket *sock, RoRnet::UserInfo user) { //try to find a place for him Logger::Log(LOG_DEBUG, "got instance in createClient()"); - MutexLocker scoped_lock(m_clients_mutex); + std::lock_guard scoped_lock(m_clients_mutex); std::string nick = Str::SanitizeUtf8(user.username); // check if banned @@ -368,7 +367,7 @@ void Sequencer::broadcastUserInfo(int client_id) { memset(info_for_others.usertoken, 0, 40); memset(info_for_others.clientGUID, 0, 40); { // Lock scope - MutexLocker scoped_lock(m_clients_mutex); + std::lock_guard scoped_lock(m_clients_mutex); for (unsigned int i = 0; i < m_clients.size(); i++) { m_clients[i]->QueueMessage(RoRnet::MSG2_USER_INFO, info_for_others.uniqueid, 0, sizeof(RoRnet::UserInfo), (char *) &info_for_others); @@ -377,7 +376,7 @@ void Sequencer::broadcastUserInfo(int client_id) { } void Sequencer::GetHeartbeatUserList(Json::Value &out_array) { - MutexLocker scoped_lock(m_clients_mutex); + std::lock_guard scoped_lock(m_clients_mutex); auto itor = m_clients.begin(); auto endi = m_clients.end(); @@ -397,12 +396,12 @@ void Sequencer::GetHeartbeatUserList(Json::Value &out_array) { } int Sequencer::getNumClients() { - MutexLocker scoped_lock(m_clients_mutex); + std::lock_guard scoped_lock(m_clients_mutex); return (int) m_clients.size(); } int Sequencer::AuthorizeNick(std::string token, std::string &nickname) { - MutexLocker scoped_lock(m_clients_mutex); + std::lock_guard scoped_lock(m_clients_mutex); if (m_auth_resolver == nullptr) { return RoRnet::AUTH_NONE; } @@ -433,7 +432,6 @@ void Sequencer::killerthreadstart() { } void Sequencer::QueueClientForDisconnect(int uid, const char *errormsg, bool isError /*=true*/, bool doScriptCallback /*= true*/) { - MutexLocker scoped_lock(m_clients_mutex); Client *client = this->FindClientById(static_cast(uid)); if (client == nullptr) { @@ -494,7 +492,7 @@ void Sequencer::QueueClientForDisconnect(int uid, const char *errormsg, bool isE //this is called from the listener thread initial handshake void Sequencer::enableFlow(int uid) { - MutexLocker scoped_lock(m_clients_mutex); + std::lock_guard scoped_lock(m_clients_mutex); Client *client = this->FindClientById(static_cast(uid)); if (client == nullptr) { @@ -755,7 +753,7 @@ void Sequencer::streamDebug() { //this is called by the receivers threads, like crazy & concurrently void Sequencer::queueMessage(int uid, int type, unsigned int streamid, char *data, unsigned int len) { - MutexLocker scoped_lock(m_clients_mutex); + std::lock_guard scoped_lock(m_clients_mutex); Client *client = this->FindClientById(static_cast(uid)); if (client == nullptr) { @@ -1219,7 +1217,7 @@ Client *Sequencer::getClient(int uid) { } void Sequencer::UpdateMinuteStats() { - MutexLocker scoped_lock(m_clients_mutex); + std::lock_guard scoped_lock(m_clients_mutex); for (unsigned int i = 0; i < m_clients.size(); i++) { if (m_clients[i]->GetStatus() == Client::STATUS_USED) { @@ -1306,7 +1304,7 @@ Client *Sequencer::FindClientById(unsigned int client_id) { } std::vector Sequencer::GetClientListCopy() { - MutexLocker scoped_lock(m_clients_mutex); + std::lock_guard scoped_lock(m_clients_mutex); std::vector output; for (Client *c : m_clients) { diff --git a/source/server/sequencer.h b/source/server/sequencer.h index c5db9e53..61f9cc95 100644 --- a/source/server/sequencer.h +++ b/source/server/sequencer.h @@ -23,7 +23,6 @@ along with Foobar. If not, see . #include "blacklist.h" #include "prerequisites.h" #include "rornet.h" -#include "mutexutils.h" #include "broadcaster.h" #include "receiver.h" #include "spamfilter.h" @@ -40,6 +39,7 @@ along with Foobar. If not, see . #include #include #include +#include #include // How many not-vehicles streams has every user by default? (e.g.: "default" and "chat" are not-vehicles streams) @@ -260,10 +260,10 @@ class Sequencer { static unsigned int connCrash, connCount; private: + std::mutex m_clients_mutex; //!< Protects: m_clients, m_script_engine, m_auth_resolver, m_bot_count, m_num_disconnects_[total/crash] pthread_t m_killer_thread; //!< thread to handle the killing of clients Condition m_killer_cond; //!< wait condition that there are clients to kill Mutex m_killer_mutex; //!< mutex used for locking access to the killqueue - Mutex m_clients_mutex; //!< Protects: m_clients, m_script_engine, m_auth_resolver, m_bot_count, m_num_disconnects_[total/crash] ScriptEngine *m_script_engine; UserAuth *m_auth_resolver; int m_bot_count; //!< Amount of registered bots on the server. From b8b7046b681592b034472c025e0d33e110f21570 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Tue, 24 May 2022 22:33:22 +0200 Subject: [PATCH 03/15] codechange - Logger: replaced pthread with STL thread --- source/server/logger.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/source/server/logger.cpp b/source/server/logger.cpp index e5ac8f9e..ae3b599d 100644 --- a/source/server/logger.cpp +++ b/source/server/logger.cpp @@ -21,15 +21,16 @@ along with Foobar. If not, see . #include "logger.h" -#include "pthread.h" #include "utils.h" -#include "mutexutils.h" #include #include #include #include #include +#include +#include +#include #ifndef _WIN32 @@ -41,7 +42,7 @@ static FILE *s_file = nullptr; static LogLevel s_log_level[2] = {LOG_VERBOSE, LOG_INFO}; static const char *s_log_level_names[] = {"STACK", "DEBUG", "VERBO", "INFO", "WARN", "ERROR"}; static std::string s_log_filename = "server.log"; -static Mutex s_log_mutex; +static std::mutex s_log_mutex; namespace Logger { @@ -67,11 +68,15 @@ namespace Logger { strftime(time_str, 20, "%d-%m-%Y %H:%M:%S", localtime(¤t_time)); const char *level_str = s_log_level_names[(int) level]; + std::stringstream tid_ss; + tid_ss << std::this_thread::get_id(); + std::string tid_str = tid_ss.str(); + if (level >= s_log_level[LOGTYPE_DISPLAY]) { - printf("%s|t%02d|%5s|%s\n", time_str, ThreadID::getID(), level_str, msg); + printf("%s|t%s|%5s|%s\n", time_str, tid_str.c_str(), level_str, msg); } - pthread_mutex_lock(s_log_mutex.getRaw()); + std::lock_guard scoped_lock(s_log_mutex); if (s_file && level >= s_log_level[LOGTYPE_FILE]) { #ifndef _WIN32 @@ -83,11 +88,10 @@ namespace Logger { freopen(s_log_filename.c_str(), "a+", s_file); } #endif // _WIN32 - fprintf(s_file, "%s|t%02d|%5s| %s\n", time_str, ThreadID::getID(), level_str, msg); + + fprintf(s_file, "%s|t%s|%5s| %s\n", time_str, tid_str.c_str(), level_str, msg); fflush(s_file); } - - pthread_mutex_unlock(s_log_mutex.getRaw()); } void SetOutputFile(const std::string &filename) { From 8d1c49681faf7a8bbc243c5a5d807a5a9253360e Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Fri, 20 May 2022 23:42:33 +0200 Subject: [PATCH 04/15] codechange - Sequencer: removed 1 dead function --- source/server/sequencer.cpp | 12 ------------ source/server/sequencer.h | 2 -- 2 files changed, 14 deletions(-) diff --git a/source/server/sequencer.cpp b/source/server/sequencer.cpp index e323bef8..b5a39d94 100644 --- a/source/server/sequencer.cpp +++ b/source/server/sequencer.cpp @@ -490,18 +490,6 @@ void Sequencer::QueueClientForDisconnect(int uid, const char *errormsg, bool isE m_num_disconnects_crash, m_num_disconnects_total); } -//this is called from the listener thread initial handshake -void Sequencer::enableFlow(int uid) { - std::lock_guard scoped_lock(m_clients_mutex); - - Client *client = this->FindClientById(static_cast(uid)); - if (client == nullptr) { - return; - } - - client->SetReceiveData(true); -} - //this is called from the listener thread initial handshake int Sequencer::sendMOTD(int uid) { diff --git a/source/server/sequencer.h b/source/server/sequencer.h index 61f9cc95..c83a9723 100644 --- a/source/server/sequencer.h +++ b/source/server/sequencer.h @@ -203,8 +203,6 @@ class Sequencer { void queueMessage(int uid, int type, unsigned int streamid, char *data, unsigned int len); - void enableFlow(int id); - int sendMOTD(int id); void IntroduceNewClientToAllVehicles(Client *client); From 77d28ebb30dd8fedc3f6ce56fdc4eacc24f41848 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Tue, 24 May 2022 22:49:12 +0200 Subject: [PATCH 05/15] codechange - Sequencer(Killer): replaced pthread with STL thread --- source/server/sequencer.cpp | 100 ++++++++++++++++++++++++++---------- source/server/sequencer.h | 37 +++++++++---- 2 files changed, 99 insertions(+), 38 deletions(-) diff --git a/source/server/sequencer.cpp b/source/server/sequencer.cpp index b5a39d94..a6dcb05d 100644 --- a/source/server/sequencer.cpp +++ b/source/server/sequencer.cpp @@ -138,12 +138,6 @@ void Client::NotifyAllVehicles(Sequencer *sequencer) { } } -void *LaunchKillerThread(void *data) { - Sequencer *sequencer = static_cast(data); - sequencer->killerthreadstart(); - return nullptr; -} - Sequencer::Sequencer() : m_script_engine(nullptr), m_auth_resolver(nullptr), @@ -168,7 +162,7 @@ void Sequencer::Initialize() { } #endif //WITH_ANGELSCRIPT - pthread_create(&m_killer_thread, NULL, LaunchKillerThread, this); + this->StartKillerThread(); m_auth_resolver = new UserAuth(Config::getAuthFile()); @@ -203,8 +197,38 @@ void Sequencer::Close() { m_auth_resolver = nullptr; } - pthread_cancel(m_killer_thread); - pthread_detach(m_killer_thread); + this->StopKillerThread(); +} + +void Sequencer::StartKillerThread() +{ + std::lock_guard lock(m_killer_mutex); + if (m_killer_state != KillerThreadState::NOT_RUNNING) + { + return; + } + m_killer_thread = std::thread(&Sequencer::KillerThreadMain, this); + m_killer_state = KillerThreadState::RUNNING; +} + +void Sequencer::StopKillerThread() +{ + { + std::lock_guard lock(m_killer_mutex); + if (m_killer_state != KillerThreadState::RUNNING) + { + return; + } + m_killer_state = KillerThreadState::STOP_REQUESTED; + } + + m_killer_cond.notify_one(); + m_killer_thread.join(); + + { + std::lock_guard lock(m_killer_mutex); + m_killer_state = KillerThreadState::NOT_RUNNING; + } } bool Sequencer::CheckNickIsUnique(std::string &nick) { @@ -408,27 +432,49 @@ int Sequencer::AuthorizeNick(std::string token, std::string &nickname) { return m_auth_resolver->resolve(token, nickname, m_free_user_id); } -void Sequencer::killerthreadstart() { +void Sequencer::KillerThreadMain() +{ Logger::Log(LOG_DEBUG, "Killer thread ready"); - while (1) { - Logger::Log(LOG_DEBUG, "Killer entering cycle"); - - m_killer_mutex.lock(); - while (m_kill_queue.empty()) { - m_killer_mutex.wait(m_killer_cond); + while (true) + { + Client* client = nullptr; + KillerThreadState state = this->KillerThreadWaitForClient(/*out:*/ client); + if (state == KillerThreadState::STOP_REQUESTED) + { + Logger::Log(LOG_DEBUG, "Killer thread requested to stop"); + break; } + else if (client) + { + this->KillerThreadProcessClient(client); + } + } +} - //pop the kill queue - Client *to_del = m_kill_queue.front(); - m_kill_queue.pop(); - m_killer_mutex.unlock(); +KillerThreadState Sequencer::KillerThreadWaitForClient(Client*& out_client) +{ + std::unique_lock uni_lock(m_killer_mutex); + if (m_kill_queue.empty()) + { + m_killer_cond.wait(uni_lock); + } + if (!m_kill_queue.empty()) + { + out_client = m_kill_queue.front(); + m_kill_queue.pop(); // pop front + } + return m_killer_state; +} + +void Sequencer::KillerThreadProcessClient(Client* client) +{ + // Give the client time to disconnect itself + std::this_thread::sleep_for(std::chrono::seconds(5)); - Logger::Log(LOG_DEBUG, "Killer called to kill %s", Str::SanitizeUtf8(to_del->user.username).c_str()); - to_del->Disconnect(); + // Join the send/recv threads and close socket + client->Disconnect(); - delete to_del; - to_del = NULL; - } + delete client; } void Sequencer::QueueClientForDisconnect(int uid, const char *errormsg, bool isError /*=true*/, bool doScriptCallback /*= true*/) { @@ -477,10 +523,10 @@ void Sequencer::QueueClientForDisconnect(int uid, const char *errormsg, bool isE Logger::Log(LOG_VERBOSE, "Disconnecting client ID %d: %s", uid, errormsg); Logger::Log(LOG_DEBUG, "adding client to kill queue, size: %d", m_kill_queue.size()); { - MutexLocker scoped_lock(m_killer_mutex); + std::lock_guard lock(m_killer_mutex); m_kill_queue.push(client); } - m_killer_cond.signal(); + m_killer_cond.notify_one(); m_num_disconnects_total++; if (isError) { diff --git a/source/server/sequencer.h b/source/server/sequencer.h index c83a9723..6e12b8de 100644 --- a/source/server/sequencer.h +++ b/source/server/sequencer.h @@ -41,6 +41,8 @@ along with Foobar. If not, see . #include #include #include +#include +#include // How many not-vehicles streams has every user by default? (e.g.: "default" and "chat" are not-vehicles streams) // This is used for the vehicle-limit @@ -179,11 +181,14 @@ struct ban_t { char banmsg[256]; //!< why he got banned }; -void *LaunchKillerThread(void *); +enum class KillerThreadState +{ + NOT_RUNNING, + RUNNING, + STOP_REQUESTED +}; class Sequencer { - friend void *LaunchKillerThread(void *); - public: Sequencer(); @@ -196,9 +201,6 @@ class Sequencer { //! initilize client information void createClient(SWInetSocket *sock, RoRnet::UserInfo user); - //! call to start the thread to disconnect clients from the server. - void killerthreadstart(); - void QueueClientForDisconnect(int client_id, const char *error, bool isError = true, bool doScriptCallback = true); void queueMessage(int uid, int type, unsigned int streamid, char *data, unsigned int len); @@ -255,13 +257,22 @@ class Sequencer { std::vector GetBanListCopy(); + // Killer thread control + void StartKillerThread(); + void StopKillerThread(); + static unsigned int connCrash, connCount; private: + // Helpers (not thread safe) + Client *FindClientById(unsigned int client_id); + + // Killer thread + void KillerThreadMain(); + KillerThreadState KillerThreadWaitForClient(Client*& out_client); + void KillerThreadProcessClient(Client* client); + std::mutex m_clients_mutex; //!< Protects: m_clients, m_script_engine, m_auth_resolver, m_bot_count, m_num_disconnects_[total/crash] - pthread_t m_killer_thread; //!< thread to handle the killing of clients - Condition m_killer_cond; //!< wait condition that there are clients to kill - Mutex m_killer_mutex; //!< mutex used for locking access to the killqueue ScriptEngine *m_script_engine; UserAuth *m_auth_resolver; int m_bot_count; //!< Amount of registered bots on the server. @@ -271,10 +282,14 @@ class Sequencer { size_t m_num_disconnects_crash; //!< Statistic Blacklist m_blacklist; - std::queue m_kill_queue; //!< holds pointer for client deletion std::vector m_clients; std::vector m_bans; - Client *FindClientById(unsigned int client_id); + // Killer thread context + std::queue m_kill_queue; + std::thread m_killer_thread; + std::condition_variable m_killer_cond; + std::mutex m_killer_mutex; + KillerThreadState m_killer_state = KillerThreadState::NOT_RUNNING; }; From a6e47e1e4a7a238ebe0495f50e6ffcddd75fa800 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Mon, 24 May 2021 02:40:27 +0200 Subject: [PATCH 06/15] codechange - Receiver: replaced pthread with STL thread --- source/server/receiver.cpp | 71 ++++++++++++++++++++------------------ source/server/receiver.h | 34 +++++++++--------- 2 files changed, 55 insertions(+), 50 deletions(-) diff --git a/source/server/receiver.cpp b/source/server/receiver.cpp index c66c64ff..e38f57d4 100644 --- a/source/server/receiver.cpp +++ b/source/server/receiver.cpp @@ -27,68 +27,73 @@ along with Foobar. If not, see . #include "logger.h" #include +#include -void *LaunchReceiverThread(void *data) { - Receiver *receiver = static_cast(data); - receiver->Thread(); - return nullptr; -} -Receiver::Receiver(Sequencer *sequencer) : - m_client(nullptr), - m_sequencer(sequencer) { +Receiver::Receiver(Sequencer *sequencer): + m_sequencer(sequencer) +{ } Receiver::~Receiver() { - this->Stop(); + assert(m_thread_state == ThreadState::NOT_RUNNING); } void Receiver::Start(Client* client) { - m_client = client; - m_keep_running.store(true); + std::lock_guard lock(m_mutex); // Scoped - pthread_create(&m_thread, nullptr, LaunchReceiverThread, this); + assert(m_thread_state == ThreadState::NOT_RUNNING); + m_client = client; + m_thread = std::thread(&Receiver::ThreadMain, this); + m_thread_state = ThreadState::RUNNING; } void Receiver::Stop() { - bool was_running = m_keep_running.exchange(false); - if (was_running) { - //TODO: how do I signal the thread to stop waiting for the socket? - // For now I stick to the existing solution - I just don't ~ only_a_ptr, 03/2019 - pthread_join(m_thread, nullptr); + { + std::lock_guard lock(m_mutex); // Scoped + if (m_thread_state != ThreadState::RUNNING) + return; + m_thread_state = ThreadState::STOP_REQUESTED; + } + + m_thread.join(); + + { + std::lock_guard lock(m_mutex); // Scoped + m_thread_state = ThreadState::NOT_RUNNING; } } -void Receiver::Thread() { - Logger::Log(LOG_DEBUG, "Started receiver thread %d owned by user ID %d", ThreadID::getID(), m_client->GetUserId()); +Receiver::ThreadState Receiver::GetThreadState() +{ + std::lock_guard lock(m_mutex); // Scoped + return m_thread_state; +} + +void Receiver::ThreadMain() { + Logger::Log(LOG_DEBUG, "Started receiver thread (user ID %d)", m_client->GetUserId()); - //okay, we are ready, we can receive data frames - m_client->SetReceiveData(true); - //send motd - m_sequencer->sendMOTD(m_client->GetUserId()); + m_sequencer->sendMOTD(m_client->GetUserId()); // send MOTD + m_client->GetSocket()->set_timeout((Uint32)60, 0); // 60sec + + m_client->SetReceiveData(true); Logger::Log(LOG_VERBOSE, "UID %d is switching to FLOW", m_client->GetUserId()); - // this prevents the socket from hangingwhen sending data - // which is the cause of threads getting blocked - m_client->GetSocket()->set_timeout(60, 0); - while (true) { + while (this->GetThreadState() == ThreadState::RUNNING) { if (!this->ThreadReceiveMessage()) { m_sequencer->QueueClientForDisconnect(m_client->GetUserId(), "Game connection closed"); break; } - if (m_keep_running.load() == false) - break; - if (m_recv_header.command != RoRnet::MSG2_STREAM_DATA && m_recv_header.command != RoRnet::MSG2_STREAM_DATA_DISCARDABLE) { Logger::Log(LOG_VERBOSE, "got message: type: %d, source: %d:%d, len: %d", - (int)m_recv_header.command, m_recv_header.source, m_recv_header.streamid, m_recv_header.size); + (int)m_recv_header.command, (int)m_recv_header.source, (int)m_recv_header.streamid, (int)m_recv_header.size); } - if (m_recv_header.command < 1000 || m_recv_header.command > 1050) { + if (m_recv_header.command < 1000u || m_recv_header.command > 1050u) { m_sequencer->QueueClientForDisconnect(m_client->GetUserId(), "Protocol error 3"); break; } @@ -97,7 +102,7 @@ void Receiver::Thread() { (int)m_recv_header.command, m_recv_header.streamid, m_recv_payload, m_recv_header.size); } - Logger::Log(LOG_DEBUG, "Receiver thread %d (user ID %d) exits", ThreadID::getID(), m_client->GetUserId()); + Logger::Log(LOG_DEBUG, "Receiver thread (user ID %d) exits", m_client->GetUserId()); } bool Receiver::ThreadReceiveMessage() diff --git a/source/server/receiver.h b/source/server/receiver.h index b6acaebd..0665d59f 100644 --- a/source/server/receiver.h +++ b/source/server/receiver.h @@ -23,37 +23,37 @@ along with Foobar. If not, see . #include "rornet.h" // For RORNET_MAX_MESSAGE_LENGTH #include "prerequisites.h" -#include -#include - -class SWInetSocket; - -class Sequencer; - -void *LaunchReceiverThread(void *); +#include +#include +/// Provides a receiver thread for a single client. class Receiver { - friend void *LaunchReceiverThread(void *); - public: - Receiver(Sequencer *sequencer); + enum class ThreadState + { + NOT_RUNNING, // Initial/terminal state - thread not running, nothing waiting on socket. + RUNNING, // Thread running, may be blocked by socket. + STOP_REQUESTED, // Thread running, may be blocked by socket. + }; + Receiver(Sequencer *sequencer); ~Receiver(); void Start(Client* client); - void Stop(); + ThreadState GetThreadState(); private: - void Thread(); + void ThreadMain(); bool ThreadReceiveMessage(); //!< @return false if thread should be stopped, true to continue. bool ThreadReceiveHeader(); //!< @return false if thread should be stopped, true to continue. bool ThreadReceivePayload(); //!< @return false if thread should be stopped, true to continue. - pthread_t m_thread; - Client* m_client; - std::atomic m_keep_running; - Sequencer *m_sequencer; + Sequencer* m_sequencer = nullptr; // global + Client* m_client = nullptr; // data owner + std::mutex m_mutex; + ThreadState m_thread_state = ThreadState::NOT_RUNNING; + std::thread m_thread; // Received data buffers -- Keep here to be allocated on heap (along with Client) RoRnet::Header m_recv_header; From a283cfab2f16b29c77dc5c97d8915368b6ef87fe Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Sun, 22 May 2022 20:52:04 +0200 Subject: [PATCH 07/15] codechange - ScriptEngine: deleted unused function --- source/server/ScriptEngine.cpp | 17 ----------------- source/server/ScriptEngine.h | 2 -- 2 files changed, 19 deletions(-) diff --git a/source/server/ScriptEngine.cpp b/source/server/ScriptEngine.cpp index e8fd819b..a129beea 100644 --- a/source/server/ScriptEngine.cpp +++ b/source/server/ScriptEngine.cpp @@ -589,23 +589,6 @@ int ScriptEngine::loadScriptFile(const char *fileName, string &script) { return 0; } -// unused method -int ScriptEngine::executeString(std::string command) { - // This method would work if you include the scriptHelper add-on -#if 0 - if(!engine) return 0; - if(!context) context = engine->CreateContext(); - asIScriptModule* mod = engine->GetModule("script", asGM_CREATE_IF_NOT_EXISTS); - int result = ExecuteString(engine, command.c_str(), mod, context); - if(result<0) - { - Logger::Log(LOG_ERROR, "ScriptEngine: Error while executing string: '" + command + "'."); - } - return result; -#endif // 0 - return 0; -} - int ScriptEngine::framestep(float dt) { if (!engine) return 0; MutexLocker scoped_lock(context_mutex); diff --git a/source/server/ScriptEngine.h b/source/server/ScriptEngine.h index f345bfa2..a3991473 100644 --- a/source/server/ScriptEngine.h +++ b/source/server/ScriptEngine.h @@ -54,8 +54,6 @@ class ScriptEngine { int loadScript(std::string scriptName); - int executeString(std::string command); - void playerDeleted(int uid, int crash, bool doNestedCall = false); void playerAdded(int uid); From c317d7d8ae93c020fa740e82700eee7c4fd17059 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Tue, 24 May 2022 23:23:28 +0200 Subject: [PATCH 08/15] bugfix - ScriptEngine: fixed thread sync of callbacks. All script callbacks must be invoked while Sequencer's clients-mutex is locked. This makes the ScriptEngine's context-mutex redundant. --- source/server/ScriptEngine.cpp | 11 +++-------- source/server/ScriptEngine.h | 3 +-- source/server/sequencer.cpp | 7 +++++++ source/server/sequencer.h | 1 + 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/source/server/ScriptEngine.cpp b/source/server/ScriptEngine.cpp index a129beea..86f2c766 100644 --- a/source/server/ScriptEngine.cpp +++ b/source/server/ScriptEngine.cpp @@ -589,9 +589,8 @@ int ScriptEngine::loadScriptFile(const char *fileName, string &script) { return 0; } -int ScriptEngine::framestep(float dt) { +int ScriptEngine::frameStep(float dt) { if (!engine) return 0; - MutexLocker scoped_lock(context_mutex); if (!context) context = engine->CreateContext(); int r; @@ -625,7 +624,6 @@ int ScriptEngine::framestep(float dt) { void ScriptEngine::playerDeleted(int uid, int crash, bool doNestedCall /*= false*/) { if (!engine) return; - if (!doNestedCall) MutexLocker scoped_lock(context_mutex); if (!context) context = engine->CreateContext(); int r; @@ -670,7 +668,6 @@ void ScriptEngine::playerDeleted(int uid, int crash, bool doNestedCall /*= false void ScriptEngine::playerAdded(int uid) { if (!engine) return; - MutexLocker scoped_lock(context_mutex); if (!context) context = engine->CreateContext(); int r; @@ -700,7 +697,6 @@ void ScriptEngine::playerAdded(int uid) { int ScriptEngine::streamAdded(int uid, RoRnet::StreamRegister *reg) { if (!engine) return 0; - MutexLocker scoped_lock(context_mutex); if (!context) context = engine->CreateContext(); int r; int ret = BROADCAST_AUTO; @@ -740,7 +736,6 @@ int ScriptEngine::streamAdded(int uid, RoRnet::StreamRegister *reg) { int ScriptEngine::playerChat(int uid, std::string msg) { if (!engine) return 0; - MutexLocker scoped_lock(context_mutex); if (!context) context = engine->CreateContext(); int r; int ret = BROADCAST_AUTO; @@ -780,7 +775,6 @@ int ScriptEngine::playerChat(int uid, std::string msg) { void ScriptEngine::gameCmd(int uid, const std::string &cmd) { if (!engine) return; - MutexLocker scoped_lock(context_mutex); if (!context) context = engine->CreateContext(); int r; @@ -818,8 +812,9 @@ void ScriptEngine::timerLoop() { #else // _WIN32 Sleep(200); #endif // _WIN32 + // call script - framestep(200); + seq->frameStepScripts(200); } } diff --git a/source/server/ScriptEngine.h b/source/server/ScriptEngine.h index a3991473..25e30cbf 100644 --- a/source/server/ScriptEngine.h +++ b/source/server/ScriptEngine.h @@ -64,7 +64,7 @@ class ScriptEngine { void gameCmd(int uid, const std::string &cmd); - int framestep(float dt); + int frameStep(float dt); /** * A loop that makes sure that does a regular call to the frameStep method. @@ -134,7 +134,6 @@ class ScriptEngine { Sequencer *seq; asIScriptEngine *engine; //!< instance of the scripting engine asIScriptContext *context; //!< context in which all scripting happens - Mutex context_mutex; //!< mutex used for locking access to the context bool frameStepThreadRunning; //!< indicates whether the thread for the frameStep is running or not bool exit; //!< indicates whether the script engine is shutting down pthread_t timer_thread; diff --git a/source/server/sequencer.cpp b/source/server/sequencer.cpp index a6dcb05d..899b41c5 100644 --- a/source/server/sequencer.cpp +++ b/source/server/sequencer.cpp @@ -1323,6 +1323,13 @@ void Sequencer::printStats() { } } +void Sequencer::frameStepScripts(float dt) +{ + // All script callbacks must be invoked while clients-mutex is locked + std::lock_guard scoped_lock(m_clients_mutex); + m_script_engine->frameStep(dt); +} + // clients_mutex needs to be locked wen calling this method // Invoked either from Sequencer or ServerScript Client *Sequencer::FindClientById(unsigned int client_id) { diff --git a/source/server/sequencer.h b/source/server/sequencer.h index 6e12b8de..201c3bb9 100644 --- a/source/server/sequencer.h +++ b/source/server/sequencer.h @@ -204,6 +204,7 @@ class Sequencer { void QueueClientForDisconnect(int client_id, const char *error, bool isError = true, bool doScriptCallback = true); void queueMessage(int uid, int type, unsigned int streamid, char *data, unsigned int len); + void frameStepScripts(float dt); int sendMOTD(int id); From 02de04f29f30a55a8ef866a9c3666d330222cfee Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Wed, 25 May 2022 00:15:09 +0200 Subject: [PATCH 09/15] codechange - ScriptEngine: replaced pthread with STL thread --- source/server/ScriptEngine.cpp | 59 ++++++++++++++++++++++------------ source/server/ScriptEngine.h | 33 +++++++++++++------ 2 files changed, 63 insertions(+), 29 deletions(-) diff --git a/source/server/ScriptEngine.cpp b/source/server/ScriptEngine.cpp index 86f2c766..0879a04c 100644 --- a/source/server/ScriptEngine.cpp +++ b/source/server/ScriptEngine.cpp @@ -22,7 +22,6 @@ along with Foobar. If not, see . #ifdef WITH_ANGELSCRIPT #include "logger.h" -#include "mutexutils.h" #include "ScriptEngine.h" #include "sequencer.h" #include "config.h" @@ -72,25 +71,18 @@ std::string stream_register_get_name(RoRnet::StreamRegister *reg) { return std::string(reg->name); } -void *s_sethreadstart(void *se) { - ((ScriptEngine *) se)->timerLoop(); - return NULL; -} + ScriptEngine::ScriptEngine(Sequencer *seq) : seq(seq), engine(0), - context(0), - frameStepThreadRunning(false), - exit(false) { + context(0) +{ init(); } ScriptEngine::~ScriptEngine() { - // Stop thread first - if (frameStepThreadRunning) { - exit = true; // signal thread to exit. TODO: protect by mutex. - pthread_join(timer_thread, NULL); - } + // Stop thread first + this->StopTimerThread(); // Clean up deleteAllCallbacks(); @@ -804,8 +796,8 @@ void ScriptEngine::gameCmd(int uid, const std::string &cmd) { return; } -void ScriptEngine::timerLoop() { - while (!exit) { +void ScriptEngine::TimerThreadMain() { + while (this->GetTimerThreadState() == ThreadState::RUNNING) { // sleep 200 miliseconds #ifndef _WIN32 usleep(200000); @@ -818,6 +810,36 @@ void ScriptEngine::timerLoop() { } } +void ScriptEngine::EnsureTimerThreadRunning() { + std::lock_guard scoped_lock(m_timer_thread_mutex); + if (m_timer_thread_state == ThreadState::NOT_RUNNING) { + Logger::Log(LOG_DEBUG, "ScriptEngine: starting framestep thread"); + m_timer_thread = std::thread(&ScriptEngine::TimerThreadMain, this); + m_timer_thread_state = ThreadState::RUNNING; + } +} + +ScriptEngine::ThreadState ScriptEngine::GetTimerThreadState() { + std::lock_guard scoped_lock(m_timer_thread_mutex); + return m_timer_thread_state; +} + +void ScriptEngine::StopTimerThread() { + { + std::lock_guard scoped_lock(m_timer_thread_mutex); + if (m_timer_thread_state != ThreadState::RUNNING) + return; + m_timer_thread_state = ThreadState::STOP_REQUESTED; + } + + m_timer_thread.join(); + + { + std::lock_guard scoped_lock(m_timer_thread_mutex); + m_timer_thread_state = ThreadState::NOT_RUNNING; + } +} + void ScriptEngine::setException(const std::string &message) { if (!engine || !context) { // There's not much we can do, except for logging the message @@ -906,10 +928,8 @@ void ScriptEngine::addCallback(const std::string &type, asIScriptFunction *func, callbacks[type].push_back(tmp); // Do we need to start the frameStep thread? - if (type == "frameStep" && !frameStepThreadRunning) { - frameStepThreadRunning = true; - Logger::Log(LOG_DEBUG, "ScriptEngine: starting timer thread"); - pthread_create(&timer_thread, NULL, s_sethreadstart, this); + if (type == "frameStep") { + this->EnsureTimerThreadRunning(); } // finished :) @@ -1199,5 +1219,4 @@ void ServerScript::broadcastUserInfo(int uid) { seq->broadcastUserInfo(uid); } - #endif //WITH_ANGELSCRIPT diff --git a/source/server/ScriptEngine.h b/source/server/ScriptEngine.h index 25e30cbf..8050b595 100644 --- a/source/server/ScriptEngine.h +++ b/source/server/ScriptEngine.h @@ -24,6 +24,8 @@ along with Foobar. If not, see . #include "UnicodeStrings.h" #include +#include +#include #include #include "angelscript.h" #include "rornet.h" @@ -48,6 +50,13 @@ typedef std::vector callbackList; class ScriptEngine { public: + enum class ThreadState + { + NOT_RUNNING, + RUNNING, + STOP_REQUESTED + }; + ScriptEngine(Sequencer *seq); ~ScriptEngine(); @@ -66,12 +75,6 @@ class ScriptEngine { int frameStep(float dt); - /** - * A loop that makes sure that does a regular call to the frameStep method. - * @see frameStep - */ - void timerLoop(); - /** * Gets the currently used AngelScript script engine. * @return a pointer to the currently used AngelScript script engine @@ -130,15 +133,22 @@ class ScriptEngine { */ bool callbackExists(const std::string &type, asIScriptFunction *func, asIScriptObject *obj); + // Timer thread control + void EnsureTimerThreadRunning(); + void StopTimerThread(); + ThreadState GetTimerThreadState(); + protected: Sequencer *seq; asIScriptEngine *engine; //!< instance of the scripting engine asIScriptContext *context; //!< context in which all scripting happens - bool frameStepThreadRunning; //!< indicates whether the thread for the frameStep is running or not - bool exit; //!< indicates whether the script engine is shutting down - pthread_t timer_thread; std::map callbacks; //!< A map containing the script callbacks by type. + // Timer thread context + std::thread m_timer_thread; + ThreadState m_timer_thread_state = ThreadState::NOT_RUNNING; + std::mutex m_timer_thread_mutex; + /** * This function initialzies the engine and registeres all types */ @@ -179,6 +189,11 @@ class ScriptEngine { * unused */ void LineCallback(asIScriptContext *ctx, void *param); + + /** + * A loop that periodically the frameStep() script callback. + */ + void TimerThreadMain(); }; class ServerScript { From 5c3af3dab1975a269f91b0319d2ec4616409e533 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Tue, 24 May 2022 00:15:41 +0200 Subject: [PATCH 10/15] bugfix - Sequencer: added missing thread sync, part 1 Unsafe methods made private, public threadsafe counterparts were created where needed. --- source/server/ScriptEngine.cpp | 2 +- source/server/broadcaster.cpp | 2 +- source/server/receiver.cpp | 4 ++-- source/server/sequencer.cpp | 14 +++++++++----- source/server/sequencer.h | 23 ++++++++++++++--------- source/server/spamfilter.cpp | 3 +++ 6 files changed, 30 insertions(+), 18 deletions(-) diff --git a/source/server/ScriptEngine.cpp b/source/server/ScriptEngine.cpp index 0879a04c..f6d3ae55 100644 --- a/source/server/ScriptEngine.cpp +++ b/source/server/ScriptEngine.cpp @@ -1034,7 +1034,7 @@ void ServerScript::log(std::string &msg) { } void ServerScript::say(std::string &msg, int uid, int type) { - seq->serverSayThreadSave(msg, uid, type); + seq->serverSay(msg, uid, type); } void ServerScript::kick(int kuid, std::string &msg) { diff --git a/source/server/broadcaster.cpp b/source/server/broadcaster.cpp index 95db9505..8e981504 100644 --- a/source/server/broadcaster.cpp +++ b/source/server/broadcaster.cpp @@ -89,7 +89,7 @@ void Broadcaster::Thread() { // TODO WARNING THE SOCKET IS NOT PROTECTED!!! if (Messaging::SendMessage(m_client->GetSocket(), msg.type, msg.uid, msg.streamid, msg.datalen, msg.data) != 0) { - m_sequencer->QueueClientForDisconnect(m_client->GetUserId(), "Broadcaster: Send error", true, true); + m_sequencer->disconnectClient(m_client->GetUserId(), "Broadcaster: Send error", true, true); socket_error = true; break; } diff --git a/source/server/receiver.cpp b/source/server/receiver.cpp index e38f57d4..a166b578 100644 --- a/source/server/receiver.cpp +++ b/source/server/receiver.cpp @@ -83,7 +83,7 @@ void Receiver::ThreadMain() { while (this->GetThreadState() == ThreadState::RUNNING) { if (!this->ThreadReceiveMessage()) { - m_sequencer->QueueClientForDisconnect(m_client->GetUserId(), "Game connection closed"); + m_sequencer->disconnectClient(m_client->GetUserId(), "Game connection closed"); break; } @@ -94,7 +94,7 @@ void Receiver::ThreadMain() { } if (m_recv_header.command < 1000u || m_recv_header.command > 1050u) { - m_sequencer->QueueClientForDisconnect(m_client->GetUserId(), "Protocol error 3"); + m_sequencer->disconnectClient(m_client->GetUserId(), "Protocol error 3"); break; } diff --git a/source/server/sequencer.cpp b/source/server/sequencer.cpp index 899b41c5..1e46a2cd 100644 --- a/source/server/sequencer.cpp +++ b/source/server/sequencer.cpp @@ -80,6 +80,9 @@ void Client::Disconnect() { bool Client::CheckSpawnRate() { + // CAUTION - called by Sequencer with clients-mutex locked + // ------------------------------------------------------- + std::chrono::seconds spawn_interval(Config::getSpawnIntervalSec()); if (spawn_interval.count() == 0 || Config::getMaxSpawnRate() == 0) { return true; // Spawn rate not limited @@ -264,7 +267,6 @@ int Sequencer::GetFreePlayerColour() { } } -//this is called by the Listener thread void Sequencer::createClient(SWInetSocket *sock, RoRnet::UserInfo user) { //we have a confirmed client that wants to play //try to find a place for him @@ -378,6 +380,12 @@ void Sequencer::createClient(SWInetSocket *sock, RoRnet::UserInfo user) { Logger::Log(LOG_VERBOSE, "Sequencer: New client added"); } +void Sequencer::disconnectClient(int client_id, const char* error, bool isError /*= true*/, bool doScriptCallback /*= true*/) +{ + std::lock_guard scoped_lock(m_clients_mutex); + this->QueueClientForDisconnect(client_id, error, isError, doScriptCallback); +} + // Only used by scripting void Sequencer::broadcastUserInfo(int client_id) { Client *client = this->FindClientById(static_cast(client_id)); @@ -645,10 +653,6 @@ void Sequencer::serverSay(std::string msg, int uid, int type) { } } -void Sequencer::serverSayThreadSave(std::string msg, int uid, int type) { - this->serverSay(msg, uid, type); -} - bool Sequencer::Kick(int kuid, int modUID, const char *msg) { Client *kicked_client = this->FindClientById(static_cast(kuid)); if (kicked_client == nullptr) { diff --git a/source/server/sequencer.h b/source/server/sequencer.h index 201c3bb9..7487491a 100644 --- a/source/server/sequencer.h +++ b/source/server/sequencer.h @@ -189,21 +189,24 @@ enum class KillerThreadState }; class Sequencer { + friend class SpamFilter; + friend class Client; + friend class ServerScript; public: + // Startup and shutdown Sequencer(); - void Initialize(); - - //! destructor call, used for clean up void Close(); - //! initilize client information + // Synchronized public interface void createClient(SWInetSocket *sock, RoRnet::UserInfo user); + void disconnectClient(int client_id, const char* error, bool isError = true, bool doScriptCallback = true); + void queueMessage(int uid, int type, unsigned int streamid, char *data, unsigned int len); - void QueueClientForDisconnect(int client_id, const char *error, bool isError = true, bool doScriptCallback = true); + - void queueMessage(int uid, int type, unsigned int streamid, char *data, unsigned int len); + void frameStepScripts(float dt); int sendMOTD(int id); @@ -222,11 +225,11 @@ class Sequencer { void UpdateMinuteStats(); - void serverSay(std::string msg, int uid = -1, int type = 0); + int sendGameCommand(int uid, std::string cmd); - void serverSayThreadSave(std::string msg, int notto = -1, int type = 0); + bool CheckNickIsUnique(std::string &nick); @@ -266,7 +269,9 @@ class Sequencer { private: // Helpers (not thread safe) - Client *FindClientById(unsigned int client_id); + Client* FindClientById(unsigned int client_id); + void QueueClientForDisconnect(int client_id, const char *error, bool isError = true, bool doScriptCallback = true); + void serverSay(std::string msg, int uid = -1, int type = 0); // Killer thread void KillerThreadMain(); diff --git a/source/server/spamfilter.cpp b/source/server/spamfilter.cpp index 295d6ede..2c63a2f2 100644 --- a/source/server/spamfilter.cpp +++ b/source/server/spamfilter.cpp @@ -53,6 +53,9 @@ SpamFilter::SpamFilter(Sequencer* seq, Client* c) {} bool SpamFilter::CheckForSpam(std::string const& msg) { + // CAUTION - called by Sequencer with clients-mutex locked + // ------------------------------------------------------- + const TimePoint now = std::chrono::system_clock::now(); const std::chrono::seconds cache_expiry(Config::getSpamFilterMsgIntervalSec()); From ae816feb20873ed599cdd94a9a11f7d7358ec658 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Tue, 24 May 2022 00:28:46 +0200 Subject: [PATCH 11/15] bugfix - Sequencer: added missing thread sync, part 2 Unsafe methods made private, public threadsafe counterparts were created where needed. --- source/server/receiver.cpp | 6 +-- source/server/sequencer.cpp | 22 ++++++----- source/server/sequencer.h | 74 +++++++++++-------------------------- 3 files changed, 36 insertions(+), 66 deletions(-) diff --git a/source/server/receiver.cpp b/source/server/receiver.cpp index a166b578..dd6ecd98 100644 --- a/source/server/receiver.cpp +++ b/source/server/receiver.cpp @@ -73,14 +73,12 @@ Receiver::ThreadState Receiver::GetThreadState() void Receiver::ThreadMain() { Logger::Log(LOG_DEBUG, "Started receiver thread (user ID %d)", m_client->GetUserId()); - - m_sequencer->sendMOTD(m_client->GetUserId()); // send MOTD - m_client->GetSocket()->set_timeout((Uint32)60, 0); // 60sec - m_client->SetReceiveData(true); Logger::Log(LOG_VERBOSE, "UID %d is switching to FLOW", m_client->GetUserId()); + m_sequencer->sendMOTDSynchronized(m_client->GetUserId()); + while (this->GetThreadState() == ThreadState::RUNNING) { if (!this->ThreadReceiveMessage()) { m_sequencer->disconnectClient(m_client->GetUserId(), "Game connection closed"); diff --git a/source/server/sequencer.cpp b/source/server/sequencer.cpp index 1e46a2cd..8957ce36 100644 --- a/source/server/sequencer.cpp +++ b/source/server/sequencer.cpp @@ -135,6 +135,9 @@ void Client::QueueMessage(int msg_type, int client_id, unsigned int stream_id, u // Yes, this is weird. To be refactored. void Client::NotifyAllVehicles(Sequencer *sequencer) { + // CAUTION: called by Sequencer with clients-mutex locked + // ------------------------------------------------------ + if (!m_is_initialized) { sequencer->IntroduceNewClientToAllVehicles(this); m_is_initialized = true; @@ -386,7 +389,6 @@ void Sequencer::disconnectClient(int client_id, const char* error, bool isError this->QueueClientForDisconnect(client_id, error, isError, doScriptCallback); } -// Only used by scripting void Sequencer::broadcastUserInfo(int client_id) { Client *client = this->FindClientById(static_cast(client_id)); if (client == nullptr) { @@ -544,23 +546,25 @@ void Sequencer::QueueClientForDisconnect(int uid, const char *errormsg, bool isE m_num_disconnects_crash, m_num_disconnects_total); } +void Sequencer::sendMOTDSynchronized(int uid) +{ + std::lock_guard scoped_lock(m_clients_mutex); + this->sendMOTD(uid); +} -//this is called from the listener thread initial handshake -int Sequencer::sendMOTD(int uid) { +void Sequencer::sendMOTD(int uid) { std::vector lines; int res = Utils::ReadLinesFromFile(Config::getMOTDFile(), lines); if (res) - return res; + { + Logger::Log(LOG_ERROR, "Could not read MOTD file, error code: %d", res); + return; + } std::vector::iterator it; for (it = lines.begin(); it != lines.end(); it++) { serverSay(*it, uid, FROM_MOTD); } - return 0; -} - -UserAuth *Sequencer::getUserAuth() { - return m_auth_resolver; } //this is called from the listener thread initial handshake diff --git a/source/server/sequencer.h b/source/server/sequencer.h index 7487491a..af6a8576 100644 --- a/source/server/sequencer.h +++ b/source/server/sequencer.h @@ -192,6 +192,7 @@ class Sequencer { friend class SpamFilter; friend class Client; friend class ServerScript; + friend class Blacklist; public: // Startup and shutdown @@ -202,64 +203,15 @@ class Sequencer { // Synchronized public interface void createClient(SWInetSocket *sock, RoRnet::UserInfo user); void disconnectClient(int client_id, const char* error, bool isError = true, bool doScriptCallback = true); + int getNumClients(); void queueMessage(int uid, int type, unsigned int streamid, char *data, unsigned int len); - - - - + void sendMOTDSynchronized(int uid); void frameStepScripts(float dt); - - int sendMOTD(int id); - - void IntroduceNewClientToAllVehicles(Client *client); - - UserAuth *getUserAuth(); - - int getNumClients(); //! number of clients connected to this server - Client *getClient(int uid); - void GetHeartbeatUserList(Json::Value &out_array); - - //! prints the Stats view, of who is connected and what slot they are in - void printStats(); - void UpdateMinuteStats(); - - - - int sendGameCommand(int uid, std::string cmd); - - - - bool CheckNickIsUnique(std::string &nick); - - int GetFreePlayerColour(); - int AuthorizeNick(std::string token, std::string &nickname); - - bool Kick(int to_kick_uid, int modUID, const char *msg = 0); - - void RecordBan(int bid, std::string const& ip_addr, - std::string const& nickname, std::string const& by_nickname, - std::string const& banmsg); - - bool Ban(int to_ban_uid, int modUID, const char *msg = 0); - - void SilentBan(int to_ban_uid, const char *msg = 0, bool doScriptCallback = true); - - bool UnBan(int bid); - - bool IsBanned(const char *ip); - - void streamDebug(); - - int getStartTime(); - - void broadcastUserInfo(int uid); - std::vector GetClientListCopy(); - - std::vector GetBanListCopy(); + int getStartTime(); // Killer thread control void StartKillerThread(); @@ -268,10 +220,26 @@ class Sequencer { static unsigned int connCrash, connCount; private: - // Helpers (not thread safe) + // Helpers (not thread safe - only call when clients-mutex is locked!) Client* FindClientById(unsigned int client_id); + Client* getClient(int uid); void QueueClientForDisconnect(int client_id, const char *error, bool isError = true, bool doScriptCallback = true); void serverSay(std::string msg, int uid = -1, int type = 0); + void sendMOTD(int id); + void IntroduceNewClientToAllVehicles(Client *client); + int sendGameCommand(int uid, std::string cmd); + void printStats(); //! prints the Stats view, of who is connected and what slot they are in + bool CheckNickIsUnique(std::string &nick); + int GetFreePlayerColour(); + bool Kick(int to_kick_uid, int modUID, const char *msg = 0); + bool Ban(int to_ban_uid, int modUID, const char *msg = 0); + void SilentBan(int to_ban_uid, const char *msg = 0, bool doScriptCallback = true); + void RecordBan(int bid, std::string const& ip_addr, std::string const& nickname, std::string const& by_nickname, std::string const& banmsg); + bool IsBanned(const char *ip); + bool UnBan(int bid); + void streamDebug(); + std::vector GetBanListCopy(); + void broadcastUserInfo(int uid); // Killer thread void KillerThreadMain(); From 9e9d0babc04184e1f515a29a6be5292f3dd1e635 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Sat, 23 Apr 2022 20:52:55 +0200 Subject: [PATCH 12/15] bugfix - HTTP error logging is broken and may cause crash. --- source/server/http.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/server/http.cpp b/source/server/http.cpp index ca5fb84c..7f388018 100644 --- a/source/server/http.cpp +++ b/source/server/http.cpp @@ -51,8 +51,8 @@ namespace Http { SWInetSocket::SWBaseError result; if (!socket.connect(80, host, &result) || (result != SWInetSocket::ok)) { Logger::Log(LOG_ERROR, - "Could not process HTTP %s request %s%s failed, error: ", - method, host, url, result.get_error().c_str()); + "Could not process HTTP %s request %s%s failed, error: %s", + method.c_str(), host.c_str(), url.c_str(), result.get_error().c_str()); return ""; } @@ -61,16 +61,16 @@ namespace Http { if (socket.fsendmsg(query, &result) < 0) { Logger::Log(LOG_ERROR, - "Could not process HTTP %s request %s%s failed, error: ", - method, host, url, result.get_error().c_str()); + "Could not process HTTP %s request %s%s failed, error: %s", + method.c_str(), host.c_str(), url.c_str(), result.get_error().c_str()); return ""; } std::string response = socket.recvmsg(5000, &result); if (result != SWInetSocket::ok) { Logger::Log(LOG_ERROR, - "Could not process HTTP %s request %s%s failed, invalid response length, error message: ", - method, host, url, result.get_error().c_str()); + "Could not process HTTP %s request %s%s failed, invalid response length, error message: %s", + method.c_str(), host.c_str(), url.c_str(), result.get_error().c_str()); return ""; } From 4b43ba365ca27036e94a26fe6577f7b3ce338bbf Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Wed, 25 May 2022 00:33:45 +0200 Subject: [PATCH 13/15] codechange - ScriptEngine: fixed compiler warnings --- source/server/ScriptEngine.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/server/ScriptEngine.cpp b/source/server/ScriptEngine.cpp index f6d3ae55..fcc47b3e 100644 --- a/source/server/ScriptEngine.cpp +++ b/source/server/ScriptEngine.cpp @@ -1103,13 +1103,13 @@ void ServerScript::setUserColourNum(int uid, int num) { std::string ServerScript::getUserToken(int uid) { Client *c = seq->getClient(uid); - if (!c) return 0; + if (!c) return ""; return std::string(c->user.usertoken, 40); } std::string ServerScript::getUserVersion(int uid) { Client *c = seq->getClient(uid); - if (!c) return 0; + if (!c) return ""; return std::string(c->user.clientversion, 25); } @@ -1201,7 +1201,7 @@ std::string ServerScript::get_IPAddr() { return Config::getIPAddr(); } unsigned int ServerScript::get_listenPort() { return Config::getListenPort(); } -int ServerScript::get_serverMode() { return Config::getServerMode(); } +int ServerScript::get_serverMode() { return (int)Config::getServerMode(); } std::string ServerScript::get_owner() { return Config::getOwner(); } From 889498127845a34d62579e34168cf50e8901a569 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Wed, 25 May 2022 11:31:28 +0200 Subject: [PATCH 14/15] codechange - Broadcaster: replaced pthread with STL thread --- source/protocol/rornet.h | 6 +- source/server/broadcaster.cpp | 149 ++++++++++++++++++++-------------- source/server/broadcaster.h | 59 ++++++++------ 3 files changed, 122 insertions(+), 92 deletions(-) diff --git a/source/protocol/rornet.h b/source/protocol/rornet.h index 6faae902..0b7ff6b7 100644 --- a/source/protocol/rornet.h +++ b/source/protocol/rornet.h @@ -65,7 +65,9 @@ enum MessageType MSG2_STREAM_DATA_DISCARDABLE, //!< stream data that is allowed to be discarded // Legacy values (RoRnet_2.38 and earlier) - MSG2_WRONG_VER_LEGACY = 1003 //!< Wrong version + MSG2_WRONG_VER_LEGACY = 1003, //!< Wrong version + + MSG2_INVALID = 0 //!< Not to be transmitted }; enum UserAuth @@ -100,7 +102,7 @@ enum Netmask NETMASK_CLIGHT10 = BITMASK(18), //!< custom light 10 on NETMASK_POLICEAUDIO = BITMASK(19), //!< police siren on NETMASK_PARTICLE = BITMASK(20), //!< custom particles on - NETMASK_PBRAKE = BITMASK(21), //!< custom particles on + NETMASK_PBRAKE = BITMASK(21), //!< parking brake on NETMASK_TC_ACTIVE = BITMASK(22), //!< traction control light on? NETMASK_ALB_ACTIVE = BITMASK(23), //!< anti lock brake light on? NETMASK_ENGINE_CONT = BITMASK(24), //!< ignition on? diff --git a/source/server/broadcaster.cpp b/source/server/broadcaster.cpp index 8e981504..3e925cf2 100644 --- a/source/server/broadcaster.cpp +++ b/source/server/broadcaster.cpp @@ -25,106 +25,129 @@ along with Foobar. If not, see . #include "SocketW.h" #include "sequencer.h" +#include +#include #include #include -void *StartBroadcasterThread(void *data) { - Broadcaster *broadcaster = static_cast(data); - broadcaster->Thread(); - return nullptr; +Broadcaster::Broadcaster(Sequencer *sequencer) : + m_sequencer(sequencer) { } -Broadcaster::Broadcaster(Sequencer *sequencer) : - m_sequencer(sequencer), - m_client(nullptr), - m_is_dropping_packets(false), - m_packet_drop_counter(0), - m_packet_good_counter(0) { + +Broadcaster::~Broadcaster() { } + void Broadcaster::Start(Client* client) { + std::lock_guard scoped_lock(m_mutex); + m_client = client; m_is_dropping_packets = false; m_packet_drop_counter = 0; m_packet_good_counter = 0; - m_keep_running.store(true); m_msg_queue.clear(); - pthread_create(&m_thread, nullptr, StartBroadcasterThread, this); + m_thread = std::thread(&Broadcaster::ThreadMain, this); + m_thread_state = ThreadState::RUNNING; } + void Broadcaster::Stop() { - const bool was_running = m_keep_running.exchange(false); - if (was_running) { - m_queue_cond.signal(); - pthread_join(m_thread, nullptr); + { + std::lock_guard scoped_lock(m_mutex); + switch (m_thread_state) { + case ThreadState::RUNNING: + Logger::Log(LOG_DEBUG, "Broadcaster::Stop() (client_id %d) Thread state is RUNNING -> stopping", m_client->GetUserId()); + m_thread_state = ThreadState::STOP_REQUESTED; + break; + case ThreadState::NOT_RUNNING: + Logger::Log(LOG_DEBUG, "Broadcaster::Stop() (client_id %d) Thread state is NOT_RUNNING -> nothing to do", m_client->GetUserId()); + return; // We're done here. + case ThreadState::STOP_REQUESTED: + Logger::Log(LOG_DEBUG, "Broadcaster::Stop() (client_id %d) Thread state is STOP_REQUESTED -> nothing to do", m_client->GetUserId()); + return; // We're done here. + } + } + + m_queue_cond.notify_one(); // Unblock the thread. + m_thread.join(); // Wait for thread to exit. + + { + std::lock_guard scoped_lock(m_mutex); + m_thread_state = ThreadState::NOT_RUNNING; } } -void Broadcaster::Thread() { - Logger::Log(LOG_DEBUG, "Started broadcaster thread %u owned by client_id %d", ThreadID::getID(), m_client->GetUserId()); - bool socket_error = false; - while (true) { - queue_entry_t msg; - // define a new scope and use a scope lock - { - MutexLocker scoped_lock(m_queue_mutex); - while (m_msg_queue.empty() && m_keep_running.load()) { - m_queue_mutex.wait(m_queue_cond); - } - if (!m_keep_running.load()) { - break; - } - else if (!m_msg_queue.empty()) { // This shouldn't be needed, but rorserver is haunted: https://github.com/RigsOfRods/ror-server/pull/90#issuecomment-500597467 ~ only_a_ptr, 06/2019 - msg = m_msg_queue.front(); +void Broadcaster::ThreadMain() { + Logger::Log(LOG_DEBUG, "Started broadcaster thread (client_id %d)", m_client->GetUserId()); + + bool exit_loop = false; + while (!exit_loop) { + QueueEntry message; + ThreadState state = this->ThreadWaitForMessage(message); + + if (state == ThreadState::STOP_REQUESTED) { + Logger::Log(LOG_DEBUG, "Broadcaster thread (client_id %d) was requested to stop", m_client->GetUserId()); + // Synchronously send all the remaining messages and exit. + std::lock_guard scoped_lock(m_mutex); + while (!m_msg_queue.empty() && this->ThreadTransmitMessage(m_msg_queue.front())) { m_msg_queue.pop_front(); } + exit_loop = true; + } else { + if (!this->ThreadTransmitMessage(message)) { + m_sequencer->disconnectClient(m_client->GetUserId(), "Broadcaster: Send error", true, true); + exit_loop = true; + } } + } - if (msg.type == RoRnet::MSG2_STREAM_DATA_DISCARDABLE) - { - msg.type = RoRnet::MSG2_STREAM_DATA; - } + Logger::Log(LOG_DEBUG, "Broadcaster thread (client_id %d) exits", m_client->GetUserId()); +} - // TODO WARNING THE SOCKET IS NOT PROTECTED!!! - if (Messaging::SendMessage(m_client->GetSocket(), msg.type, msg.uid, msg.streamid, msg.datalen, msg.data) != 0) { - m_sequencer->disconnectClient(m_client->GetUserId(), "Broadcaster: Send error", true, true); - socket_error = true; - break; - } - } - if (!socket_error) { - MutexLocker scoped_lock(m_queue_mutex); - for (const auto& msg : m_msg_queue) { - if (msg.type != RoRnet::MSG2_STREAM_DATA && msg.type != RoRnet::MSG2_STREAM_DATA_DISCARDABLE) { - Messaging::SendMessage(m_client->GetSocket(), msg.type, msg.uid, msg.streamid, msg.datalen, msg.data); - } - } +Broadcaster::ThreadState Broadcaster::ThreadWaitForMessage(QueueEntry& out_message) { + std::unique_lock uni_lock(m_mutex); // Scoped + if (m_msg_queue.empty()) { + m_queue_cond.wait(uni_lock); } + if (!m_msg_queue.empty()) { + out_message = m_msg_queue.front(); + m_msg_queue.pop_front(); + } + return m_thread_state; +} - Logger::Log(LOG_DEBUG, "Broadcaster thread %u (client_id %d) exits", ThreadID::getID(), m_client->GetUserId()); + +bool Broadcaster::ThreadTransmitMessage(QueueEntry const& msg) { + int type = msg.type; + if (type == RoRnet::MSG2_INVALID) + return true; // No error. + if (type == RoRnet::MSG2_STREAM_DATA_DISCARDABLE) + type = RoRnet::MSG2_STREAM_DATA; + + int res = Messaging::SendMessage(m_client->GetSocket(), type, msg.uid, msg.streamid, msg.datalen, msg.data); + return res == 0; } -//this is called all the way from the receiver threads, we should process this swiftly -//and keep in mind that it is called crazily and concurently from lots of threads -//we MUST copy the data too -//also, this function can be called by threads owning clients_mutex !!! + void Broadcaster::QueueMessage(int type, int uid, unsigned int streamid, unsigned int len, const char *data) { - if (m_keep_running.load() == false) { - return; - } - queue_entry_t msg = {type, uid, streamid, len, ""}; - memcpy(msg.data, data, len); + QueueEntry msg; + msg.type = (RoRnet::MessageType)type; + msg.uid = uid; + msg.streamid = streamid; + msg.datalen = len; + std::memcpy(msg.data, data, len); { - MutexLocker scoped_lock(m_queue_mutex); + std::lock_guard scoped_lock(m_mutex); if (m_msg_queue.empty()) { m_packet_drop_counter = 0; m_is_dropping_packets = (++m_packet_good_counter > 3) ? false : m_is_dropping_packets; } else if (type == RoRnet::MSG2_STREAM_DATA_DISCARDABLE) { - auto search = std::find_if(m_msg_queue.begin(), m_msg_queue.end(), [&](const queue_entry_t& m) + auto search = std::find_if(m_msg_queue.begin(), m_msg_queue.end(), [&](const QueueEntry& m) { return m.type == RoRnet::MSG2_STREAM_DATA_DISCARDABLE && m.uid == uid && m.streamid == streamid; }); if (search != m_msg_queue.end()) { // Found outdated discardable streamdata -> replace it @@ -138,6 +161,6 @@ void Broadcaster::QueueMessage(int type, int uid, unsigned int streamid, unsigne m_msg_queue.push_back(msg); } - m_queue_cond.signal(); + m_queue_cond.notify_one(); } diff --git a/source/server/broadcaster.h b/source/server/broadcaster.h index 0bb72897..def67f80 100644 --- a/source/server/broadcaster.h +++ b/source/server/broadcaster.h @@ -21,56 +21,61 @@ along with Foobar. If not, see . #pragma once #include "rornet.h" -#include "mutexutils.h" #include "prerequisites.h" -#include -#include +#include #include +#include +#include -class SWInetSocket; - -class Sequencer; - -struct queue_entry_t { - int type; +struct QueueEntry { + RoRnet::MessageType type = RoRnet::MSG2_INVALID; int uid; unsigned int streamid; unsigned int datalen; char data[RORNET_MAX_MESSAGE_LENGTH]; }; -void *StartBroadcasterThread(void *); class Broadcaster { - friend void *StartBroadcasterThread(void *); - public: static const int QUEUE_SOFT_LIMIT = 100; static const int QUEUE_HARD_LIMIT = 300; + enum class ThreadState + { + NOT_RUNNING, //!< Initial/terminal state - thread not running. + RUNNING, //!< Thread running. + STOP_REQUESTED, //!< Thread running. + }; + Broadcaster(Sequencer *sequencer); + ~Broadcaster(); void Start(Client* client); - void Stop(); void QueueMessage(int msg_type, int client_id, unsigned int streamid, unsigned int payload_len, const char *payload); - bool IsDroppingPackets() const { return m_is_dropping_packets; } private: - void Thread(); - - Sequencer *m_sequencer; - pthread_t m_thread; - Mutex m_queue_mutex; - Condition m_queue_cond; - Client* m_client; - std::atomic m_keep_running; - bool m_is_dropping_packets; - int m_packet_drop_counter; - int m_packet_good_counter; - - std::deque m_msg_queue; + void ThreadMain(); + ThreadState ThreadWaitForMessage(QueueEntry& out_message); + bool ThreadTransmitMessage(QueueEntry const& message); //!< Returns false on error. + + // Thread context + std::thread m_thread; + ThreadState m_thread_state = ThreadState::NOT_RUNNING; + std::mutex m_mutex; + + // Queue + std::deque m_msg_queue; + std::condition_variable m_queue_cond; + + // Broadcaster state + Sequencer* m_sequencer = nullptr; + Client* m_client = nullptr; + bool m_is_dropping_packets = false; + int m_packet_drop_counter = 0; + int m_packet_good_counter = 0; }; From f7ac9dccdb5093847fe1f6920ef57b3298c0f1e5 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Wed, 25 May 2022 12:02:07 +0200 Subject: [PATCH 15/15] Removed win32_pthread dependency (replaced by STL thread) --- CMakeLists.txt | 4 +- dependencies/win32_pthread/.gitignore | 36 - dependencies/win32_pthread/CMakeLists.txt | 34 - dependencies/win32_pthread/README.md | 30 - dependencies/win32_pthread/include/config.h | 151 -- dependencies/win32_pthread/include/context.h | 75 - .../win32_pthread/include/implement.h | 1027 ------------ .../win32_pthread/include/need_errno.h | 145 -- dependencies/win32_pthread/include/pthread.h | 1416 ----------------- dependencies/win32_pthread/include/sched.h | 286 ---- .../win32_pthread/include/semaphore.h | 174 -- dependencies/win32_pthread/src/autostatic.c | 111 -- dependencies/win32_pthread/src/cleanup.c | 153 -- dependencies/win32_pthread/src/create.c | 314 ---- dependencies/win32_pthread/src/dll.c | 113 -- dependencies/win32_pthread/src/errno.c | 106 -- dependencies/win32_pthread/src/global.c | 112 -- dependencies/win32_pthread/src/pthread.c | 188 --- .../win32_pthread/src/pthread_attr_destroy.c | 84 - .../src/pthread_attr_getdetachstate.c | 91 -- .../src/pthread_attr_getinheritsched.c | 56 - .../src/pthread_attr_getschedparam.c | 57 - .../src/pthread_attr_getschedpolicy.c | 57 - .../win32_pthread/src/pthread_attr_getscope.c | 59 - .../src/pthread_attr_getstackaddr.c | 102 -- .../src/pthread_attr_getstacksize.c | 105 -- .../win32_pthread/src/pthread_attr_init.c | 122 -- .../src/pthread_attr_setdetachstate.c | 96 -- .../src/pthread_attr_setinheritsched.c | 62 - .../src/pthread_attr_setschedparam.c | 68 - .../src/pthread_attr_setschedpolicy.c | 60 - .../win32_pthread/src/pthread_attr_setscope.c | 67 - .../src/pthread_attr_setstackaddr.c | 102 -- .../src/pthread_attr_setstacksize.c | 115 -- .../src/pthread_barrier_destroy.c | 108 -- .../win32_pthread/src/pthread_barrier_init.c | 74 - .../win32_pthread/src/pthread_barrier_wait.c | 109 -- .../src/pthread_barrierattr_destroy.c | 88 - .../src/pthread_barrierattr_getpshared.c | 100 -- .../src/pthread_barrierattr_init.c | 90 -- .../src/pthread_barrierattr_setpshared.c | 124 -- .../win32_pthread/src/pthread_cancel.c | 194 --- .../win32_pthread/src/pthread_cond_destroy.c | 258 --- .../win32_pthread/src/pthread_cond_init.c | 172 -- .../win32_pthread/src/pthread_cond_signal.c | 236 --- .../win32_pthread/src/pthread_cond_wait.c | 571 ------- .../src/pthread_condattr_destroy.c | 91 -- .../src/pthread_condattr_getpshared.c | 102 -- .../win32_pthread/src/pthread_condattr_init.c | 92 -- .../src/pthread_condattr_setpshared.c | 122 -- .../win32_pthread/src/pthread_delay_np.c | 177 --- .../win32_pthread/src/pthread_detach.c | 141 -- .../win32_pthread/src/pthread_equal.c | 81 - dependencies/win32_pthread/src/pthread_exit.c | 110 -- .../src/pthread_getconcurrency.c | 50 - .../win32_pthread/src/pthread_getschedparam.c | 76 - .../win32_pthread/src/pthread_getspecific.c | 92 -- .../win32_pthread/src/pthread_getunique_np.c | 52 - .../src/pthread_getw32threadhandle_np.c | 70 - dependencies/win32_pthread/src/pthread_join.c | 162 -- .../win32_pthread/src/pthread_key_create.c | 113 -- .../win32_pthread/src/pthread_key_delete.c | 130 -- dependencies/win32_pthread/src/pthread_kill.c | 110 -- .../src/pthread_mutex_consistent.c | 195 --- .../win32_pthread/src/pthread_mutex_destroy.c | 153 -- .../win32_pthread/src/pthread_mutex_init.c | 135 -- .../win32_pthread/src/pthread_mutex_lock.c | 274 ---- .../src/pthread_mutex_timedlock.c | 328 ---- .../win32_pthread/src/pthread_mutex_trylock.c | 159 -- .../win32_pthread/src/pthread_mutex_unlock.c | 184 --- .../src/pthread_mutexattr_destroy.c | 88 - .../src/pthread_mutexattr_getkind_np.c | 49 - .../src/pthread_mutexattr_getpshared.c | 100 -- .../src/pthread_mutexattr_getrobust.c | 118 -- .../src/pthread_mutexattr_gettype.c | 61 - .../src/pthread_mutexattr_init.c | 92 -- .../src/pthread_mutexattr_setkind_np.c | 49 - .../src/pthread_mutexattr_setpshared.c | 124 -- .../src/pthread_mutexattr_setrobust.c | 124 -- .../src/pthread_mutexattr_settype.c | 148 -- .../src/pthread_num_processors_np.c | 61 - dependencies/win32_pthread/src/pthread_once.c | 92 -- .../src/pthread_rwlock_destroy.c | 148 -- .../win32_pthread/src/pthread_rwlock_init.c | 114 -- .../win32_pthread/src/pthread_rwlock_rdlock.c | 107 -- .../src/pthread_rwlock_timedrdlock.c | 114 -- .../src/pthread_rwlock_timedwrlock.c | 144 -- .../src/pthread_rwlock_tryrdlock.c | 107 -- .../src/pthread_rwlock_trywrlock.c | 127 -- .../win32_pthread/src/pthread_rwlock_unlock.c | 98 -- .../win32_pthread/src/pthread_rwlock_wrlock.c | 138 -- .../src/pthread_rwlockattr_destroy.c | 89 -- .../src/pthread_rwlockattr_getpshared.c | 102 -- .../src/pthread_rwlockattr_init.c | 88 - .../src/pthread_rwlockattr_setpshared.c | 125 -- dependencies/win32_pthread/src/pthread_self.c | 177 --- .../win32_pthread/src/pthread_setaffinity.c | 225 --- .../src/pthread_setcancelstate.c | 130 -- .../win32_pthread/src/pthread_setcanceltype.c | 131 -- .../src/pthread_setconcurrency.c | 58 - .../win32_pthread/src/pthread_setschedparam.c | 128 -- .../win32_pthread/src/pthread_setspecific.c | 172 -- .../win32_pthread/src/pthread_spin_destroy.c | 116 -- .../win32_pthread/src/pthread_spin_init.c | 128 -- .../win32_pthread/src/pthread_spin_lock.c | 85 - .../win32_pthread/src/pthread_spin_trylock.c | 82 - .../win32_pthread/src/pthread_spin_unlock.c | 76 - .../win32_pthread/src/pthread_testcancel.c | 108 -- .../src/pthread_timechange_handler_np.c | 113 -- .../win32_pthread/src/pthread_timedjoin_np.c | 188 --- .../win32_pthread/src/pthread_tryjoin_np.c | 173 -- .../src/pthread_win32_attach_detach_np.c | 268 ---- .../win32_pthread/src/ptw32_MCS_lock.c | 283 ---- .../src/ptw32_callUserDestroyRoutines.c | 237 --- dependencies/win32_pthread/src/ptw32_calloc.c | 61 - .../src/ptw32_cond_check_need_init.c | 83 - .../win32_pthread/src/ptw32_getprocessors.c | 96 -- .../win32_pthread/src/ptw32_is_attr.c | 52 - .../src/ptw32_mutex_check_need_init.c | 97 -- dependencies/win32_pthread/src/ptw32_new.c | 99 -- .../src/ptw32_processInitialize.c | 95 -- .../src/ptw32_processTerminate.c | 119 -- .../win32_pthread/src/ptw32_relmillisecs.c | 137 -- dependencies/win32_pthread/src/ptw32_reuse.c | 156 -- .../src/ptw32_rwlock_cancelwrwait.c | 55 - .../src/ptw32_rwlock_check_need_init.c | 82 - .../win32_pthread/src/ptw32_semwait.c | 140 -- .../src/ptw32_spinlock_check_need_init.c | 83 - .../win32_pthread/src/ptw32_threadDestroy.c | 84 - .../win32_pthread/src/ptw32_threadStart.c | 330 ---- dependencies/win32_pthread/src/ptw32_throw.c | 194 --- .../win32_pthread/src/ptw32_timespec.c | 88 - .../win32_pthread/src/ptw32_tkAssocCreate.c | 123 -- .../win32_pthread/src/ptw32_tkAssocDestroy.c | 119 -- .../src/sched_get_priority_max.c | 139 -- .../src/sched_get_priority_min.c | 140 -- .../win32_pthread/src/sched_getscheduler.c | 74 - .../win32_pthread/src/sched_setaffinity.c | 352 ---- .../win32_pthread/src/sched_setscheduler.c | 86 - dependencies/win32_pthread/src/sched_yield.c | 76 - dependencies/win32_pthread/src/sem_close.c | 63 - dependencies/win32_pthread/src/sem_destroy.c | 149 -- dependencies/win32_pthread/src/sem_getvalue.c | 119 -- dependencies/win32_pthread/src/sem_init.c | 173 -- dependencies/win32_pthread/src/sem_open.c | 63 - dependencies/win32_pthread/src/sem_post.c | 136 -- .../win32_pthread/src/sem_post_multiple.c | 147 -- .../win32_pthread/src/sem_timedwait.c | 243 --- dependencies/win32_pthread/src/sem_trywait.c | 122 -- dependencies/win32_pthread/src/sem_unlink.c | 63 - dependencies/win32_pthread/src/sem_wait.c | 191 --- dependencies/win32_pthread/src/signal.c | 184 --- dependencies/win32_pthread/src/version.rc | 406 ----- .../win32_pthread/src/w32_CancelableWait.c | 166 -- source/server/CMakeLists.txt | 5 +- source/server/mutexutils.cpp | 195 --- source/server/mutexutils.h | 113 -- 157 files changed, 3 insertions(+), 22281 deletions(-) delete mode 100644 dependencies/win32_pthread/.gitignore delete mode 100644 dependencies/win32_pthread/CMakeLists.txt delete mode 100644 dependencies/win32_pthread/README.md delete mode 100644 dependencies/win32_pthread/include/config.h delete mode 100644 dependencies/win32_pthread/include/context.h delete mode 100644 dependencies/win32_pthread/include/implement.h delete mode 100644 dependencies/win32_pthread/include/need_errno.h delete mode 100644 dependencies/win32_pthread/include/pthread.h delete mode 100644 dependencies/win32_pthread/include/sched.h delete mode 100644 dependencies/win32_pthread/include/semaphore.h delete mode 100644 dependencies/win32_pthread/src/autostatic.c delete mode 100644 dependencies/win32_pthread/src/cleanup.c delete mode 100644 dependencies/win32_pthread/src/create.c delete mode 100644 dependencies/win32_pthread/src/dll.c delete mode 100644 dependencies/win32_pthread/src/errno.c delete mode 100644 dependencies/win32_pthread/src/global.c delete mode 100644 dependencies/win32_pthread/src/pthread.c delete mode 100644 dependencies/win32_pthread/src/pthread_attr_destroy.c delete mode 100644 dependencies/win32_pthread/src/pthread_attr_getdetachstate.c delete mode 100644 dependencies/win32_pthread/src/pthread_attr_getinheritsched.c delete mode 100644 dependencies/win32_pthread/src/pthread_attr_getschedparam.c delete mode 100644 dependencies/win32_pthread/src/pthread_attr_getschedpolicy.c delete mode 100644 dependencies/win32_pthread/src/pthread_attr_getscope.c delete mode 100644 dependencies/win32_pthread/src/pthread_attr_getstackaddr.c delete mode 100644 dependencies/win32_pthread/src/pthread_attr_getstacksize.c delete mode 100644 dependencies/win32_pthread/src/pthread_attr_init.c delete mode 100644 dependencies/win32_pthread/src/pthread_attr_setdetachstate.c delete mode 100644 dependencies/win32_pthread/src/pthread_attr_setinheritsched.c delete mode 100644 dependencies/win32_pthread/src/pthread_attr_setschedparam.c delete mode 100644 dependencies/win32_pthread/src/pthread_attr_setschedpolicy.c delete mode 100644 dependencies/win32_pthread/src/pthread_attr_setscope.c delete mode 100644 dependencies/win32_pthread/src/pthread_attr_setstackaddr.c delete mode 100644 dependencies/win32_pthread/src/pthread_attr_setstacksize.c delete mode 100644 dependencies/win32_pthread/src/pthread_barrier_destroy.c delete mode 100644 dependencies/win32_pthread/src/pthread_barrier_init.c delete mode 100644 dependencies/win32_pthread/src/pthread_barrier_wait.c delete mode 100644 dependencies/win32_pthread/src/pthread_barrierattr_destroy.c delete mode 100644 dependencies/win32_pthread/src/pthread_barrierattr_getpshared.c delete mode 100644 dependencies/win32_pthread/src/pthread_barrierattr_init.c delete mode 100644 dependencies/win32_pthread/src/pthread_barrierattr_setpshared.c delete mode 100644 dependencies/win32_pthread/src/pthread_cancel.c delete mode 100644 dependencies/win32_pthread/src/pthread_cond_destroy.c delete mode 100644 dependencies/win32_pthread/src/pthread_cond_init.c delete mode 100644 dependencies/win32_pthread/src/pthread_cond_signal.c delete mode 100644 dependencies/win32_pthread/src/pthread_cond_wait.c delete mode 100644 dependencies/win32_pthread/src/pthread_condattr_destroy.c delete mode 100644 dependencies/win32_pthread/src/pthread_condattr_getpshared.c delete mode 100644 dependencies/win32_pthread/src/pthread_condattr_init.c delete mode 100644 dependencies/win32_pthread/src/pthread_condattr_setpshared.c delete mode 100644 dependencies/win32_pthread/src/pthread_delay_np.c delete mode 100644 dependencies/win32_pthread/src/pthread_detach.c delete mode 100644 dependencies/win32_pthread/src/pthread_equal.c delete mode 100644 dependencies/win32_pthread/src/pthread_exit.c delete mode 100644 dependencies/win32_pthread/src/pthread_getconcurrency.c delete mode 100644 dependencies/win32_pthread/src/pthread_getschedparam.c delete mode 100644 dependencies/win32_pthread/src/pthread_getspecific.c delete mode 100644 dependencies/win32_pthread/src/pthread_getunique_np.c delete mode 100644 dependencies/win32_pthread/src/pthread_getw32threadhandle_np.c delete mode 100644 dependencies/win32_pthread/src/pthread_join.c delete mode 100644 dependencies/win32_pthread/src/pthread_key_create.c delete mode 100644 dependencies/win32_pthread/src/pthread_key_delete.c delete mode 100644 dependencies/win32_pthread/src/pthread_kill.c delete mode 100644 dependencies/win32_pthread/src/pthread_mutex_consistent.c delete mode 100644 dependencies/win32_pthread/src/pthread_mutex_destroy.c delete mode 100644 dependencies/win32_pthread/src/pthread_mutex_init.c delete mode 100644 dependencies/win32_pthread/src/pthread_mutex_lock.c delete mode 100644 dependencies/win32_pthread/src/pthread_mutex_timedlock.c delete mode 100644 dependencies/win32_pthread/src/pthread_mutex_trylock.c delete mode 100644 dependencies/win32_pthread/src/pthread_mutex_unlock.c delete mode 100644 dependencies/win32_pthread/src/pthread_mutexattr_destroy.c delete mode 100644 dependencies/win32_pthread/src/pthread_mutexattr_getkind_np.c delete mode 100644 dependencies/win32_pthread/src/pthread_mutexattr_getpshared.c delete mode 100644 dependencies/win32_pthread/src/pthread_mutexattr_getrobust.c delete mode 100644 dependencies/win32_pthread/src/pthread_mutexattr_gettype.c delete mode 100644 dependencies/win32_pthread/src/pthread_mutexattr_init.c delete mode 100644 dependencies/win32_pthread/src/pthread_mutexattr_setkind_np.c delete mode 100644 dependencies/win32_pthread/src/pthread_mutexattr_setpshared.c delete mode 100644 dependencies/win32_pthread/src/pthread_mutexattr_setrobust.c delete mode 100644 dependencies/win32_pthread/src/pthread_mutexattr_settype.c delete mode 100644 dependencies/win32_pthread/src/pthread_num_processors_np.c delete mode 100644 dependencies/win32_pthread/src/pthread_once.c delete mode 100644 dependencies/win32_pthread/src/pthread_rwlock_destroy.c delete mode 100644 dependencies/win32_pthread/src/pthread_rwlock_init.c delete mode 100644 dependencies/win32_pthread/src/pthread_rwlock_rdlock.c delete mode 100644 dependencies/win32_pthread/src/pthread_rwlock_timedrdlock.c delete mode 100644 dependencies/win32_pthread/src/pthread_rwlock_timedwrlock.c delete mode 100644 dependencies/win32_pthread/src/pthread_rwlock_tryrdlock.c delete mode 100644 dependencies/win32_pthread/src/pthread_rwlock_trywrlock.c delete mode 100644 dependencies/win32_pthread/src/pthread_rwlock_unlock.c delete mode 100644 dependencies/win32_pthread/src/pthread_rwlock_wrlock.c delete mode 100644 dependencies/win32_pthread/src/pthread_rwlockattr_destroy.c delete mode 100644 dependencies/win32_pthread/src/pthread_rwlockattr_getpshared.c delete mode 100644 dependencies/win32_pthread/src/pthread_rwlockattr_init.c delete mode 100644 dependencies/win32_pthread/src/pthread_rwlockattr_setpshared.c delete mode 100644 dependencies/win32_pthread/src/pthread_self.c delete mode 100644 dependencies/win32_pthread/src/pthread_setaffinity.c delete mode 100644 dependencies/win32_pthread/src/pthread_setcancelstate.c delete mode 100644 dependencies/win32_pthread/src/pthread_setcanceltype.c delete mode 100644 dependencies/win32_pthread/src/pthread_setconcurrency.c delete mode 100644 dependencies/win32_pthread/src/pthread_setschedparam.c delete mode 100644 dependencies/win32_pthread/src/pthread_setspecific.c delete mode 100644 dependencies/win32_pthread/src/pthread_spin_destroy.c delete mode 100644 dependencies/win32_pthread/src/pthread_spin_init.c delete mode 100644 dependencies/win32_pthread/src/pthread_spin_lock.c delete mode 100644 dependencies/win32_pthread/src/pthread_spin_trylock.c delete mode 100644 dependencies/win32_pthread/src/pthread_spin_unlock.c delete mode 100644 dependencies/win32_pthread/src/pthread_testcancel.c delete mode 100644 dependencies/win32_pthread/src/pthread_timechange_handler_np.c delete mode 100644 dependencies/win32_pthread/src/pthread_timedjoin_np.c delete mode 100644 dependencies/win32_pthread/src/pthread_tryjoin_np.c delete mode 100644 dependencies/win32_pthread/src/pthread_win32_attach_detach_np.c delete mode 100644 dependencies/win32_pthread/src/ptw32_MCS_lock.c delete mode 100644 dependencies/win32_pthread/src/ptw32_callUserDestroyRoutines.c delete mode 100644 dependencies/win32_pthread/src/ptw32_calloc.c delete mode 100644 dependencies/win32_pthread/src/ptw32_cond_check_need_init.c delete mode 100644 dependencies/win32_pthread/src/ptw32_getprocessors.c delete mode 100644 dependencies/win32_pthread/src/ptw32_is_attr.c delete mode 100644 dependencies/win32_pthread/src/ptw32_mutex_check_need_init.c delete mode 100644 dependencies/win32_pthread/src/ptw32_new.c delete mode 100644 dependencies/win32_pthread/src/ptw32_processInitialize.c delete mode 100644 dependencies/win32_pthread/src/ptw32_processTerminate.c delete mode 100644 dependencies/win32_pthread/src/ptw32_relmillisecs.c delete mode 100644 dependencies/win32_pthread/src/ptw32_reuse.c delete mode 100644 dependencies/win32_pthread/src/ptw32_rwlock_cancelwrwait.c delete mode 100644 dependencies/win32_pthread/src/ptw32_rwlock_check_need_init.c delete mode 100644 dependencies/win32_pthread/src/ptw32_semwait.c delete mode 100644 dependencies/win32_pthread/src/ptw32_spinlock_check_need_init.c delete mode 100644 dependencies/win32_pthread/src/ptw32_threadDestroy.c delete mode 100644 dependencies/win32_pthread/src/ptw32_threadStart.c delete mode 100644 dependencies/win32_pthread/src/ptw32_throw.c delete mode 100644 dependencies/win32_pthread/src/ptw32_timespec.c delete mode 100644 dependencies/win32_pthread/src/ptw32_tkAssocCreate.c delete mode 100644 dependencies/win32_pthread/src/ptw32_tkAssocDestroy.c delete mode 100644 dependencies/win32_pthread/src/sched_get_priority_max.c delete mode 100644 dependencies/win32_pthread/src/sched_get_priority_min.c delete mode 100644 dependencies/win32_pthread/src/sched_getscheduler.c delete mode 100644 dependencies/win32_pthread/src/sched_setaffinity.c delete mode 100644 dependencies/win32_pthread/src/sched_setscheduler.c delete mode 100644 dependencies/win32_pthread/src/sched_yield.c delete mode 100644 dependencies/win32_pthread/src/sem_close.c delete mode 100644 dependencies/win32_pthread/src/sem_destroy.c delete mode 100644 dependencies/win32_pthread/src/sem_getvalue.c delete mode 100644 dependencies/win32_pthread/src/sem_init.c delete mode 100644 dependencies/win32_pthread/src/sem_open.c delete mode 100644 dependencies/win32_pthread/src/sem_post.c delete mode 100644 dependencies/win32_pthread/src/sem_post_multiple.c delete mode 100644 dependencies/win32_pthread/src/sem_timedwait.c delete mode 100644 dependencies/win32_pthread/src/sem_trywait.c delete mode 100644 dependencies/win32_pthread/src/sem_unlink.c delete mode 100644 dependencies/win32_pthread/src/sem_wait.c delete mode 100644 dependencies/win32_pthread/src/signal.c delete mode 100644 dependencies/win32_pthread/src/version.rc delete mode 100644 dependencies/win32_pthread/src/w32_CancelableWait.c delete mode 100644 source/server/mutexutils.cpp delete mode 100644 source/server/mutexutils.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b2e40979..f4cb48f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,9 +57,7 @@ SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${RUNTIME_OUTPUT_DIRECTORY}) SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${RUNTIME_OUTPUT_DIRECTORY}) -if (WIN32) - add_subdirectory(dependencies/win32_pthread) -else () +if (NOT WIN32) add_definitions(-Wall) option(RORSERVER_CRASHHANDLER "enables linux startup script crashhandling" FALSE) diff --git a/dependencies/win32_pthread/.gitignore b/dependencies/win32_pthread/.gitignore deleted file mode 100644 index 4d492991..00000000 --- a/dependencies/win32_pthread/.gitignore +++ /dev/null @@ -1,36 +0,0 @@ -# Prerequisites -*.d - -# Compiled Object files -*.slo -*.lo -*.o -*.obj - -# Precompiled Headers -*.gch -*.pch - -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod -*.smod - -# Compiled Static libraries -*.lai -*.la -*.a -*.lib - -# Executables -*.exe -*.out -*.app - -# Folders -build/** -.vscode/** \ No newline at end of file diff --git a/dependencies/win32_pthread/CMakeLists.txt b/dependencies/win32_pthread/CMakeLists.txt deleted file mode 100644 index b06b641e..00000000 --- a/dependencies/win32_pthread/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -cmake_minimum_required(VERSION 3.0) - -project(pthread) - -add_definitions( - -DHAVE_CONFIG_H - -DNDEBUG - -DUNICODE - -D_UNICODE -) - -if(MSVC) - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MP /GS /GL /Wall /wd\"4820\" /wd\"4668\" /wd\"4255\" /Oi /Gy /Zc:wchar_t /Zi /Gm-") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MP /GS /GL /Wall /wd\"4820\" /wd\"4668\" /wd\"4255\" /Oi /Gy /Zc:wchar_t /Zi /Gm-") -endif() -if(NOT MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") - if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") - endif() -endif() - -set(PTHREAD_LIBRARY_TYPE STATIC) -add_definitions(-DPTW32_STATIC_LIB) - - -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src SOURCES) -list(REMOVE_ITEM SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/pthread.c) - -add_library(${PROJECT_NAME} ${PTHREAD_LIBRARY_TYPE} ${SOURCES}) -if(MSVC) - target_link_libraries(${PROJECT_NAME} ws2_32) -endif() diff --git a/dependencies/win32_pthread/README.md b/dependencies/win32_pthread/README.md deleted file mode 100644 index d6e743b3..00000000 --- a/dependencies/win32_pthread/README.md +++ /dev/null @@ -1,30 +0,0 @@ -# pthread-win ~ POSIX Threads (pthreads) for Windows - -This is an adaptation of the library [pthread-win32](https://github.com/GerHobbelt/pthread-win32.git) for CMake. - -# Example -```js -cmake_minimum_required(VERSION 2.8) -include(ExternalProject) - -project(example) - -set(externals_prefix "${CMAKE_CURRENT_BINARY_DIR}/externals") -set(externals_install_dir "${CMAKE_CURRENT_BINARY_DIR}/libs") - -set_property(DIRECTORY PROPERTY EP_BASE ${externals_prefix}) -ExternalProject_Add(lpthread - GIT_REPOSITORY "https://github.com/Puasonych/pthread-win.git" - GIT_TAG "master" - CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${externals_install_dir} -DPTHREAD_BUILD_SHARED=OFF -) - -include_directories(${externals_install_dir}/include) -set(PTHREAD_LIB "${externals_install_dir}/lib/libpthread.lib") -add_executable(${PROJECT_NAME} main.cpp) -add_dependencies(${PROJECT_NAME} lpthread) -target_link_libraries( - ${PROJECT_NAME} - ${PTHREAD_LIB} -) -``` diff --git a/dependencies/win32_pthread/include/config.h b/dependencies/win32_pthread/include/config.h deleted file mode 100644 index ccdff48d..00000000 --- a/dependencies/win32_pthread/include/config.h +++ /dev/null @@ -1,151 +0,0 @@ -/* config.h */ - -#ifndef PTW32_CONFIG_H -#define PTW32_CONFIG_H - -/********************************************************************* - * Defaults: see target specific redefinitions below. - *********************************************************************/ - -/* We're building the pthreads-win32 library */ -#define PTW32_BUILD - -/* Do we know about the C type sigset_t? */ -#undef HAVE_SIGSET_T - -/* Define if you have the header file. */ -#undef HAVE_SIGNAL_H - -/* Define if you have the Borland TASM32 or compatible assembler. */ -#undef HAVE_TASM32 - -/* Define if you don't have Win32 DuplicateHandle. (eg. WinCE) */ -#undef NEED_DUPLICATEHANDLE - -/* Define if you don't have Win32 _beginthreadex. (eg. WinCE) */ -#undef NEED_CREATETHREAD - -/* Define if you don't have Win32 errno. (eg. WinCE) */ -#undef NEED_ERRNO - -/* Define if you don't have Win32 calloc. (eg. WinCE) */ -#undef NEED_CALLOC - -/* Define if you don't have Win32 ftime. (eg. WinCE) */ -#undef NEED_FTIME - -/* Define if you don't have Win32 semaphores. (eg. WinCE 2.1 or earlier) */ -#undef NEED_SEM - -/* Define if you need to convert string parameters to unicode. (eg. WinCE) */ -#undef NEED_UNICODE_CONSTS - -/* Define if your C (not C++) compiler supports "inline" functions. */ -#undef HAVE_C_INLINE - -/* Do we know about type mode_t? */ -#undef HAVE_MODE_T - -/* - * Define if GCC has atomic builtins, i.e. __sync_* intrinsics - * __sync_lock_* is implemented in mingw32 gcc 4.5.2 at least - * so this define does not turn those on or off. If you get an - * error from __sync_lock* then consider upgrading your gcc. - */ -#undef HAVE_GCC_ATOMIC_BUILTINS - -/* Define if you have the timespec struct */ -#undef HAVE_STRUCT_TIMESPEC - -/* Define if you don't have the GetProcessAffinityMask() */ -#undef NEED_PROCESS_AFFINITY_MASK - -/* Define if your version of Windows TLSGetValue() clears WSALastError - * and calling SetLastError() isn't enough restore it. You'll also need to - * link against wsock32.lib (or libwsock32.a for MinGW). - */ -#undef RETAIN_WSALASTERROR - -/* -# ---------------------------------------------------------------------- -# The library can be built with some alternative behaviour to better -# facilitate development of applications on Win32 that will be ported -# to other POSIX systems. -# -# Nothing described here will make the library non-compliant and strictly -# compliant applications will not be affected in any way, but -# applications that make assumptions that POSIX does not guarantee are -# not strictly compliant and may fail or misbehave with some settings. -# -# PTW32_THREAD_ID_REUSE_INCREMENT -# Purpose: -# POSIX says that applications should assume that thread IDs can be -# recycled. However, Solaris (and some other systems) use a [very large] -# sequence number as the thread ID, which provides virtual uniqueness. -# This provides a very high but finite level of safety for applications -# that are not meticulous in tracking thread lifecycles e.g. applications -# that call functions which target detached threads without some form of -# thread exit synchronisation. -# -# Usage: -# Set to any value in the range: 0 <= value < 2^wordsize. -# Set to 0 to emulate reusable thread ID behaviour like Linux or *BSD. -# Set to 1 for unique thread IDs like Solaris (this is the default). -# Set to some factor of 2^wordsize to emulate smaller word size types -# (i.e. will wrap sooner). This might be useful to emulate some embedded -# systems. -# -# define PTW32_THREAD_ID_REUSE_INCREMENT 0 -# -# ---------------------------------------------------------------------- - */ -#undef PTW32_THREAD_ID_REUSE_INCREMENT - - -/********************************************************************* - * Target specific groups - * - * If you find that these are incorrect or incomplete please report it - * to the pthreads-win32 maintainer. Thanks. - *********************************************************************/ -#if defined(WINCE) -#define NEED_DUPLICATEHANDLE -#define NEED_CREATETHREAD -#define NEED_ERRNO -#define NEED_CALLOC -#define NEED_FTIME -/* #define NEED_SEM */ -#define NEED_UNICODE_CONSTS -#define NEED_PROCESS_AFFINITY_MASK -/* This may not be needed */ -#define RETAIN_WSALASTERROR -#endif - -#if defined(_UWIN) -#define HAVE_MODE_T -#define HAVE_STRUCT_TIMESPEC -#endif - -#if defined(__GNUC__) -#define HAVE_C_INLINE -#endif - -#if defined(__MINGW64__) -#define HAVE_MODE_T -#define HAVE_STRUCT_TIMESPEC -#elif defined(__MINGW32__) -#define HAVE_MODE_T -#endif - -#if defined(__BORLANDC__) -#endif - -#if defined(__WATCOMC__) -#endif - -#if defined(__DMC__) -#define HAVE_SIGNAL_H -#define HAVE_C_INLINE -#endif - -#endif /* PTW32_CONFIG_H */ diff --git a/dependencies/win32_pthread/include/context.h b/dependencies/win32_pthread/include/context.h deleted file mode 100644 index b7140019..00000000 --- a/dependencies/win32_pthread/include/context.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * context.h - * - * Description: - * POSIX thread macros related to thread cancellation. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef PTW32_CONTEXT_H -#define PTW32_CONTEXT_H - -#undef PTW32_PROGCTR - -#if defined(_M_IX86) || (defined(_X86_) && !defined(__amd64__)) -#define PTW32_PROGCTR(Context) ((Context).Eip) -#endif - -#if defined (_M_IA64) || defined(_IA64) -#define PTW32_PROGCTR(Context) ((Context).StIIP) -#endif - -#if defined(_MIPS_) || defined(MIPS) -#define PTW32_PROGCTR(Context) ((Context).Fir) -#endif - -#if defined(_ALPHA_) -#define PTW32_PROGCTR(Context) ((Context).Fir) -#endif - -#if defined(_PPC_) -#define PTW32_PROGCTR(Context) ((Context).Iar) -#endif - -#if defined(_AMD64_) || defined(__amd64__) -#define PTW32_PROGCTR(Context) ((Context).Rip) -#endif - -#if defined(_ARM_) || defined(ARM) -#define PTW32_PROGCTR(Context) ((Context).Pc) -#endif - -#if !defined(PTW32_PROGCTR) -#error Module contains CPU-specific code; modify and recompile. -#endif - -#endif diff --git a/dependencies/win32_pthread/include/implement.h b/dependencies/win32_pthread/include/implement.h deleted file mode 100644 index e8eeba20..00000000 --- a/dependencies/win32_pthread/include/implement.h +++ /dev/null @@ -1,1027 +0,0 @@ -/* - * implement.h - * - * Definitions that don't need to be public. - * - * Keeps all the internals out of pthread.h - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Contact Email: Ross.Johnson@homemail.com.au - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#if !defined(_IMPLEMENT_H) -#define _IMPLEMENT_H - -#if !defined(PTW32_CONFIG_H) && !defined(_PTHREAD_TEST_H_) -# error "config.h was not #included" -#endif - -#if !defined(_WIN32_WINNT) -# define _WIN32_WINNT 0x0400 -#endif - -#include - -/* - * In case windows.h doesn't define it (e.g. WinCE perhaps) - */ -#if defined(WINCE) -typedef VOID (APIENTRY *PAPCFUNC)(DWORD dwParam); -#endif - -/* - * Designed to allow error values to be set and retrieved in builds where - * MSCRT libraries are statically linked to DLLs. - */ -#if ( defined(PTW32_CONFIG_MINGW) && __MSVCRT_VERSION__ >= 0x0800 ) || \ - ( defined(_MSC_VER) && _MSC_VER >= 1400 ) /* MSVC8+ */ -# if defined(PTW32_CONFIG_MINGW) -__attribute__((unused)) -# endif -static int ptw32_get_errno(void) { int err = 0; _get_errno(&err); return err; } -# define PTW32_GET_ERRNO() ptw32_get_errno() -# if defined(PTW32_USES_SEPARATE_CRT) -# if defined(PTW32_CONFIG_MINGW) -__attribute__((unused)) -# endif -static void ptw32_set_errno(int err) { _set_errno(err); SetLastError(err); } -# define PTW32_SET_ERRNO(err) ptw32_set_errno(err) -# else -# define PTW32_SET_ERRNO(err) _set_errno(err) -# endif -#else -# define PTW32_GET_ERRNO() (errno) -# if defined(PTW32_USES_SEPARATE_CRT) -# if defined(PTW32_CONFIG_MINGW) -__attribute__((unused)) -# endif -static void ptw32_set_errno(int err) { errno = err; SetLastError(err); } -# define PTW32_SET_ERRNO(err) ptw32_set_errno(err) -# else -# define PTW32_SET_ERRNO(err) (errno = (err)) -# endif -#endif - -/* - * note: ETIMEDOUT is correctly defined in winsock.h - */ -#include - -/* - * In case ETIMEDOUT hasn't been defined above somehow. - */ -#if !defined(ETIMEDOUT) -# define ETIMEDOUT 10060 /* This is the value in winsock.h. */ -#endif - -#if !defined(malloc) -# include -#endif - -#if defined(__CLEANUP_C) -# include -#endif - -#if !defined(INT_MAX) -# include -#endif - -/* _tcsncat_s() et al: mapping to the correct TCHAR prototypes: */ -#include - -/* use local include files during development */ -#include "semaphore.h" -#include "sched.h" - -/* MSVC 7.1 doesn't like complex #if expressions */ -#define INLINE -#if defined(PTW32_BUILD_INLINED) -# if defined(HAVE_C_INLINE) || defined(__cplusplus) -# undef INLINE -# define INLINE inline -# endif -#endif - -#if defined(PTW32_CONFIG_MSVC6) -/* - * MSVC 6 does not use the "volatile" qualifier - */ -# define PTW32_INTERLOCKED_VOLATILE -#else -# define PTW32_INTERLOCKED_VOLATILE volatile -#endif - -#define PTW32_INTERLOCKED_LONG long -#if defined(_M_IA64) -#define PTW32_INTERLOCKED_SIZE LONG64 -#elif defined(_M_AMD64) -#define PTW32_INTERLOCKED_SIZE LONG64 -#elif defined(_WIN64) -#define PTW32_INTERLOCKED_SIZE LONGLONG -#else -#define PTW32_INTERLOCKED_SIZE LONG -#endif -#define PTW32_INTERLOCKED_PVOID PVOID -#define PTW32_INTERLOCKED_LONGPTR PTW32_INTERLOCKED_VOLATILE long* -#if defined(_M_IA64) -#define PTW32_INTERLOCKED_SIZEPTR PTW32_INTERLOCKED_VOLATILE LONG64* -#elif defined(_M_AMD64) -#define PTW32_INTERLOCKED_SIZEPTR PTW32_INTERLOCKED_VOLATILE LONG64* -#elif defined(_WIN64) -#define PTW32_INTERLOCKED_SIZEPTR PTW32_INTERLOCKED_VOLATILE LONGLONG* -#else -#define PTW32_INTERLOCKED_SIZEPTR PTW32_INTERLOCKED_VOLATILE LONG* -#endif -#define PTW32_INTERLOCKED_PVOID_PTR PTW32_INTERLOCKED_VOLATILE PVOID* - -#if defined(PTW32_CONFIG_MINGW) -# include -#elif defined(__BORLANDC__) -# define int64_t ULONGLONG -#else -# define int64_t _int64 -# if defined(PTW32_CONFIG_MSVC6) - typedef long intptr_t; -# endif -#endif - -/* - * Don't allow the linker to optimize away autostatic.obj in static builds. - */ -#if defined(PTW32_STATIC_LIB) && defined(PTW32_BUILD) - void ptw32_autostatic_anchor(void); -# if defined(PTW32_CONFIG_MINGW) - __attribute__((unused, used)) -# endif - static void (*local_autostatic_anchor)(void) = ptw32_autostatic_anchor; -#endif - -typedef enum -{ - /* - * This enumeration represents the state of the thread; - * The thread is still "alive" if the numeric value of the - * state is greater or equal "PThreadStateRunning". - */ - PThreadStateInitial = 0, /* Thread not running */ - PThreadStateRunning, /* Thread alive & kicking */ - PThreadStateSuspended, /* Thread alive but suspended */ - PThreadStateCancelPending, /* Thread alive but */ - /* has cancellation pending. */ - PThreadStateCanceling, /* Thread alive but is */ - /* in the process of terminating */ - /* due to a cancellation request */ - PThreadStateExiting, /* Thread alive but exiting */ - /* due to an exception */ - PThreadStateLast, /* All handlers have been run and now */ - /* final cleanup can be done. */ - PThreadStateReuse /* In reuse pool. */ -} -PThreadState; - -typedef struct ptw32_mcs_node_t_ ptw32_mcs_local_node_t; -typedef struct ptw32_mcs_node_t_* ptw32_mcs_lock_t; -typedef struct ptw32_robust_node_t_ ptw32_robust_node_t; -typedef struct ptw32_thread_t_ ptw32_thread_t; - -struct ptw32_thread_t_ -{ - unsigned __int64 seqNumber; /* Process-unique thread sequence number */ - HANDLE threadH; /* Win32 thread handle - POSIX thread is invalid if threadH == 0 */ - pthread_t ptHandle; /* This thread's permanent pthread_t handle */ - ptw32_thread_t * prevReuse; /* Links threads on reuse stack; sentinel is PTW32_THREAD_REUSE_EMPTY */ - volatile PThreadState state; - ptw32_mcs_lock_t threadLock; /* Used for serialised access to public thread state */ - ptw32_mcs_lock_t stateLock; /* Used for async-cancel safety */ - HANDLE cancelEvent; - void *exitStatus; - void *parms; - void *keys; - void *nextAssoc; -#if defined(__CLEANUP_C) - jmp_buf start_mark; /* Jump buffer follows void* so should be aligned */ -#endif /* __CLEANUP_C */ -#if defined(HAVE_SIGSET_T) - sigset_t sigmask; -#endif /* HAVE_SIGSET_T */ - ptw32_mcs_lock_t - robustMxListLock; /* robustMxList lock */ - ptw32_robust_node_t* - robustMxList; /* List of currenty held robust mutexes */ - int ptErrno; - int detachState; - int sched_priority; /* As set, not as currently is */ - int cancelState; - int cancelType; - int implicit:1; - DWORD thread; /* Windows thread ID */ - size_t cpuset; /* Thread CPU affinity set */ -#if defined(_UWIN) - DWORD dummy[5]; -#endif - size_t align; /* Force alignment if this struct is packed */ -}; - - -/* - * Special value to mark attribute objects as valid. - */ -#define PTW32_ATTR_VALID ((unsigned long) 0xC4C0FFEE) - -struct pthread_attr_t_ -{ - unsigned long valid; - void *stackaddr; - size_t stacksize; - int detachstate; - struct sched_param param; - int inheritsched; - int contentionscope; -#if defined(HAVE_SIGSET_T) - sigset_t sigmask; -#endif /* HAVE_SIGSET_T */ -}; - - -/* - * ==================== - * ==================== - * Semaphores, Mutexes and Condition Variables - * ==================== - * ==================== - */ - -struct sem_t_ -{ - int value; - pthread_mutex_t lock; - HANDLE sem; -#if defined(NEED_SEM) - int leftToUnblock; -#endif -}; - -#define PTW32_OBJECT_AUTO_INIT ((void *)(size_t) -1) -#define PTW32_OBJECT_INVALID NULL - -struct pthread_mutex_t_ -{ - LONG lock_idx; /* Provides exclusive access to mutex state - via the Interlocked* mechanism. - 0: unlocked/free. - 1: locked - no other waiters. - -1: locked - with possible other waiters. - */ - int recursive_count; /* Number of unlocks a thread needs to perform - before the lock is released (recursive - mutexes only). */ - int kind; /* Mutex type. */ - pthread_t ownerThread; - HANDLE event; /* Mutex release notification to waiting - threads. */ - ptw32_robust_node_t* - robustNode; /* Extra state for robust mutexes */ -}; - -enum ptw32_robust_state_t_ -{ - PTW32_ROBUST_CONSISTENT, - PTW32_ROBUST_INCONSISTENT, - PTW32_ROBUST_NOTRECOVERABLE -}; - -typedef enum ptw32_robust_state_t_ ptw32_robust_state_t; - -/* - * Node used to manage per-thread lists of currently-held robust mutexes. - */ -struct ptw32_robust_node_t_ -{ - pthread_mutex_t mx; - ptw32_robust_state_t stateInconsistent; - ptw32_robust_node_t* prev; - ptw32_robust_node_t* next; -}; - -struct pthread_mutexattr_t_ -{ - int pshared; - int kind; - int robustness; -}; - -/* - * Possible values, other than PTW32_OBJECT_INVALID, - * for the "interlock" element in a spinlock. - * - * In this implementation, when a spinlock is initialised, - * the number of cpus available to the process is checked. - * If there is only one cpu then "interlock" is set equal to - * PTW32_SPIN_USE_MUTEX and u.mutex is an initialised mutex. - * If the number of cpus is greater than 1 then "interlock" - * is set equal to PTW32_SPIN_UNLOCKED and the number is - * stored in u.cpus. This arrangement allows the spinlock - * routines to attempt an InterlockedCompareExchange on "interlock" - * immediately and, if that fails, to try the inferior mutex. - * - * "u.cpus" isn't used for anything yet, but could be used at - * some point to optimise spinlock behaviour. - */ -#define PTW32_SPIN_INVALID (0) -#define PTW32_SPIN_UNLOCKED (1) -#define PTW32_SPIN_LOCKED (2) -#define PTW32_SPIN_USE_MUTEX (3) - -struct pthread_spinlock_t_ -{ - long interlock; /* Locking element for multi-cpus. */ - union - { - int cpus; /* No. of cpus if multi cpus, or */ - pthread_mutex_t mutex; /* mutex if single cpu. */ - } u; -}; - -/* - * MCS lock queue node - see ptw32_MCS_lock.c - */ -struct ptw32_mcs_node_t_ -{ - struct ptw32_mcs_node_t_ **lock; /* ptr to tail of queue */ - struct ptw32_mcs_node_t_ *next; /* ptr to successor in queue */ - HANDLE readyFlag; /* set after lock is released by - predecessor */ - HANDLE nextFlag; /* set after 'next' ptr is set by - successor */ -}; - - -struct pthread_barrier_t_ -{ - unsigned int nCurrentBarrierHeight; - unsigned int nInitialBarrierHeight; - int pshared; - sem_t semBarrierBreeched; - ptw32_mcs_lock_t lock; - ptw32_mcs_local_node_t proxynode; -}; - -struct pthread_barrierattr_t_ -{ - int pshared; -}; - -struct pthread_key_t_ -{ - DWORD key; - void (PTW32_CDECL *destructor) (void *); - ptw32_mcs_lock_t keyLock; - void *threads; -}; - - -typedef struct ThreadParms ThreadParms; - -struct ThreadParms -{ - pthread_t tid; - void *(PTW32_CDECL *start) (void *); - void *arg; -}; - - -struct pthread_cond_t_ -{ - long nWaitersBlocked; /* Number of threads blocked */ - long nWaitersGone; /* Number of threads timed out */ - long nWaitersToUnblock; /* Number of threads to unblock */ - sem_t semBlockQueue; /* Queue up threads waiting for the */ - /* condition to become signalled */ - sem_t semBlockLock; /* Semaphore that guards access to */ - /* | waiters blocked count/block queue */ - /* +-> Mandatory Sync.LEVEL-1 */ - pthread_mutex_t mtxUnblockLock; /* Mutex that guards access to */ - /* | waiters (to)unblock(ed) counts */ - /* +-> Optional* Sync.LEVEL-2 */ - pthread_cond_t next; /* Doubly linked list */ - pthread_cond_t prev; -}; - - -struct pthread_condattr_t_ -{ - int pshared; -}; - -#define PTW32_RWLOCK_MAGIC 0xfacade2 - -struct pthread_rwlock_t_ -{ - pthread_mutex_t mtxExclusiveAccess; - pthread_mutex_t mtxSharedAccessCompleted; - pthread_cond_t cndSharedAccessCompleted; - int nSharedAccessCount; - int nExclusiveAccessCount; - int nCompletedSharedAccessCount; - int nMagic; -}; - -struct pthread_rwlockattr_t_ -{ - int pshared; -}; - -typedef union -{ - char cpuset[CPU_SETSIZE/8]; - size_t _cpuset; -} _sched_cpu_set_vector_; - -typedef struct ThreadKeyAssoc ThreadKeyAssoc; - -struct ThreadKeyAssoc -{ - /* - * Purpose: - * This structure creates an association between a thread and a key. - * It is used to implement the implicit invocation of a user defined - * destroy routine for thread specific data registered by a user upon - * exiting a thread. - * - * Graphically, the arrangement is as follows, where: - * - * K - Key with destructor - * (head of chain is key->threads) - * T - Thread that has called pthread_setspecific(Kn) - * (head of chain is thread->keys) - * A - Association. Each association is a node at the - * intersection of two doubly-linked lists. - * - * T1 T2 T3 - * | | | - * | | | - * K1 -----+-----A-----A-----> - * | | | - * | | | - * K2 -----A-----A-----+-----> - * | | | - * | | | - * K3 -----A-----+-----A-----> - * | | | - * | | | - * V V V - * - * Access to the association is guarded by two locks: the key's - * general lock (guarding the row) and the thread's general - * lock (guarding the column). This avoids the need for a - * dedicated lock for each association, which not only consumes - * more handles but requires that the lock resources persist - * until both the key is deleted and the thread has called the - * destructor. The two-lock arrangement allows those resources - * to be freed as soon as either thread or key is concluded. - * - * To avoid deadlock, whenever both locks are required both the - * key and thread locks are acquired consistently in the order - * "key lock then thread lock". An exception to this exists - * when a thread calls the destructors, however, this is done - * carefully (but inelegantly) to avoid deadlock. - * - * An association is created when a thread first calls - * pthread_setspecific() on a key that has a specified - * destructor. - * - * An association is destroyed either immediately after the - * thread calls the key destructor function on thread exit, or - * when the key is deleted. - * - * Attributes: - * thread - * reference to the thread that owns the - * association. This is actually the pointer to the - * thread struct itself. Since the association is - * destroyed before the thread exits, this can never - * point to a different logical thread to the one that - * created the assoc, i.e. after thread struct reuse. - * - * key - * reference to the key that owns the association. - * - * nextKey - * The pthread_t->keys attribute is the head of a - * chain of associations that runs through the nextKey - * link. This chain provides the 1 to many relationship - * between a pthread_t and all pthread_key_t on which - * it called pthread_setspecific. - * - * prevKey - * Similarly. - * - * nextThread - * The pthread_key_t->threads attribute is the head of - * a chain of associations that runs through the - * nextThreads link. This chain provides the 1 to many - * relationship between a pthread_key_t and all the - * PThreads that have called pthread_setspecific for - * this pthread_key_t. - * - * prevThread - * Similarly. - * - * Notes: - * 1) As soon as either the key or the thread is no longer - * referencing the association, it can be destroyed. The - * association will be removed from both chains. - * - * 2) Under WIN32, an association is only created by - * pthread_setspecific if the user provided a - * destroyRoutine when they created the key. - * - * - */ - ptw32_thread_t * thread; - pthread_key_t key; - ThreadKeyAssoc *nextKey; - ThreadKeyAssoc *nextThread; - ThreadKeyAssoc *prevKey; - ThreadKeyAssoc *prevThread; -}; - - -#if defined(__CLEANUP_SEH) -/* - * -------------------------------------------------------------- - * MAKE_SOFTWARE_EXCEPTION - * This macro constructs a software exception code following - * the same format as the standard Win32 error codes as defined - * in WINERROR.H - * Values are 32 bit values laid out as follows: - * - * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 - * +---+-+-+-----------------------+-------------------------------+ - * |Sev|C|R| Facility | Code | - * +---+-+-+-----------------------+-------------------------------+ - * - * Severity Values: - */ -#define SE_SUCCESS 0x00 -#define SE_INFORMATION 0x01 -#define SE_WARNING 0x02 -#define SE_ERROR 0x03 - -#define MAKE_SOFTWARE_EXCEPTION( _severity, _facility, _exception ) \ -( (DWORD) ( ( (_severity) << 30 ) | /* Severity code */ \ - ( 1 << 29 ) | /* MS=0, User=1 */ \ - ( 0 << 28 ) | /* Reserved */ \ - ( (_facility) << 16 ) | /* Facility Code */ \ - ( (_exception) << 0 ) /* Exception Code */ \ - ) ) - -/* - * We choose one specific Facility/Error code combination to - * identify our software exceptions vs. WIN32 exceptions. - * We store our actual component and error code within - * the optional information array. - */ -#define EXCEPTION_PTW32_SERVICES \ - MAKE_SOFTWARE_EXCEPTION( SE_ERROR, \ - PTW32_SERVICES_FACILITY, \ - PTW32_SERVICES_ERROR ) - -#define PTW32_SERVICES_FACILITY 0xBAD -#define PTW32_SERVICES_ERROR 0xDEED - -#endif /* __CLEANUP_SEH */ - -/* - * Services available through EXCEPTION_PTW32_SERVICES - * and also used [as parameters to ptw32_throw()] as - * generic exception selectors. - */ - -#define PTW32_EPS_EXIT (1) -#define PTW32_EPS_CANCEL (2) - - -/* Useful macros */ -#define PTW32_MAX(a,b) ((a)<(b)?(b):(a)) -#define PTW32_MIN(a,b) ((a)>(b)?(b):(a)) - - -/* Declared in pthread_cancel.c */ -extern DWORD (*ptw32_register_cancellation) (PAPCFUNC, HANDLE, DWORD); - -/* Thread Reuse stack bottom marker. Must not be NULL or any valid pointer to memory. */ -#define PTW32_THREAD_REUSE_EMPTY ((ptw32_thread_t *)(size_t) 1) - -extern int ptw32_processInitialized; -extern ptw32_thread_t * ptw32_threadReuseTop; -extern ptw32_thread_t * ptw32_threadReuseBottom; -extern pthread_key_t ptw32_selfThreadKey; -extern pthread_key_t ptw32_cleanupKey; -extern pthread_cond_t ptw32_cond_list_head; -extern pthread_cond_t ptw32_cond_list_tail; - -extern int ptw32_mutex_default_kind; - -extern unsigned __int64 ptw32_threadSeqNumber; - -extern int ptw32_concurrency; - -extern int ptw32_features; - -extern ptw32_mcs_lock_t ptw32_thread_reuse_lock; -extern ptw32_mcs_lock_t ptw32_mutex_test_init_lock; -extern ptw32_mcs_lock_t ptw32_cond_list_lock; -extern ptw32_mcs_lock_t ptw32_cond_test_init_lock; -extern ptw32_mcs_lock_t ptw32_rwlock_test_init_lock; -extern ptw32_mcs_lock_t ptw32_spinlock_test_init_lock; - -#if defined(_UWIN) -extern int pthread_count; -#endif - -#if defined(__cplusplus) -extern "C" -{ -#endif /* __cplusplus */ - -/* - * ===================== - * ===================== - * Forward Declarations - * ===================== - * ===================== - */ - - int ptw32_is_attr (const pthread_attr_t * attr); - - int ptw32_cond_check_need_init (pthread_cond_t * cond); - int ptw32_mutex_check_need_init (pthread_mutex_t * mutex); - int ptw32_rwlock_check_need_init (pthread_rwlock_t * rwlock); - int ptw32_spinlock_check_need_init (pthread_spinlock_t * lock); - - int ptw32_robust_mutex_inherit(pthread_mutex_t * mutex); - void ptw32_robust_mutex_add(pthread_mutex_t* mutex, pthread_t self); - void ptw32_robust_mutex_remove(pthread_mutex_t* mutex, ptw32_thread_t* otp); - - DWORD - ptw32_RegisterCancellation (PAPCFUNC callback, - HANDLE threadH, DWORD callback_arg); - - int ptw32_processInitialize (void); - - void ptw32_processTerminate (void); - - void ptw32_threadDestroy (pthread_t tid); - - void ptw32_pop_cleanup_all (int execute); - - pthread_t ptw32_new (void); - - pthread_t ptw32_threadReusePop (void); - - void ptw32_threadReusePush (pthread_t thread); - - int ptw32_getprocessors (int *count); - - int ptw32_setthreadpriority (pthread_t thread, int policy, int priority); - - void PTW32_CDECL ptw32_rwlock_cancelwrwait (void *arg); /* matches type ptw32_cleanup_callback_t this way */ - -#if ! defined (PTW32_CONFIG_MINGW) || (defined (__MSVCRT__) && ! defined (__DMC__)) - unsigned __stdcall -#else - void -#endif - ptw32_threadStart (void *vthreadParms); - - void ptw32_callUserDestroyRoutines (pthread_t thread); - - int ptw32_tkAssocCreate (ptw32_thread_t * thread, pthread_key_t key); - - void ptw32_tkAssocDestroy (ThreadKeyAssoc * assoc); - - int ptw32_semwait (sem_t * sem); - - DWORD ptw32_relmillisecs (const struct timespec * abstime); - - void ptw32_mcs_lock_acquire (ptw32_mcs_lock_t * lock, ptw32_mcs_local_node_t * node); - - int ptw32_mcs_lock_try_acquire (ptw32_mcs_lock_t * lock, ptw32_mcs_local_node_t * node); - - void ptw32_mcs_lock_release (ptw32_mcs_local_node_t * node); - - void ptw32_mcs_node_transfer (ptw32_mcs_local_node_t * new_node, ptw32_mcs_local_node_t * old_node); - -#if defined(NEED_FTIME) - void ptw32_timespec_to_filetime (const struct timespec *ts, FILETIME * ft); - void ptw32_filetime_to_timespec (const FILETIME * ft, struct timespec *ts); -#endif - -/* Declared in misc.c */ -#if defined(NEED_CALLOC) -#define calloc(n, s) ptw32_calloc(n, s) - void *ptw32_calloc (size_t n, size_t s); -#endif - -/* Declared in private.c */ -#if defined(_MSC_VER) -/* - * Ignore the warning: - * "C++ exception specification ignored except to indicate that - * the function is not __declspec(nothrow)." - */ -#pragma warning(disable:4290) -#endif - void ptw32_throw (DWORD exception) -#if defined(__CLEANUP_CXX) - throw(ptw32_exception_cancel,ptw32_exception_exit) -#endif -; - -#if defined(__cplusplus) -} -#endif /* __cplusplus */ - - -#if defined(_UWIN_) -# if defined(_MT) -# if defined(__cplusplus) -extern "C" -{ -# endif - _CRTIMP unsigned long __cdecl _beginthread (void (__cdecl *) (void *), - unsigned, void *); - _CRTIMP void __cdecl _endthread (void); - _CRTIMP unsigned long __cdecl _beginthreadex (void *, unsigned, - unsigned (__stdcall *) (void *), - void *, unsigned, unsigned *); - _CRTIMP void __cdecl _endthreadex (unsigned); -# if defined(__cplusplus) -} -# endif -# endif -#else -# include -# endif - - -/* - * Use intrinsic versions wherever possible. VC will do this - * automatically where possible and GCC define these if available: - * __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 - * __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 - * __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 - * __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 - * __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 - * - * The full set of Interlocked intrinsics in GCC are (check versions): - * type __sync_fetch_and_add (type *ptr, type value, ...) - * type __sync_fetch_and_sub (type *ptr, type value, ...) - * type __sync_fetch_and_or (type *ptr, type value, ...) - * type __sync_fetch_and_and (type *ptr, type value, ...) - * type __sync_fetch_and_xor (type *ptr, type value, ...) - * type __sync_fetch_and_nand (type *ptr, type value, ...) - * type __sync_add_and_fetch (type *ptr, type value, ...) - * type __sync_sub_and_fetch (type *ptr, type value, ...) - * type __sync_or_and_fetch (type *ptr, type value, ...) - * type __sync_and_and_fetch (type *ptr, type value, ...) - * type __sync_xor_and_fetch (type *ptr, type value, ...) - * type __sync_nand_and_fetch (type *ptr, type value, ...) - * bool __sync_bool_compare_and_swap (type *ptr, type oldval type newval, ...) - * type __sync_val_compare_and_swap (type *ptr, type oldval type newval, ...) - * __sync_synchronize (...) // Full memory barrier - * type __sync_lock_test_and_set (type *ptr, type value, ...) // Acquire barrier - * void __sync_lock_release (type *ptr, ...) // Release barrier - * - * These are all overloaded and take 1,2,4,8 byte scalar or pointer types. - * - * The above aren't available in Mingw32 as of gcc 4.5.2 so define our own. - */ -#if defined(__cplusplus) -# define PTW32_TO_VLONG64PTR(ptr) reinterpret_cast(ptr) -#else -# define PTW32_TO_VLONG64PTR(ptr) (ptr) -#endif - -#if defined(__GNUC__) -# if defined(_WIN64) -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_64(location, value, comparand) \ - ({ \ - __typeof (value) _result; \ - __asm__ __volatile__ \ - ( \ - "lock\n\t" \ - "cmpxchgq %2,(%1)" \ - :"=a" (_result) \ - :"r" (location), "r" (value), "a" (comparand) \ - :"memory", "cc"); \ - _result; \ - }) -# define PTW32_INTERLOCKED_EXCHANGE_64(location, value) \ - ({ \ - __typeof (value) _result; \ - __asm__ __volatile__ \ - ( \ - "xchgq %0,(%1)" \ - :"=r" (_result) \ - :"r" (location), "0" (value) \ - :"memory", "cc"); \ - _result; \ - }) -# define PTW32_INTERLOCKED_EXCHANGE_ADD_64(location, value) \ - ({ \ - __typeof (value) _result; \ - __asm__ __volatile__ \ - ( \ - "lock\n\t" \ - "xaddq %0,(%1)" \ - :"=r" (_result) \ - :"r" (location), "0" (value) \ - :"memory", "cc"); \ - _result; \ - }) -# define PTW32_INTERLOCKED_INCREMENT_64(location) \ - ({ \ - PTW32_INTERLOCKED_LONG _temp = 1; \ - __asm__ __volatile__ \ - ( \ - "lock\n\t" \ - "xaddq %0,(%1)" \ - :"+r" (_temp) \ - :"r" (location) \ - :"memory", "cc"); \ - ++_temp; \ - }) -# define PTW32_INTERLOCKED_DECREMENT_64(location) \ - ({ \ - PTW32_INTERLOCKED_LONG _temp = -1; \ - __asm__ __volatile__ \ - ( \ - "lock\n\t" \ - "xaddq %2,(%1)" \ - :"+r" (_temp) \ - :"r" (location) \ - :"memory", "cc"); \ - --_temp; \ - }) -#endif -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG(location, value, comparand) \ - ({ \ - __typeof (value) _result; \ - __asm__ __volatile__ \ - ( \ - "lock\n\t" \ - "cmpxchgl %2,(%1)" \ - :"=a" (_result) \ - :"r" (location), "r" (value), "a" (comparand) \ - :"memory", "cc"); \ - _result; \ - }) -# define PTW32_INTERLOCKED_EXCHANGE_LONG(location, value) \ - ({ \ - __typeof (value) _result; \ - __asm__ __volatile__ \ - ( \ - "xchgl %0,(%1)" \ - :"=r" (_result) \ - :"r" (location), "0" (value) \ - :"memory", "cc"); \ - _result; \ - }) -# define PTW32_INTERLOCKED_EXCHANGE_ADD_LONG(location, value) \ - ({ \ - __typeof (value) _result; \ - __asm__ __volatile__ \ - ( \ - "lock\n\t" \ - "xaddl %0,(%1)" \ - :"=r" (_result) \ - :"r" (location), "0" (value) \ - :"memory", "cc"); \ - _result; \ - }) -# define PTW32_INTERLOCKED_INCREMENT_LONG(location) \ - ({ \ - PTW32_INTERLOCKED_LONG _temp = 1; \ - __asm__ __volatile__ \ - ( \ - "lock\n\t" \ - "xaddl %0,(%1)" \ - :"+r" (_temp) \ - :"r" (location) \ - :"memory", "cc"); \ - ++_temp; \ - }) -# define PTW32_INTERLOCKED_DECREMENT_LONG(location) \ - ({ \ - PTW32_INTERLOCKED_LONG _temp = -1; \ - __asm__ __volatile__ \ - ( \ - "lock\n\t" \ - "xaddl %0,(%1)" \ - :"+r" (_temp) \ - :"r" (location) \ - :"memory", "cc"); \ - --_temp; \ - }) -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR(location, value, comparand) \ - PTW32_INTERLOCKED_COMPARE_EXCHANGE_SIZE((PTW32_INTERLOCKED_SIZEPTR)location, \ - (PTW32_INTERLOCKED_SIZE)value, \ - (PTW32_INTERLOCKED_SIZE)comparand) -# define PTW32_INTERLOCKED_EXCHANGE_PTR(location, value) \ - PTW32_INTERLOCKED_EXCHANGE_SIZE((PTW32_INTERLOCKED_SIZEPTR)location, \ - (PTW32_INTERLOCKED_SIZE)value) -#else -# if defined(_WIN64) -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_64(p,v,c) InterlockedCompareExchange64(PTW32_TO_VLONG64PTR(p),(v),(c)) -# define PTW32_INTERLOCKED_EXCHANGE_64(p,v) InterlockedExchange64(PTW32_TO_VLONG64PTR(p),(v)) -# define PTW32_INTERLOCKED_EXCHANGE_ADD_64(p,v) InterlockedExchangeAdd64(PTW32_TO_VLONG64PTR(p),(v)) -# define PTW32_INTERLOCKED_INCREMENT_64(p) InterlockedIncrement64(PTW32_TO_VLONG64PTR(p)) -# define PTW32_INTERLOCKED_DECREMENT_64(p) InterlockedDecrement64(PTW32_TO_VLONG64PTR(p)) -# endif -# if defined(PTW32_CONFIG_MSVC6) && !defined(_WIN64) -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG(location, value, comparand) \ - ((LONG)InterlockedCompareExchange((PVOID *)(location), (PVOID)(value), (PVOID)(comparand))) -# else -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG InterlockedCompareExchange -# endif -# define PTW32_INTERLOCKED_EXCHANGE_LONG(p,v) InterlockedExchange((p),(v)) -# define PTW32_INTERLOCKED_EXCHANGE_ADD_LONG(p,v) InterlockedExchangeAdd((p),(v)) -# define PTW32_INTERLOCKED_INCREMENT_LONG(p) InterlockedIncrement((p)) -# define PTW32_INTERLOCKED_DECREMENT_LONG(p) InterlockedDecrement((p)) -# if defined(PTW32_CONFIG_MSVC6) && !defined(_WIN64) -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR InterlockedCompareExchange -# define PTW32_INTERLOCKED_EXCHANGE_PTR(location, value) \ - ((PVOID)InterlockedExchange((LPLONG)(location), (LONG)(value))) -# else -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR(p,v,c) InterlockedCompareExchangePointer((p),(v),(c)) -# define PTW32_INTERLOCKED_EXCHANGE_PTR(p,v) InterlockedExchangePointer((p),(v)) -# endif -#endif -#if defined(_WIN64) -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_SIZE(p,v,c) PTW32_INTERLOCKED_COMPARE_EXCHANGE_64(PTW32_TO_VLONG64PTR(p),(v),(c)) -# define PTW32_INTERLOCKED_EXCHANGE_SIZE(p,v) PTW32_INTERLOCKED_EXCHANGE_64(PTW32_TO_VLONG64PTR(p),(v)) -# define PTW32_INTERLOCKED_EXCHANGE_ADD_SIZE(p,v) PTW32_INTERLOCKED_EXCHANGE_ADD_64(PTW32_TO_VLONG64PTR(p),(v)) -# define PTW32_INTERLOCKED_INCREMENT_SIZE(p) PTW32_INTERLOCKED_INCREMENT_64(PTW32_TO_VLONG64PTR(p)) -# define PTW32_INTERLOCKED_DECREMENT_SIZE(p) PTW32_INTERLOCKED_DECREMENT_64(PTW32_TO_VLONG64PTR(p)) -#else -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_SIZE(p,v,c) PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG((p),(v),(c)) -# define PTW32_INTERLOCKED_EXCHANGE_SIZE(p,v) PTW32_INTERLOCKED_EXCHANGE_LONG((p),(v)) -# define PTW32_INTERLOCKED_EXCHANGE_ADD_SIZE(p,v) PTW32_INTERLOCKED_EXCHANGE_ADD_LONG((p),(v)) -# define PTW32_INTERLOCKED_INCREMENT_SIZE(p) PTW32_INTERLOCKED_INCREMENT_LONG((p)) -# define PTW32_INTERLOCKED_DECREMENT_SIZE(p) PTW32_INTERLOCKED_DECREMENT_LONG((p)) -#endif - -#if defined(NEED_CREATETHREAD) - -/* - * Macro uses args so we can cast start_proc to LPTHREAD_START_ROUTINE - * in order to avoid warnings because of return type - */ - -#define _beginthreadex(security, \ - stack_size, \ - start_proc, \ - arg, \ - flags, \ - pid) \ - CreateThread(security, \ - stack_size, \ - (LPTHREAD_START_ROUTINE) start_proc, \ - arg, \ - flags, \ - pid) - -#define _endthreadex ExitThread - -#endif /* NEED_CREATETHREAD */ - - -#endif /* _IMPLEMENT_H */ diff --git a/dependencies/win32_pthread/include/need_errno.h b/dependencies/win32_pthread/include/need_errno.h deleted file mode 100644 index abf1c955..00000000 --- a/dependencies/win32_pthread/include/need_errno.h +++ /dev/null @@ -1,145 +0,0 @@ -/*** -* errno.h - system wide error numbers (set by system calls) -* -* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. -* -* Purpose: -* This file defines the system-wide error numbers (set by -* system calls). Conforms to the XENIX standard. Extended -* for compatibility with Uniforum standard. -* [System V] -* -* [Public] -* -****/ - -#if _MSC_VER > 1000 -#pragma once -#endif - -#if !defined(_INC_ERRNO) -#define _INC_ERRNO - -#if !defined(_WIN32) -#error ERROR: Only Win32 targets supported! -#endif - -#include - -#if defined(__cplusplus) -extern "C" { -#endif - - - -/* Define _CRTIMP */ - -#ifndef _CRTIMP -#if defined(_DLL) -#define _CRTIMP __declspec(dllimport) -#else /* ndef _DLL */ -#define _CRTIMP -#endif /* _DLL */ -#endif /* _CRTIMP */ - - -/* Define __cdecl for non-Microsoft compilers */ - -#if ( !defined(_MSC_VER) && !defined(__cdecl) ) -#define __cdecl -#endif - -/* Define _CRTAPI1 (for compatibility with the NT SDK) */ - -#if !defined(_CRTAPI1) -#if _MSC_VER >= 800 && _M_IX86 >= 300 -#define _CRTAPI1 __cdecl -#else -#define _CRTAPI1 -#endif -#endif - -#if !defined(PTW32_STATIC_LIB) -# if defined(PTW32_BUILD) -# define PTW32_DLLPORT __declspec (dllexport) -# else -# define PTW32_DLLPORT __declspec (dllimport) -# endif -#else -# define PTW32_DLLPORT -#endif - -/* declare reference to errno */ - -#if (defined(_MT) || defined(_MD) || defined(_DLL)) && !defined(_MAC) -PTW32_DLLPORT int * __cdecl _errno(void); -#define errno (*_errno()) -#else /* ndef _MT && ndef _MD && ndef _DLL */ -_CRTIMP extern int errno; -#endif /* _MT || _MD || _DLL */ - -/* Error Codes */ - -#define EPERM 1 -#define ENOENT 2 -#define ESRCH 3 -#define EINTR 4 -#define EIO 5 -#define ENXIO 6 -#define E2BIG 7 -#define ENOEXEC 8 -#define EBADF 9 -#define ECHILD 10 -#define EAGAIN 11 -#define ENOMEM 12 -#define EACCES 13 -#define EFAULT 14 -#define EBUSY 16 -#define EEXIST 17 -#define EXDEV 18 -#define ENODEV 19 -#define ENOTDIR 20 -#define EISDIR 21 -#define EINVAL 22 -#define ENFILE 23 -#define EMFILE 24 -#define ENOTTY 25 -#define EFBIG 27 -#define ENOSPC 28 -#define ESPIPE 29 -#define EROFS 30 -#define EMLINK 31 -#define EPIPE 32 -#define EDOM 33 -#define ERANGE 34 -#define EDEADLK 36 - -/* defined differently in winsock.h on WinCE */ -#if !defined(ENAMETOOLONG) -#define ENAMETOOLONG 38 -#endif - -#define ENOLCK 39 -#define ENOSYS 40 - -/* defined differently in winsock.h on WinCE */ -#if !defined(ENOTEMPTY) -#define ENOTEMPTY 41 -#endif - -#define EILSEQ 42 - -/* POSIX 2008 - robust mutexes */ -#define EOWNERDEAD 43 -#define ENOTRECOVERABLE 44 - -/* - * Support EDEADLOCK for compatibiity with older MS-C versions. - */ -#define EDEADLOCK EDEADLK - -#if defined(__cplusplus) -} -#endif - -#endif /* _INC_ERRNO */ diff --git a/dependencies/win32_pthread/include/pthread.h b/dependencies/win32_pthread/include/pthread.h deleted file mode 100644 index 9b2b74c1..00000000 --- a/dependencies/win32_pthread/include/pthread.h +++ /dev/null @@ -1,1416 +0,0 @@ -/* This is an implementation of the threads API of POSIX 1003.1-2001. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#if !defined( PTHREAD_H ) -#define PTHREAD_H - -/* - * See the README file for an explanation of the pthreads-win32 version - * numbering scheme and how the DLL is named etc. - */ -#define PTW32_VERSION 2,10,0,0 -#define PTW32_VERSION_STRING "2, 10, 0, 0\0" - -/* There are three implementations of cancel cleanup. - * Note that pthread.h is included in both application - * compilation units and also internally for the library. - * The code here and within the library aims to work - * for all reasonable combinations of environments. - * - * The three implementations are: - * - * WIN32 SEH - * C - * C++ - * - * Please note that exiting a push/pop block via - * "return", "exit", "break", or "continue" will - * lead to different behaviour amongst applications - * depending upon whether the library was built - * using SEH, C++, or C. For example, a library built - * with SEH will call the cleanup routine, while both - * C++ and C built versions will not. - */ - -/* - * Define defaults for cleanup code. - * Note: Unless the build explicitly defines one of the following, then - * we default to standard C style cleanup. This style uses setjmp/longjmp - * in the cancellation and thread exit implementations and therefore won't - * do stack unwinding if linked to applications that have it (e.g. - * C++ apps). This is currently consistent with most/all commercial Unix - * POSIX threads implementations. - */ -#if !defined( __CLEANUP_SEH ) && !defined( __CLEANUP_CXX ) && !defined( __CLEANUP_C ) -/* - [i_a] fix for apps using pthreads-Win32: when they do not define __CLEANUP_SEH themselves, - they're screwed as they'll receive the '__CLEANUP_C' macros which do NOT work when - the pthreads library code itself has actually been build with __CLEANUP_SEH, - which is the case when building this stuff in MSVC. - - Hence this section is made to 'sensibly autodetect' the cleanup mode, when it hasn't - been hardwired in the makefiles / project files. - - After all, who expects he MUST define one of these __CLEANUP_XXX defines in his own - code when using pthreads-Win32, for whatever reason. - */ -#if (defined(_MSC_VER) || defined(PTW32_RC_MSC)) -#define __CLEANUP_SEH -#elif defined(__cplusplus) -#define __CLEANUP_CXX -#else -#define __CLEANUP_C -#endif -#endif - -#if defined( __CLEANUP_SEH ) && ( !defined( _MSC_VER ) && !defined(PTW32_RC_MSC)) -#error ERROR [__FILE__, line __LINE__]: SEH is not supported for this compiler. -#endif - -/* - * Stop here if we are being included by the resource compiler. - */ -#if !defined(RC_INVOKED) - -#undef PTW32_LEVEL - -#if defined(_POSIX_SOURCE) -#define PTW32_LEVEL 0 /* Early POSIX */ -#endif - -#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309 -#undef PTW32_LEVEL -#define PTW32_LEVEL 1 /* Include 1b, 1c and 1d */ -#endif - -#if defined(INCLUDE_NP) -#undef PTW32_LEVEL -#define PTW32_LEVEL 2 /* Include Non-Portable extensions */ -#endif - -#define PTW32_LEVEL_MAX 3 - -#if ( defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112 ) || !defined(PTW32_LEVEL) -#define PTW32_LEVEL PTW32_LEVEL_MAX /* Include everything */ -#endif - -#if defined(__MINGW32__) || defined(__MINGW64__) -# define PTW32_CONFIG_MINGW -#endif -#if defined(_MSC_VER) -# if _MSC_VER < 1300 -# define PTW32_CONFIG_MSVC6 -# endif -# if _MSC_VER < 1400 -# define PTW32_CONFIG_MSVC7 -# endif -#endif - -/* - * ------------------------------------------------------------- - * - * - * Module: pthread.h - * - * Purpose: - * Provides an implementation of PThreads based upon the - * standard: - * - * POSIX 1003.1-2001 - * and - * The Single Unix Specification version 3 - * - * (these two are equivalent) - * - * in order to enhance code portability between Windows, - * various commercial Unix implementations, and Linux. - * - * See the ANNOUNCE file for a full list of conforming - * routines and defined constants, and a list of missing - * routines and constants not defined in this implementation. - * - * Authors: - * There have been many contributors to this library. - * The initial implementation was contributed by - * John Bossom, and several others have provided major - * sections or revisions of parts of the implementation. - * Often significant effort has been contributed to - * find and fix important bugs and other problems to - * improve the reliability of the library, which sometimes - * is not reflected in the amount of code which changed as - * result. - * As much as possible, the contributors are acknowledged - * in the ChangeLog file in the source code distribution - * where their changes are noted in detail. - * - * Contributors are listed in the CONTRIBUTORS file. - * - * As usual, all bouquets go to the contributors, and all - * brickbats go to the project maintainer. - * - * Maintainer: - * The code base for this project is coordinated and - * eventually pre-tested, packaged, and made available by - * - * Ross Johnson - * - * QA Testers: - * Ultimately, the library is tested in the real world by - * a host of competent and demanding scientists and - * engineers who report bugs and/or provide solutions - * which are then fixed or incorporated into subsequent - * versions of the library. Each time a bug is fixed, a - * test case is written to prove the fix and ensure - * that later changes to the code don't reintroduce the - * same error. The number of test cases is slowly growing - * and therefore so is the code reliability. - * - * Compliance: - * See the file ANNOUNCE for the list of implemented - * and not-implemented routines and defined options. - * Of course, these are all defined is this file as well. - * - * Web site: - * The source code and other information about this library - * are available from - * - * http://sources.redhat.com/pthreads-win32/ - * - * ------------------------------------------------------------- - */ - -/* Try to avoid including windows.h */ -#if defined(PTW32_CONFIG_MINGW) && defined(__cplusplus) -#define PTW32_INCLUDE_WINDOWS_H -#endif - -#if defined(PTW32_INCLUDE_WINDOWS_H) -#include -#endif - -/* - * Boolean values to make us independent of system includes. - */ -enum { - PTW32_FALSE = 0, - PTW32_TRUE = (! PTW32_FALSE) -}; - -/* - * This is a duplicate of what is in the autoconf config.h, - * which is only used when building the pthread-win32 libraries. - */ - -#if !defined(PTW32_CONFIG_H) -# if defined(WINCE) -# define NEED_ERRNO -# define NEED_SEM -# elif defined(_UWIN) -# define HAVE_MODE_T -# define HAVE_STRUCT_TIMESPEC -# define HAVE_SIGNAL_H -# elif defined(__MINGW64__) -# define HAVE_STRUCT_TIMESPEC -# define HAVE_MODE_T -# elif defined(__MINGW32__) -# define HAVE_MODE_T -# endif -#endif - -#if !defined(NEED_FTIME) -#include -#else /* NEED_FTIME */ -/* use native WIN32 time API */ -#endif /* NEED_FTIME */ - -#if defined(HAVE_SIGNAL_H) -#include -#endif - -#include - -#if PTW32_LEVEL >= PTW32_LEVEL_MAX -#if defined(NEED_ERRNO) -#include "need_errno.h" -#else -#include -#endif -#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ - -#include - -/* - * Several systems don't define some error numbers. - */ -#if !defined(ENOTSUP) -# define ENOTSUP 48 /* This is the value in Solaris. */ -#endif - -#if !defined(ETIMEDOUT) -# define ETIMEDOUT 10060 /* Same as WSAETIMEDOUT */ -#endif - -#if !defined(ENOSYS) -# define ENOSYS 140 /* Semi-arbitrary value */ -#endif - -#if !defined(EDEADLK) -# if defined(EDEADLOCK) -# define EDEADLK EDEADLOCK -# else -# define EDEADLK 36 /* This is the value in MSVC. */ -# endif -#endif - -/* POSIX 2008 - related to robust mutexes */ -#if !defined(EOWNERDEAD) -# define EOWNERDEAD 43 -#endif -#if !defined(ENOTRECOVERABLE) -# define ENOTRECOVERABLE 44 -#endif - -/* - * To avoid including windows.h we define only those things that we - * actually need from it. - */ -#if !defined(PTW32_INCLUDE_WINDOWS_H) -#if !defined(HANDLE) -# define PTW32__HANDLE_DEF -# define HANDLE void * -#endif -#if !defined(DWORD) -# define PTW32__DWORD_DEF -# define DWORD unsigned long -#endif -#endif - -#if defined(_MSC_VER) && _MSC_VER >= 1900 -#define HAVE_STRUCT_TIMESPEC -#define _TIMESPEC_DEFINED -#endif - -#if !defined(HAVE_STRUCT_TIMESPEC) -#define HAVE_STRUCT_TIMESPEC -#if !defined(_TIMESPEC_DEFINED) -#define _TIMESPEC_DEFINED -struct timespec { - time_t tv_sec; - long tv_nsec; -}; -#endif /* _TIMESPEC_DEFINED */ -#endif /* HAVE_STRUCT_TIMESPEC */ - -#if !defined(SIG_BLOCK) -#define SIG_BLOCK 0 -#endif /* SIG_BLOCK */ - -#if !defined(SIG_UNBLOCK) -#define SIG_UNBLOCK 1 -#endif /* SIG_UNBLOCK */ - -#if !defined(SIG_SETMASK) -#define SIG_SETMASK 2 -#endif /* SIG_SETMASK */ - -#if defined(__cplusplus) -extern "C" -{ -#endif /* __cplusplus */ - -/* - * ------------------------------------------------------------- - * - * POSIX 1003.1-2001 Options - * ========================= - * - * Options are normally set in , which is not provided - * with pthreads-win32. - * - * For conformance with the Single Unix Specification (version 3), all of the - * options below are defined, and have a value of either -1 (not supported) - * or 200112L (supported). - * - * These options can neither be left undefined nor have a value of 0, because - * either indicates that sysconf(), which is not implemented, may be used at - * runtime to check the status of the option. - * - * _POSIX_THREADS (== 20080912L) - * If == 20080912L, you can use threads - * - * _POSIX_THREAD_ATTR_STACKSIZE (== 200809L) - * If == 200809L, you can control the size of a thread's - * stack - * pthread_attr_getstacksize - * pthread_attr_setstacksize - * - * _POSIX_THREAD_ATTR_STACKADDR (== -1) - * If == 200809L, you can allocate and control a thread's - * stack. If not supported, the following functions - * will return ENOSYS, indicating they are not - * supported: - * pthread_attr_getstackaddr - * pthread_attr_setstackaddr - * - * _POSIX_THREAD_PRIORITY_SCHEDULING (== -1) - * If == 200112L, you can use realtime scheduling. - * This option indicates that the behaviour of some - * implemented functions conforms to the additional TPS - * requirements in the standard. E.g. rwlocks favour - * writers over readers when threads have equal priority. - * - * _POSIX_THREAD_PRIO_INHERIT (== -1) - * If == 200809L, you can create priority inheritance - * mutexes. - * pthread_mutexattr_getprotocol + - * pthread_mutexattr_setprotocol + - * - * _POSIX_THREAD_PRIO_PROTECT (== -1) - * If == 200809L, you can create priority ceiling mutexes - * Indicates the availability of: - * pthread_mutex_getprioceiling - * pthread_mutex_setprioceiling - * pthread_mutexattr_getprioceiling - * pthread_mutexattr_getprotocol + - * pthread_mutexattr_setprioceiling - * pthread_mutexattr_setprotocol + - * - * _POSIX_THREAD_PROCESS_SHARED (== -1) - * If set, you can create mutexes and condition - * variables that can be shared with another - * process.If set, indicates the availability - * of: - * pthread_mutexattr_getpshared - * pthread_mutexattr_setpshared - * pthread_condattr_getpshared - * pthread_condattr_setpshared - * - * _POSIX_THREAD_SAFE_FUNCTIONS (== 200809L) - * If == 200809L you can use the special *_r library - * functions that provide thread-safe behaviour - * - * _POSIX_READER_WRITER_LOCKS (== 200809L) - * If == 200809L, you can use read/write locks - * - * _POSIX_SPIN_LOCKS (== 200809L) - * If == 200809L, you can use spin locks - * - * _POSIX_BARRIERS (== 200809L) - * If == 200809L, you can use barriers - * - * _POSIX_ROBUST_MUTEXES (== 200809L) - * If == 200809L, you can use robust mutexes - * Officially this should also imply - * _POSIX_THREAD_PROCESS_SHARED != -1 however - * not here yet. - * - * ------------------------------------------------------------- - */ - -/* - * POSIX Options - */ -#undef _POSIX_THREADS -#define _POSIX_THREADS 200809L - -#undef _POSIX_READER_WRITER_LOCKS -#define _POSIX_READER_WRITER_LOCKS 200809L - -#undef _POSIX_SPIN_LOCKS -#define _POSIX_SPIN_LOCKS 200809L - -#undef _POSIX_BARRIERS -#define _POSIX_BARRIERS 200809L - -#undef _POSIX_THREAD_SAFE_FUNCTIONS -#define _POSIX_THREAD_SAFE_FUNCTIONS 200809L - -#undef _POSIX_THREAD_ATTR_STACKSIZE -#define _POSIX_THREAD_ATTR_STACKSIZE 200809L - -#undef _POSIX_ROBUST_MUTEXES -#define _POSIX_ROBUST_MUTEXES 200809L - -/* - * The following options are not supported - */ -#undef _POSIX_THREAD_ATTR_STACKADDR -#define _POSIX_THREAD_ATTR_STACKADDR -1 - -#undef _POSIX_THREAD_PRIO_INHERIT -#define _POSIX_THREAD_PRIO_INHERIT -1 - -#undef _POSIX_THREAD_PRIO_PROTECT -#define _POSIX_THREAD_PRIO_PROTECT -1 - -/* TPS is not fully supported. */ -#undef _POSIX_THREAD_PRIORITY_SCHEDULING -#define _POSIX_THREAD_PRIORITY_SCHEDULING -1 - -#undef _POSIX_THREAD_PROCESS_SHARED -#define _POSIX_THREAD_PROCESS_SHARED -1 - - -/* - * POSIX 1003.1-2001 Limits - * =========================== - * - * These limits are normally set in , which is not provided with - * pthreads-win32. - * - * PTHREAD_DESTRUCTOR_ITERATIONS - * Maximum number of attempts to destroy - * a thread's thread-specific data on - * termination (must be at least 4) - * - * PTHREAD_KEYS_MAX - * Maximum number of thread-specific data keys - * available per process (must be at least 128) - * - * PTHREAD_STACK_MIN - * Minimum supported stack size for a thread - * - * PTHREAD_THREADS_MAX - * Maximum number of threads supported per - * process (must be at least 64). - * - * SEM_NSEMS_MAX - * The maximum number of semaphores a process can have. - * (must be at least 256) - * - * SEM_VALUE_MAX - * The maximum value a semaphore can have. - * (must be at least 32767) - * - */ -#undef _POSIX_THREAD_DESTRUCTOR_ITERATIONS -#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 - -#undef PTHREAD_DESTRUCTOR_ITERATIONS -#define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS - -#undef _POSIX_THREAD_KEYS_MAX -#define _POSIX_THREAD_KEYS_MAX 128 - -#undef PTHREAD_KEYS_MAX -#define PTHREAD_KEYS_MAX _POSIX_THREAD_KEYS_MAX - -#undef PTHREAD_STACK_MIN -#define PTHREAD_STACK_MIN 0 - -#undef _POSIX_THREAD_THREADS_MAX -#define _POSIX_THREAD_THREADS_MAX 64 - - /* Arbitrary value */ -#undef PTHREAD_THREADS_MAX -#define PTHREAD_THREADS_MAX 2019 - -#undef _POSIX_SEM_NSEMS_MAX -#define _POSIX_SEM_NSEMS_MAX 256 - - /* Arbitrary value */ -#undef SEM_NSEMS_MAX -#define SEM_NSEMS_MAX 1024 - -#undef _POSIX_SEM_VALUE_MAX -#define _POSIX_SEM_VALUE_MAX 32767 - -#undef SEM_VALUE_MAX -#define SEM_VALUE_MAX INT_MAX - - -#if defined(__GNUC__) && !defined(__declspec) -# error Please upgrade your GNU compiler to one that supports __declspec. -#endif - -/* - * When building the library, you should define PTW32_BUILD so that - * the variables/functions are exported correctly. When using the library, - * do NOT define PTW32_BUILD, and then the variables/functions will - * be imported correctly. - */ -#if !defined(PTW32_STATIC_LIB) -# if defined(PTW32_BUILD) -# define PTW32_DLLPORT __declspec (dllexport) -# else -# define PTW32_DLLPORT __declspec (dllimport) -# endif -#else -# define PTW32_DLLPORT -#endif - -#if defined(_UWIN) && PTW32_LEVEL >= PTW32_LEVEL_MAX -# include -#else -/* - * Generic handle type - intended to extend uniqueness beyond - * that available with a simple pointer. It should scale for either - * IA-32 or IA-64. - */ -typedef struct { - void * p; /* Pointer to actual object */ - unsigned int x; /* Extra information - reuse count etc */ -} ptw32_handle_t; - -typedef ptw32_handle_t pthread_t; -typedef struct pthread_attr_t_ * pthread_attr_t; -typedef struct pthread_once_t_ pthread_once_t; -typedef struct pthread_key_t_ * pthread_key_t; -typedef struct pthread_mutex_t_ * pthread_mutex_t; -typedef struct pthread_mutexattr_t_ * pthread_mutexattr_t; -typedef struct pthread_cond_t_ * pthread_cond_t; -typedef struct pthread_condattr_t_ * pthread_condattr_t; -#endif - -typedef struct pthread_rwlock_t_ * pthread_rwlock_t; -typedef struct pthread_rwlockattr_t_ * pthread_rwlockattr_t; -typedef struct pthread_spinlock_t_ * pthread_spinlock_t; -typedef struct pthread_barrier_t_ * pthread_barrier_t; -typedef struct pthread_barrierattr_t_ * pthread_barrierattr_t; - -/* - * ==================== - * ==================== - * POSIX Threads - * ==================== - * ==================== - */ - -enum { -/* - * pthread_attr_{get,set}detachstate - */ - PTHREAD_CREATE_JOINABLE = 0, /* Default */ - PTHREAD_CREATE_DETACHED = 1, - -/* - * pthread_attr_{get,set}inheritsched - */ - PTHREAD_INHERIT_SCHED = 0, - PTHREAD_EXPLICIT_SCHED = 1, /* Default */ - -/* - * pthread_{get,set}scope - */ - PTHREAD_SCOPE_PROCESS = 0, - PTHREAD_SCOPE_SYSTEM = 1, /* Default */ - -/* - * pthread_setcancelstate paramters - */ - PTHREAD_CANCEL_ENABLE = 0, /* Default */ - PTHREAD_CANCEL_DISABLE = 1, - -/* - * pthread_setcanceltype parameters - */ - PTHREAD_CANCEL_ASYNCHRONOUS = 0, - PTHREAD_CANCEL_DEFERRED = 1, /* Default */ - -/* - * pthread_mutexattr_{get,set}pshared - * pthread_condattr_{get,set}pshared - */ - PTHREAD_PROCESS_PRIVATE = 0, - PTHREAD_PROCESS_SHARED = 1, - -/* - * pthread_mutexattr_{get,set}robust - */ - PTHREAD_MUTEX_STALLED = 0, /* Default */ - PTHREAD_MUTEX_ROBUST = 1, - -/* - * pthread_barrier_wait - */ - PTHREAD_BARRIER_SERIAL_THREAD = -1 -}; - -/* - * ==================== - * ==================== - * Cancellation - * ==================== - * ==================== - */ -#define PTHREAD_CANCELED ((void *)(size_t) -1) - - -/* - * ==================== - * ==================== - * Once Key - * ==================== - * ==================== - */ -#define PTHREAD_ONCE_INIT { PTW32_FALSE, 0, 0, 0} - -struct pthread_once_t_ -{ - int done; /* indicates if user function has been executed */ - void * lock; - int reserved1; - int reserved2; -}; - - -/* - * ==================== - * ==================== - * Object initialisers - * ==================== - * ==================== - */ -#define PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t)(size_t) -1) -#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER ((pthread_mutex_t)(size_t) -2) -#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER ((pthread_mutex_t)(size_t) -3) - -/* - * Compatibility with LinuxThreads - */ -#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP PTHREAD_RECURSIVE_MUTEX_INITIALIZER -#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP PTHREAD_ERRORCHECK_MUTEX_INITIALIZER - -#define PTHREAD_COND_INITIALIZER ((pthread_cond_t)(size_t) -1) - -#define PTHREAD_RWLOCK_INITIALIZER ((pthread_rwlock_t)(size_t) -1) - -#define PTHREAD_SPINLOCK_INITIALIZER ((pthread_spinlock_t)(size_t) -1) - - -/* - * Mutex types. - */ -enum -{ - /* Compatibility with LinuxThreads */ - PTHREAD_MUTEX_FAST_NP, - PTHREAD_MUTEX_RECURSIVE_NP, - PTHREAD_MUTEX_ERRORCHECK_NP, - PTHREAD_MUTEX_TIMED_NP = PTHREAD_MUTEX_FAST_NP, - PTHREAD_MUTEX_ADAPTIVE_NP = PTHREAD_MUTEX_FAST_NP, - /* For compatibility with POSIX */ - PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_FAST_NP, - PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP, - PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP, - PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL -}; - - -typedef struct ptw32_cleanup_t ptw32_cleanup_t; - -#if defined(_MSC_VER) -/* Disable MSVC 'anachronism used' warning */ -#pragma warning( disable : 4229 ) -#endif - -typedef void (* PTW32_CDECL ptw32_cleanup_callback_t)(void *); - -#if defined(_MSC_VER) -#pragma warning( default : 4229 ) -#endif - -struct ptw32_cleanup_t -{ - ptw32_cleanup_callback_t routine; - void *arg; - struct ptw32_cleanup_t *prev; -}; - -#if defined(__CLEANUP_SEH) - /* - * WIN32 SEH version of cancel cleanup. - */ - -#define pthread_cleanup_push( _rout, _arg ) \ - { \ - ptw32_cleanup_t _cleanup; \ - \ - _cleanup.routine = (ptw32_cleanup_callback_t)(_rout); \ - _cleanup.arg = (_arg); \ - __try \ - { \ - -#define pthread_cleanup_pop( _execute ) \ - } \ - __finally \ - { \ - if( _execute || AbnormalTermination()) \ - { \ - (*(_cleanup.routine))( _cleanup.arg ); \ - } \ - } \ - } - -#else /* __CLEANUP_SEH */ - -#if defined(__CLEANUP_C) - - /* - * C implementation of PThreads cancel cleanup - */ - -#define pthread_cleanup_push( _rout, _arg ) \ - { \ - ptw32_cleanup_t _cleanup; \ - \ - ptw32_push_cleanup( &_cleanup, (ptw32_cleanup_callback_t) (_rout), (_arg) ); \ - -#define pthread_cleanup_pop( _execute ) \ - (void) ptw32_pop_cleanup( _execute ); \ - } - -#else /* __CLEANUP_C */ - -#if defined(__CLEANUP_CXX) - - /* - * C++ version of cancel cleanup. - * - John E. Bossom. - */ - - class PThreadCleanup { - /* - * PThreadCleanup - * - * Purpose - * This class is a C++ helper class that is - * used to implement pthread_cleanup_push/ - * pthread_cleanup_pop. - * The destructor of this class automatically - * pops the pushed cleanup routine regardless - * of how the code exits the scope - * (i.e. such as by an exception) - */ - ptw32_cleanup_callback_t cleanUpRout; - void * obj; - int executeIt; - - public: - PThreadCleanup() : - cleanUpRout( 0 ), - obj( 0 ), - executeIt( 0 ) - /* - * No cleanup performed - */ - { - } - - PThreadCleanup( - ptw32_cleanup_callback_t routine, - void * arg ) : - cleanUpRout( routine ), - obj( arg ), - executeIt( 1 ) - /* - * Registers a cleanup routine for 'arg' - */ - { - } - - ~PThreadCleanup() - { - if ( executeIt && ((void *) cleanUpRout != (void *) 0) ) - { - (void) (*cleanUpRout)( obj ); - } - } - - void execute( int exec ) - { - executeIt = exec; - } - }; - - /* - * C++ implementation of PThreads cancel cleanup; - * This implementation takes advantage of a helper - * class who's destructor automatically calls the - * cleanup routine if we exit our scope weirdly - */ -#define pthread_cleanup_push( _rout, _arg ) \ - { \ - PThreadCleanup cleanup((ptw32_cleanup_callback_t)(_rout), \ - (void *) (_arg) ); - -#define pthread_cleanup_pop( _execute ) \ - cleanup.execute( _execute ); \ - } - -#else - -#error ERROR [__FILE__, line __LINE__]: Cleanup type undefined. - -#endif /* __CLEANUP_CXX */ - -#endif /* __CLEANUP_C */ - -#endif /* __CLEANUP_SEH */ - -/* - * =============== - * =============== - * Methods - * =============== - * =============== - */ - -/* - * PThread Attribute Functions - */ -PTW32_DLLPORT int PTW32_CDECL pthread_attr_init (pthread_attr_t * attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_destroy (pthread_attr_t * attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_getdetachstate (const pthread_attr_t * attr, - int *detachstate); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstackaddr (const pthread_attr_t * attr, - void **stackaddr); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstacksize (const pthread_attr_t * attr, - size_t * stacksize); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_setdetachstate (pthread_attr_t * attr, - int detachstate); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_setstackaddr (pthread_attr_t * attr, - void *stackaddr); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_setstacksize (pthread_attr_t * attr, - size_t stacksize); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_getschedparam (const pthread_attr_t *attr, - struct sched_param *param); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_setschedparam (pthread_attr_t *attr, - const struct sched_param *param); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_setschedpolicy (pthread_attr_t *, - int); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_getschedpolicy (const pthread_attr_t *, - int *); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_setinheritsched(pthread_attr_t * attr, - int inheritsched); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_getinheritsched(const pthread_attr_t * attr, - int * inheritsched); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_setscope (pthread_attr_t *, - int); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_getscope (const pthread_attr_t *, - int *); - -/* - * PThread Functions - */ -PTW32_DLLPORT int PTW32_CDECL pthread_create (pthread_t * tid, - const pthread_attr_t * attr, - void *(PTW32_CDECL *start) (void *), - void *arg); - -PTW32_DLLPORT int PTW32_CDECL pthread_detach (pthread_t tid); - -PTW32_DLLPORT int PTW32_CDECL pthread_equal (pthread_t t1, - pthread_t t2); - -PTW32_DLLPORT void PTW32_CDECL pthread_exit (void *value_ptr); - -PTW32_DLLPORT int PTW32_CDECL pthread_join (pthread_t thread, - void **value_ptr); - -PTW32_DLLPORT pthread_t PTW32_CDECL pthread_self (void); - -PTW32_DLLPORT int PTW32_CDECL pthread_cancel (pthread_t thread); - -PTW32_DLLPORT int PTW32_CDECL pthread_setcancelstate (int state, - int *oldstate); - -PTW32_DLLPORT int PTW32_CDECL pthread_setcanceltype (int type, - int *oldtype); - -PTW32_DLLPORT void PTW32_CDECL pthread_testcancel (void); - -PTW32_DLLPORT int PTW32_CDECL pthread_once (pthread_once_t * once_control, - void (PTW32_CDECL *init_routine) (void)); - -#if PTW32_LEVEL >= PTW32_LEVEL_MAX -PTW32_DLLPORT ptw32_cleanup_t * PTW32_CDECL ptw32_pop_cleanup (int execute); - -PTW32_DLLPORT void PTW32_CDECL ptw32_push_cleanup (ptw32_cleanup_t * cleanup, - ptw32_cleanup_callback_t routine, - void *arg); -#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ - -/* - * Thread Specific Data Functions - */ -PTW32_DLLPORT int PTW32_CDECL pthread_key_create (pthread_key_t * key, - void (PTW32_CDECL *destructor) (void *)); - -PTW32_DLLPORT int PTW32_CDECL pthread_key_delete (pthread_key_t key); - -PTW32_DLLPORT int PTW32_CDECL pthread_setspecific (pthread_key_t key, - const void *value); - -PTW32_DLLPORT void * PTW32_CDECL pthread_getspecific (pthread_key_t key); - - -/* - * Mutex Attribute Functions - */ -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_init (pthread_mutexattr_t * attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_destroy (pthread_mutexattr_t * attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getpshared (const pthread_mutexattr_t - * attr, - int *pshared); - -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setpshared (pthread_mutexattr_t * attr, - int pshared); - -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_settype (pthread_mutexattr_t * attr, int kind); -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_gettype (const pthread_mutexattr_t * attr, int *kind); - -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setrobust( - pthread_mutexattr_t *attr, - int robust); -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getrobust( - const pthread_mutexattr_t * attr, - int * robust); - -/* - * Barrier Attribute Functions - */ -PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_init (pthread_barrierattr_t * attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_destroy (pthread_barrierattr_t * attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_getpshared (const pthread_barrierattr_t - * attr, - int *pshared); - -PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_setpshared (pthread_barrierattr_t * attr, - int pshared); - -/* - * Mutex Functions - */ -PTW32_DLLPORT int PTW32_CDECL pthread_mutex_init (pthread_mutex_t * mutex, - const pthread_mutexattr_t * attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_mutex_destroy (pthread_mutex_t * mutex); - -PTW32_DLLPORT int PTW32_CDECL pthread_mutex_lock (pthread_mutex_t * mutex); - -PTW32_DLLPORT int PTW32_CDECL pthread_mutex_timedlock(pthread_mutex_t * mutex, - const struct timespec *abstime); - -PTW32_DLLPORT int PTW32_CDECL pthread_mutex_trylock (pthread_mutex_t * mutex); - -PTW32_DLLPORT int PTW32_CDECL pthread_mutex_unlock (pthread_mutex_t * mutex); - -PTW32_DLLPORT int PTW32_CDECL pthread_mutex_consistent (pthread_mutex_t * mutex); - -/* - * Spinlock Functions - */ -PTW32_DLLPORT int PTW32_CDECL pthread_spin_init (pthread_spinlock_t * lock, int pshared); - -PTW32_DLLPORT int PTW32_CDECL pthread_spin_destroy (pthread_spinlock_t * lock); - -PTW32_DLLPORT int PTW32_CDECL pthread_spin_lock (pthread_spinlock_t * lock); - -PTW32_DLLPORT int PTW32_CDECL pthread_spin_trylock (pthread_spinlock_t * lock); - -PTW32_DLLPORT int PTW32_CDECL pthread_spin_unlock (pthread_spinlock_t * lock); - -/* - * Barrier Functions - */ -PTW32_DLLPORT int PTW32_CDECL pthread_barrier_init (pthread_barrier_t * barrier, - const pthread_barrierattr_t * attr, - unsigned int count); - -PTW32_DLLPORT int PTW32_CDECL pthread_barrier_destroy (pthread_barrier_t * barrier); - -PTW32_DLLPORT int PTW32_CDECL pthread_barrier_wait (pthread_barrier_t * barrier); - -/* - * Condition Variable Attribute Functions - */ -PTW32_DLLPORT int PTW32_CDECL pthread_condattr_init (pthread_condattr_t * attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_condattr_destroy (pthread_condattr_t * attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_condattr_getpshared (const pthread_condattr_t * attr, - int *pshared); - -PTW32_DLLPORT int PTW32_CDECL pthread_condattr_setpshared (pthread_condattr_t * attr, - int pshared); - -/* - * Condition Variable Functions - */ -PTW32_DLLPORT int PTW32_CDECL pthread_cond_init (pthread_cond_t * cond, - const pthread_condattr_t * attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_cond_destroy (pthread_cond_t * cond); - -PTW32_DLLPORT int PTW32_CDECL pthread_cond_wait (pthread_cond_t * cond, - pthread_mutex_t * mutex); - -PTW32_DLLPORT int PTW32_CDECL pthread_cond_timedwait (pthread_cond_t * cond, - pthread_mutex_t * mutex, - const struct timespec *abstime); - -PTW32_DLLPORT int PTW32_CDECL pthread_cond_signal (pthread_cond_t * cond); - -PTW32_DLLPORT int PTW32_CDECL pthread_cond_broadcast (pthread_cond_t * cond); - -/* - * Scheduling - */ -PTW32_DLLPORT int PTW32_CDECL pthread_setschedparam (pthread_t thread, - int policy, - const struct sched_param *param); - -PTW32_DLLPORT int PTW32_CDECL pthread_getschedparam (pthread_t thread, - int *policy, - struct sched_param *param); - -PTW32_DLLPORT int PTW32_CDECL pthread_setconcurrency (int); - -PTW32_DLLPORT int PTW32_CDECL pthread_getconcurrency (void); - -/* - * Read-Write Lock Functions - */ -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_init(pthread_rwlock_t *lock, - const pthread_rwlockattr_t *attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_destroy(pthread_rwlock_t *lock); - -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_tryrdlock(pthread_rwlock_t *); - -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_trywrlock(pthread_rwlock_t *); - -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_rdlock(pthread_rwlock_t *lock); - -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedrdlock(pthread_rwlock_t *lock, - const struct timespec *abstime); - -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_wrlock(pthread_rwlock_t *lock); - -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedwrlock(pthread_rwlock_t *lock, - const struct timespec *abstime); - -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_unlock(pthread_rwlock_t *lock); - -PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_init (pthread_rwlockattr_t * attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_destroy (pthread_rwlockattr_t * attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_getpshared (const pthread_rwlockattr_t * attr, - int *pshared); - -PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_setpshared (pthread_rwlockattr_t * attr, - int pshared); - -#if PTW32_LEVEL >= PTW32_LEVEL_MAX - 1 - -/* - * Signal Functions. Should be defined in but MSVC and MinGW32 - * already have signal.h that don't define these. - */ -PTW32_DLLPORT int PTW32_CDECL pthread_kill(pthread_t thread, int sig); - -/* - * Non-portable functions - */ - -/* - * Compatibility with Linux. - */ -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setkind_np(pthread_mutexattr_t * attr, - int kind); -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getkind_np(pthread_mutexattr_t * attr, - int *kind); -PTW32_DLLPORT int PTW32_CDECL pthread_timedjoin_np(pthread_t thread, - void **value_ptr, - const struct timespec *abstime); -PTW32_DLLPORT int PTW32_CDECL pthread_tryjoin_np(pthread_t thread, - void **value_ptr); -PTW32_DLLPORT int PTW32_CDECL pthread_setaffinity_np(pthread_t thread, - size_t cpusetsize, - const cpu_set_t *cpuset); -PTW32_DLLPORT int PTW32_CDECL pthread_getaffinity_np(pthread_t thread, - size_t cpusetsize, - cpu_set_t *cpuset); - -/* - * Possibly supported by other POSIX threads implementations - */ -PTW32_DLLPORT int PTW32_CDECL pthread_delay_np (struct timespec * interval); -PTW32_DLLPORT int PTW32_CDECL pthread_num_processors_np(void); -PTW32_DLLPORT unsigned __int64 PTW32_CDECL pthread_getunique_np(pthread_t thread); - -/* - * Useful if an application wants to statically link - * the lib rather than load the DLL at run-time. - */ -PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_attach_np(void); -PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_detach_np(void); -PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_attach_np(void); -PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_detach_np(void); - -/* - * Features that are auto-detected at load/run time. - */ -PTW32_DLLPORT int PTW32_CDECL pthread_win32_test_features_np(int); -enum ptw32_features { - PTW32_SYSTEM_INTERLOCKED_COMPARE_EXCHANGE = 0x0001, /* System provides it. */ - PTW32_ALERTABLE_ASYNC_CANCEL = 0x0002 /* Can cancel blocked threads. */ -}; - -/* - * Register a system time change with the library. - * Causes the library to perform various functions - * in response to the change. Should be called whenever - * the application's top level window receives a - * WM_TIMECHANGE message. It can be passed directly to - * pthread_create() as a new thread if desired. - */ -PTW32_DLLPORT void * PTW32_CDECL pthread_timechange_handler_np(void *); - -#endif /*PTW32_LEVEL >= PTW32_LEVEL_MAX - 1 */ - -#if PTW32_LEVEL >= PTW32_LEVEL_MAX - -/* - * Returns the Win32 HANDLE for the POSIX thread. - */ -PTW32_DLLPORT HANDLE PTW32_CDECL pthread_getw32threadhandle_np(pthread_t thread); -/* - * Returns the win32 thread ID for POSIX thread. - */ -PTW32_DLLPORT DWORD PTW32_CDECL pthread_getw32threadid_np (pthread_t thread); - - -/* - * Protected Methods - * - * This function blocks until the given WIN32 handle - * is signaled or pthread_cancel had been called. - * This function allows the caller to hook into the - * PThreads cancel mechanism. It is implemented using - * - * WaitForMultipleObjects - * - * on 'waitHandle' and a manually reset WIN32 Event - * used to implement pthread_cancel. The 'timeout' - * argument to TimedWait is simply passed to - * WaitForMultipleObjects. - */ -PTW32_DLLPORT int PTW32_CDECL pthreadCancelableWait (HANDLE waitHandle); -PTW32_DLLPORT int PTW32_CDECL pthreadCancelableTimedWait (HANDLE waitHandle, - DWORD timeout); - -#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ - -/* - * Declare a thread-safe errno for Open Watcom - * (note: this has not been tested in a long time) - */ -#if defined(__WATCOMC__) && !defined(errno) -# if defined(_MT) || defined(_DLL) - __declspec(dllimport) extern int * __cdecl _errno(void); -# define errno (*_errno()) -# endif -#endif - -/* - * If pthreads-win32 is compiled as a DLL with MSVC, and - * both it and the application are linked against the static - * C runtime (i.e. with the /MT compiler flag), then the - * application will not see the same C runtime globals as - * the library. These include the errno variable, and the - * termination routine called by terminate(). For details, - * refer to the following links: - * - * http://support.microsoft.com/kb/94248 - * (Section 4: Problems Encountered When Using Multiple CRT Libraries) - * - * http://social.msdn.microsoft.com/forums/en-US/vclanguage/thread/b4500c0d-1b69-40c7-9ef5-08da1025b5bf - * - * When pthreads-win32 is built with PTW32_USES_SEPARATE_CRT - * defined, the following features are enabled: - * - * (1) In addition to setting the errno variable when errors - * occur, the library will also call SetLastError() with the - * same value. The application can then use GetLastError() - * to obtain the value of errno. (This pair of routines are - * in kernel32.dll, and so are not affected by the use of - * multiple CRT libraries.) - * - * (2) When C++ or SEH cleanup is used, the library defines - * a function pthread_win32_set_terminate_np(), which can be - * used to set the termination routine that should be called - * when an unhandled exception occurs in a thread function - * (or otherwise inside the library). - * - * Note: "_DLL" implies the /MD compiler flag. - */ -#if defined(_MSC_VER) && !defined(_DLL) && !defined(PTW32_STATIC_LIB) -# define PTW32_USES_SEPARATE_CRT -#endif - -#if defined(PTW32_USES_SEPARATE_CRT) && (defined(__CLEANUP_CXX) || defined(__CLEANUP_SEH)) -typedef void (*ptw32_terminate_handler)(); -PTW32_DLLPORT ptw32_terminate_handler PTW32_CDECL pthread_win32_set_terminate_np(ptw32_terminate_handler termFunction); -#endif - -/* - * Some compiler environments don't define some things. - */ -#if defined(__BORLANDC__) -# define _ftime ftime -# define _timeb timeb -#endif - -#if defined(__cplusplus) - -/* - * Internal exceptions - */ -class ptw32_exception {}; -class ptw32_exception_cancel : public ptw32_exception {}; -class ptw32_exception_exit : public ptw32_exception {}; - -#endif - -#if PTW32_LEVEL >= PTW32_LEVEL_MAX - -/* FIXME: This is only required if the library was built using SEH */ -/* - * Get internal SEH tag - */ -PTW32_DLLPORT DWORD PTW32_CDECL ptw32_get_exception_services_code(void); - -#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ - -#if !defined(PTW32_BUILD) - -#if defined(__CLEANUP_SEH) - -/* - * Redefine the SEH __except keyword to ensure that applications - * propagate our internal exceptions up to the library's internal handlers. - */ -#define __except( E ) \ - __except( ( GetExceptionCode() == ptw32_get_exception_services_code() ) \ - ? EXCEPTION_CONTINUE_SEARCH : ( E ) ) - -#endif /* __CLEANUP_SEH */ - -#if defined(__CLEANUP_CXX) - -/* - * Redefine the C++ catch keyword to ensure that applications - * propagate our internal exceptions up to the library's internal handlers. - */ -#if defined(_MSC_VER) - /* - * WARNING: Replace any 'catch( ... )' with 'PtW32CatchAll' - * if you want Pthread-Win32 cancellation and pthread_exit to work. - */ - -#if !defined(PtW32NoCatchWarn) - -#pragma message("Specify \"/DPtW32NoCatchWarn\" compiler flag to skip this message.") -#pragma message("------------------------------------------------------------------") -#pragma message("When compiling applications with MSVC++ and C++ exception handling:") -#pragma message(" Replace any 'catch( ... )' in routines called from POSIX threads") -#pragma message(" with 'PtW32CatchAll' or 'CATCHALL' if you want POSIX thread") -#pragma message(" cancellation and pthread_exit to work. For example:") -#pragma message("") -#pragma message(" #if defined(PtW32CatchAll)") -#pragma message(" PtW32CatchAll") -#pragma message(" #else") -#pragma message(" catch(...)") -#pragma message(" #endif") -#pragma message(" {") -#pragma message(" /* Catchall block processing */") -#pragma message(" }") -#pragma message("------------------------------------------------------------------") - -#endif - -#define PtW32CatchAll \ - catch( ptw32_exception & ) { throw; } \ - catch( ... ) - -#else /* _MSC_VER */ - -#define catch( E ) \ - catch( ptw32_exception & ) { throw; } \ - catch( E ) - -#endif /* _MSC_VER */ - -#endif /* __CLEANUP_CXX */ - -#endif /* ! PTW32_BUILD */ - -#if defined(__cplusplus) -} /* End of extern "C" */ -#endif /* __cplusplus */ - -#if defined(PTW32__HANDLE_DEF) -# undef HANDLE -#endif -#if defined(PTW32__DWORD_DEF) -# undef DWORD -#endif - -#undef PTW32_LEVEL -#undef PTW32_LEVEL_MAX - -#endif /* ! RC_INVOKED */ - -#endif /* PTHREAD_H */ diff --git a/dependencies/win32_pthread/include/sched.h b/dependencies/win32_pthread/include/sched.h deleted file mode 100644 index ad0fb2ec..00000000 --- a/dependencies/win32_pthread/include/sched.h +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Module: sched.h - * - * Purpose: - * Provides an implementation of POSIX realtime extensions - * as defined in - * - * POSIX 1003.1b-1993 (POSIX.1b) - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ -#if !defined(_SCHED_H) -#define _SCHED_H - -#if defined(_MSC_VER) -# if _MSC_VER < 1300 -# define PTW32_CONFIG_MSVC6 -# endif -# if _MSC_VER < 1400 -# define PTW32_CONFIG_MSVC7 -# endif -#endif - -#undef PTW32_SCHED_LEVEL - -#if defined(_POSIX_SOURCE) -#define PTW32_SCHED_LEVEL 0 -/* Early POSIX */ -#endif - -#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309 -#undef PTW32_SCHED_LEVEL -#define PTW32_SCHED_LEVEL 1 -/* Include 1b, 1c and 1d */ -#endif - -#if defined(INCLUDE_NP) -#undef PTW32_SCHED_LEVEL -#define PTW32_SCHED_LEVEL 2 -/* Include Non-Portable extensions */ -#endif - -#define PTW32_SCHED_LEVEL_MAX 3 - -#if ( defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112 ) || !defined(PTW32_SCHED_LEVEL) -#define PTW32_SCHED_LEVEL PTW32_SCHED_LEVEL_MAX -/* Include everything */ -#endif - - -#if defined(__GNUC__) && !defined(__declspec) -# error Please upgrade your GNU compiler to one that supports __declspec. -#endif - -/* - * When building the library, you should define PTW32_BUILD so that - * the variables/functions are exported correctly. When using the library, - * do NOT define PTW32_BUILD, and then the variables/functions will - * be imported correctly. - */ -#if !defined(PTW32_STATIC_LIB) -# if defined(PTW32_BUILD) -# define PTW32_DLLPORT __declspec (dllexport) -# else -# define PTW32_DLLPORT __declspec (dllimport) -# endif -#else -# define PTW32_DLLPORT -#endif - -/* - * The Open Watcom C/C++ compiler uses a non-standard calling convention - * that passes function args in registers unless __cdecl is explicitly specified - * in exposed function prototypes. - * - * We force all calls to cdecl even though this could slow Watcom code down - * slightly. If you know that the Watcom compiler will be used to build both - * the DLL and application, then you can probably define this as a null string. - * Remember that sched.h (this file) is used for both the DLL and application builds. - */ -#if !defined(PTW32_CDECL) -# define PTW32_CDECL __cdecl -#endif - -/* - * This is a duplicate of what is in the autoconf config.h, - * which is only used when building the pthread-win32 libraries. - */ - -#if !defined(PTW32_CONFIG_H) -# if defined(WINCE) -# define NEED_ERRNO -# define NEED_SEM -# endif -# if defined(__MINGW64__) -# define HAVE_STRUCT_TIMESPEC -# define HAVE_MODE_T -# elif defined(_UWIN) || defined(__MINGW32__) -# define HAVE_MODE_T -# endif -#endif - -/* - * - */ - -#include - -#if PTW32_SCHED_LEVEL >= PTW32_SCHED_LEVEL_MAX -#if defined(NEED_ERRNO) -#include "need_errno.h" -#else -#include -#endif -#endif /* PTW32_SCHED_LEVEL >= PTW32_SCHED_LEVEL_MAX */ - -#if (defined(__MINGW64__) || defined(__MINGW32__)) || defined(_UWIN) -# if PTW32_SCHED_LEVEL >= PTW32_SCHED_LEVEL_MAX -/* For pid_t */ -# include -/* Required by Unix 98 */ -# include -# else - typedef int pid_t; -# endif -#else - /* [i_a] fix for using pthread_win32 with mongoose code, which #define's its own pid_t akin to typedef HANDLE pid_t; */ - #undef pid_t -# if defined(_MSC_VER) - typedef void *pid_t; -# else - typedef int pid_t; -# endif -#endif - -/* - * Microsoft VC++6.0 lacks these *_PTR types - */ -#if defined(_MSC_VER) && _MSC_VER < 1300 && !defined(PTW32_HAVE_DWORD_PTR) -typedef unsigned long ULONG_PTR; -typedef ULONG_PTR DWORD_PTR; -#endif - -/* Thread scheduling policies */ - -enum { - SCHED_OTHER = 0, - SCHED_FIFO, - SCHED_RR, - SCHED_MIN = SCHED_OTHER, - SCHED_MAX = SCHED_RR -}; - -struct sched_param { - int sched_priority; -}; - -/* - * CPU affinity - * - * cpu_set_t: - * Considered opaque but cannot be an opaque pointer - * due to the need for compatibility with GNU systems - * and sched_setaffinity() et.al. which include the - * cpusetsize parameter "normally set to sizeof(cpu_set_t)". - */ - -#define CPU_SETSIZE (sizeof(size_t)*8) - -#define CPU_COUNT(setptr) (_sched_affinitycpucount(setptr)) - -#define CPU_ZERO(setptr) (_sched_affinitycpuzero(setptr)) - -#define CPU_SET(cpu, setptr) (_sched_affinitycpuset((cpu),(setptr))) - -#define CPU_CLR(cpu, setptr) (_sched_affinitycpuclr((cpu),(setptr))) - -#define CPU_ISSET(cpu, setptr) (_sched_affinitycpuisset((cpu),(setptr))) - -#define CPU_AND(destsetptr, srcset1ptr, srcset2ptr) (_sched_affinitycpuand((destsetptr),(srcset1ptr),(srcset2ptr))) - -#define CPU_OR(destsetptr, srcset1ptr, srcset2ptr) (_sched_affinitycpuor((destsetptr),(srcset1ptr),(srcset2ptr))) - -#define CPU_XOR(destsetptr, srcset1ptr, srcset2ptr) (_sched_affinitycpuxor((destsetptr),(srcset1ptr),(srcset2ptr))) - -#define CPU_EQUAL(set1ptr, set2ptr) (_sched_affinitycpuequal((set1ptr),(set2ptr))) - -typedef union -{ - char cpuset[CPU_SETSIZE/8]; - size_t _align; -} cpu_set_t; - -#if defined(__cplusplus) -extern "C" -{ -#endif /* __cplusplus */ - -PTW32_DLLPORT int PTW32_CDECL sched_yield (void); - -PTW32_DLLPORT int PTW32_CDECL sched_get_priority_min (int policy); - -PTW32_DLLPORT int PTW32_CDECL sched_get_priority_max (int policy); - -PTW32_DLLPORT int PTW32_CDECL sched_setscheduler (pid_t pid, int policy); - -PTW32_DLLPORT int PTW32_CDECL sched_getscheduler (pid_t pid); - -/* Compatibility with Linux - not standard */ - -PTW32_DLLPORT int PTW32_CDECL sched_setaffinity (pid_t pid, size_t cpusetsize, cpu_set_t *mask); - -PTW32_DLLPORT int PTW32_CDECL sched_getaffinity (pid_t pid, size_t cpusetsize, cpu_set_t *mask); - -/* - * Support routines and macros for cpu_set_t - */ -PTW32_DLLPORT int PTW32_CDECL _sched_affinitycpucount (const cpu_set_t *set); - -PTW32_DLLPORT void PTW32_CDECL _sched_affinitycpuzero (cpu_set_t *pset); - -PTW32_DLLPORT void PTW32_CDECL _sched_affinitycpuset (int cpu, cpu_set_t *pset); - -PTW32_DLLPORT void PTW32_CDECL _sched_affinitycpuclr (int cpu, cpu_set_t *pset); - -PTW32_DLLPORT int PTW32_CDECL _sched_affinitycpuisset (int cpu, const cpu_set_t *pset); - -PTW32_DLLPORT void PTW32_CDECL _sched_affinitycpuand(cpu_set_t *pdestset, const cpu_set_t *psrcset1, const cpu_set_t *psrcset2); - -PTW32_DLLPORT void PTW32_CDECL _sched_affinitycpuor(cpu_set_t *pdestset, const cpu_set_t *psrcset1, const cpu_set_t *psrcset2); - -PTW32_DLLPORT void PTW32_CDECL _sched_affinitycpuxor(cpu_set_t *pdestset, const cpu_set_t *psrcset1, const cpu_set_t *psrcset2); - -PTW32_DLLPORT int PTW32_CDECL _sched_affinitycpuequal (const cpu_set_t *pset1, const cpu_set_t *pset2); - -/* - * Note that this macro returns ENOTSUP rather than - * ENOSYS as might be expected. However, returning ENOSYS - * should mean that sched_get_priority_{min,max} are - * not implemented as well as sched_rr_get_interval. - * This is not the case, since we just don't support - * round-robin scheduling. Therefore I have chosen to - * return the same value as sched_setscheduler when - * SCHED_RR is passed to it. - */ -#define sched_rr_get_interval(_pid, _interval) \ - ( errno = ENOTSUP, (int) -1 ) - - -#if defined(__cplusplus) -} /* End of extern "C" */ -#endif /* __cplusplus */ - -#undef PTW32_SCHED_LEVEL -#undef PTW32_SCHED_LEVEL_MAX - -#endif /* !_SCHED_H */ - diff --git a/dependencies/win32_pthread/include/semaphore.h b/dependencies/win32_pthread/include/semaphore.h deleted file mode 100644 index 835677b4..00000000 --- a/dependencies/win32_pthread/include/semaphore.h +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Module: semaphore.h - * - * Purpose: - * Semaphores aren't actually part of the PThreads standard. - * They are defined by the POSIX Standard: - * - * POSIX 1003.1b-1993 (POSIX.1b) - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ -#if !defined( SEMAPHORE_H ) -#define SEMAPHORE_H - -#undef PTW32_SEMAPHORE_LEVEL - -#if defined(_POSIX_SOURCE) -#define PTW32_SEMAPHORE_LEVEL 0 -/* Early POSIX */ -#endif - -#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309 -#undef PTW32_SEMAPHORE_LEVEL -#define PTW32_SEMAPHORE_LEVEL 1 -/* Include 1b, 1c and 1d */ -#endif - -#if defined(INCLUDE_NP) -#undef PTW32_SEMAPHORE_LEVEL -#define PTW32_SEMAPHORE_LEVEL 2 -/* Include Non-Portable extensions */ -#endif - -#define PTW32_SEMAPHORE_LEVEL_MAX 3 - -#if !defined(PTW32_SEMAPHORE_LEVEL) -#define PTW32_SEMAPHORE_LEVEL PTW32_SEMAPHORE_LEVEL_MAX -/* Include everything */ -#endif - -#if defined(__GNUC__) && ! defined (__declspec) -# error Please upgrade your GNU compiler to one that supports __declspec. -#endif - -/* - * When building the library, you should define PTW32_BUILD so that - * the variables/functions are exported correctly. When using the library, - * do NOT define PTW32_BUILD, and then the variables/functions will - * be imported correctly. - */ -#if !defined(PTW32_STATIC_LIB) -# if defined(PTW32_BUILD) -# define PTW32_DLLPORT __declspec (dllexport) -# else -# define PTW32_DLLPORT __declspec (dllimport) -# endif -#else -# define PTW32_DLLPORT -#endif - -#if !defined(PTW32_CDECL) -# define PTW32_CDECL __cdecl -#endif - -/* - * This is a duplicate of what is in the autoconf config.h, - * which is only used when building the pthread-win32 libraries. - */ - -#if !defined(PTW32_CONFIG_H) -# if defined(WINCE) -# define NEED_ERRNO -# define NEED_SEM -# endif -# if defined(__MINGW64__) -# define HAVE_STRUCT_TIMESPEC -# define HAVE_MODE_T -# elif defined(_UWIN) || defined(__MINGW32__) -# define HAVE_MODE_T -# endif -#endif - -/* - * - */ - -#if PTW32_SEMAPHORE_LEVEL >= PTW32_SEMAPHORE_LEVEL_MAX -#if defined(NEED_ERRNO) -#include "need_errno.h" -#else -#include -#endif -#endif /* PTW32_SEMAPHORE_LEVEL >= PTW32_SEMAPHORE_LEVEL_MAX */ - -#define _POSIX_SEMAPHORES - -#if defined(__cplusplus) -extern "C" -{ -#endif /* __cplusplus */ - -#if !defined(HAVE_MODE_T) -typedef unsigned int mode_t; -#endif - - -typedef struct sem_t_ * sem_t; - -PTW32_DLLPORT int PTW32_CDECL sem_init (sem_t * sem, - int pshared, - unsigned int value); - -PTW32_DLLPORT int PTW32_CDECL sem_destroy (sem_t * sem); - -PTW32_DLLPORT int PTW32_CDECL sem_trywait (sem_t * sem); - -PTW32_DLLPORT int PTW32_CDECL sem_wait (sem_t * sem); - -PTW32_DLLPORT int PTW32_CDECL sem_timedwait (sem_t * sem, - const struct timespec * abstime); - -PTW32_DLLPORT int PTW32_CDECL sem_post (sem_t * sem); - -PTW32_DLLPORT int PTW32_CDECL sem_post_multiple (sem_t * sem, - int count); - -PTW32_DLLPORT int PTW32_CDECL sem_open (const char * name, - int oflag, - mode_t mode, - unsigned int value); - -PTW32_DLLPORT int PTW32_CDECL sem_close (sem_t * sem); - -PTW32_DLLPORT int PTW32_CDECL sem_unlink (const char * name); - -PTW32_DLLPORT int PTW32_CDECL sem_getvalue (sem_t * sem, - int * sval); - -#if defined(__cplusplus) -} /* End of extern "C" */ -#endif /* __cplusplus */ - -#undef PTW32_SEMAPHORE_LEVEL -#undef PTW32_SEMAPHORE_LEVEL_MAX - -#endif /* !SEMAPHORE_H */ diff --git a/dependencies/win32_pthread/src/autostatic.c b/dependencies/win32_pthread/src/autostatic.c deleted file mode 100644 index 3f793888..00000000 --- a/dependencies/win32_pthread/src/autostatic.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * autostatic.c - * - * Description: - * This translation unit implements static auto-init and auto-exit logic. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -#if defined(PTW32_STATIC_LIB) - -#if defined(PTW32_CONFIG_MINGW) || defined(_MSC_VER) - -/* For an explanation of this code (at least the MSVC parts), refer to - * - * http://www.codeguru.com/cpp/misc/misc/threadsprocesses/article.php/c6945/ - * ("Running Code Before and After Main") - * - * Compatibility with MSVC8 was cribbed from Boost: - * - * http://svn.boost.org/svn/boost/trunk/libs/thread/src/win32/tss_pe.cpp - * - * In addition to that, because we are in a static library, and the linker - * can't tell that the constructor/destructor functions are actually - * needed, we need a way to prevent the linker from optimizing away this - * module. The pthread_win32_autostatic_anchor() hack below (and in - * implement.h) does the job in a portable manner. - */ - -static int on_process_init(void) -{ - pthread_win32_process_attach_np (); - return 0; -} - -static int on_process_exit(void) -{ - pthread_win32_thread_detach_np (); - pthread_win32_process_detach_np (); - return 0; -} - -#if defined(PTW32_CONFIG_MINGW) -__attribute__((section(".ctors"), used)) static int (*gcc_ctor)(void) = on_process_init; -__attribute__((section(".dtors"), used)) static int (*gcc_dtor)(void) = on_process_exit; -#elif defined(_MSC_VER) -# if _MSC_VER >= 1400 /* MSVC8 */ -# pragma section(".CRT$XCU", long, read) -# pragma section(".CRT$XPU", long, read) -__declspec(allocate(".CRT$XCU")) static int (*msc_ctor)(void) = on_process_init; -__declspec(allocate(".CRT$XPU")) static int (*msc_dtor)(void) = on_process_exit; -# else -# pragma data_seg(".CRT$XCU") -static int (*msc_ctor)(void) = on_process_init; -# pragma data_seg(".CRT$XPU") -static int (*msc_dtor)(void) = on_process_exit; -# pragma data_seg() /* reset data segment */ -# endif -#endif - -#endif /* defined(PTW32_CONFIG_MINGW) || defined(_MSC_VER) */ - -/* This dummy function exists solely to be referenced by other modules - * (specifically, in implement.h), so that the linker can't optimize away - * this module. Don't call it. - */ -void ptw32_autostatic_anchor(void) { abort(); } - -#endif /* PTW32_STATIC_LIB */ - -#if ! defined(PTW32_BUILD_INLINED) -/* - * Avoid "translation unit is empty" warnings - */ -typedef int foo; -#endif diff --git a/dependencies/win32_pthread/src/cleanup.c b/dependencies/win32_pthread/src/cleanup.c deleted file mode 100644 index ae8ae418..00000000 --- a/dependencies/win32_pthread/src/cleanup.c +++ /dev/null @@ -1,153 +0,0 @@ -/* - * cleanup.c - * - * Description: - * This translation unit implements routines associated - * with cleaning up threads. - * - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -/* - * The functions ptw32_pop_cleanup and ptw32_push_cleanup - * are implemented here for applications written in C with no - * SEH or C++ destructor support. - */ - -ptw32_cleanup_t * -ptw32_pop_cleanup (int execute) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function pops the most recently pushed cleanup - * handler. If execute is nonzero, then the cleanup handler - * is executed if non-null. - * - * PARAMETERS - * execute - * if nonzero, execute the cleanup handler - * - * - * DESCRIPTION - * This function pops the most recently pushed cleanup - * handler. If execute is nonzero, then the cleanup handler - * is executed if non-null. - * NOTE: specify 'execute' as nonzero to avoid duplication - * of common cleanup code. - * - * RESULTS - * N/A - * - * ------------------------------------------------------ - */ -{ - ptw32_cleanup_t *cleanup; - - cleanup = (ptw32_cleanup_t *) pthread_getspecific (ptw32_cleanupKey); - - if (cleanup != NULL) - { - if (execute && (cleanup->routine != NULL)) - { - - (*cleanup->routine) (cleanup->arg); - - } - - pthread_setspecific (ptw32_cleanupKey, (void *) cleanup->prev); - - } - - return (cleanup); - -} /* ptw32_pop_cleanup */ - - -void -ptw32_push_cleanup (ptw32_cleanup_t * cleanup, - ptw32_cleanup_callback_t routine, void *arg) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function pushes a new cleanup handler onto the thread's stack - * of cleanup handlers. Each cleanup handler pushed onto the stack is - * popped and invoked with the argument 'arg' when - * a) the thread exits by calling 'pthread_exit', - * b) when the thread acts on a cancellation request, - * c) or when the thread calls pthread_cleanup_pop with a nonzero - * 'execute' argument - * - * PARAMETERS - * cleanup - * a pointer to an instance of pthread_cleanup_t, - * - * routine - * pointer to a cleanup handler, - * - * arg - * parameter to be passed to the cleanup handler - * - * - * DESCRIPTION - * This function pushes a new cleanup handler onto the thread's stack - * of cleanup handlers. Each cleanup handler pushed onto the stack is - * popped and invoked with the argument 'arg' when - * a) the thread exits by calling 'pthread_exit', - * b) when the thread acts on a cancellation request, - * c) or when the thrad calls pthread_cleanup_pop with a nonzero - * 'execute' argument - * NOTE: pthread_push_cleanup, ptw32_pop_cleanup must be paired - * in the same lexical scope. - * - * RESULTS - * pthread_cleanup_t * - * pointer to the previous cleanup - * - * ------------------------------------------------------ - */ -{ - cleanup->routine = routine; - cleanup->arg = arg; - - cleanup->prev = (ptw32_cleanup_t *) pthread_getspecific (ptw32_cleanupKey); - - pthread_setspecific (ptw32_cleanupKey, (void *) cleanup); - -} /* ptw32_push_cleanup */ diff --git a/dependencies/win32_pthread/src/create.c b/dependencies/win32_pthread/src/create.c deleted file mode 100644 index fc170924..00000000 --- a/dependencies/win32_pthread/src/create.c +++ /dev/null @@ -1,314 +0,0 @@ -/* - * create.c - * - * Description: - * This translation unit implements routines associated with spawning a new - * thread. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" -#if ! defined(_UWIN) && ! defined(WINCE) -#include -#endif - -int -pthread_create (pthread_t * tid, - const pthread_attr_t * attr, - void *(PTW32_CDECL *start) (void *), void *arg) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function creates a thread running the start function, - * passing it the parameter value, 'arg'. The 'attr' - * argument specifies optional creation attributes. - * The identity of the new thread is returned - * via 'tid', which should not be NULL. - * - * PARAMETERS - * tid - * pointer to an instance of pthread_t - * - * attr - * optional pointer to an instance of pthread_attr_t - * - * start - * pointer to the starting routine for the new thread - * - * arg - * optional parameter passed to 'start' - * - * - * DESCRIPTION - * This function creates a thread running the start function, - * passing it the parameter value, 'arg'. The 'attr' - * argument specifies optional creation attributes. - * The identity of the new thread is returned - * via 'tid', which should not be the NULL pointer. - * - * RESULTS - * 0 successfully created thread, - * EINVAL attr invalid, - * EAGAIN insufficient resources. - * - * ------------------------------------------------------ - */ -{ - pthread_t thread = { 0 }; // init to shut up MSVC2013: warning C4701 : potentially uninitialized local variable 'thread' used - ptw32_thread_t * tp; - ptw32_thread_t * sp; - register pthread_attr_t a; - HANDLE threadH = 0; - int result = EAGAIN; - int run = PTW32_TRUE; - ThreadParms *parms = NULL; - unsigned int stackSize; - int priority; - - /* - * Before doing anything, check that tid can be stored through - * without invoking a memory protection error (segfault). - * Make sure that the assignment below can't be optimised out by the compiler. - * This is assured by conditionally assigning *tid again at the end. - */ - tid->x = 0; - - if (NULL == (sp = (ptw32_thread_t *)pthread_self().p)) - { - goto FAIL0; - } - - if (attr != NULL) - { - a = *attr; - } - else - { - a = NULL; - } - - if ((thread = ptw32_new ()).p == NULL) - { - goto FAIL0; - } - - tp = (ptw32_thread_t *) thread.p; - - priority = tp->sched_priority; - - if ((parms = (ThreadParms *) malloc (sizeof (*parms))) == NULL) - { - goto FAIL0; - } - - parms->tid = thread; - parms->start = start; - parms->arg = arg; - - /* - * Threads inherit their initial sigmask and CPU affinity from their creator thread. - */ -#if defined(HAVE_SIGSET_T) - tp->sigmask = sp->sigmask; -#endif - tp->cpuset = sp->cpuset; - - if (a != NULL) - { - stackSize = (unsigned int)a->stacksize; - tp->detachState = a->detachstate; - priority = a->param.sched_priority; - -#if (THREAD_PRIORITY_LOWEST > THREAD_PRIORITY_NORMAL) - /* WinCE */ -#else - /* Everything else */ - - /* - * Thread priority must be set to a valid system level - * without altering the value set by pthread_attr_setschedparam(). - */ - - /* - * PTHREAD_EXPLICIT_SCHED is the default because Win32 threads - * don't inherit their creator's priority. They are started with - * THREAD_PRIORITY_NORMAL (win32 value). The result of not supplying - * an 'attr' arg to pthread_create() is equivalent to defaulting to - * PTHREAD_EXPLICIT_SCHED and priority THREAD_PRIORITY_NORMAL. - */ - if (PTHREAD_INHERIT_SCHED == a->inheritsched) - { - /* - * If the thread that called pthread_create() is a Win32 thread - * then the inherited priority could be the result of a temporary - * system adjustment. This is not the case for POSIX threads. - */ - priority = sp->sched_priority; - } - -#endif - - } - else - { - /* - * Default stackSize - */ - stackSize = PTHREAD_STACK_MIN; - } - - tp->state = run ? PThreadStateInitial : PThreadStateSuspended; - - tp->keys = NULL; - - /* - * Threads must be started in suspended mode and resumed if necessary - * after _beginthreadex returns us the handle. Otherwise we set up a - * race condition between the creating and the created threads. - * Note that we also retain a local copy of the handle for use - * by us in case thread.p->threadH gets NULLed later but before we've - * finished with it here. - */ - -#if ! defined (PTW32_CONFIG_MINGW) || defined (__MSVCRT__) || defined (__DMC__) - - tp->threadH = - threadH = - (HANDLE) _beginthreadex ((void *) NULL, /* No security info */ - stackSize, /* default stack size */ - ptw32_threadStart, - parms, - (unsigned) - CREATE_SUSPENDED, - (unsigned *) &(tp->thread)); - - if (threadH != 0) - { - if (a != NULL) - { - (void) ptw32_setthreadpriority (thread, SCHED_OTHER, priority); - } - - SetThreadAffinityMask(tp->threadH, tp->cpuset); - - if (run) - { - ResumeThread (threadH); - } - } - -#else - - { - ptw32_mcs_local_node_t stateLock; - - /* - * This lock will force pthread_threadStart() to wait until we have - * the thread handle and have set the priority. - */ - ptw32_mcs_lock_acquire(&tp->stateLock, &stateLock); - - tp->threadH = - threadH = - (HANDLE) _beginthread (ptw32_threadStart, stackSize, /* default stack size */ - parms); - - /* - * Make the return code match _beginthreadex's. - */ - if (threadH == (HANDLE) - 1L) - { - tp->threadH = threadH = 0; - } - else - { - if (!run) - { - /* - * beginthread does not allow for create flags, so we do it now. - * Note that beginthread itself creates the thread in SUSPENDED - * mode, and then calls ResumeThread to start it. - */ - SuspendThread (threadH); - } - - if (a != NULL) - { - (void) ptw32_setthreadpriority (thread, SCHED_OTHER, priority); - } - - SetThreadAffinityMask(tp->threadH, tp->cpuset); - } - - ptw32_mcs_lock_release (&stateLock); - } -#endif - - result = (threadH != 0) ? 0 : EAGAIN; - - /* - * Fall Through Intentionally - */ - - /* - * ------------ - * Failure Code - * ------------ - */ - -FAIL0: - if (result != 0) - { - ptw32_threadDestroy (thread); - tp = NULL; - - if (parms != NULL) - { - free (parms); - } - } - else - { - *tid = thread; - } - -#if defined(_UWIN) - if (result == 0) - pthread_count++; -#endif - return (result); -} /* pthread_create */ diff --git a/dependencies/win32_pthread/src/dll.c b/dependencies/win32_pthread/src/dll.c deleted file mode 100644 index 0c01eca9..00000000 --- a/dependencies/win32_pthread/src/dll.c +++ /dev/null @@ -1,113 +0,0 @@ -/* - * dll.c - * - * Description: - * This translation unit implements DLL initialisation. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -/* [i_a] sanity build checks */ -#if defined(_MSC_VER) && (defined(_WIN32) || defined(_WIN64)) -#if !defined(PTW32_STATIC_LIB) && !defined(_WINDLL) -#error "Should not compile dynamic library code when apparently trying to build a static lib" -#elif defined(PTW32_STATIC_LIB) && defined(_WINDLL) -#error "Should not compile static library code when apparently trying to build a dynamic lib DLL" -#endif -#endif - -#include "pthread.h" -#include "implement.h" - -#if !defined(PTW32_STATIC_LIB) - -#if defined(_MSC_VER) -/* - * lpvReserved yields an unreferenced formal parameter; - * ignore it - */ -#pragma warning( disable : 4100 ) -#endif - -#if defined(__cplusplus) -/* - * Dear c++: Please don't mangle this name. -thanks - */ -extern "C" -#endif /* __cplusplus */ - BOOL WINAPI -DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved) -{ - BOOL result = PTW32_TRUE; - - switch (fdwReason) - { - - case DLL_PROCESS_ATTACH: - result = pthread_win32_process_attach_np (); - break; - - case DLL_THREAD_ATTACH: - /* - * A thread is being created - */ - result = pthread_win32_thread_attach_np (); - break; - - case DLL_THREAD_DETACH: - /* - * A thread is exiting cleanly - */ - result = pthread_win32_thread_detach_np (); - break; - - case DLL_PROCESS_DETACH: - (void) pthread_win32_thread_detach_np (); - result = pthread_win32_process_detach_np (); - break; - } - - return (result); -} /* DllMain */ - -#endif /* !PTW32_STATIC_LIB */ - -#if ! defined(PTW32_BUILD_INLINED) -/* - * Avoid "translation unit is empty" warnings - */ -typedef int foo; -#endif - diff --git a/dependencies/win32_pthread/src/errno.c b/dependencies/win32_pthread/src/errno.c deleted file mode 100644 index 857c0092..00000000 --- a/dependencies/win32_pthread/src/errno.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * errno.c - * - * Description: - * This translation unit implements routines associated with spawning a new - * thread. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -#if defined(NEED_ERRNO) - -static int reallyBad = ENOMEM; - -/* - * Re-entrant errno. - * - * Each thread has it's own errno variable in pthread_t. - * - * The benefit of using the pthread_t structure - * instead of another TSD key is TSD keys are limited - * on Win32 to 64 per process. Secondly, to implement - * it properly without using pthread_t you'd need - * to dynamically allocate an int on starting the thread - * and store it manually into TLS and then ensure that you free - * it on thread termination. We get all that for free - * by simply storing the errno on the pthread_t structure. - * - * MSVC and Mingw32 already have their own thread-safe errno. - * - * #if defined( _REENTRANT ) || defined( _MT ) - * #define errno *_errno() - * - * int *_errno( void ); - * #else - * extern int errno; - * #endif - * - */ - -int * -_errno (void) -{ - pthread_t self; - int *result; - - if ((self = pthread_self ()).p == NULL) - { - /* - * Yikes! unable to allocate a thread! - * Throw an exception? return an error? - */ - result = &reallyBad; - } - else - { - result = (int *)(&self.p->exitStatus); - } - - return (result); - -} /* _errno */ - -#endif /* (NEED_ERRNO) */ - -#if ! defined(PTW32_BUILD_INLINED) -/* - * Avoid "translation unit is empty" warnings - */ -typedef int foo; -#endif diff --git a/dependencies/win32_pthread/src/global.c b/dependencies/win32_pthread/src/global.c deleted file mode 100644 index 548455f0..00000000 --- a/dependencies/win32_pthread/src/global.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * global.c - * - * Description: - * This translation unit instantiates data associated with the implementation - * as a whole. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int ptw32_processInitialized = PTW32_FALSE; -ptw32_thread_t * ptw32_threadReuseTop = PTW32_THREAD_REUSE_EMPTY; -ptw32_thread_t * ptw32_threadReuseBottom = PTW32_THREAD_REUSE_EMPTY; -pthread_key_t ptw32_selfThreadKey = NULL; -pthread_key_t ptw32_cleanupKey = NULL; -pthread_cond_t ptw32_cond_list_head = NULL; -pthread_cond_t ptw32_cond_list_tail = NULL; - -int ptw32_concurrency = 0; - -/* What features have been auto-detected */ -int ptw32_features = 0; - -/* - * Global [process wide] thread sequence Number - */ -unsigned __int64 ptw32_threadSeqNumber = 0; - -/* - * Function pointer to QueueUserAPCEx if it exists, otherwise - * it will be set at runtime to a substitute routine which cannot unblock - * blocked threads. - */ -DWORD (*ptw32_register_cancellation) (PAPCFUNC, HANDLE, DWORD) = NULL; - -/* - * Global lock for managing pthread_t struct reuse. - */ -ptw32_mcs_lock_t ptw32_thread_reuse_lock = 0; - -/* - * Global lock for testing internal state of statically declared mutexes. - */ -ptw32_mcs_lock_t ptw32_mutex_test_init_lock = 0; - -/* - * Global lock for testing internal state of PTHREAD_COND_INITIALIZER - * created condition variables. - */ -ptw32_mcs_lock_t ptw32_cond_test_init_lock = 0; - -/* - * Global lock for testing internal state of PTHREAD_RWLOCK_INITIALIZER - * created read/write locks. - */ -ptw32_mcs_lock_t ptw32_rwlock_test_init_lock = 0; - -/* - * Global lock for testing internal state of PTHREAD_SPINLOCK_INITIALIZER - * created spin locks. - */ -ptw32_mcs_lock_t ptw32_spinlock_test_init_lock = 0; - -/* - * Global lock for condition variable linked list. The list exists - * to wake up CVs when a WM_TIMECHANGE message arrives. See - * w32_TimeChangeHandler.c. - */ -ptw32_mcs_lock_t ptw32_cond_list_lock = 0; - -#if defined(_UWIN) -/* - * Keep a count of the number of threads. - */ -int pthread_count = 0; -#endif diff --git a/dependencies/win32_pthread/src/pthread.c b/dependencies/win32_pthread/src/pthread.c deleted file mode 100644 index 9d882d0a..00000000 --- a/dependencies/win32_pthread/src/pthread.c +++ /dev/null @@ -1,188 +0,0 @@ -/* - * pthread.c - * - * Description: - * This translation unit agregates pthreads-win32 translation units. - * It is used for inline optimisation of the library, - * maximising for speed at the expense of size. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -/* The following are ordered for inlining */ - -#include "ptw32_MCS_lock.c" -#include "ptw32_is_attr.c" -#include "ptw32_processInitialize.c" -#include "ptw32_processTerminate.c" -#include "ptw32_threadStart.c" -#include "ptw32_threadDestroy.c" -#include "ptw32_tkAssocCreate.c" -#include "ptw32_tkAssocDestroy.c" -#include "ptw32_callUserDestroyRoutines.c" -#include "ptw32_semwait.c" -#include "ptw32_timespec.c" -#include "ptw32_throw.c" -#include "ptw32_getprocessors.c" -#include "ptw32_calloc.c" -#include "ptw32_new.c" -#include "ptw32_reuse.c" -#include "ptw32_relmillisecs.c" -#include "ptw32_cond_check_need_init.c" -#include "ptw32_mutex_check_need_init.c" -#include "ptw32_rwlock_check_need_init.c" -#include "ptw32_rwlock_cancelwrwait.c" -#include "ptw32_spinlock_check_need_init.c" -#include "pthread_attr_init.c" -#include "pthread_attr_destroy.c" -#include "pthread_attr_getdetachstate.c" -#include "pthread_attr_setdetachstate.c" -#include "pthread_attr_getscope.c" -#include "pthread_attr_setscope.c" -#include "pthread_attr_getstackaddr.c" -#include "pthread_attr_setstackaddr.c" -#include "pthread_attr_getstacksize.c" -#include "pthread_attr_setstacksize.c" -#include "pthread_barrier_init.c" -#include "pthread_barrier_destroy.c" -#include "pthread_barrier_wait.c" -#include "pthread_barrierattr_init.c" -#include "pthread_barrierattr_destroy.c" -#include "pthread_barrierattr_setpshared.c" -#include "pthread_barrierattr_getpshared.c" -#include "pthread_setcancelstate.c" -#include "pthread_setcanceltype.c" -#include "pthread_testcancel.c" -#include "pthread_cancel.c" -#include "pthread_condattr_destroy.c" -#include "pthread_condattr_getpshared.c" -#include "pthread_condattr_init.c" -#include "pthread_condattr_setpshared.c" -#include "pthread_cond_destroy.c" -#include "pthread_cond_init.c" -#include "pthread_cond_signal.c" -#include "pthread_cond_wait.c" -#include "create.c" -#include "cleanup.c" -#include "dll.c" -#include "autostatic.c" -#include "errno.c" -#include "pthread_exit.c" -#include "global.c" -#include "pthread_equal.c" -#include "pthread_getconcurrency.c" -#include "pthread_kill.c" -#include "pthread_once.c" -#include "pthread_self.c" -#include "pthread_setconcurrency.c" -#include "w32_CancelableWait.c" -#include "pthread_mutex_init.c" -#include "pthread_mutex_destroy.c" -#include "pthread_mutexattr_init.c" -#include "pthread_mutexattr_destroy.c" -#include "pthread_mutexattr_getpshared.c" -#include "pthread_mutexattr_setpshared.c" -#include "pthread_mutexattr_settype.c" -#include "pthread_mutexattr_gettype.c" -#include "pthread_mutexattr_setrobust.c" -#include "pthread_mutexattr_getrobust.c" -#include "pthread_mutex_lock.c" -#include "pthread_mutex_timedlock.c" -#include "pthread_mutex_unlock.c" -#include "pthread_mutex_trylock.c" -#include "pthread_mutex_consistent.c" -#include "pthread_mutexattr_setkind_np.c" -#include "pthread_mutexattr_getkind_np.c" -#include "pthread_getw32threadhandle_np.c" -#include "pthread_getunique_np.c" -#include "pthread_timedjoin_np.c" -#include "pthread_tryjoin_np.c" -#include "pthread_setaffinity.c" -#include "pthread_delay_np.c" -#include "pthread_num_processors_np.c" -#include "pthread_win32_attach_detach_np.c" -#include "pthread_timechange_handler_np.c" -#include "pthread_rwlock_init.c" -#include "pthread_rwlock_destroy.c" -#include "pthread_rwlockattr_init.c" -#include "pthread_rwlockattr_destroy.c" -#include "pthread_rwlockattr_getpshared.c" -#include "pthread_rwlockattr_setpshared.c" -#include "pthread_rwlock_rdlock.c" -#include "pthread_rwlock_timedrdlock.c" -#include "pthread_rwlock_wrlock.c" -#include "pthread_rwlock_timedwrlock.c" -#include "pthread_rwlock_unlock.c" -#include "pthread_rwlock_tryrdlock.c" -#include "pthread_rwlock_trywrlock.c" -#include "pthread_attr_setschedpolicy.c" -#include "pthread_attr_getschedpolicy.c" -#include "pthread_attr_setschedparam.c" -#include "pthread_attr_getschedparam.c" -#include "pthread_attr_setinheritsched.c" -#include "pthread_attr_getinheritsched.c" -#include "pthread_setschedparam.c" -#include "pthread_getschedparam.c" -#include "sched_get_priority_max.c" -#include "sched_get_priority_min.c" -#include "sched_setscheduler.c" -#include "sched_getscheduler.c" -#include "sched_yield.c" -#include "sched_setaffinity.c" -#include "sem_init.c" -#include "sem_destroy.c" -#include "sem_trywait.c" -#include "sem_timedwait.c" -#include "sem_wait.c" -#include "sem_post.c" -#include "sem_post_multiple.c" -#include "sem_getvalue.c" -#include "sem_open.c" -#include "sem_close.c" -#include "sem_unlink.c" -#include "pthread_spin_init.c" -#include "pthread_spin_destroy.c" -#include "pthread_spin_lock.c" -#include "pthread_spin_unlock.c" -#include "pthread_spin_trylock.c" -#include "pthread_detach.c" -#include "pthread_join.c" -#include "pthread_key_create.c" -#include "pthread_key_delete.c" -#include "pthread_setspecific.c" -#include "pthread_getspecific.c" diff --git a/dependencies/win32_pthread/src/pthread_attr_destroy.c b/dependencies/win32_pthread/src/pthread_attr_destroy.c deleted file mode 100644 index 7bb0e320..00000000 --- a/dependencies/win32_pthread/src/pthread_attr_destroy.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * pthread_attr_destroy.c - * - * Description: - * This translation unit implements operations on thread attribute objects. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_attr_destroy (pthread_attr_t * attr) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * Destroys a thread attributes object. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_attr_t - * - * - * DESCRIPTION - * Destroys a thread attributes object. - * - * NOTES: - * 1) Does not affect threads created with 'attr'. - * - * RESULTS - * 0 successfully destroyed attr, - * EINVAL 'attr' is invalid. - * - * ------------------------------------------------------ - */ -{ - if (ptw32_is_attr (attr) != 0) - { - return EINVAL; - } - - /* - * Set the attribute object to a specific invalid value. - */ - (*attr)->valid = 0; - free (*attr); - *attr = NULL; - - return 0; -} diff --git a/dependencies/win32_pthread/src/pthread_attr_getdetachstate.c b/dependencies/win32_pthread/src/pthread_attr_getdetachstate.c deleted file mode 100644 index 93d61335..00000000 --- a/dependencies/win32_pthread/src/pthread_attr_getdetachstate.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * pthread_attr_getdetachstate.c - * - * Description: - * This translation unit implements operations on thread attribute objects. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_attr_getdetachstate (const pthread_attr_t * attr, int *detachstate) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function determines whether threads created with - * 'attr' will run detached. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_attr_t - * - * detachstate - * pointer to an integer into which is returned one - * of: - * - * PTHREAD_CREATE_JOINABLE - * Thread ID is valid, must be joined - * - * PTHREAD_CREATE_DETACHED - * Thread ID is invalid, cannot be joined, - * canceled, or modified - * - * - * DESCRIPTION - * This function determines whether threads created with - * 'attr' will run detached. - * - * NOTES: - * 1) You cannot join or cancel detached threads. - * - * RESULTS - * 0 successfully retrieved detach state, - * EINVAL 'attr' is invalid - * - * ------------------------------------------------------ - */ -{ - if (ptw32_is_attr (attr) != 0 || detachstate == NULL) - { - return EINVAL; - } - - *detachstate = (*attr)->detachstate; - return 0; -} diff --git a/dependencies/win32_pthread/src/pthread_attr_getinheritsched.c b/dependencies/win32_pthread/src/pthread_attr_getinheritsched.c deleted file mode 100644 index 657624cc..00000000 --- a/dependencies/win32_pthread/src/pthread_attr_getinheritsched.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * pthread_attr_getinheritsched.c - * - * Description: - * POSIX thread functions that deal with thread scheduling. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" -#include "sched.h" - -int -pthread_attr_getinheritsched (const pthread_attr_t * attr, int *inheritsched) -{ - if (ptw32_is_attr (attr) != 0 || inheritsched == NULL) - { - return EINVAL; - } - - *inheritsched = (*attr)->inheritsched; - return 0; -} diff --git a/dependencies/win32_pthread/src/pthread_attr_getschedparam.c b/dependencies/win32_pthread/src/pthread_attr_getschedparam.c deleted file mode 100644 index b7be1cba..00000000 --- a/dependencies/win32_pthread/src/pthread_attr_getschedparam.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * pthread_attr_getschedparam.c - * - * Description: - * POSIX thread functions that deal with thread scheduling. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" -#include "sched.h" - -int -pthread_attr_getschedparam (const pthread_attr_t * attr, - struct sched_param *param) -{ - if (ptw32_is_attr (attr) != 0 || param == NULL) - { - return EINVAL; - } - - memcpy (param, &(*attr)->param, sizeof (*param)); - return 0; -} diff --git a/dependencies/win32_pthread/src/pthread_attr_getschedpolicy.c b/dependencies/win32_pthread/src/pthread_attr_getschedpolicy.c deleted file mode 100644 index f27f5ee3..00000000 --- a/dependencies/win32_pthread/src/pthread_attr_getschedpolicy.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * pthread_attr_getschedpolicy.c - * - * Description: - * POSIX thread functions that deal with thread scheduling. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" -#include "sched.h" - -int -pthread_attr_getschedpolicy (const pthread_attr_t * attr, int *policy) -{ - if (ptw32_is_attr (attr) != 0 || policy == NULL) - { - return EINVAL; - } - - *policy = SCHED_OTHER; - - return 0; -} diff --git a/dependencies/win32_pthread/src/pthread_attr_getscope.c b/dependencies/win32_pthread/src/pthread_attr_getscope.c deleted file mode 100644 index c5c5f064..00000000 --- a/dependencies/win32_pthread/src/pthread_attr_getscope.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * pthread_attr_getscope.c - * - * Description: - * This translation unit implements operations on thread attribute objects. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -/* ignore warning "unreferenced formal parameter" */ -#if defined(_MSC_VER) -#pragma warning( disable : 4100 ) -#endif - -int -pthread_attr_getscope (const pthread_attr_t * attr, int *contentionscope) -{ -#if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) - *contentionscope = (*attr)->contentionscope; - return 0; -#else - return ENOSYS; -#endif -} diff --git a/dependencies/win32_pthread/src/pthread_attr_getstackaddr.c b/dependencies/win32_pthread/src/pthread_attr_getstackaddr.c deleted file mode 100644 index 17a7147f..00000000 --- a/dependencies/win32_pthread/src/pthread_attr_getstackaddr.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * pthread_attr_getstackaddr.c - * - * Description: - * This translation unit implements operations on thread attribute objects. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -/* ignore warning "unreferenced formal parameter" */ -#if defined(_MSC_VER) -#pragma warning( disable : 4100 ) -#endif - -int -pthread_attr_getstackaddr (const pthread_attr_t * attr, void **stackaddr) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function determines the address of the stack - * on which threads created with 'attr' will run. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_attr_t - * - * stackaddr - * pointer into which is returned the stack address. - * - * - * DESCRIPTION - * This function determines the address of the stack - * on which threads created with 'attr' will run. - * - * NOTES: - * 1) Function supported only if this macro is - * defined: - * - * _POSIX_THREAD_ATTR_STACKADDR - * - * 2) Create only one thread for each stack - * address.. - * - * RESULTS - * 0 successfully retreived stack address, - * EINVAL 'attr' is invalid - * ENOSYS function not supported - * - * ------------------------------------------------------ - */ -{ -#if defined( _POSIX_THREAD_ATTR_STACKADDR ) - - if (ptw32_is_attr (attr) != 0) - { - return EINVAL; - } - - *stackaddr = (*attr)->stackaddr; - return 0; - -#else - - return ENOSYS; - -#endif /* _POSIX_THREAD_ATTR_STACKADDR */ -} diff --git a/dependencies/win32_pthread/src/pthread_attr_getstacksize.c b/dependencies/win32_pthread/src/pthread_attr_getstacksize.c deleted file mode 100644 index f606afc4..00000000 --- a/dependencies/win32_pthread/src/pthread_attr_getstacksize.c +++ /dev/null @@ -1,105 +0,0 @@ -/* - * pthread_attr_getstacksize.c - * - * Description: - * This translation unit implements operations on thread attribute objects. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -/* ignore warning "unreferenced formal parameter" */ -#if defined(_MSC_VER) -#pragma warning( disable : 4100 ) -#endif - -int -pthread_attr_getstacksize (const pthread_attr_t * attr, size_t * stacksize) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function determines the size of the stack on - * which threads created with 'attr' will run. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_attr_t - * - * stacksize - * pointer to size_t into which is returned the - * stack size, in bytes. - * - * - * DESCRIPTION - * This function determines the size of the stack on - * which threads created with 'attr' will run. - * - * NOTES: - * 1) Function supported only if this macro is - * defined: - * - * _POSIX_THREAD_ATTR_STACKSIZE - * - * 2) Use on newly created attributes object to - * find the default stack size. - * - * RESULTS - * 0 successfully retrieved stack size, - * EINVAL 'attr' is invalid - * ENOSYS function not supported - * - * ------------------------------------------------------ - */ -{ -#if defined(_POSIX_THREAD_ATTR_STACKSIZE) - - if (ptw32_is_attr (attr) != 0) - { - return EINVAL; - } - - /* Everything is okay. */ - *stacksize = (*attr)->stacksize; - return 0; - -#else - - return ENOSYS; - -#endif /* _POSIX_THREAD_ATTR_STACKSIZE */ - -} diff --git a/dependencies/win32_pthread/src/pthread_attr_init.c b/dependencies/win32_pthread/src/pthread_attr_init.c deleted file mode 100644 index 49626dd0..00000000 --- a/dependencies/win32_pthread/src/pthread_attr_init.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * pthread_attr_init.c - * - * Description: - * This translation unit implements operations on thread attribute objects. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_attr_init (pthread_attr_t * attr) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * Initializes a thread attributes object with default - * attributes. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_attr_t - * - * - * DESCRIPTION - * Initializes a thread attributes object with default - * attributes. - * - * NOTES: - * 1) Used to define thread attributes - * - * RESULTS - * 0 successfully initialized attr, - * ENOMEM insufficient memory for attr. - * - * ------------------------------------------------------ - */ -{ - pthread_attr_t attr_result; - - if (attr == NULL) - { - /* This is disallowed. */ - return EINVAL; - } - - attr_result = (pthread_attr_t) malloc (sizeof (*attr_result)); - - if (attr_result == NULL) - { - return ENOMEM; - } - -#if defined(_POSIX_THREAD_ATTR_STACKSIZE) - /* - * Default to zero size. Unless changed explicitly this - * will allow Win32 to set the size to that of the - * main thread. - */ - attr_result->stacksize = 0; -#endif - -#if defined(_POSIX_THREAD_ATTR_STACKADDR) - /* FIXME: Set this to something sensible when we support it. */ - attr_result->stackaddr = NULL; -#endif - - attr_result->detachstate = PTHREAD_CREATE_JOINABLE; - -#if defined(HAVE_SIGSET_T) - memset (&(attr_result->sigmask), 0, sizeof (sigset_t)); -#endif /* HAVE_SIGSET_T */ - - /* - * Win32 sets new threads to THREAD_PRIORITY_NORMAL and - * not to that of the parent thread. We choose to default to - * this arrangement. - */ - attr_result->param.sched_priority = THREAD_PRIORITY_NORMAL; - attr_result->inheritsched = PTHREAD_EXPLICIT_SCHED; - attr_result->contentionscope = PTHREAD_SCOPE_SYSTEM; - - attr_result->valid = PTW32_ATTR_VALID; - - *attr = attr_result; - - return 0; -} diff --git a/dependencies/win32_pthread/src/pthread_attr_setdetachstate.c b/dependencies/win32_pthread/src/pthread_attr_setdetachstate.c deleted file mode 100644 index 02dd88bf..00000000 --- a/dependencies/win32_pthread/src/pthread_attr_setdetachstate.c +++ /dev/null @@ -1,96 +0,0 @@ -/* - * pthread_attr_setdetachstate.c - * - * Description: - * This translation unit implements operations on thread attribute objects. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_attr_setdetachstate (pthread_attr_t * attr, int detachstate) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function specifies whether threads created with - * 'attr' will run detached. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_attr_t - * - * detachstate - * an integer containing one of: - * - * PTHREAD_CREATE_JOINABLE - * Thread ID is valid, must be joined - * - * PTHREAD_CREATE_DETACHED - * Thread ID is invalid, cannot be joined, - * canceled, or modified - * - * - * DESCRIPTION - * This function specifies whether threads created with - * 'attr' will run detached. - * - * NOTES: - * 1) You cannot join or cancel detached threads. - * - * RESULTS - * 0 successfully set detach state, - * EINVAL 'attr' or 'detachstate' is invalid - * - * ------------------------------------------------------ - */ -{ - if (ptw32_is_attr (attr) != 0) - { - return EINVAL; - } - - if (detachstate != PTHREAD_CREATE_JOINABLE && - detachstate != PTHREAD_CREATE_DETACHED) - { - return EINVAL; - } - - (*attr)->detachstate = detachstate; - return 0; -} diff --git a/dependencies/win32_pthread/src/pthread_attr_setinheritsched.c b/dependencies/win32_pthread/src/pthread_attr_setinheritsched.c deleted file mode 100644 index d551190c..00000000 --- a/dependencies/win32_pthread/src/pthread_attr_setinheritsched.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * pthread_attr_setinheritsched.c - * - * Description: - * POSIX thread functions that deal with thread scheduling. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" -#include "sched.h" - -int -pthread_attr_setinheritsched (pthread_attr_t * attr, int inheritsched) -{ - if (ptw32_is_attr (attr) != 0) - { - return EINVAL; - } - - if (PTHREAD_INHERIT_SCHED != inheritsched - && PTHREAD_EXPLICIT_SCHED != inheritsched) - { - return EINVAL; - } - - (*attr)->inheritsched = inheritsched; - return 0; -} diff --git a/dependencies/win32_pthread/src/pthread_attr_setschedparam.c b/dependencies/win32_pthread/src/pthread_attr_setschedparam.c deleted file mode 100644 index 3505c9a5..00000000 --- a/dependencies/win32_pthread/src/pthread_attr_setschedparam.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * pthread_attr_setschedparam.c - * - * Description: - * POSIX thread functions that deal with thread scheduling. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" -#include "sched.h" - -int -pthread_attr_setschedparam (pthread_attr_t * attr, - const struct sched_param *param) -{ - int priority; - - if (ptw32_is_attr (attr) != 0 || param == NULL) - { - return EINVAL; - } - - priority = param->sched_priority; - - /* Validate priority level. */ - if (priority < sched_get_priority_min (SCHED_OTHER) || - priority > sched_get_priority_max (SCHED_OTHER)) - { - return EINVAL; - } - - memcpy (&(*attr)->param, param, sizeof (*param)); - return 0; -} diff --git a/dependencies/win32_pthread/src/pthread_attr_setschedpolicy.c b/dependencies/win32_pthread/src/pthread_attr_setschedpolicy.c deleted file mode 100644 index 5fe0c0c7..00000000 --- a/dependencies/win32_pthread/src/pthread_attr_setschedpolicy.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * pthread_attr_setschedpolicy.c - * - * Description: - * POSIX thread functions that deal with thread scheduling. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" -#include "sched.h" - -int -pthread_attr_setschedpolicy (pthread_attr_t * attr, int policy) -{ - if (ptw32_is_attr (attr) != 0) - { - return EINVAL; - } - - if (policy != SCHED_OTHER) - { - return ENOTSUP; - } - - return 0; -} diff --git a/dependencies/win32_pthread/src/pthread_attr_setscope.c b/dependencies/win32_pthread/src/pthread_attr_setscope.c deleted file mode 100644 index 96bc4941..00000000 --- a/dependencies/win32_pthread/src/pthread_attr_setscope.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * pthread_attr_setscope.c - * - * Description: - * This translation unit implements operations on thread attribute objects. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -/* ignore warning "unreferenced formal parameter" */ -#if defined(_MSC_VER) -#pragma warning( disable : 4100 ) -#endif - -int -pthread_attr_setscope (pthread_attr_t * attr, int contentionscope) -{ -#if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) - switch (contentionscope) - { - case PTHREAD_SCOPE_SYSTEM: - (*attr)->contentionscope = contentionscope; - return 0; - case PTHREAD_SCOPE_PROCESS: - return ENOTSUP; - default: - return EINVAL; - } -#else - return ENOSYS; -#endif -} diff --git a/dependencies/win32_pthread/src/pthread_attr_setstackaddr.c b/dependencies/win32_pthread/src/pthread_attr_setstackaddr.c deleted file mode 100644 index e527ec3d..00000000 --- a/dependencies/win32_pthread/src/pthread_attr_setstackaddr.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * pthread_attr_setstackaddr.c - * - * Description: - * This translation unit implements operations on thread attribute objects. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_attr_setstackaddr (pthread_attr_t * attr, void *stackaddr) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * Threads created with 'attr' will run on the stack - * starting at 'stackaddr'. - * Stack must be at least PTHREAD_STACK_MIN bytes. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_attr_t - * - * stackaddr - * the address of the stack to use - * - * - * DESCRIPTION - * Threads created with 'attr' will run on the stack - * starting at 'stackaddr'. - * Stack must be at least PTHREAD_STACK_MIN bytes. - * - * NOTES: - * 1) Function supported only if this macro is - * defined: - * - * _POSIX_THREAD_ATTR_STACKADDR - * - * 2) Create only one thread for each stack - * address.. - * - * 3) Ensure that stackaddr is aligned. - * - * RESULTS - * 0 successfully set stack address, - * EINVAL 'attr' is invalid - * ENOSYS function not supported - * - * ------------------------------------------------------ - */ -{ -#if defined( _POSIX_THREAD_ATTR_STACKADDR ) - - if (ptw32_is_attr (attr) != 0) - { - return EINVAL; - } - - (*attr)->stackaddr = stackaddr; - return 0; - -#else - - return ENOSYS; - -#endif /* _POSIX_THREAD_ATTR_STACKADDR */ -} diff --git a/dependencies/win32_pthread/src/pthread_attr_setstacksize.c b/dependencies/win32_pthread/src/pthread_attr_setstacksize.c deleted file mode 100644 index 5acec7e2..00000000 --- a/dependencies/win32_pthread/src/pthread_attr_setstacksize.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - * pthread_attr_setstacksize.c - * - * Description: - * This translation unit implements operations on thread attribute objects. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_attr_setstacksize (pthread_attr_t * attr, size_t stacksize) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function specifies the size of the stack on - * which threads created with 'attr' will run. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_attr_t - * - * stacksize - * stack size, in bytes. - * - * - * DESCRIPTION - * This function specifies the size of the stack on - * which threads created with 'attr' will run. - * - * NOTES: - * 1) Function supported only if this macro is - * defined: - * - * _POSIX_THREAD_ATTR_STACKSIZE - * - * 2) Find the default first (using - * pthread_attr_getstacksize), then increase - * by multiplying. - * - * 3) Only use if thread needs more than the - * default. - * - * RESULTS - * 0 successfully set stack size, - * EINVAL 'attr' is invalid or stacksize too - * small or too big. - * ENOSYS function not supported - * - * ------------------------------------------------------ - */ -{ -#if defined(_POSIX_THREAD_ATTR_STACKSIZE) - -#if PTHREAD_STACK_MIN > 0 - - /* Verify that the stack size is within range. */ - if (stacksize < PTHREAD_STACK_MIN) - { - return EINVAL; - } - -#endif - - if (ptw32_is_attr (attr) != 0) - { - return EINVAL; - } - - /* Everything is okay. */ - (*attr)->stacksize = stacksize; - return 0; - -#else - - return ENOSYS; - -#endif /* _POSIX_THREAD_ATTR_STACKSIZE */ - -} diff --git a/dependencies/win32_pthread/src/pthread_barrier_destroy.c b/dependencies/win32_pthread/src/pthread_barrier_destroy.c deleted file mode 100644 index 61cd0cda..00000000 --- a/dependencies/win32_pthread/src/pthread_barrier_destroy.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * pthread_barrier_destroy.c - * - * Description: - * This translation unit implements barrier primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -int -pthread_barrier_destroy (pthread_barrier_t * barrier) -{ - int result = 0; - pthread_barrier_t b; - ptw32_mcs_local_node_t node; - - if (barrier == NULL || *barrier == (pthread_barrier_t) PTW32_OBJECT_INVALID) - { - return EINVAL; - } - - if (0 != ptw32_mcs_lock_try_acquire(&(*barrier)->lock, &node)) - { - return EBUSY; - } - - b = *barrier; - - if (b->nCurrentBarrierHeight < b->nInitialBarrierHeight) - { - result = EBUSY; - } - else - { - if (0 == (result = sem_destroy (&(b->semBarrierBreeched)))) - { - *barrier = (pthread_barrier_t) PTW32_OBJECT_INVALID; - /* - * Release the lock before freeing b. - * - * FIXME: There may be successors which, when we release the lock, - * will be linked into b->lock, which will be corrupted at some - * point with undefined results for the application. To fix this - * will require changing pthread_barrier_t from a pointer to - * pthread_barrier_t_ to an instance. This is a change to the ABI - * and will require a major version number increment. - */ - ptw32_mcs_lock_release(&node); - (void) free (b); - return 0; - } - else - { - /* - * This should not ever be reached. - * Restore the barrier to working condition before returning. - */ - (void) sem_init (&(b->semBarrierBreeched), b->pshared, 0); - } - - if (result != 0) - { - /* - * The barrier still exists and is valid - * in the event of any error above. - */ - result = EBUSY; - } - } - - ptw32_mcs_lock_release(&node); - return (result); -} diff --git a/dependencies/win32_pthread/src/pthread_barrier_init.c b/dependencies/win32_pthread/src/pthread_barrier_init.c deleted file mode 100644 index bc76fcd7..00000000 --- a/dependencies/win32_pthread/src/pthread_barrier_init.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * pthread_barrier_init.c - * - * Description: - * This translation unit implements barrier primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_barrier_init (pthread_barrier_t * barrier, - const pthread_barrierattr_t * attr, unsigned int count) -{ - pthread_barrier_t b; - - if (barrier == NULL || count == 0) - { - return EINVAL; - } - - if (NULL != (b = (pthread_barrier_t) calloc (1, sizeof (*b)))) - { - b->pshared = (attr != NULL && *attr != NULL - ? (*attr)->pshared : PTHREAD_PROCESS_PRIVATE); - - b->nCurrentBarrierHeight = b->nInitialBarrierHeight = count; - b->lock = 0; - - if (0 == sem_init (&(b->semBarrierBreeched), b->pshared, 0)) - { - *barrier = b; - return 0; - } - (void) free (b); - } - - return ENOMEM; -} diff --git a/dependencies/win32_pthread/src/pthread_barrier_wait.c b/dependencies/win32_pthread/src/pthread_barrier_wait.c deleted file mode 100644 index 9d573afe..00000000 --- a/dependencies/win32_pthread/src/pthread_barrier_wait.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * pthread_barrier_wait.c - * - * Description: - * This translation unit implements barrier primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_barrier_wait (pthread_barrier_t * barrier) -{ - int result; - pthread_barrier_t b; - - ptw32_mcs_local_node_t node; - - if (barrier == NULL || *barrier == (pthread_barrier_t) PTW32_OBJECT_INVALID) - { - return EINVAL; - } - - ptw32_mcs_lock_acquire(&(*barrier)->lock, &node); - - b = *barrier; - if (--b->nCurrentBarrierHeight == 0) - { - /* - * We are the last thread to arrive at the barrier before it releases us. - * Move our MCS local node to the global scope barrier handle so that the - * last thread out (not necessarily us) can release the lock. - */ - ptw32_mcs_node_transfer(&b->proxynode, &node); - - /* - * Any threads that have not quite entered sem_wait below when the - * multiple_post has completed will nevertheless continue through - * the semaphore (barrier). - */ - result = (b->nInitialBarrierHeight > 1 - ? sem_post_multiple (&(b->semBarrierBreeched), - b->nInitialBarrierHeight - 1) : 0); - } - else - { - ptw32_mcs_lock_release(&node); - /* - * Use the non-cancelable version of sem_wait(). - * - * It is possible that all nInitialBarrierHeight-1 threads are - * at this point when the last thread enters the barrier, resets - * nCurrentBarrierHeight = nInitialBarrierHeight and leaves. - * If pthread_barrier_destroy is called at that moment then the - * barrier will be destroyed along with the semas. - */ - result = ptw32_semwait (&(b->semBarrierBreeched)); - } - - if ((PTW32_INTERLOCKED_LONG)PTW32_INTERLOCKED_INCREMENT_LONG((PTW32_INTERLOCKED_LONGPTR)&b->nCurrentBarrierHeight) - == (PTW32_INTERLOCKED_LONG)b->nInitialBarrierHeight) - { - /* - * We are the last thread to cross this barrier - */ - ptw32_mcs_lock_release(&b->proxynode); - if (0 == result) - { - result = PTHREAD_BARRIER_SERIAL_THREAD; - } - } - - return (result); -} diff --git a/dependencies/win32_pthread/src/pthread_barrierattr_destroy.c b/dependencies/win32_pthread/src/pthread_barrierattr_destroy.c deleted file mode 100644 index d8953a9b..00000000 --- a/dependencies/win32_pthread/src/pthread_barrierattr_destroy.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * pthread_barrier_attr_destroy.c - * - * Description: - * This translation unit implements barrier primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_barrierattr_destroy (pthread_barrierattr_t * attr) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * Destroys a barrier attributes object. The object can - * no longer be used. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_barrierattr_t - * - * - * DESCRIPTION - * Destroys a barrier attributes object. The object can - * no longer be used. - * - * NOTES: - * 1) Does not affect barrieres created using 'attr' - * - * RESULTS - * 0 successfully released attr, - * EINVAL 'attr' is invalid. - * - * ------------------------------------------------------ - */ -{ - int result = 0; - - if (attr == NULL || *attr == NULL) - { - result = EINVAL; - } - else - { - pthread_barrierattr_t ba = *attr; - - *attr = NULL; - free (ba); - } - - return (result); -} /* pthread_barrierattr_destroy */ diff --git a/dependencies/win32_pthread/src/pthread_barrierattr_getpshared.c b/dependencies/win32_pthread/src/pthread_barrierattr_getpshared.c deleted file mode 100644 index 7d9736c0..00000000 --- a/dependencies/win32_pthread/src/pthread_barrierattr_getpshared.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * pthread_barrier_attr_getpshared.c - * - * Description: - * This translation unit implements barrier primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_barrierattr_getpshared (const pthread_barrierattr_t * attr, - int *pshared) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * Determine whether barriers created with 'attr' can be - * shared between processes. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_barrierattr_t - * - * pshared - * will be set to one of: - * - * PTHREAD_PROCESS_SHARED - * May be shared if in shared memory - * - * PTHREAD_PROCESS_PRIVATE - * Cannot be shared. - * - * - * DESCRIPTION - * Mutexes creatd with 'attr' can be shared between - * processes if pthread_barrier_t variable is allocated - * in memory shared by these processes. - * NOTES: - * 1) pshared barriers MUST be allocated in shared - * memory. - * 2) The following macro is defined if shared barriers - * are supported: - * _POSIX_THREAD_PROCESS_SHARED - * - * RESULTS - * 0 successfully retrieved attribute, - * EINVAL 'attr' is invalid, - * - * ------------------------------------------------------ - */ -{ - int result; - - if ((attr != NULL && *attr != NULL) && (pshared != NULL)) - { - *pshared = (*attr)->pshared; - result = 0; - } - else - { - result = EINVAL; - } - - return (result); -} /* pthread_barrierattr_getpshared */ diff --git a/dependencies/win32_pthread/src/pthread_barrierattr_init.c b/dependencies/win32_pthread/src/pthread_barrierattr_init.c deleted file mode 100644 index aef72b4f..00000000 --- a/dependencies/win32_pthread/src/pthread_barrierattr_init.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * pthread_barrier_attr_init.c - * - * Description: - * This translation unit implements barrier primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_barrierattr_init (pthread_barrierattr_t * attr) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * Initializes a barrier attributes object with default - * attributes. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_barrierattr_t - * - * - * DESCRIPTION - * Initializes a barrier attributes object with default - * attributes. - * - * NOTES: - * 1) Used to define barrier types - * - * RESULTS - * 0 successfully initialized attr, - * ENOMEM insufficient memory for attr. - * - * ------------------------------------------------------ - */ -{ - pthread_barrierattr_t ba; - int result = 0; - - ba = (pthread_barrierattr_t) calloc (1, sizeof (*ba)); - - if (ba == NULL) - { - result = ENOMEM; - } - else - { - ba->pshared = PTHREAD_PROCESS_PRIVATE; - } - - *attr = ba; - - return (result); -} /* pthread_barrierattr_init */ diff --git a/dependencies/win32_pthread/src/pthread_barrierattr_setpshared.c b/dependencies/win32_pthread/src/pthread_barrierattr_setpshared.c deleted file mode 100644 index 7f5dc549..00000000 --- a/dependencies/win32_pthread/src/pthread_barrierattr_setpshared.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * pthread_barrier_attr_setpshared.c - * - * Description: - * This translation unit implements barrier primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_barrierattr_setpshared (pthread_barrierattr_t * attr, int pshared) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * Barriers created with 'attr' can be shared between - * processes if pthread_barrier_t variable is allocated - * in memory shared by these processes. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_barrierattr_t - * - * pshared - * must be one of: - * - * PTHREAD_PROCESS_SHARED - * May be shared if in shared memory - * - * PTHREAD_PROCESS_PRIVATE - * Cannot be shared. - * - * DESCRIPTION - * Mutexes creatd with 'attr' can be shared between - * processes if pthread_barrier_t variable is allocated - * in memory shared by these processes. - * - * NOTES: - * 1) pshared barriers MUST be allocated in shared - * memory. - * - * 2) The following macro is defined if shared barriers - * are supported: - * _POSIX_THREAD_PROCESS_SHARED - * - * RESULTS - * 0 successfully set attribute, - * EINVAL 'attr' or pshared is invalid, - * ENOSYS PTHREAD_PROCESS_SHARED not supported, - * - * ------------------------------------------------------ - */ -{ - int result; - - if ((attr != NULL && *attr != NULL) && - ((pshared == PTHREAD_PROCESS_SHARED) || - (pshared == PTHREAD_PROCESS_PRIVATE))) - { - if (pshared == PTHREAD_PROCESS_SHARED) - { - -#if !defined( _POSIX_THREAD_PROCESS_SHARED ) - - result = ENOSYS; - pshared = PTHREAD_PROCESS_PRIVATE; - -#else - - result = 0; - -#endif /* _POSIX_THREAD_PROCESS_SHARED */ - - } - else - { - result = 0; - } - - (*attr)->pshared = pshared; - } - else - { - result = EINVAL; - } - - return (result); - -} /* pthread_barrierattr_setpshared */ diff --git a/dependencies/win32_pthread/src/pthread_cancel.c b/dependencies/win32_pthread/src/pthread_cancel.c deleted file mode 100644 index ec001a32..00000000 --- a/dependencies/win32_pthread/src/pthread_cancel.c +++ /dev/null @@ -1,194 +0,0 @@ -/* - * pthread_cancel.c - * - * Description: - * POSIX thread functions related to thread cancellation. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" -#include "context.h" - -static void -ptw32_cancel_self (void) -{ - ptw32_throw (PTW32_EPS_CANCEL); - - /* Never reached */ -} - -static void CALLBACK -ptw32_cancel_callback (ULONG_PTR unused) -{ - ptw32_throw (PTW32_EPS_CANCEL); - - /* Never reached */ -} - -/* - * ptw32_RegisterCancellation() - - * Must have args of same type as QueueUserAPCEx because this function - * is a substitute for QueueUserAPCEx if it's not available. - */ -DWORD -ptw32_RegisterCancellation (PAPCFUNC unused1, HANDLE threadH, DWORD unused2) -{ - CONTEXT context; - - context.ContextFlags = CONTEXT_CONTROL; - GetThreadContext (threadH, &context); - PTW32_PROGCTR (context) = (DWORD_PTR) ptw32_cancel_self; - SetThreadContext (threadH, &context); - return 0; -} - -int -pthread_cancel (pthread_t thread) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function requests cancellation of 'thread'. - * - * PARAMETERS - * thread - * reference to an instance of pthread_t - * - * - * DESCRIPTION - * This function requests cancellation of 'thread'. - * NOTE: cancellation is asynchronous; use pthread_join to - * wait for termination of 'thread' if necessary. - * - * RESULTS - * 0 successfully requested cancellation, - * ESRCH no thread found corresponding to 'thread', - * ENOMEM implicit self thread create failed. - * ------------------------------------------------------ - */ -{ - int result; - int cancel_self; - pthread_t self; - ptw32_thread_t * tp; - ptw32_mcs_local_node_t stateLock; - - result = pthread_kill (thread, 0); - - if (0 != result) - { - return result; - } - - if ((self = pthread_self ()).p == NULL) - { - return ENOMEM; - }; - - /* - * For self cancellation we need to ensure that a thread can't - * deadlock itself trying to cancel itself asynchronously - * (pthread_cancel is required to be an async-cancel - * safe function). - */ - cancel_self = pthread_equal (thread, self); - - tp = (ptw32_thread_t *) thread.p; - - /* - * Lock for async-cancel safety. - */ - ptw32_mcs_lock_acquire (&tp->stateLock, &stateLock); - - if (tp->cancelType == PTHREAD_CANCEL_ASYNCHRONOUS - && tp->cancelState == PTHREAD_CANCEL_ENABLE - && tp->state < PThreadStateCanceling) - { - if (cancel_self) - { - tp->state = PThreadStateCanceling; - tp->cancelState = PTHREAD_CANCEL_DISABLE; - - ptw32_mcs_lock_release (&stateLock); - ptw32_throw (PTW32_EPS_CANCEL); - - /* Never reached */ - } - else - { - HANDLE threadH = tp->threadH; - - SuspendThread (threadH); - - if (WaitForSingleObject (threadH, 0) == WAIT_TIMEOUT) - { - tp->state = PThreadStateCanceling; - tp->cancelState = PTHREAD_CANCEL_DISABLE; - /* - * If alertdrv and QueueUserAPCEx is available then the following - * will result in a call to QueueUserAPCEx with the args given, otherwise - * this will result in a call to ptw32_RegisterCancellation and only - * the threadH arg will be used. - */ - ptw32_register_cancellation ((PAPCFUNC)ptw32_cancel_callback, threadH, 0); - ptw32_mcs_lock_release (&stateLock); - ResumeThread (threadH); - } - } - } - else - { - /* - * Set for deferred cancellation. - */ - if (tp->state < PThreadStateCancelPending) - { - tp->state = PThreadStateCancelPending; - if (!SetEvent (tp->cancelEvent)) - { - result = ESRCH; - } - } - else if (tp->state >= PThreadStateCanceling) - { - result = ESRCH; - } - - ptw32_mcs_lock_release (&stateLock); - } - - return (result); -} diff --git a/dependencies/win32_pthread/src/pthread_cond_destroy.c b/dependencies/win32_pthread/src/pthread_cond_destroy.c deleted file mode 100644 index 12e76330..00000000 --- a/dependencies/win32_pthread/src/pthread_cond_destroy.c +++ /dev/null @@ -1,258 +0,0 @@ -/* - * pthread_cond_destroy.c - * - * Description: - * This translation unit implements condition variables and their primitives. - * - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -int -pthread_cond_destroy (pthread_cond_t * cond) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function destroys a condition variable - * - * - * PARAMETERS - * cond - * pointer to an instance of pthread_cond_t - * - * - * DESCRIPTION - * This function destroys a condition variable. - * - * NOTES: - * 1) A condition variable can be destroyed - * immediately after all the threads that - * are blocked on it are awakened. e.g. - * - * struct list { - * pthread_mutex_t lm; - * ... - * } - * - * struct elt { - * key k; - * int busy; - * pthread_cond_t notbusy; - * ... - * } - * - * - * struct elt * - * list_find(struct list *lp, key k) - * { - * struct elt *ep; - * - * pthread_mutex_lock(&lp->lm); - * while ((ep = find_elt(l,k) != NULL) && ep->busy) - * pthread_cond_wait(&ep->notbusy, &lp->lm); - * if (ep != NULL) - * ep->busy = 1; - * pthread_mutex_unlock(&lp->lm); - * return(ep); - * } - * - * delete_elt(struct list *lp, struct elt *ep) - * { - * pthread_mutex_lock(&lp->lm); - * assert(ep->busy); - * ... remove ep from list ... - * ep->busy = 0; - * (A) pthread_cond_broadcast(&ep->notbusy); - * pthread_mutex_unlock(&lp->lm); - * (B) pthread_cond_destroy(&rp->notbusy); - * free(ep); - * } - * - * In this example, the condition variable - * and its list element may be freed (line B) - * immediately after all threads waiting for - * it are awakened (line A), since the mutex - * and the code ensure that no other thread - * can touch the element to be deleted. - * - * RESULTS - * 0 successfully released condition variable, - * EINVAL 'cond' is invalid, - * EBUSY 'cond' is in use, - * - * ------------------------------------------------------ - */ -{ - pthread_cond_t cv; - int result = 0, result1 = 0, result2 = 0; - - /* - * Assuming any race condition here is harmless. - */ - if (cond == NULL || *cond == NULL) - { - return EINVAL; - } - - if (*cond != PTHREAD_COND_INITIALIZER) - { - ptw32_mcs_local_node_t node; - ptw32_mcs_lock_acquire(&ptw32_cond_list_lock, &node); - - cv = *cond; - - /* - * Close the gate; this will synchronize this thread with - * all already signaled waiters to let them retract their - * waiter status - SEE NOTE 1 ABOVE!!! - */ - if (ptw32_semwait (&(cv->semBlockLock)) != 0) /* Non-cancelable */ - { - result = PTW32_GET_ERRNO(); - } - else - { - /* - * !TRY! lock mtxUnblockLock; try will detect busy condition - * and will not cause a deadlock with respect to concurrent - * signal/broadcast. - */ - if ((result = pthread_mutex_trylock (&(cv->mtxUnblockLock))) != 0) - { - (void) sem_post (&(cv->semBlockLock)); - } - } - - if (result != 0) - { - ptw32_mcs_lock_release(&node); - return result; - } - - /* - * Check whether cv is still busy (still has waiters) - */ - if (cv->nWaitersBlocked > cv->nWaitersGone) - { - if (sem_post (&(cv->semBlockLock)) != 0) - { - result = PTW32_GET_ERRNO(); - } - result1 = pthread_mutex_unlock (&(cv->mtxUnblockLock)); - result2 = EBUSY; - } - else - { - /* - * Now it is safe to destroy - */ - *cond = NULL; - - if (sem_destroy (&(cv->semBlockLock)) != 0) - { - result = PTW32_GET_ERRNO(); - } - if (sem_destroy (&(cv->semBlockQueue)) != 0) - { - result1 = PTW32_GET_ERRNO(); - } - if ((result2 = pthread_mutex_unlock (&(cv->mtxUnblockLock))) == 0) - { - result2 = pthread_mutex_destroy (&(cv->mtxUnblockLock)); - } - - /* Unlink the CV from the list */ - - if (ptw32_cond_list_head == cv) - { - ptw32_cond_list_head = cv->next; - } - else - { - cv->prev->next = cv->next; - } - - if (ptw32_cond_list_tail == cv) - { - ptw32_cond_list_tail = cv->prev; - } - else - { - cv->next->prev = cv->prev; - } - - (void) free (cv); - } - - ptw32_mcs_lock_release(&node); - } - else - { - ptw32_mcs_local_node_t node; - /* - * See notes in ptw32_cond_check_need_init() above also. - */ - ptw32_mcs_lock_acquire(&ptw32_cond_test_init_lock, &node); - - /* - * Check again. - */ - if (*cond == PTHREAD_COND_INITIALIZER) - { - /* - * This is all we need to do to destroy a statically - * initialised cond that has not yet been used (initialised). - * If we get to here, another thread waiting to initialise - * this cond will get an EINVAL. That's OK. - */ - *cond = NULL; - } - else - { - /* - * The cv has been initialised while we were waiting - * so assume it's in use. - */ - result = EBUSY; - } - - ptw32_mcs_lock_release(&node); - } - - return ((result != 0) ? result : ((result1 != 0) ? result1 : result2)); -} diff --git a/dependencies/win32_pthread/src/pthread_cond_init.c b/dependencies/win32_pthread/src/pthread_cond_init.c deleted file mode 100644 index b9379a37..00000000 --- a/dependencies/win32_pthread/src/pthread_cond_init.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - * pthread_cond_init.c - * - * Description: - * This translation unit implements condition variables and their primitives. - * - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_cond_init (pthread_cond_t * cond, const pthread_condattr_t * attr) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function initializes a condition variable. - * - * PARAMETERS - * cond - * pointer to an instance of pthread_cond_t - * - * attr - * specifies optional creation attributes. - * - * - * DESCRIPTION - * This function initializes a condition variable. - * - * RESULTS - * 0 successfully created condition variable, - * EINVAL 'attr' is invalid, - * EAGAIN insufficient resources (other than - * memory, - * ENOMEM insufficient memory, - * EBUSY 'cond' is already initialized, - * - * ------------------------------------------------------ - */ -{ - int result; - pthread_cond_t cv = NULL; - - if (cond == NULL) - { - return EINVAL; - } - - if ((attr != NULL && *attr != NULL) && - ((*attr)->pshared == PTHREAD_PROCESS_SHARED)) - { - /* - * Creating condition variable that can be shared between - * processes. - */ - result = ENOSYS; - goto DONE; - } - - cv = (pthread_cond_t) calloc (1, sizeof (*cv)); - - if (cv == NULL) - { - result = ENOMEM; - goto DONE; - } - - cv->nWaitersBlocked = 0; - cv->nWaitersToUnblock = 0; - cv->nWaitersGone = 0; - - if (sem_init (&(cv->semBlockLock), 0, 1) != 0) - { - result = PTW32_GET_ERRNO(); - goto FAIL0; - } - - if (sem_init (&(cv->semBlockQueue), 0, 0) != 0) - { - result = PTW32_GET_ERRNO(); - goto FAIL1; - } - - if ((result = pthread_mutex_init (&(cv->mtxUnblockLock), 0)) != 0) - { - goto FAIL2; - } - - result = 0; - - goto DONE; - - /* - * ------------- - * Failed... - * ------------- - */ -FAIL2: - (void) sem_destroy (&(cv->semBlockQueue)); - -FAIL1: - (void) sem_destroy (&(cv->semBlockLock)); - -FAIL0: - (void) free (cv); - cv = NULL; - -DONE: - if (0 == result) - { - ptw32_mcs_local_node_t node; - - ptw32_mcs_lock_acquire(&ptw32_cond_list_lock, &node); - - cv->next = NULL; - cv->prev = ptw32_cond_list_tail; - - if (ptw32_cond_list_tail != NULL) - { - ptw32_cond_list_tail->next = cv; - } - - ptw32_cond_list_tail = cv; - - if (ptw32_cond_list_head == NULL) - { - ptw32_cond_list_head = cv; - } - - ptw32_mcs_lock_release(&node); - } - - *cond = cv; - - return result; - -} /* pthread_cond_init */ diff --git a/dependencies/win32_pthread/src/pthread_cond_signal.c b/dependencies/win32_pthread/src/pthread_cond_signal.c deleted file mode 100644 index 6c9a1c1c..00000000 --- a/dependencies/win32_pthread/src/pthread_cond_signal.c +++ /dev/null @@ -1,236 +0,0 @@ -/* - * pthread_cond_signal.c - * - * Description: - * This translation unit implements condition variables and their primitives. - * - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * ------------------------------------------------------------- - * Algorithm: - * See the comments at the top of pthread_cond_wait.c. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -static INLINE int -ptw32_cond_unblock (pthread_cond_t * cond, int unblockAll) - /* - * Notes. - * - * Does not use the external mutex for synchronisation, - * therefore semBlockLock is needed. - * mtxUnblockLock is for LEVEL-2 synch. LEVEL-2 is the - * state where the external mutex is not necessarily locked by - * any thread, ie. between cond_wait unlocking and re-acquiring - * the lock after having been signaled or a timeout or - * cancellation. - * - * Uses the following CV elements: - * nWaitersBlocked - * nWaitersToUnblock - * nWaitersGone - * mtxUnblockLock - * semBlockLock - * semBlockQueue - */ -{ - int result; - pthread_cond_t cv; - int nSignalsToIssue; - - if (cond == NULL || *cond == NULL) - { - return EINVAL; - } - - cv = *cond; - - /* - * No-op if the CV is static and hasn't been initialised yet. - * Assuming that any race condition is harmless. - */ - if (cv == PTHREAD_COND_INITIALIZER) - { - return 0; - } - - if ((result = pthread_mutex_lock (&(cv->mtxUnblockLock))) != 0) - { - return result; - } - - if (0 != cv->nWaitersToUnblock) - { - if (0 == cv->nWaitersBlocked) - { - return pthread_mutex_unlock (&(cv->mtxUnblockLock)); - } - if (unblockAll) - { - cv->nWaitersToUnblock += (nSignalsToIssue = cv->nWaitersBlocked); - cv->nWaitersBlocked = 0; - } - else - { - nSignalsToIssue = 1; - cv->nWaitersToUnblock++; - cv->nWaitersBlocked--; - } - } - else if (cv->nWaitersBlocked > cv->nWaitersGone) - { - /* Use the non-cancellable version of sem_wait() */ - if (ptw32_semwait (&(cv->semBlockLock)) != 0) - { - result = PTW32_GET_ERRNO(); - (void) pthread_mutex_unlock (&(cv->mtxUnblockLock)); - return result; - } - if (0 != cv->nWaitersGone) - { - cv->nWaitersBlocked -= cv->nWaitersGone; - cv->nWaitersGone = 0; - } - if (unblockAll) - { - nSignalsToIssue = cv->nWaitersToUnblock = cv->nWaitersBlocked; - cv->nWaitersBlocked = 0; - } - else - { - nSignalsToIssue = cv->nWaitersToUnblock = 1; - cv->nWaitersBlocked--; - } - } - else - { - return pthread_mutex_unlock (&(cv->mtxUnblockLock)); - } - - if ((result = pthread_mutex_unlock (&(cv->mtxUnblockLock))) == 0) - { - if (sem_post_multiple (&(cv->semBlockQueue), nSignalsToIssue) != 0) - { - result = PTW32_GET_ERRNO(); - } - } - - return result; - -} /* ptw32_cond_unblock */ - -int -pthread_cond_signal (pthread_cond_t * cond) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function signals a condition variable, waking - * one waiting thread. - * If SCHED_FIFO or SCHED_RR policy threads are waiting - * the highest priority waiter is awakened; otherwise, - * an unspecified waiter is awakened. - * - * PARAMETERS - * cond - * pointer to an instance of pthread_cond_t - * - * - * DESCRIPTION - * This function signals a condition variable, waking - * one waiting thread. - * If SCHED_FIFO or SCHED_RR policy threads are waiting - * the highest priority waiter is awakened; otherwise, - * an unspecified waiter is awakened. - * - * NOTES: - * - * 1) Use when any waiter can respond and only one need - * respond (all waiters being equal). - * - * RESULTS - * 0 successfully signaled condition, - * EINVAL 'cond' is invalid, - * - * ------------------------------------------------------ - */ -{ - /* - * The '0'(FALSE) unblockAll arg means unblock ONE waiter. - */ - return (ptw32_cond_unblock (cond, 0)); - -} /* pthread_cond_signal */ - -int -pthread_cond_broadcast (pthread_cond_t * cond) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function broadcasts the condition variable, - * waking all current waiters. - * - * PARAMETERS - * cond - * pointer to an instance of pthread_cond_t - * - * - * DESCRIPTION - * This function signals a condition variable, waking - * all waiting threads. - * - * NOTES: - * - * 1) Use when more than one waiter may respond to - * predicate change or if any waiting thread may - * not be able to respond - * - * RESULTS - * 0 successfully signalled condition to all - * waiting threads, - * EINVAL 'cond' is invalid - * ENOSPC a required resource has been exhausted, - * - * ------------------------------------------------------ - */ -{ - /* - * The TRUE unblockAll arg means unblock ALL waiters. - */ - return (ptw32_cond_unblock (cond, PTW32_TRUE)); - -} /* pthread_cond_broadcast */ diff --git a/dependencies/win32_pthread/src/pthread_cond_wait.c b/dependencies/win32_pthread/src/pthread_cond_wait.c deleted file mode 100644 index 0dd695cb..00000000 --- a/dependencies/win32_pthread/src/pthread_cond_wait.c +++ /dev/null @@ -1,571 +0,0 @@ -/* - * pthread_cond_wait.c - * - * Description: - * This translation unit implements condition variables and their primitives. - * - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * ------------------------------------------------------------- - * Algorithm: - * The algorithm used in this implementation is that developed by - * Alexander Terekhov in colaboration with Louis Thomas. The bulk - * of the discussion is recorded in the file README.CV, which contains - * several generations of both colaborators original algorithms. The final - * algorithm used here is the one referred to as - * - * Algorithm 8a / IMPL_SEM,UNBLOCK_STRATEGY == UNBLOCK_ALL - * - * presented below in pseudo-code as it appeared: - * - * - * given: - * semBlockLock - bin.semaphore - * semBlockQueue - semaphore - * mtxExternal - mutex or CS - * mtxUnblockLock - mutex or CS - * nWaitersGone - int - * nWaitersBlocked - int - * nWaitersToUnblock - int - * - * wait( timeout ) { - * - * [auto: register int result ] // error checking omitted - * [auto: register int nSignalsWasLeft ] - * [auto: register int nWaitersWasGone ] - * - * sem_wait( semBlockLock ); - * nWaitersBlocked++; - * sem_post( semBlockLock ); - * - * unlock( mtxExternal ); - * bTimedOut = sem_wait( semBlockQueue,timeout ); - * - * lock( mtxUnblockLock ); - * if ( 0 != (nSignalsWasLeft = nWaitersToUnblock) ) { - * if ( bTimeout ) { // timeout (or canceled) - * if ( 0 != nWaitersBlocked ) { - * nWaitersBlocked--; - * } - * else { - * nWaitersGone++; // count spurious wakeups. - * } - * } - * if ( 0 == --nWaitersToUnblock ) { - * if ( 0 != nWaitersBlocked ) { - * sem_post( semBlockLock ); // open the gate. - * nSignalsWasLeft = 0; // do not open the gate - * // below again. - * } - * else if ( 0 != (nWaitersWasGone = nWaitersGone) ) { - * nWaitersGone = 0; - * } - * } - * } - * else if ( INT_MAX/2 == ++nWaitersGone ) { // timeout/canceled or - * // spurious semaphore :-) - * sem_wait( semBlockLock ); - * nWaitersBlocked -= nWaitersGone; // something is going on here - * // - test of timeouts? :-) - * sem_post( semBlockLock ); - * nWaitersGone = 0; - * } - * unlock( mtxUnblockLock ); - * - * if ( 1 == nSignalsWasLeft ) { - * if ( 0 != nWaitersWasGone ) { - * // sem_adjust( semBlockQueue,-nWaitersWasGone ); - * while ( nWaitersWasGone-- ) { - * sem_wait( semBlockQueue ); // better now than spurious later - * } - * } sem_post( semBlockLock ); // open the gate - * } - * - * lock( mtxExternal ); - * - * return ( bTimedOut ) ? ETIMEOUT : 0; - * } - * - * signal(bAll) { - * - * [auto: register int result ] - * [auto: register int nSignalsToIssue] - * - * lock( mtxUnblockLock ); - * - * if ( 0 != nWaitersToUnblock ) { // the gate is closed!!! - * if ( 0 == nWaitersBlocked ) { // NO-OP - * return unlock( mtxUnblockLock ); - * } - * if (bAll) { - * nWaitersToUnblock += nSignalsToIssue=nWaitersBlocked; - * nWaitersBlocked = 0; - * } - * else { - * nSignalsToIssue = 1; - * nWaitersToUnblock++; - * nWaitersBlocked--; - * } - * } - * else if ( nWaitersBlocked > nWaitersGone ) { // HARMLESS RACE CONDITION! - * sem_wait( semBlockLock ); // close the gate - * if ( 0 != nWaitersGone ) { - * nWaitersBlocked -= nWaitersGone; - * nWaitersGone = 0; - * } - * if (bAll) { - * nSignalsToIssue = nWaitersToUnblock = nWaitersBlocked; - * nWaitersBlocked = 0; - * } - * else { - * nSignalsToIssue = nWaitersToUnblock = 1; - * nWaitersBlocked--; - * } - * } - * else { // NO-OP - * return unlock( mtxUnblockLock ); - * } - * - * unlock( mtxUnblockLock ); - * sem_post( semBlockQueue,nSignalsToIssue ); - * return result; - * } - * ------------------------------------------------------------- - * - * Algorithm 9 / IMPL_SEM,UNBLOCK_STRATEGY == UNBLOCK_ALL - * - * presented below in pseudo-code; basically 8a... - * ...BUT W/O "spurious wakes" prevention: - * - * - * given: - * semBlockLock - bin.semaphore - * semBlockQueue - semaphore - * mtxExternal - mutex or CS - * mtxUnblockLock - mutex or CS - * nWaitersGone - int - * nWaitersBlocked - int - * nWaitersToUnblock - int - * - * wait( timeout ) { - * - * [auto: register int result ] // error checking omitted - * [auto: register int nSignalsWasLeft ] - * - * sem_wait( semBlockLock ); - * ++nWaitersBlocked; - * sem_post( semBlockLock ); - * - * unlock( mtxExternal ); - * bTimedOut = sem_wait( semBlockQueue,timeout ); - * - * lock( mtxUnblockLock ); - * if ( 0 != (nSignalsWasLeft = nWaitersToUnblock) ) { - * --nWaitersToUnblock; - * } - * else if ( INT_MAX/2 == ++nWaitersGone ) { // timeout/canceled or - * // spurious semaphore :-) - * sem_wait( semBlockLock ); - * nWaitersBlocked -= nWaitersGone; // something is going on here - * // - test of timeouts? :-) - * sem_post( semBlockLock ); - * nWaitersGone = 0; - * } - * unlock( mtxUnblockLock ); - * - * if ( 1 == nSignalsWasLeft ) { - * sem_post( semBlockLock ); // open the gate - * } - * - * lock( mtxExternal ); - * - * return ( bTimedOut ) ? ETIMEOUT : 0; - * } - * - * signal(bAll) { - * - * [auto: register int result ] - * [auto: register int nSignalsToIssue] - * - * lock( mtxUnblockLock ); - * - * if ( 0 != nWaitersToUnblock ) { // the gate is closed!!! - * if ( 0 == nWaitersBlocked ) { // NO-OP - * return unlock( mtxUnblockLock ); - * } - * if (bAll) { - * nWaitersToUnblock += nSignalsToIssue=nWaitersBlocked; - * nWaitersBlocked = 0; - * } - * else { - * nSignalsToIssue = 1; - * ++nWaitersToUnblock; - * --nWaitersBlocked; - * } - * } - * else if ( nWaitersBlocked > nWaitersGone ) { // HARMLESS RACE CONDITION! - * sem_wait( semBlockLock ); // close the gate - * if ( 0 != nWaitersGone ) { - * nWaitersBlocked -= nWaitersGone; - * nWaitersGone = 0; - * } - * if (bAll) { - * nSignalsToIssue = nWaitersToUnblock = nWaitersBlocked; - * nWaitersBlocked = 0; - * } - * else { - * nSignalsToIssue = nWaitersToUnblock = 1; - * --nWaitersBlocked; - * } - * } - * else { // NO-OP - * return unlock( mtxUnblockLock ); - * } - * - * unlock( mtxUnblockLock ); - * sem_post( semBlockQueue,nSignalsToIssue ); - * return result; - * } - * ------------------------------------------------------------- - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -/* - * Arguments for cond_wait_cleanup, since we can only pass a - * single void * to it. - */ -typedef struct -{ - pthread_mutex_t *mutexPtr; - pthread_cond_t cv; - int *resultPtr; -} ptw32_cond_wait_cleanup_args_t; - -static void PTW32_CDECL -ptw32_cond_wait_cleanup (void *args) -{ - ptw32_cond_wait_cleanup_args_t *cleanup_args = - (ptw32_cond_wait_cleanup_args_t *) args; - pthread_cond_t cv = cleanup_args->cv; - int *resultPtr = cleanup_args->resultPtr; - int nSignalsWasLeft; - int result; - - /* - * Whether we got here as a result of signal/broadcast or because of - * timeout on wait or thread cancellation we indicate that we are no - * longer waiting. The waiter is responsible for adjusting waiters - * (to)unblock(ed) counts (protected by unblock lock). - */ - if ((result = pthread_mutex_lock (&(cv->mtxUnblockLock))) != 0) - { - *resultPtr = result; - return; - } - - if (0 != (nSignalsWasLeft = cv->nWaitersToUnblock)) - { - --(cv->nWaitersToUnblock); - } - else if (INT_MAX / 2 == ++(cv->nWaitersGone)) - { - /* Use the non-cancellable version of sem_wait() */ - if (ptw32_semwait (&(cv->semBlockLock)) != 0) - { - *resultPtr = PTW32_GET_ERRNO(); - /* - * This is a fatal error for this CV, - * so we deliberately don't unlock - * cv->mtxUnblockLock before returning. - */ - return; - } - cv->nWaitersBlocked -= cv->nWaitersGone; - if (sem_post (&(cv->semBlockLock)) != 0) - { - *resultPtr = PTW32_GET_ERRNO(); - /* - * This is a fatal error for this CV, - * so we deliberately don't unlock - * cv->mtxUnblockLock before returning. - */ - return; - } - cv->nWaitersGone = 0; - } - - if ((result = pthread_mutex_unlock (&(cv->mtxUnblockLock))) != 0) - { - *resultPtr = result; - return; - } - - if (1 == nSignalsWasLeft) - { - if (sem_post (&(cv->semBlockLock)) != 0) - { - *resultPtr = PTW32_GET_ERRNO(); - return; - } - } - - /* - * XSH: Upon successful return, the mutex has been locked and is owned - * by the calling thread. - */ - if ((result = pthread_mutex_lock (cleanup_args->mutexPtr)) != 0) - { - *resultPtr = result; - } -} /* ptw32_cond_wait_cleanup */ - -static INLINE int -ptw32_cond_timedwait (pthread_cond_t * cond, - pthread_mutex_t * mutex, const struct timespec *abstime) -{ - int result = 0; - pthread_cond_t cv; - ptw32_cond_wait_cleanup_args_t cleanup_args; - - if (cond == NULL || *cond == NULL) - { - return EINVAL; - } - - /* - * We do a quick check to see if we need to do more work - * to initialise a static condition variable. We check - * again inside the guarded section of ptw32_cond_check_need_init() - * to avoid race conditions. - */ - if (*cond == PTHREAD_COND_INITIALIZER) - { - result = ptw32_cond_check_need_init (cond); - } - - if (result != 0 && result != EBUSY) - { - return result; - } - - cv = *cond; - - /* Thread can be cancelled in sem_wait() but this is OK */ - if (sem_wait (&(cv->semBlockLock)) != 0) - { - return PTW32_GET_ERRNO(); - } - - ++(cv->nWaitersBlocked); - - if (sem_post (&(cv->semBlockLock)) != 0) - { - return PTW32_GET_ERRNO(); - } - - /* - * Setup this waiter cleanup handler - */ - cleanup_args.mutexPtr = mutex; - cleanup_args.cv = cv; - cleanup_args.resultPtr = &result; - -#if defined(PTW32_CONFIG_MSVC7) -#pragma inline_depth(0) -#endif - pthread_cleanup_push (ptw32_cond_wait_cleanup, (void *) &cleanup_args); - - /* - * Now we can release 'mutex' and... - */ - if ((result = pthread_mutex_unlock (mutex)) == 0) - { - - /* - * ...wait to be awakened by - * pthread_cond_signal, or - * pthread_cond_broadcast, or - * timeout, or - * thread cancellation - * - * Note: - * - * sem_timedwait is a cancellation point, - * hence providing the mechanism for making - * pthread_cond_wait a cancellation point. - * We use the cleanup mechanism to ensure we - * re-lock the mutex and adjust (to)unblock(ed) waiters - * counts if we are cancelled, timed out or signalled. - */ - if (sem_timedwait (&(cv->semBlockQueue), abstime) != 0) - { - result = PTW32_GET_ERRNO(); - } - } - - /* - * Always cleanup - */ - pthread_cleanup_pop (1); -#if defined(PTW32_CONFIG_MSVC7) -#pragma inline_depth() -#endif - - /* - * "result" can be modified by the cleanup handler. - */ - return result; - -} /* ptw32_cond_timedwait */ - - -int -pthread_cond_wait (pthread_cond_t * cond, pthread_mutex_t * mutex) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function waits on a condition variable until - * awakened by a signal or broadcast. - * - * Caller MUST be holding the mutex lock; the - * lock is released and the caller is blocked waiting - * on 'cond'. When 'cond' is signaled, the mutex - * is re-acquired before returning to the caller. - * - * PARAMETERS - * cond - * pointer to an instance of pthread_cond_t - * - * mutex - * pointer to an instance of pthread_mutex_t - * - * - * DESCRIPTION - * This function waits on a condition variable until - * awakened by a signal or broadcast. - * - * NOTES: - * - * 1) The function must be called with 'mutex' LOCKED - * by the calling thread, or undefined behaviour - * will result. - * - * 2) This routine atomically releases 'mutex' and causes - * the calling thread to block on the condition variable. - * The blocked thread may be awakened by - * pthread_cond_signal or - * pthread_cond_broadcast. - * - * Upon successful completion, the 'mutex' has been locked and - * is owned by the calling thread. - * - * - * RESULTS - * 0 caught condition; mutex released, - * EINVAL 'cond' or 'mutex' is invalid, - * EINVAL different mutexes for concurrent waits, - * EINVAL mutex is not held by the calling thread, - * - * ------------------------------------------------------ - */ -{ - /* - * The NULL abstime arg means INFINITE waiting. - */ - return (ptw32_cond_timedwait (cond, mutex, NULL)); - -} /* pthread_cond_wait */ - - -int -pthread_cond_timedwait (pthread_cond_t * cond, - pthread_mutex_t * mutex, - const struct timespec *abstime) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function waits on a condition variable either until - * awakened by a signal or broadcast; or until the time - * specified by abstime passes. - * - * PARAMETERS - * cond - * pointer to an instance of pthread_cond_t - * - * mutex - * pointer to an instance of pthread_mutex_t - * - * abstime - * pointer to an instance of (const struct timespec) - * - * - * DESCRIPTION - * This function waits on a condition variable either until - * awakened by a signal or broadcast; or until the time - * specified by abstime passes. - * - * NOTES: - * 1) The function must be called with 'mutex' LOCKED - * by the calling thread, or undefined behaviour - * will result. - * - * 2) This routine atomically releases 'mutex' and causes - * the calling thread to block on the condition variable. - * The blocked thread may be awakened by - * pthread_cond_signal or - * pthread_cond_broadcast. - * - * - * RESULTS - * 0 caught condition; mutex released, - * EINVAL 'cond', 'mutex', or abstime is invalid, - * EINVAL different mutexes for concurrent waits, - * EINVAL mutex is not held by the calling thread, - * ETIMEDOUT abstime ellapsed before cond was signaled. - * - * ------------------------------------------------------ - */ -{ - if (abstime == NULL) - { - return EINVAL; - } - - return (ptw32_cond_timedwait (cond, mutex, abstime)); - -} /* pthread_cond_timedwait */ diff --git a/dependencies/win32_pthread/src/pthread_condattr_destroy.c b/dependencies/win32_pthread/src/pthread_condattr_destroy.c deleted file mode 100644 index 696065ef..00000000 --- a/dependencies/win32_pthread/src/pthread_condattr_destroy.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * condvar_attr_destroy.c - * - * Description: - * This translation unit implements condition variables and their primitives. - * - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_condattr_destroy (pthread_condattr_t * attr) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * Destroys a condition variable attributes object. - * The object can no longer be used. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_condattr_t - * - * - * DESCRIPTION - * Destroys a condition variable attributes object. - * The object can no longer be used. - * - * NOTES: - * 1) Does not affect condition variables created - * using 'attr' - * - * RESULTS - * 0 successfully released attr, - * EINVAL 'attr' is invalid. - * - * ------------------------------------------------------ - */ -{ - int result = 0; - - if (attr == NULL || *attr == NULL) - { - result = EINVAL; - } - else - { - (void) free (*attr); - - *attr = NULL; - result = 0; - } - - return result; - -} /* pthread_condattr_destroy */ diff --git a/dependencies/win32_pthread/src/pthread_condattr_getpshared.c b/dependencies/win32_pthread/src/pthread_condattr_getpshared.c deleted file mode 100644 index dc161a9d..00000000 --- a/dependencies/win32_pthread/src/pthread_condattr_getpshared.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * pthread_condattr_getpshared.c - * - * Description: - * This translation unit implements condition variables and their primitives. - * - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_condattr_getpshared (const pthread_condattr_t * attr, int *pshared) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * Determine whether condition variables created with 'attr' - * can be shared between processes. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_condattr_t - * - * pshared - * will be set to one of: - * - * PTHREAD_PROCESS_SHARED - * May be shared if in shared memory - * - * PTHREAD_PROCESS_PRIVATE - * Cannot be shared. - * - * - * DESCRIPTION - * Condition Variables created with 'attr' can be shared - * between processes if pthread_cond_t variable is allocated - * in memory shared by these processes. - * NOTES: - * 1) pshared condition variables MUST be allocated in - * shared memory. - * - * 2) The following macro is defined if shared mutexes - * are supported: - * _POSIX_THREAD_PROCESS_SHARED - * - * RESULTS - * 0 successfully retrieved attribute, - * EINVAL 'attr' or 'pshared' is invalid, - * - * ------------------------------------------------------ - */ -{ - int result; - - if ((attr != NULL && *attr != NULL) && (pshared != NULL)) - { - *pshared = (*attr)->pshared; - result = 0; - } - else - { - result = EINVAL; - } - - return result; - -} /* pthread_condattr_getpshared */ diff --git a/dependencies/win32_pthread/src/pthread_condattr_init.c b/dependencies/win32_pthread/src/pthread_condattr_init.c deleted file mode 100644 index aa32cc6d..00000000 --- a/dependencies/win32_pthread/src/pthread_condattr_init.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * pthread_condattr_init.c - * - * Description: - * This translation unit implements condition variables and their primitives. - * - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_condattr_init (pthread_condattr_t * attr) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * Initializes a condition variable attributes object - * with default attributes. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_condattr_t - * - * - * DESCRIPTION - * Initializes a condition variable attributes object - * with default attributes. - * - * NOTES: - * 1) Use to define condition variable types - * 2) It is up to the application to ensure - * that it doesn't re-init an attribute - * without destroying it first. Otherwise - * a memory leak is created. - * - * RESULTS - * 0 successfully initialized attr, - * ENOMEM insufficient memory for attr. - * - * ------------------------------------------------------ - */ -{ - pthread_condattr_t attr_result; - int result = 0; - - attr_result = (pthread_condattr_t) calloc (1, sizeof (*attr_result)); - - if (attr_result == NULL) - { - result = ENOMEM; - } - - *attr = attr_result; - - return result; - -} /* pthread_condattr_init */ diff --git a/dependencies/win32_pthread/src/pthread_condattr_setpshared.c b/dependencies/win32_pthread/src/pthread_condattr_setpshared.c deleted file mode 100644 index 977b5a5c..00000000 --- a/dependencies/win32_pthread/src/pthread_condattr_setpshared.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * pthread_condattr_setpshared.c - * - * Description: - * This translation unit implements condition variables and their primitives. - * - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_condattr_setpshared (pthread_condattr_t * attr, int pshared) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * Mutexes created with 'attr' can be shared between - * processes if pthread_mutex_t variable is allocated - * in memory shared by these processes. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_mutexattr_t - * - * pshared - * must be one of: - * - * PTHREAD_PROCESS_SHARED - * May be shared if in shared memory - * - * PTHREAD_PROCESS_PRIVATE - * Cannot be shared. - * - * DESCRIPTION - * Mutexes creatd with 'attr' can be shared between - * processes if pthread_mutex_t variable is allocated - * in memory shared by these processes. - * - * NOTES: - * 1) pshared mutexes MUST be allocated in shared - * memory. - * - * 2) The following macro is defined if shared mutexes - * are supported: - * _POSIX_THREAD_PROCESS_SHARED - * - * RESULTS - * 0 successfully set attribute, - * EINVAL 'attr' or pshared is invalid, - * ENOSYS PTHREAD_PROCESS_SHARED not supported, - * - * ------------------------------------------------------ - */ -{ - int result; - - if ((attr != NULL && *attr != NULL) - && ((pshared == PTHREAD_PROCESS_SHARED) - || (pshared == PTHREAD_PROCESS_PRIVATE))) - { - if (pshared == PTHREAD_PROCESS_SHARED) - { - -#if !defined( _POSIX_THREAD_PROCESS_SHARED ) - result = ENOSYS; - pshared = PTHREAD_PROCESS_PRIVATE; -#else - result = 0; - -#endif /* _POSIX_THREAD_PROCESS_SHARED */ - - } - else - { - result = 0; - } - - (*attr)->pshared = pshared; - } - else - { - result = EINVAL; - } - - return result; - -} /* pthread_condattr_setpshared */ diff --git a/dependencies/win32_pthread/src/pthread_delay_np.c b/dependencies/win32_pthread/src/pthread_delay_np.c deleted file mode 100644 index 76a54b65..00000000 --- a/dependencies/win32_pthread/src/pthread_delay_np.c +++ /dev/null @@ -1,177 +0,0 @@ -/* - * pthreads_delay_np.c - * - * Description: - * This translation unit implements non-portable thread functions. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -/* - * pthread_delay_np - * - * DESCRIPTION - * - * This routine causes a thread to delay execution for a specific period of time. - * This period ends at the current time plus the specified interval. The routine - * will not return before the end of the period is reached, but may return an - * arbitrary amount of time after the period has gone by. This can be due to - * system load, thread priorities, and system timer granularity. - * - * Specifying an interval of zero (0) seconds and zero (0) nanoseconds is - * allowed and can be used to force the thread to give up the processor or to - * deliver a pending cancellation request. - * - * The timespec structure contains the following two fields: - * - * tv_sec is an integer number of seconds. - * tv_nsec is an integer number of nanoseconds. - * - * Return Values - * - * If an error condition occurs, this routine returns an integer value indicating - * the type of error. Possible return values are as follows: - * - * 0 - * Successful completion. - * [EINVAL] - * The value specified by interval is invalid. - * - * Example - * - * The following code segment would wait for 5 and 1/2 seconds - * - * struct timespec tsWait; - * int intRC; - * - * tsWait.tv_sec = 5; - * tsWait.tv_nsec = 500000000L; - * intRC = pthread_delay_np(&tsWait); - */ -int -pthread_delay_np (struct timespec *interval) -{ - DWORD wait_time; - DWORD secs_in_millisecs; - DWORD millisecs; - DWORD status; - pthread_t self; - ptw32_thread_t * sp; - - if (interval == NULL) - { - return EINVAL; - } - - if (interval->tv_sec == 0L && interval->tv_nsec == 0L) - { - pthread_testcancel (); - Sleep (0); - pthread_testcancel (); - return (0); - } - - /* convert secs to millisecs */ - secs_in_millisecs = (DWORD)interval->tv_sec * 1000L; - - /* convert nanosecs to millisecs (rounding up) */ - millisecs = (interval->tv_nsec + 999999L) / 1000000L; - -#if defined(__WATCOMC__) -#pragma disable_message (124) -#endif - - /* - * Most compilers will issue a warning 'comparison always 0' - * because the variable type is unsigned, but we need to keep this - * for some reason I can't recall now. - */ - if (0 > (wait_time = secs_in_millisecs + millisecs)) - { - return EINVAL; - } - -#if defined(__WATCOMC__) -#pragma enable_message (124) -#endif - - if (NULL == (self = pthread_self ()).p) - { - return ENOMEM; - } - - sp = (ptw32_thread_t *) self.p; - - if (sp->cancelState == PTHREAD_CANCEL_ENABLE) - { - /* - * Async cancellation won't catch us until wait_time is up. - * Deferred cancellation will cancel us immediately. - */ - if (WAIT_OBJECT_0 == - (status = WaitForSingleObject (sp->cancelEvent, wait_time))) - { - ptw32_mcs_local_node_t stateLock; - /* - * Canceling! - */ - ptw32_mcs_lock_acquire (&sp->stateLock, &stateLock); - if (sp->state < PThreadStateCanceling) - { - sp->state = PThreadStateCanceling; - sp->cancelState = PTHREAD_CANCEL_DISABLE; - ptw32_mcs_lock_release (&stateLock); - - ptw32_throw (PTW32_EPS_CANCEL); - } - - ptw32_mcs_lock_release (&stateLock); - return ESRCH; - } - else if (status != WAIT_TIMEOUT) - { - return EINVAL; - } - } - else - { - Sleep (wait_time); - } - - return (0); -} diff --git a/dependencies/win32_pthread/src/pthread_detach.c b/dependencies/win32_pthread/src/pthread_detach.c deleted file mode 100644 index 412fd92a..00000000 --- a/dependencies/win32_pthread/src/pthread_detach.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - * pthread_detach.c - * - * Description: - * This translation unit implements functions related to thread - * synchronisation. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -/* - * Not needed yet, but defining it should indicate clashes with build target - * environment that should be fixed. - */ -#if !defined(WINCE) -# include -#endif - - -int -pthread_detach (pthread_t thread) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function detaches the given thread. - * - * PARAMETERS - * thread - * an instance of a pthread_t - * - * - * DESCRIPTION - * This function detaches the given thread. You may use it to - * detach the main thread or to detach a joinable thread. - * NOTE: detached threads cannot be joined; - * storage is freed immediately on termination. - * - * RESULTS - * 0 successfully detached the thread, - * EINVAL thread is not a joinable thread, - * ENOSPC a required resource has been exhausted, - * ESRCH no thread could be found for 'thread', - * - * ------------------------------------------------------ - */ -{ - int result; - BOOL destroyIt = PTW32_FALSE; - ptw32_thread_t * tp = (ptw32_thread_t *) thread.p; - ptw32_mcs_local_node_t reuseLock; - - ptw32_mcs_lock_acquire(&ptw32_thread_reuse_lock, &reuseLock); - - if (NULL == tp - || thread.x != tp->ptHandle.x) - { - result = ESRCH; - } - else if (PTHREAD_CREATE_DETACHED == tp->detachState) - { - result = EINVAL; - } - else - { - ptw32_mcs_local_node_t stateLock; - /* - * Joinable ptw32_thread_t structs are not scavenged until - * a join or detach is done. The thread may have exited already, - * but all of the state and locks etc are still there. - */ - result = 0; - - ptw32_mcs_lock_acquire (&tp->stateLock, &stateLock); - if (tp->state != PThreadStateLast) - { - tp->detachState = PTHREAD_CREATE_DETACHED; - } - else if (tp->detachState != PTHREAD_CREATE_DETACHED) - { - /* - * Thread is joinable and has exited or is exiting. - */ - destroyIt = PTW32_TRUE; - } - ptw32_mcs_lock_release (&stateLock); - } - - ptw32_mcs_lock_release(&reuseLock); - - if (result == 0) - { - /* Thread is joinable */ - - if (destroyIt) - { - /* The thread has exited or is exiting but has not been joined or - * detached. Need to wait in case it's still exiting. - */ - (void) WaitForSingleObject(tp->threadH, INFINITE); - ptw32_threadDestroy (thread); - } - } - - return (result); - -} /* pthread_detach */ diff --git a/dependencies/win32_pthread/src/pthread_equal.c b/dependencies/win32_pthread/src/pthread_equal.c deleted file mode 100644 index 48da7e20..00000000 --- a/dependencies/win32_pthread/src/pthread_equal.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * pthread_equal.c - * - * Description: - * This translation unit implements miscellaneous thread functions. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_equal (pthread_t t1, pthread_t t2) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function returns nonzero if t1 and t2 are equal, else - * returns zero - * - * PARAMETERS - * t1, - * t2 - * thread IDs - * - * - * DESCRIPTION - * This function returns nonzero if t1 and t2 are equal, else - * returns zero. - * - * RESULTS - * non-zero if t1 and t2 refer to the same thread, - * 0 t1 and t2 do not refer to the same thread - * - * ------------------------------------------------------ - */ -{ - int result; - - /* - * We also accept NULL == NULL - treating NULL as a thread - * for this special case, because there is no error that we can return. - */ - result = ( t1.p == t2.p && t1.x == t2.x ); - - return (result); - -} /* pthread_equal */ diff --git a/dependencies/win32_pthread/src/pthread_exit.c b/dependencies/win32_pthread/src/pthread_exit.c deleted file mode 100644 index 885ab267..00000000 --- a/dependencies/win32_pthread/src/pthread_exit.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * pthread_exit.c - * - * Description: - * This translation unit implements routines associated with exiting from - * a thread. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" -#if !defined(_UWIN) -/*# include */ -#endif - -void -pthread_exit (void *value_ptr) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function terminates the calling thread, returning - * the value 'value_ptr' to any joining thread. - * - * PARAMETERS - * value_ptr - * a generic data value (i.e. not the address of a value) - * - * - * DESCRIPTION - * This function terminates the calling thread, returning - * the value 'value_ptr' to any joining thread. - * NOTE: thread should be joinable. - * - * RESULTS - * N/A - * - * ------------------------------------------------------ - */ -{ - ptw32_thread_t * sp; - - /* - * Don't use pthread_self() to avoid creating an implicit POSIX thread handle - * unnecessarily. - */ - sp = (ptw32_thread_t *) pthread_getspecific (ptw32_selfThreadKey); - -#if defined(_UWIN) - if (--pthread_count <= 0) - exit ((int) value_ptr); -#endif - - if (NULL == sp) - { - /* - * A POSIX thread handle was never created. I.e. this is a - * Win32 thread that has never called a pthreads-win32 routine that - * required a POSIX handle. - * - * Implicit POSIX handles are cleaned up in ptw32_throw() now. - */ - -#if ! defined (PTW32_CONFIG_MINGW) || defined (__MSVCRT__) || defined (__DMC__) - _endthreadex ((unsigned) (size_t) value_ptr); -#else - _endthread (); -#endif - - /* Never reached */ - } - - sp->exitStatus = value_ptr; - - ptw32_throw (PTW32_EPS_EXIT); - - /* Never reached. */ -} diff --git a/dependencies/win32_pthread/src/pthread_getconcurrency.c b/dependencies/win32_pthread/src/pthread_getconcurrency.c deleted file mode 100644 index de46fe7c..00000000 --- a/dependencies/win32_pthread/src/pthread_getconcurrency.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * pthread_getconcurrency.c - * - * Description: - * This translation unit implements miscellaneous thread functions. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_getconcurrency (void) -{ - return ptw32_concurrency; -} diff --git a/dependencies/win32_pthread/src/pthread_getschedparam.c b/dependencies/win32_pthread/src/pthread_getschedparam.c deleted file mode 100644 index 04458118..00000000 --- a/dependencies/win32_pthread/src/pthread_getschedparam.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * sched_getschedparam.c - * - * Description: - * POSIX thread functions that deal with thread scheduling. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" -#include "sched.h" - -int -pthread_getschedparam (pthread_t thread, int *policy, - struct sched_param *param) -{ - int result; - - /* Validate the thread id. */ - result = pthread_kill (thread, 0); - if (0 != result) - { - return result; - } - - if (policy == NULL) - { - return EINVAL; - } - - /* Fill out the policy. */ - *policy = SCHED_OTHER; - - /* - * This function must return the priority value set by - * the most recent pthread_setschedparam() or pthread_create() - * for the target thread. It must not return the actual thread - * priority as altered by any system priority adjustments etc. - */ - param->sched_priority = ((ptw32_thread_t *)thread.p)->sched_priority; - - return 0; -} diff --git a/dependencies/win32_pthread/src/pthread_getspecific.c b/dependencies/win32_pthread/src/pthread_getspecific.c deleted file mode 100644 index 77caa6b1..00000000 --- a/dependencies/win32_pthread/src/pthread_getspecific.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * pthread_getspecific.c - * - * Description: - * POSIX thread functions which implement thread-specific data (TSD). - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -void * -pthread_getspecific (pthread_key_t key) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function returns the current value of key in the - * calling thread. If no value has been set for 'key' in - * the thread, NULL is returned. - * - * PARAMETERS - * key - * an instance of pthread_key_t - * - * - * DESCRIPTION - * This function returns the current value of key in the - * calling thread. If no value has been set for 'key' in - * the thread, NULL is returned. - * - * RESULTS - * key value or NULL on failure - * - * ------------------------------------------------------ - */ -{ - void * ptr; - - if (key == NULL) - { - ptr = NULL; - } - else - { - int lasterror = GetLastError (); -#if defined(RETAIN_WSALASTERROR) - int lastWSAerror = WSAGetLastError (); -#endif - ptr = TlsGetValue (key->key); - - SetLastError (lasterror); -#if defined(RETAIN_WSALASTERROR) - WSASetLastError (lastWSAerror); -#endif - } - - return ptr; -} diff --git a/dependencies/win32_pthread/src/pthread_getunique_np.c b/dependencies/win32_pthread/src/pthread_getunique_np.c deleted file mode 100644 index 55031f04..00000000 --- a/dependencies/win32_pthread/src/pthread_getunique_np.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * pthread_getunique_np.c - * - * Description: - * This translation unit implements non-portable thread functions. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -/* - * - */ -unsigned __int64 -pthread_getunique_np (pthread_t thread) -{ - return ((ptw32_thread_t*)thread.p)->seqNumber; -} diff --git a/dependencies/win32_pthread/src/pthread_getw32threadhandle_np.c b/dependencies/win32_pthread/src/pthread_getw32threadhandle_np.c deleted file mode 100644 index b6ab544d..00000000 --- a/dependencies/win32_pthread/src/pthread_getw32threadhandle_np.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * pthread_getw32threadhandle_np.c - * - * Description: - * This translation unit implements non-portable thread functions. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -/* - * pthread_getw32threadhandle_np() - * - * Returns the win32 thread handle that the POSIX - * thread "thread" is running as. - * - * Applications can use the win32 handle to set - * win32 specific attributes of the thread. - */ -HANDLE -pthread_getw32threadhandle_np (pthread_t thread) -{ - return ((ptw32_thread_t *)thread.p)->threadH; -} - -/* - * pthread_getw32threadid_np() - * - * Returns the win32 thread id that the POSIX - * thread "thread" is running as. - */ -DWORD -pthread_getw32threadid_np (pthread_t thread) -{ - return ((ptw32_thread_t *)thread.p)->thread; -} diff --git a/dependencies/win32_pthread/src/pthread_join.c b/dependencies/win32_pthread/src/pthread_join.c deleted file mode 100644 index 96372551..00000000 --- a/dependencies/win32_pthread/src/pthread_join.c +++ /dev/null @@ -1,162 +0,0 @@ -/* - * pthread_join.c - * - * Description: - * This translation unit implements functions related to thread - * synchronisation. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -/* - * Not needed yet, but defining it should indicate clashes with build target - * environment that should be fixed. - */ -#if !defined(WINCE) -# include -#endif - - -int -pthread_join (pthread_t thread, void **value_ptr) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function waits for 'thread' to terminate and - * returns the thread's exit value if 'value_ptr' is not - * NULL. This also detaches the thread on successful - * completion. - * - * PARAMETERS - * thread - * an instance of pthread_t - * - * value_ptr - * pointer to an instance of pointer to void - * - * - * DESCRIPTION - * This function waits for 'thread' to terminate and - * returns the thread's exit value if 'value_ptr' is not - * NULL. This also detaches the thread on successful - * completion. - * NOTE: detached threads cannot be joined or canceled - * - * RESULTS - * 0 'thread' has completed - * EINVAL thread is not a joinable thread, - * ESRCH no thread could be found with ID 'thread', - * ENOENT thread couldn't find it's own valid handle, - * EDEADLK attempt to join thread with self - * - * ------------------------------------------------------ - */ -{ - int result; - pthread_t self; - ptw32_thread_t * tp = (ptw32_thread_t *) thread.p; - ptw32_mcs_local_node_t node; - - ptw32_mcs_lock_acquire(&ptw32_thread_reuse_lock, &node); - - if (NULL == tp - || thread.x != tp->ptHandle.x) - { - result = ESRCH; - } - else if (PTHREAD_CREATE_DETACHED == tp->detachState) - { - result = EINVAL; - } - else - { - result = 0; - } - - ptw32_mcs_lock_release(&node); - - if (result == 0) - { - /* - * The target thread is joinable and can't be reused before we join it. - */ - self = pthread_self(); - - if (NULL == self.p) - { - result = ENOENT; - } - else if (pthread_equal (self, thread)) - { - result = EDEADLK; - } - else - { - /* - * Pthread_join is a cancellation point. - * If we are canceled then our target thread must not be - * detached (destroyed). This is guaranteed because - * pthreadCancelableWait will not return if we - * are canceled. - */ - result = pthreadCancelableWait (tp->threadH); - - if (0 == result) - { - if (value_ptr != NULL) - { - *value_ptr = tp->exitStatus; - } - - /* - * The result of making multiple simultaneous calls to - * pthread_join() or pthread_detach() specifying the same - * target is undefined. - */ - result = pthread_detach (thread); - } - else - { - result = ESRCH; - } - } - } - - return (result); - -} /* pthread_join */ diff --git a/dependencies/win32_pthread/src/pthread_key_create.c b/dependencies/win32_pthread/src/pthread_key_create.c deleted file mode 100644 index 1ffda8c8..00000000 --- a/dependencies/win32_pthread/src/pthread_key_create.c +++ /dev/null @@ -1,113 +0,0 @@ -/* - * pthread_key_create.c - * - * Description: - * POSIX thread functions which implement thread-specific data (TSD). - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -/* TLS_OUT_OF_INDEXES not defined on WinCE */ -#if !defined(TLS_OUT_OF_INDEXES) -#define TLS_OUT_OF_INDEXES 0xffffffff -#endif - -int -pthread_key_create (pthread_key_t * key, void (PTW32_CDECL *destructor) (void *)) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function creates a thread-specific data key visible - * to all threads. All existing and new threads have a value - * NULL for key until set using pthread_setspecific. When any - * thread with a non-NULL value for key terminates, 'destructor' - * is called with key's current value for that thread. - * - * PARAMETERS - * key - * pointer to an instance of pthread_key_t - * - * - * DESCRIPTION - * This function creates a thread-specific data key visible - * to all threads. All existing and new threads have a value - * NULL for key until set using pthread_setspecific. When any - * thread with a non-NULL value for key terminates, 'destructor' - * is called with key's current value for that thread. - * - * RESULTS - * 0 successfully created semaphore, - * EAGAIN insufficient resources or PTHREAD_KEYS_MAX - * exceeded, - * ENOMEM insufficient memory to create the key, - * - * ------------------------------------------------------ - */ -{ - int result = 0; - pthread_key_t newkey; - - if ((newkey = (pthread_key_t) calloc (1, sizeof (*newkey))) == NULL) - { - result = ENOMEM; - } - else if ((newkey->key = TlsAlloc ()) == TLS_OUT_OF_INDEXES) - { - result = EAGAIN; - - free (newkey); - newkey = NULL; - } - else if (destructor != NULL) - { - /* - * Have to manage associations between thread and key; - * Therefore, need a lock that allows competing threads - * to gain exclusive access to the key->threads list. - * - * The mutex will only be created when it is first locked. - */ - newkey->keyLock = 0; - newkey->destructor = destructor; - } - - *key = newkey; - - return (result); -} diff --git a/dependencies/win32_pthread/src/pthread_key_delete.c b/dependencies/win32_pthread/src/pthread_key_delete.c deleted file mode 100644 index 5c9dfcb5..00000000 --- a/dependencies/win32_pthread/src/pthread_key_delete.c +++ /dev/null @@ -1,130 +0,0 @@ -/* - * pthread_key_delete.c - * - * Description: - * POSIX thread functions which implement thread-specific data (TSD). - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_key_delete (pthread_key_t key) -/* - * ------------------------------------------------------ - * DOCPUBLIC - * This function deletes a thread-specific data key. This - * does not change the value of the thread specific data key - * for any thread and does not run the key's destructor - * in any thread so it should be used with caution. - * - * PARAMETERS - * key - * pointer to an instance of pthread_key_t - * - * - * DESCRIPTION - * This function deletes a thread-specific data key. This - * does not change the value of the thread specific data key - * for any thread and does not run the key's destructor - * in any thread so it should be used with caution. - * - * RESULTS - * 0 successfully deleted the key, - * EINVAL key is invalid, - * - * ------------------------------------------------------ - */ -{ - ptw32_mcs_local_node_t keyLock; - int result = 0; - - if (key != NULL) - { - if (key->threads != NULL && key->destructor != NULL) - { - ThreadKeyAssoc *assoc; - ptw32_mcs_lock_acquire (&(key->keyLock), &keyLock); - /* - * Run through all Thread<-->Key associations - * for this key. - * - * While we hold at least one of the locks guarding - * the assoc, we know that the assoc pointed to by - * key->threads is valid. - */ - while ((assoc = (ThreadKeyAssoc *) key->threads) != NULL) - { - ptw32_mcs_local_node_t threadLock; - ptw32_thread_t * thread = assoc->thread; - - if (assoc == NULL) - { - /* Finished */ - break; - } - - ptw32_mcs_lock_acquire (&(thread->threadLock), &threadLock); - /* - * Since we are starting at the head of the key's threads - * chain, this will also point key->threads at the next assoc. - * While we hold key->keyLock, no other thread can insert - * a new assoc for this key via pthread_setspecific. - */ - ptw32_tkAssocDestroy (assoc); - ptw32_mcs_lock_release (&threadLock); - } - ptw32_mcs_lock_release (&keyLock); - } - - TlsFree (key->key); - if (key->destructor != NULL) - { - /* A thread could be holding the keyLock */ - ptw32_mcs_lock_acquire (&(key->keyLock), &keyLock); - ptw32_mcs_lock_release (&keyLock); - } - -#if defined( _DEBUG ) - memset ((char *) key, 0, sizeof (*key)); -#endif - free (key); - } - - return (result); -} diff --git a/dependencies/win32_pthread/src/pthread_kill.c b/dependencies/win32_pthread/src/pthread_kill.c deleted file mode 100644 index 9bfa9fa9..00000000 --- a/dependencies/win32_pthread/src/pthread_kill.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * pthread_kill.c - * - * Description: - * This translation unit implements the pthread_kill routine. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -/* - * Not needed yet, but defining it should indicate clashes with build target - * environment that should be fixed. - */ -#if !defined(WINCE) -# include -#endif - -int -pthread_kill (pthread_t thread, int sig) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function requests that a signal be delivered to the - * specified thread. If sig is zero, error checking is - * performed but no signal is actually sent such that this - * function can be used to check for a valid thread ID. - * - * PARAMETERS - * thread reference to an instances of pthread_t - * sig signal. Currently only a value of 0 is supported. - * - * - * DESCRIPTION - * This function requests that a signal be delivered to the - * specified thread. If sig is zero, error checking is - * performed but no signal is actually sent such that this - * function can be used to check for a valid thread ID. - * - * RESULTS - * ESRCH the thread is not a valid thread ID, - * EINVAL the value of the signal is invalid - * or unsupported. - * 0 the signal was successfully sent. - * - * ------------------------------------------------------ - */ -{ - int result = 0; - ptw32_thread_t * tp; - ptw32_mcs_local_node_t node; - - ptw32_mcs_lock_acquire(&ptw32_thread_reuse_lock, &node); - - tp = (ptw32_thread_t *) thread.p; - - if (NULL == tp - || thread.x != tp->ptHandle.x - || NULL == tp->threadH) - { - result = ESRCH; - } - - ptw32_mcs_lock_release(&node); - - if (0 == result && 0 != sig) - { - /* - * Currently does not support any signals. - */ - result = EINVAL; - } - - return result; - -} /* pthread_kill */ diff --git a/dependencies/win32_pthread/src/pthread_mutex_consistent.c b/dependencies/win32_pthread/src/pthread_mutex_consistent.c deleted file mode 100644 index 053a5a6c..00000000 --- a/dependencies/win32_pthread/src/pthread_mutex_consistent.c +++ /dev/null @@ -1,195 +0,0 @@ -/* - * pthread_mutex_consistent.c - * - * Description: - * This translation unit implements mutual exclusion (mutex) primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -/* - * From the Sun Multi-threaded Programming Guide - * - * robustness defines the behavior when the owner of the mutex terminates without unlocking the - * mutex, usually because its process terminated abnormally. The value of robustness that is - * defined in pthread.h is PTHREAD_MUTEX_ROBUST or PTHREAD_MUTEX_STALLED. The - * default value is PTHREAD_MUTEX_STALLED . - * [] PTHREAD_MUTEX_STALLED - * When the owner of the mutex terminates without unlocking the mutex, all subsequent calls - * to pthread_mutex_lock() are blocked from progress in an unspecified manner. - * [] PTHREAD_MUTEX_ROBUST - * When the owner of the mutex terminates without unlocking the mutex, the mutex is - * unlocked. The next owner of this mutex acquires the mutex with an error return of - * EOWNERDEAD. - * Note - Your application must always check the return code from pthread_mutex_lock() for - * a mutex initialized with the PTHREAD_MUTEX_ROBUST attribute. - * [] The new owner of this mutex should make the state protected by the mutex consistent. - * This state might have been left inconsistent when the previous owner terminated. - * [] If the new owner is able to make the state consistent, call - * pthread_mutex_consistent() for the mutex before unlocking the mutex. This - * marks the mutex as consistent and subsequent calls to pthread_mutex_lock() and - * pthread_mutex_unlock() will behave in the normal manner. - * [] If the new owner is not able to make the state consistent, do not call - * pthread_mutex_consistent() for the mutex, but unlock the mutex. - * All waiters are woken up and all subsequent calls to pthread_mutex_lock() fail to - * acquire the mutex. The return code is ENOTRECOVERABLE. The mutex can be made - * consistent by calling pthread_mutex_destroy() to uninitialize the mutex, and calling - * pthread_mutex_int() to reinitialize the mutex.However, the state that was protected - * by the mutex remains inconsistent and some form of application recovery is required. - * [] If the thread that acquires the lock with EOWNERDEAD terminates without unlocking the - * mutex, the next owner acquires the lock with an EOWNERDEAD return code. - */ -#if !defined(_UWIN) -/*# include */ -#endif -#include "pthread.h" -#include "implement.h" - -INLINE -int -ptw32_robust_mutex_inherit(pthread_mutex_t * mutex) -{ - int result; - pthread_mutex_t mx = *mutex; - ptw32_robust_node_t* robust = mx->robustNode; - - switch ((LONG)PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG( - (PTW32_INTERLOCKED_LONGPTR)&robust->stateInconsistent, - (PTW32_INTERLOCKED_LONG)PTW32_ROBUST_INCONSISTENT, - (PTW32_INTERLOCKED_LONG)-1 /* The terminating thread sets this */)) - { - case -1L: - result = EOWNERDEAD; - break; - case (LONG)PTW32_ROBUST_NOTRECOVERABLE: - result = ENOTRECOVERABLE; - break; - default: - result = 0; - break; - } - - return result; -} - -/* - * The next two internal support functions depend on being - * called only by the thread that owns the robust mutex. This - * enables us to avoid additional locks. - * Any mutex currently in the thread's robust mutex list is held - * by the thread, again eliminating the need for locks. - * The forward/backward links allow the thread to unlock mutexes - * in any order, not necessarily the reverse locking order. - * This is all possible because it is an error if a thread that - * does not own the [robust] mutex attempts to unlock it. - */ - -INLINE -void -ptw32_robust_mutex_add(pthread_mutex_t* mutex, pthread_t self) -{ - ptw32_robust_node_t** list; - pthread_mutex_t mx = *mutex; - ptw32_thread_t* tp = (ptw32_thread_t*)self.p; - ptw32_robust_node_t* robust = mx->robustNode; - - list = &tp->robustMxList; - mx->ownerThread = self; - if (NULL == *list) - { - robust->prev = NULL; - robust->next = NULL; - *list = robust; - } - else - { - robust->prev = NULL; - robust->next = *list; - (*list)->prev = robust; - *list = robust; - } -} - -INLINE -void -ptw32_robust_mutex_remove(pthread_mutex_t* mutex, ptw32_thread_t* otp) -{ - ptw32_robust_node_t** list; - pthread_mutex_t mx = *mutex; - ptw32_robust_node_t* robust = mx->robustNode; - - list = &(((ptw32_thread_t*)mx->ownerThread.p)->robustMxList); - mx->ownerThread.p = otp; - if (robust->next != NULL) - { - robust->next->prev = robust->prev; - } - if (robust->prev != NULL) - { - robust->prev->next = robust->next; - } - if (*list == robust) - { - *list = robust->next; - } -} - - -int -pthread_mutex_consistent (pthread_mutex_t* mutex) -{ - pthread_mutex_t mx = *mutex; - int result = 0; - - /* - * Let the system deal with invalid pointers. - */ - if (mx == NULL) - { - return EINVAL; - } - - if (mx->kind >= 0 - || (PTW32_INTERLOCKED_LONG)PTW32_ROBUST_INCONSISTENT != PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG( - (PTW32_INTERLOCKED_LONGPTR)&mx->robustNode->stateInconsistent, - (PTW32_INTERLOCKED_LONG)PTW32_ROBUST_CONSISTENT, - (PTW32_INTERLOCKED_LONG)PTW32_ROBUST_INCONSISTENT)) - { - result = EINVAL; - } - - return (result); -} - diff --git a/dependencies/win32_pthread/src/pthread_mutex_destroy.c b/dependencies/win32_pthread/src/pthread_mutex_destroy.c deleted file mode 100644 index 545d0839..00000000 --- a/dependencies/win32_pthread/src/pthread_mutex_destroy.c +++ /dev/null @@ -1,153 +0,0 @@ -/* - * pthread_mutex_destroy.c - * - * Description: - * This translation unit implements mutual exclusion (mutex) primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_mutex_destroy (pthread_mutex_t * mutex) -{ - int result = 0; - pthread_mutex_t mx; - - /* - * Let the system deal with invalid pointers. - */ - - /* - * Check to see if we have something to delete. - */ - if (*mutex < PTHREAD_ERRORCHECK_MUTEX_INITIALIZER) - { - mx = *mutex; - - result = pthread_mutex_trylock (&mx); - - /* - * If trylock succeeded and the mutex is not recursively locked it - * can be destroyed. - */ - if (0 == result || ENOTRECOVERABLE == result) - { - if (mx->kind != PTHREAD_MUTEX_RECURSIVE || 1 == mx->recursive_count) - { - /* - * FIXME!!! - * The mutex isn't held by another thread but we could still - * be too late invalidating the mutex below since another thread - * may already have entered mutex_lock and the check for a valid - * *mutex != NULL. - */ - *mutex = NULL; - - result = (0 == result)?pthread_mutex_unlock(&mx):0; - - if (0 == result) - { - if (mx->robustNode != NULL) - { - free(mx->robustNode); - } - if (!CloseHandle (mx->event)) - { - *mutex = mx; - result = EINVAL; - } - else - { - free (mx); - } - } - else - { - /* - * Restore the mutex before we return the error. - */ - *mutex = mx; - } - } - else /* mx->recursive_count > 1 */ - { - /* - * The mutex must be recursive and already locked by us (this thread). - */ - mx->recursive_count--; /* Undo effect of pthread_mutex_trylock() above */ - result = EBUSY; - } - } - } - else - { - ptw32_mcs_local_node_t node; - - /* - * See notes in ptw32_mutex_check_need_init() above also. - */ - - ptw32_mcs_lock_acquire(&ptw32_mutex_test_init_lock, &node); - - /* - * Check again. - */ - if (*mutex >= PTHREAD_ERRORCHECK_MUTEX_INITIALIZER) - { - /* - * This is all we need to do to destroy a statically - * initialised mutex that has not yet been used (initialised). - * If we get to here, another thread - * waiting to initialise this mutex will get an EINVAL. - */ - *mutex = NULL; - } - else - { - /* - * The mutex has been initialised while we were waiting - * so assume it's in use. - */ - result = EBUSY; - } - ptw32_mcs_lock_release(&node); - } - - return (result); -} diff --git a/dependencies/win32_pthread/src/pthread_mutex_init.c b/dependencies/win32_pthread/src/pthread_mutex_init.c deleted file mode 100644 index 3366d203..00000000 --- a/dependencies/win32_pthread/src/pthread_mutex_init.c +++ /dev/null @@ -1,135 +0,0 @@ -/* - * pthread_mutex_init.c - * - * Description: - * This translation unit implements mutual exclusion (mutex) primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_mutex_init (pthread_mutex_t * mutex, const pthread_mutexattr_t * attr) -{ - int result = 0; - pthread_mutex_t mx; - - if (mutex == NULL) - { - return EINVAL; - } - - if (attr != NULL && *attr != NULL) - { - if ((*attr)->pshared == PTHREAD_PROCESS_SHARED) - { - /* - * Creating mutex that can be shared between - * processes. - */ -#if _POSIX_THREAD_PROCESS_SHARED >= 0 - - /* - * Not implemented yet. - */ - -#error ERROR [__FILE__, line __LINE__]: Process shared mutexes are not supported yet. - -#else - - return ENOSYS; - -#endif /* _POSIX_THREAD_PROCESS_SHARED */ - } - } - - mx = (pthread_mutex_t) calloc (1, sizeof (*mx)); - - if (mx == NULL) - { - result = ENOMEM; - } - else - { - mx->lock_idx = 0; - mx->recursive_count = 0; - mx->robustNode = NULL; - if (attr == NULL || *attr == NULL) - { - mx->kind = PTHREAD_MUTEX_DEFAULT; - } - else - { - mx->kind = (*attr)->kind; - if ((*attr)->robustness == PTHREAD_MUTEX_ROBUST) - { - /* - * Use the negative range to represent robust types. - * Replaces a memory fetch with a register negate and incr - * in pthread_mutex_lock etc. - * - * Map 0,1,..,n to -1,-2,..,(-n)-1 - */ - mx->kind = -mx->kind - 1; - - mx->robustNode = (ptw32_robust_node_t*) malloc(sizeof(ptw32_robust_node_t)); - mx->robustNode->stateInconsistent = PTW32_ROBUST_CONSISTENT; - mx->robustNode->mx = mx; - mx->robustNode->next = NULL; - mx->robustNode->prev = NULL; - } - } - - mx->ownerThread.p = NULL; - - mx->event = CreateEvent (NULL, PTW32_FALSE, /* manual reset = No */ - PTW32_FALSE, /* initial state = not signaled */ - NULL); /* event name */ - - if (0 == mx->event) - { - result = ENOSPC; - free (mx); - mx = NULL; - } - } - - *mutex = mx; - - return (result); -} diff --git a/dependencies/win32_pthread/src/pthread_mutex_lock.c b/dependencies/win32_pthread/src/pthread_mutex_lock.c deleted file mode 100644 index 5a7cb3ba..00000000 --- a/dependencies/win32_pthread/src/pthread_mutex_lock.c +++ /dev/null @@ -1,274 +0,0 @@ -/* - * pthread_mutex_lock.c - * - * Description: - * This translation unit implements mutual exclusion (mutex) primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#if !defined(_UWIN) -/*# include */ -#endif -#include "pthread.h" -#include "implement.h" - -int -pthread_mutex_lock (pthread_mutex_t * mutex) -{ - int kind; - pthread_mutex_t mx; - int result = 0; - - /* - * Let the system deal with invalid pointers. - */ - if (*mutex == NULL) - { - return EINVAL; - } - - /* - * We do a quick check to see if we need to do more work - * to initialise a static mutex. We check - * again inside the guarded section of ptw32_mutex_check_need_init() - * to avoid race conditions. - */ - if (*mutex >= PTHREAD_ERRORCHECK_MUTEX_INITIALIZER) - { - if ((result = ptw32_mutex_check_need_init (mutex)) != 0) - { - return (result); - } - } - - mx = *mutex; - kind = mx->kind; - - if (kind >= 0) - { - /* Non-robust */ - if (PTHREAD_MUTEX_NORMAL == kind) - { - if ((PTW32_INTERLOCKED_LONG) PTW32_INTERLOCKED_EXCHANGE_LONG( - (PTW32_INTERLOCKED_LONGPTR) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) 1) != 0) - { - while ((PTW32_INTERLOCKED_LONG) PTW32_INTERLOCKED_EXCHANGE_LONG( - (PTW32_INTERLOCKED_LONGPTR) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) -1) != 0) - { - if (WAIT_OBJECT_0 != WaitForSingleObject (mx->event, INFINITE)) - { - result = EINVAL; - break; - } - } - } - } - else - { - pthread_t self = pthread_self(); - - if ((PTW32_INTERLOCKED_LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG( - (PTW32_INTERLOCKED_LONGPTR) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) 1, - (PTW32_INTERLOCKED_LONG) 0) == 0) - { - mx->recursive_count = 1; - mx->ownerThread = self; - } - else - { - if (pthread_equal (mx->ownerThread, self)) - { - if (kind == PTHREAD_MUTEX_RECURSIVE) - { - mx->recursive_count++; - } - else - { - result = EDEADLK; - } - } - else - { - while ((PTW32_INTERLOCKED_LONG) PTW32_INTERLOCKED_EXCHANGE_LONG( - (PTW32_INTERLOCKED_LONGPTR) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) -1) != 0) - { - if (WAIT_OBJECT_0 != WaitForSingleObject (mx->event, INFINITE)) - { - result = EINVAL; - break; - } - } - - if (0 == result) - { - mx->recursive_count = 1; - mx->ownerThread = self; - } - } - } - } - } - else - { - /* - * Robust types - * All types record the current owner thread. - * The mutex is added to a per thread list when ownership is acquired. - */ - ptw32_robust_state_t* statePtr = &mx->robustNode->stateInconsistent; - - if ((PTW32_INTERLOCKED_LONG)PTW32_ROBUST_NOTRECOVERABLE == PTW32_INTERLOCKED_EXCHANGE_ADD_LONG( - (PTW32_INTERLOCKED_LONGPTR)statePtr, - (PTW32_INTERLOCKED_LONG)0)) - { - result = ENOTRECOVERABLE; - } - else - { - pthread_t self = pthread_self(); - - kind = -kind - 1; /* Convert to non-robust range */ - - if (PTHREAD_MUTEX_NORMAL == kind) - { - if ((PTW32_INTERLOCKED_LONG) PTW32_INTERLOCKED_EXCHANGE_LONG( - (PTW32_INTERLOCKED_LONGPTR) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) 1) != 0) - { - while (0 == (result = ptw32_robust_mutex_inherit(mutex)) - && (PTW32_INTERLOCKED_LONG) PTW32_INTERLOCKED_EXCHANGE_LONG( - (PTW32_INTERLOCKED_LONGPTR) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) -1) != 0) - { - if (WAIT_OBJECT_0 != WaitForSingleObject (mx->event, INFINITE)) - { - result = EINVAL; - break; - } - if ((PTW32_INTERLOCKED_LONG)PTW32_ROBUST_NOTRECOVERABLE == - PTW32_INTERLOCKED_EXCHANGE_ADD_LONG( - (PTW32_INTERLOCKED_LONGPTR)statePtr, - (PTW32_INTERLOCKED_LONG)0)) - { - /* Unblock the next thread */ - SetEvent(mx->event); - result = ENOTRECOVERABLE; - break; - } - } - } - if (0 == result || EOWNERDEAD == result) - { - /* - * Add mutex to the per-thread robust mutex currently-held list. - * If the thread terminates, all mutexes in this list will be unlocked. - */ - ptw32_robust_mutex_add(mutex, self); - } - } - else - { - if ((PTW32_INTERLOCKED_LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG( - (PTW32_INTERLOCKED_LONGPTR) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) 1, - (PTW32_INTERLOCKED_LONG) 0) == 0) - { - mx->recursive_count = 1; - /* - * Add mutex to the per-thread robust mutex currently-held list. - * If the thread terminates, all mutexes in this list will be unlocked. - */ - ptw32_robust_mutex_add(mutex, self); - } - else - { - if (pthread_equal (mx->ownerThread, self)) - { - if (PTHREAD_MUTEX_RECURSIVE == kind) - { - mx->recursive_count++; - } - else - { - result = EDEADLK; - } - } - else - { - while (0 == (result = ptw32_robust_mutex_inherit(mutex)) - && (PTW32_INTERLOCKED_LONG) PTW32_INTERLOCKED_EXCHANGE_LONG( - (PTW32_INTERLOCKED_LONGPTR) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) -1) != 0) - { - if (WAIT_OBJECT_0 != WaitForSingleObject (mx->event, INFINITE)) - { - result = EINVAL; - break; - } - if ((PTW32_INTERLOCKED_LONG)PTW32_ROBUST_NOTRECOVERABLE == - PTW32_INTERLOCKED_EXCHANGE_ADD_LONG( - (PTW32_INTERLOCKED_LONGPTR)statePtr, - (PTW32_INTERLOCKED_LONG)0)) - { - /* Unblock the next thread */ - SetEvent(mx->event); - result = ENOTRECOVERABLE; - break; - } - } - - if (0 == result || EOWNERDEAD == result) - { - mx->recursive_count = 1; - /* - * Add mutex to the per-thread robust mutex currently-held list. - * If the thread terminates, all mutexes in this list will be unlocked. - */ - ptw32_robust_mutex_add(mutex, self); - } - } - } - } - } - } - - return (result); -} - diff --git a/dependencies/win32_pthread/src/pthread_mutex_timedlock.c b/dependencies/win32_pthread/src/pthread_mutex_timedlock.c deleted file mode 100644 index d1091e98..00000000 --- a/dependencies/win32_pthread/src/pthread_mutex_timedlock.c +++ /dev/null @@ -1,328 +0,0 @@ -/* - * pthread_mutex_timedlock.c - * - * Description: - * This translation unit implements mutual exclusion (mutex) primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -static INLINE int -ptw32_timed_eventwait (HANDLE event, const struct timespec *abstime) - /* - * ------------------------------------------------------ - * DESCRIPTION - * This function waits on an event until signaled or until - * abstime passes. - * If abstime has passed when this routine is called then - * it returns a result to indicate this. - * - * If 'abstime' is a NULL pointer then this function will - * block until it can successfully decrease the value or - * until interrupted by a signal. - * - * This routine is not a cancellation point. - * - * RESULTS - * 0 successfully signaled, - * ETIMEDOUT abstime passed - * EINVAL 'event' is not a valid event, - * - * ------------------------------------------------------ - */ -{ - - DWORD milliseconds; - DWORD status; - - if (event == NULL) - { - return EINVAL; - } - else - { - if (abstime == NULL) - { - milliseconds = INFINITE; - } - else - { - /* - * Calculate timeout as milliseconds from current system time. - */ - milliseconds = ptw32_relmillisecs (abstime); - } - - status = WaitForSingleObject (event, milliseconds); - - if (status != WAIT_OBJECT_0) - { - if (status == WAIT_TIMEOUT) - { - return ETIMEDOUT; - } - else - { - return EINVAL; - } - } - } - - return 0; - -} /* ptw32_timed_semwait */ - - -int -pthread_mutex_timedlock (pthread_mutex_t * mutex, - const struct timespec *abstime) -{ - pthread_mutex_t mx; - int kind; - int result = 0; - - /* - * Let the system deal with invalid pointers. - */ - - /* - * We do a quick check to see if we need to do more work - * to initialise a static mutex. We check - * again inside the guarded section of ptw32_mutex_check_need_init() - * to avoid race conditions. - */ - if (*mutex >= PTHREAD_ERRORCHECK_MUTEX_INITIALIZER) - { - if ((result = ptw32_mutex_check_need_init (mutex)) != 0) - { - return (result); - } - } - - mx = *mutex; - kind = mx->kind; - - if (kind >= 0) - { - if (mx->kind == PTHREAD_MUTEX_NORMAL) - { - if ((PTW32_INTERLOCKED_LONG) PTW32_INTERLOCKED_EXCHANGE_LONG( - (PTW32_INTERLOCKED_LONGPTR) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) 1) != 0) - { - while ((PTW32_INTERLOCKED_LONG) PTW32_INTERLOCKED_EXCHANGE_LONG( - (PTW32_INTERLOCKED_LONGPTR) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) -1) != 0) - { - if (0 != (result = ptw32_timed_eventwait (mx->event, abstime))) - { - return result; - } - } - } - } - else - { - pthread_t self = pthread_self(); - - if ((PTW32_INTERLOCKED_LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG( - (PTW32_INTERLOCKED_LONGPTR) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) 1, - (PTW32_INTERLOCKED_LONG) 0) == 0) - { - mx->recursive_count = 1; - mx->ownerThread = self; - } - else - { - if (pthread_equal (mx->ownerThread, self)) - { - if (mx->kind == PTHREAD_MUTEX_RECURSIVE) - { - mx->recursive_count++; - } - else - { - return EDEADLK; - } - } - else - { - while ((PTW32_INTERLOCKED_LONG) PTW32_INTERLOCKED_EXCHANGE_LONG( - (PTW32_INTERLOCKED_LONGPTR) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) -1) != 0) - { - if (0 != (result = ptw32_timed_eventwait (mx->event, abstime))) - { - return result; - } - } - - mx->recursive_count = 1; - mx->ownerThread = self; - } - } - } - } - else - { - /* - * Robust types - * All types record the current owner thread. - * The mutex is added to a per thread list when ownership is acquired. - */ - ptw32_robust_state_t* statePtr = &mx->robustNode->stateInconsistent; - - if ((PTW32_INTERLOCKED_LONG)PTW32_ROBUST_NOTRECOVERABLE == PTW32_INTERLOCKED_EXCHANGE_ADD_LONG( - (PTW32_INTERLOCKED_LONGPTR)statePtr, - (PTW32_INTERLOCKED_LONG)0)) - { - result = ENOTRECOVERABLE; - } - else - { - pthread_t self = pthread_self(); - - kind = -kind - 1; /* Convert to non-robust range */ - - if (PTHREAD_MUTEX_NORMAL == kind) - { - if ((PTW32_INTERLOCKED_LONG) PTW32_INTERLOCKED_EXCHANGE_LONG( - (PTW32_INTERLOCKED_LONGPTR) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) 1) != 0) - { - while (0 == (result = ptw32_robust_mutex_inherit(mutex)) - && (PTW32_INTERLOCKED_LONG) PTW32_INTERLOCKED_EXCHANGE_LONG( - (PTW32_INTERLOCKED_LONGPTR) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) -1) != 0) - { - if (0 != (result = ptw32_timed_eventwait (mx->event, abstime))) - { - return result; - } - if ((PTW32_INTERLOCKED_LONG)PTW32_ROBUST_NOTRECOVERABLE == - PTW32_INTERLOCKED_EXCHANGE_ADD_LONG( - (PTW32_INTERLOCKED_LONGPTR)statePtr, - (PTW32_INTERLOCKED_LONG)0)) - { - /* Unblock the next thread */ - SetEvent(mx->event); - result = ENOTRECOVERABLE; - break; - } - } - - if (0 == result || EOWNERDEAD == result) - { - /* - * Add mutex to the per-thread robust mutex currently-held list. - * If the thread terminates, all mutexes in this list will be unlocked. - */ - ptw32_robust_mutex_add(mutex, self); - } - } - } - else - { - pthread_t self = pthread_self(); - - if (0 == (PTW32_INTERLOCKED_LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG( - (PTW32_INTERLOCKED_LONGPTR) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) 1, - (PTW32_INTERLOCKED_LONG) 0)) - { - mx->recursive_count = 1; - /* - * Add mutex to the per-thread robust mutex currently-held list. - * If the thread terminates, all mutexes in this list will be unlocked. - */ - ptw32_robust_mutex_add(mutex, self); - } - else - { - if (pthread_equal (mx->ownerThread, self)) - { - if (PTHREAD_MUTEX_RECURSIVE == kind) - { - mx->recursive_count++; - } - else - { - return EDEADLK; - } - } - else - { - while (0 == (result = ptw32_robust_mutex_inherit(mutex)) - && (PTW32_INTERLOCKED_LONG) PTW32_INTERLOCKED_EXCHANGE_LONG( - (PTW32_INTERLOCKED_LONGPTR) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) -1) != 0) - { - if (0 != (result = ptw32_timed_eventwait (mx->event, abstime))) - { - return result; - } - } - - if ((PTW32_INTERLOCKED_LONG)PTW32_ROBUST_NOTRECOVERABLE == - PTW32_INTERLOCKED_EXCHANGE_ADD_LONG( - (PTW32_INTERLOCKED_LONGPTR)statePtr, - (PTW32_INTERLOCKED_LONG)0)) - { - /* Unblock the next thread */ - SetEvent(mx->event); - result = ENOTRECOVERABLE; - } - else if (0 == result || EOWNERDEAD == result) - { - mx->recursive_count = 1; - /* - * Add mutex to the per-thread robust mutex currently-held list. - * If the thread terminates, all mutexes in this list will be unlocked. - */ - ptw32_robust_mutex_add(mutex, self); - } - } - } - } - } - } - - return result; -} diff --git a/dependencies/win32_pthread/src/pthread_mutex_trylock.c b/dependencies/win32_pthread/src/pthread_mutex_trylock.c deleted file mode 100644 index 840ec421..00000000 --- a/dependencies/win32_pthread/src/pthread_mutex_trylock.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - * pthread_mutex_trylock.c - * - * Description: - * This translation unit implements mutual exclusion (mutex) primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_mutex_trylock (pthread_mutex_t * mutex) -{ - pthread_mutex_t mx; - int kind; - int result = 0; - - /* - * Let the system deal with invalid pointers. - */ - - /* - * We do a quick check to see if we need to do more work - * to initialise a static mutex. We check - * again inside the guarded section of ptw32_mutex_check_need_init() - * to avoid race conditions. - */ - if (*mutex >= PTHREAD_ERRORCHECK_MUTEX_INITIALIZER) - { - if ((result = ptw32_mutex_check_need_init (mutex)) != 0) - { - return (result); - } - } - - mx = *mutex; - kind = mx->kind; - - if (kind >= 0) - { - /* Non-robust */ - if (0 == (PTW32_INTERLOCKED_LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG ( - (PTW32_INTERLOCKED_LONGPTR) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) 1, - (PTW32_INTERLOCKED_LONG) 0)) - { - if (kind != PTHREAD_MUTEX_NORMAL) - { - mx->recursive_count = 1; - mx->ownerThread = pthread_self (); - } - } - else - { - if (kind == PTHREAD_MUTEX_RECURSIVE && - pthread_equal (mx->ownerThread, pthread_self ())) - { - mx->recursive_count++; - } - else - { - result = EBUSY; - } - } - } - else - { - /* - * Robust types - * All types record the current owner thread. - * The mutex is added to a per thread list when ownership is acquired. - */ - pthread_t self; - ptw32_robust_state_t* statePtr = &mx->robustNode->stateInconsistent; - - if ((PTW32_INTERLOCKED_LONG)PTW32_ROBUST_NOTRECOVERABLE == - PTW32_INTERLOCKED_EXCHANGE_ADD_LONG( - (PTW32_INTERLOCKED_LONGPTR)statePtr, - (PTW32_INTERLOCKED_LONG)0)) - { - return ENOTRECOVERABLE; - } - - self = pthread_self(); - kind = -kind - 1; /* Convert to non-robust range */ - - if (0 == (PTW32_INTERLOCKED_LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG ( - (PTW32_INTERLOCKED_LONGPTR) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) 1, - (PTW32_INTERLOCKED_LONG) 0)) - { - if (kind != PTHREAD_MUTEX_NORMAL) - { - mx->recursive_count = 1; - } - ptw32_robust_mutex_add(mutex, self); - } - else - { - if (PTHREAD_MUTEX_RECURSIVE == kind && - pthread_equal (mx->ownerThread, pthread_self ())) - { - mx->recursive_count++; - } - else - { - if (EOWNERDEAD == (result = ptw32_robust_mutex_inherit(mutex))) - { - mx->recursive_count = 1; - ptw32_robust_mutex_add(mutex, self); - } - else - { - if (0 == result) - { - result = EBUSY; - } - } - } - } - } - - return (result); -} diff --git a/dependencies/win32_pthread/src/pthread_mutex_unlock.c b/dependencies/win32_pthread/src/pthread_mutex_unlock.c deleted file mode 100644 index d944e937..00000000 --- a/dependencies/win32_pthread/src/pthread_mutex_unlock.c +++ /dev/null @@ -1,184 +0,0 @@ -/* - * pthread_mutex_unlock.c - * - * Description: - * This translation unit implements mutual exclusion (mutex) primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int PTW32_CDECL -pthread_mutex_unlock (pthread_mutex_t * mutex) -{ - int result = 0; - int kind; - pthread_mutex_t mx; - - /* - * Let the system deal with invalid pointers. - */ - - mx = *mutex; - - /* - * If the thread calling us holds the mutex then there is no - * race condition. If another thread holds the - * lock then we shouldn't be in here. - */ - if (mx < PTHREAD_ERRORCHECK_MUTEX_INITIALIZER) - { - kind = mx->kind; - - if (kind >= 0) - { - if (kind == PTHREAD_MUTEX_NORMAL) - { - LONG idx; - - idx = (LONG) PTW32_INTERLOCKED_EXCHANGE_LONG ((PTW32_INTERLOCKED_LONGPTR)&mx->lock_idx, - (PTW32_INTERLOCKED_LONG)0); - if (idx != 0) - { - if (idx < 0) - { - /* - * Someone may be waiting on that mutex. - */ - if (SetEvent (mx->event) == 0) - { - result = EINVAL; - } - } - } - else /* [i_a] when unlocking an unlocked mutex, pthread_mutex_unlock() should always produce EPERM for any type of mutex -- see test mutex7.c */ - { - result = EPERM; - } - } - else - { - if (pthread_equal (mx->ownerThread, pthread_self())) - { - if (kind != PTHREAD_MUTEX_RECURSIVE - || 0 == --mx->recursive_count) - { - mx->ownerThread.p = NULL; - - if ((LONG) PTW32_INTERLOCKED_EXCHANGE_LONG ((PTW32_INTERLOCKED_LONGPTR)&mx->lock_idx, - (PTW32_INTERLOCKED_LONG)0) < 0L) - { - /* Someone may be waiting on that mutex */ - if (SetEvent (mx->event) == 0) - { - result = EINVAL; - } - } - } - } - else - { - result = EPERM; - } - } - } - else - { - /* Robust types */ - pthread_t self = pthread_self(); - kind = -kind - 1; /* Convert to non-robust range */ - - /* - * The thread must own the lock regardless of type if the mutex - * is robust. - */ - if (pthread_equal (mx->ownerThread, self)) - { - PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG((PTW32_INTERLOCKED_LONGPTR) &mx->robustNode->stateInconsistent, - (PTW32_INTERLOCKED_LONG)PTW32_ROBUST_NOTRECOVERABLE, - (PTW32_INTERLOCKED_LONG)PTW32_ROBUST_INCONSISTENT); - if (PTHREAD_MUTEX_NORMAL == kind) - { - ptw32_robust_mutex_remove(mutex, NULL); - - if ((LONG) PTW32_INTERLOCKED_EXCHANGE_LONG((PTW32_INTERLOCKED_LONGPTR) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) 0) < 0) - { - /* - * Someone may be waiting on that mutex. - */ - if (SetEvent (mx->event) == 0) - { - result = EINVAL; - } - } - } - else - { - if (kind != PTHREAD_MUTEX_RECURSIVE - || 0 == --mx->recursive_count) - { - ptw32_robust_mutex_remove(mutex, NULL); - - if ((LONG) PTW32_INTERLOCKED_EXCHANGE_LONG((PTW32_INTERLOCKED_LONGPTR) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) 0) < 0) - { - /* - * Someone may be waiting on that mutex. - */ - if (SetEvent (mx->event) == 0) - { - result = EINVAL; - } - } - } - } - } - else - { - result = EPERM; - } - } - } - else if (mx != PTHREAD_MUTEX_INITIALIZER) - { - result = EINVAL; - } - - return (result); -} diff --git a/dependencies/win32_pthread/src/pthread_mutexattr_destroy.c b/dependencies/win32_pthread/src/pthread_mutexattr_destroy.c deleted file mode 100644 index ae8428cc..00000000 --- a/dependencies/win32_pthread/src/pthread_mutexattr_destroy.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * pthread_mutexattr_destroy.c - * - * Description: - * This translation unit implements mutual exclusion (mutex) primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_mutexattr_destroy (pthread_mutexattr_t * attr) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * Destroys a mutex attributes object. The object can - * no longer be used. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_mutexattr_t - * - * - * DESCRIPTION - * Destroys a mutex attributes object. The object can - * no longer be used. - * - * NOTES: - * 1) Does not affect mutexes created using 'attr' - * - * RESULTS - * 0 successfully released attr, - * EINVAL 'attr' is invalid. - * - * ------------------------------------------------------ - */ -{ - int result = 0; - - if (attr == NULL || *attr == NULL) - { - result = EINVAL; - } - else - { - pthread_mutexattr_t ma = *attr; - - *attr = NULL; - free (ma); - } - - return (result); -} /* pthread_mutexattr_destroy */ diff --git a/dependencies/win32_pthread/src/pthread_mutexattr_getkind_np.c b/dependencies/win32_pthread/src/pthread_mutexattr_getkind_np.c deleted file mode 100644 index 13903b87..00000000 --- a/dependencies/win32_pthread/src/pthread_mutexattr_getkind_np.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * pthread_mutexattr_getkind_np.c - * - * Description: - * This translation unit implements non-portable thread functions. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -int -pthread_mutexattr_getkind_np (pthread_mutexattr_t * attr, int *kind) -{ - return pthread_mutexattr_gettype (attr, kind); -} diff --git a/dependencies/win32_pthread/src/pthread_mutexattr_getpshared.c b/dependencies/win32_pthread/src/pthread_mutexattr_getpshared.c deleted file mode 100644 index b285d2d2..00000000 --- a/dependencies/win32_pthread/src/pthread_mutexattr_getpshared.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * pthread_mutexattr_getpshared.c - * - * Description: - * This translation unit implements mutual exclusion (mutex) primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_mutexattr_getpshared (const pthread_mutexattr_t * attr, int *pshared) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * Determine whether mutexes created with 'attr' can be - * shared between processes. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_mutexattr_t - * - * pshared - * will be set to one of: - * - * PTHREAD_PROCESS_SHARED - * May be shared if in shared memory - * - * PTHREAD_PROCESS_PRIVATE - * Cannot be shared. - * - * - * DESCRIPTION - * Mutexes creatd with 'attr' can be shared between - * processes if pthread_mutex_t variable is allocated - * in memory shared by these processes. - * NOTES: - * 1) pshared mutexes MUST be allocated in shared - * memory. - * 2) The following macro is defined if shared mutexes - * are supported: - * _POSIX_THREAD_PROCESS_SHARED - * - * RESULTS - * 0 successfully retrieved attribute, - * EINVAL 'attr' is invalid, - * - * ------------------------------------------------------ - */ -{ - int result; - - if ((attr != NULL && *attr != NULL) && (pshared != NULL)) - { - *pshared = (*attr)->pshared; - result = 0; - } - else - { - result = EINVAL; - } - - return (result); - -} /* pthread_mutexattr_getpshared */ diff --git a/dependencies/win32_pthread/src/pthread_mutexattr_getrobust.c b/dependencies/win32_pthread/src/pthread_mutexattr_getrobust.c deleted file mode 100644 index 28c28657..00000000 --- a/dependencies/win32_pthread/src/pthread_mutexattr_getrobust.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * pthread_mutexattr_getrobust.c - * - * Description: - * This translation unit implements mutual exclusion (mutex) primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_mutexattr_getrobust (const pthread_mutexattr_t * attr, int * robust) - /* - * ------------------------------------------------------ - * - * DOCPUBLIC - * The pthread_mutexattr_setrobust() and - * pthread_mutexattr_getrobust() functions respectively set and - * get the mutex robust attribute. This attribute is set in the - * robust parameter to these functions. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_mutexattr_t - * - * robust - * must be one of: - * - * PTHREAD_MUTEX_STALLED - * - * PTHREAD_MUTEX_ROBUST - * - * DESCRIPTION - * The pthread_mutexattr_setrobust() and - * pthread_mutexattr_getrobust() functions respectively set and - * get the mutex robust attribute. This attribute is set in the - * robust parameter to these functions. The default value of the - * robust attribute is PTHREAD_MUTEX_STALLED. - * - * The robustness of mutex is contained in the robustness attribute - * of the mutex attributes. Valid mutex robustness values are: - * - * PTHREAD_MUTEX_STALLED - * No special actions are taken if the owner of the mutex is - * terminated while holding the mutex lock. This can lead to - * deadlocks if no other thread can unlock the mutex. - * This is the default value. - * - * PTHREAD_MUTEX_ROBUST - * If the process containing the owning thread of a robust mutex - * terminates while holding the mutex lock, the next thread that - * acquires the mutex shall be notified about the termination by - * the return value [EOWNERDEAD] from the locking function. If the - * owning thread of a robust mutex terminates while holding the mutex - * lock, the next thread that acquires the mutex may be notified - * about the termination by the return value [EOWNERDEAD]. The - * notified thread can then attempt to mark the state protected by - * the mutex as consistent again by a call to - * pthread_mutex_consistent(). After a subsequent successful call to - * pthread_mutex_unlock(), the mutex lock shall be released and can - * be used normally by other threads. If the mutex is unlocked without - * a call to pthread_mutex_consistent(), it shall be in a permanently - * unusable state and all attempts to lock the mutex shall fail with - * the error [ENOTRECOVERABLE]. The only permissible operation on such - * a mutex is pthread_mutex_destroy(). - * - * RESULTS - * 0 successfully set attribute, - * EINVAL 'attr' or 'robust' is invalid, - * - * ------------------------------------------------------ - */ -{ - int result = EINVAL; - - if ((attr != NULL && *attr != NULL && robust != NULL)) - { - *robust = (*attr)->robustness; - result = 0; - } - - return (result); -} /* pthread_mutexattr_getrobust */ diff --git a/dependencies/win32_pthread/src/pthread_mutexattr_gettype.c b/dependencies/win32_pthread/src/pthread_mutexattr_gettype.c deleted file mode 100644 index a6e4cdb8..00000000 --- a/dependencies/win32_pthread/src/pthread_mutexattr_gettype.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * pthread_mutexattr_gettype.c - * - * Description: - * This translation unit implements mutual exclusion (mutex) primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_mutexattr_gettype (const pthread_mutexattr_t * attr, int *kind) -{ - int result = 0; - - if (attr != NULL && *attr != NULL && kind != NULL) - { - *kind = (*attr)->kind; - } - else - { - result = EINVAL; - } - - return (result); -} diff --git a/dependencies/win32_pthread/src/pthread_mutexattr_init.c b/dependencies/win32_pthread/src/pthread_mutexattr_init.c deleted file mode 100644 index 037b88b3..00000000 --- a/dependencies/win32_pthread/src/pthread_mutexattr_init.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * pthread_mutexattr_init.c - * - * Description: - * This translation unit implements mutual exclusion (mutex) primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_mutexattr_init (pthread_mutexattr_t * attr) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * Initializes a mutex attributes object with default - * attributes. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_mutexattr_t - * - * - * DESCRIPTION - * Initializes a mutex attributes object with default - * attributes. - * - * NOTES: - * 1) Used to define mutex types - * - * RESULTS - * 0 successfully initialized attr, - * ENOMEM insufficient memory for attr. - * - * ------------------------------------------------------ - */ -{ - int result = 0; - pthread_mutexattr_t ma; - - ma = (pthread_mutexattr_t) calloc (1, sizeof (*ma)); - - if (ma == NULL) - { - result = ENOMEM; - } - else - { - ma->pshared = PTHREAD_PROCESS_PRIVATE; - ma->kind = PTHREAD_MUTEX_DEFAULT; - ma->robustness = PTHREAD_MUTEX_STALLED; - } - - *attr = ma; - - return (result); -} /* pthread_mutexattr_init */ diff --git a/dependencies/win32_pthread/src/pthread_mutexattr_setkind_np.c b/dependencies/win32_pthread/src/pthread_mutexattr_setkind_np.c deleted file mode 100644 index 3d55d821..00000000 --- a/dependencies/win32_pthread/src/pthread_mutexattr_setkind_np.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * pthread_mutexattr_setkind_np.c - * - * Description: - * This translation unit implements non-portable thread functions. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -int -pthread_mutexattr_setkind_np (pthread_mutexattr_t * attr, int kind) -{ - return pthread_mutexattr_settype (attr, kind); -} diff --git a/dependencies/win32_pthread/src/pthread_mutexattr_setpshared.c b/dependencies/win32_pthread/src/pthread_mutexattr_setpshared.c deleted file mode 100644 index 997f469a..00000000 --- a/dependencies/win32_pthread/src/pthread_mutexattr_setpshared.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * pthread_mutexattr_setpshared.c - * - * Description: - * This translation unit implements mutual exclusion (mutex) primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_mutexattr_setpshared (pthread_mutexattr_t * attr, int pshared) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * Mutexes created with 'attr' can be shared between - * processes if pthread_mutex_t variable is allocated - * in memory shared by these processes. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_mutexattr_t - * - * pshared - * must be one of: - * - * PTHREAD_PROCESS_SHARED - * May be shared if in shared memory - * - * PTHREAD_PROCESS_PRIVATE - * Cannot be shared. - * - * DESCRIPTION - * Mutexes creatd with 'attr' can be shared between - * processes if pthread_mutex_t variable is allocated - * in memory shared by these processes. - * - * NOTES: - * 1) pshared mutexes MUST be allocated in shared - * memory. - * - * 2) The following macro is defined if shared mutexes - * are supported: - * _POSIX_THREAD_PROCESS_SHARED - * - * RESULTS - * 0 successfully set attribute, - * EINVAL 'attr' or pshared is invalid, - * ENOSYS PTHREAD_PROCESS_SHARED not supported, - * - * ------------------------------------------------------ - */ -{ - int result; - - if ((attr != NULL && *attr != NULL) && - ((pshared == PTHREAD_PROCESS_SHARED) || - (pshared == PTHREAD_PROCESS_PRIVATE))) - { - if (pshared == PTHREAD_PROCESS_SHARED) - { - -#if !defined( _POSIX_THREAD_PROCESS_SHARED ) - - result = ENOSYS; - pshared = PTHREAD_PROCESS_PRIVATE; - -#else - - result = 0; - -#endif /* _POSIX_THREAD_PROCESS_SHARED */ - - } - else - { - result = 0; - } - - (*attr)->pshared = pshared; - } - else - { - result = EINVAL; - } - - return (result); - -} /* pthread_mutexattr_setpshared */ diff --git a/dependencies/win32_pthread/src/pthread_mutexattr_setrobust.c b/dependencies/win32_pthread/src/pthread_mutexattr_setrobust.c deleted file mode 100644 index 4f18b489..00000000 --- a/dependencies/win32_pthread/src/pthread_mutexattr_setrobust.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * pthread_mutexattr_setrobust.c - * - * Description: - * This translation unit implements mutual exclusion (mutex) primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_mutexattr_setrobust (pthread_mutexattr_t * attr, int robust) - /* - * ------------------------------------------------------ - * - * DOCPUBLIC - * The pthread_mutexattr_setrobust() and - * pthread_mutexattr_getrobust() functions respectively set and - * get the mutex robust attribute. This attribute is set in the - * robust parameter to these functions. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_mutexattr_t - * - * robust - * must be one of: - * - * PTHREAD_MUTEX_STALLED - * - * PTHREAD_MUTEX_ROBUST - * - * DESCRIPTION - * The pthread_mutexattr_setrobust() and - * pthread_mutexattr_getrobust() functions respectively set and - * get the mutex robust attribute. This attribute is set in the - * robust parameter to these functions. The default value of the - * robust attribute is PTHREAD_MUTEX_STALLED. - * - * The robustness of mutex is contained in the robustness attribute - * of the mutex attributes. Valid mutex robustness values are: - * - * PTHREAD_MUTEX_STALLED - * No special actions are taken if the owner of the mutex is - * terminated while holding the mutex lock. This can lead to - * deadlocks if no other thread can unlock the mutex. - * This is the default value. - * - * PTHREAD_MUTEX_ROBUST - * If the process containing the owning thread of a robust mutex - * terminates while holding the mutex lock, the next thread that - * acquires the mutex shall be notified about the termination by - * the return value [EOWNERDEAD] from the locking function. If the - * owning thread of a robust mutex terminates while holding the mutex - * lock, the next thread that acquires the mutex may be notified - * about the termination by the return value [EOWNERDEAD]. The - * notified thread can then attempt to mark the state protected by - * the mutex as consistent again by a call to - * pthread_mutex_consistent(). After a subsequent successful call to - * pthread_mutex_unlock(), the mutex lock shall be released and can - * be used normally by other threads. If the mutex is unlocked without - * a call to pthread_mutex_consistent(), it shall be in a permanently - * unusable state and all attempts to lock the mutex shall fail with - * the error [ENOTRECOVERABLE]. The only permissible operation on such - * a mutex is pthread_mutex_destroy(). - * - * RESULTS - * 0 successfully set attribute, - * EINVAL 'attr' or 'robust' is invalid, - * - * ------------------------------------------------------ - */ -{ - int result = EINVAL; - - if ((attr != NULL && *attr != NULL)) - { - switch (robust) - { - case PTHREAD_MUTEX_STALLED: - case PTHREAD_MUTEX_ROBUST: - (*attr)->robustness = robust; - result = 0; - break; - } - } - - return (result); -} /* pthread_mutexattr_setrobust */ diff --git a/dependencies/win32_pthread/src/pthread_mutexattr_settype.c b/dependencies/win32_pthread/src/pthread_mutexattr_settype.c deleted file mode 100644 index bb650eb4..00000000 --- a/dependencies/win32_pthread/src/pthread_mutexattr_settype.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * pthread_mutexattr_settype.c - * - * Description: - * This translation unit implements mutual exclusion (mutex) primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_mutexattr_settype (pthread_mutexattr_t * attr, int kind) - /* - * ------------------------------------------------------ - * - * DOCPUBLIC - * The pthread_mutexattr_settype() and - * pthread_mutexattr_gettype() functions respectively set and - * get the mutex type attribute. This attribute is set in the - * type parameter to these functions. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_mutexattr_t - * - * type - * must be one of: - * - * PTHREAD_MUTEX_DEFAULT - * - * PTHREAD_MUTEX_NORMAL - * - * PTHREAD_MUTEX_ERRORCHECK - * - * PTHREAD_MUTEX_RECURSIVE - * - * DESCRIPTION - * The pthread_mutexattr_settype() and - * pthread_mutexattr_gettype() functions respectively set and - * get the mutex type attribute. This attribute is set in the - * type parameter to these functions. The default value of the - * type attribute is PTHREAD_MUTEX_DEFAULT. - * - * The type of mutex is contained in the type attribute of the - * mutex attributes. Valid mutex types include: - * - * PTHREAD_MUTEX_NORMAL - * This type of mutex does not detect deadlock. A - * thread attempting to relock this mutex without - * first unlocking it will deadlock. Attempting to - * unlock a mutex locked by a different thread - * results in undefined behavior. Attempting to - * unlock an unlocked mutex results in undefined - * behavior. - * - * PTHREAD_MUTEX_ERRORCHECK - * This type of mutex provides error checking. A - * thread attempting to relock this mutex without - * first unlocking it will return with an error. A - * thread attempting to unlock a mutex which another - * thread has locked will return with an error. A - * thread attempting to unlock an unlocked mutex will - * return with an error. - * - * PTHREAD_MUTEX_DEFAULT - * Same as PTHREAD_MUTEX_NORMAL. - * - * PTHREAD_MUTEX_RECURSIVE - * A thread attempting to relock this mutex without - * first unlocking it will succeed in locking the - * mutex. The relocking deadlock which can occur with - * mutexes of type PTHREAD_MUTEX_NORMAL cannot occur - * with this type of mutex. Multiple locks of this - * mutex require the same number of unlocks to - * release the mutex before another thread can - * acquire the mutex. A thread attempting to unlock a - * mutex which another thread has locked will return - * with an error. A thread attempting to unlock an - * unlocked mutex will return with an error. This - * type of mutex is only supported for mutexes whose - * process shared attribute is - * PTHREAD_PROCESS_PRIVATE. - * - * RESULTS - * 0 successfully set attribute, - * EINVAL 'attr' or 'type' is invalid, - * - * ------------------------------------------------------ - */ -{ - int result = 0; - - if ((attr != NULL && *attr != NULL)) - { - switch (kind) - { - case PTHREAD_MUTEX_FAST_NP: - case PTHREAD_MUTEX_RECURSIVE_NP: - case PTHREAD_MUTEX_ERRORCHECK_NP: - (*attr)->kind = kind; - break; - default: - result = EINVAL; - break; - } - } - else - { - result = EINVAL; - } - - return (result); -} /* pthread_mutexattr_settype */ diff --git a/dependencies/win32_pthread/src/pthread_num_processors_np.c b/dependencies/win32_pthread/src/pthread_num_processors_np.c deleted file mode 100644 index f94b074d..00000000 --- a/dependencies/win32_pthread/src/pthread_num_processors_np.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * pthread_num_processors_np.c - * - * Description: - * This translation unit implements non-portable thread functions. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -/* - * pthread_num_processors_np() - * - * Get the number of CPUs available to the process. - */ -int -pthread_num_processors_np (void) -{ - int count; - - if (ptw32_getprocessors (&count) != 0) - { - count = 1; - } - - return (count); -} diff --git a/dependencies/win32_pthread/src/pthread_once.c b/dependencies/win32_pthread/src/pthread_once.c deleted file mode 100644 index 479fe912..00000000 --- a/dependencies/win32_pthread/src/pthread_once.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * pthread_once.c - * - * Description: - * This translation unit implements miscellaneous thread functions. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -/* [i_a] simple wrapper ensures correct calling convention for all */ -static void PTW32_CDECL -ptw32_mcs_lock_cleanup(void *args) -{ - ptw32_mcs_local_node_t *node = (ptw32_mcs_local_node_t *)args; - ptw32_mcs_lock_release(node); -} - -int -pthread_once (pthread_once_t * once_control, void (PTW32_CDECL *init_routine) (void)) -{ - if (once_control == NULL || init_routine == NULL) - { - return EINVAL; - } - - if ((PTW32_INTERLOCKED_LONG)PTW32_FALSE == - (PTW32_INTERLOCKED_LONG)PTW32_INTERLOCKED_EXCHANGE_ADD_LONG((PTW32_INTERLOCKED_LONGPTR)&once_control->done, - (PTW32_INTERLOCKED_LONG)0)) /* MBR fence */ - { - ptw32_mcs_local_node_t node; - - ptw32_mcs_lock_acquire((ptw32_mcs_lock_t *)&once_control->lock, &node); - - if (!once_control->done) - { - -#if defined(PTW32_CONFIG_MSVC7) -#pragma inline_depth(0) -#endif - - pthread_cleanup_push(ptw32_mcs_lock_cleanup, &node); - (*init_routine)(); - pthread_cleanup_pop(0); - -#if defined(PTW32_CONFIG_MSVC7) -#pragma inline_depth() -#endif - - once_control->done = PTW32_TRUE; - } - - ptw32_mcs_lock_release(&node); - } - - return 0; - -} /* pthread_once */ diff --git a/dependencies/win32_pthread/src/pthread_rwlock_destroy.c b/dependencies/win32_pthread/src/pthread_rwlock_destroy.c deleted file mode 100644 index edb6338b..00000000 --- a/dependencies/win32_pthread/src/pthread_rwlock_destroy.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * pthread_rwlock_destroy.c - * - * Description: - * This translation unit implements read/write lock primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include "pthread.h" -#include "implement.h" - -int -pthread_rwlock_destroy (pthread_rwlock_t * rwlock) -{ - pthread_rwlock_t rwl; - int result = 0, result1 = 0, result2 = 0; - - if (rwlock == NULL || *rwlock == NULL) - { - return EINVAL; - } - - if (*rwlock != PTHREAD_RWLOCK_INITIALIZER) - { - rwl = *rwlock; - - if (rwl->nMagic != PTW32_RWLOCK_MAGIC) - { - return EINVAL; - } - - if ((result = pthread_mutex_lock (&(rwl->mtxExclusiveAccess))) != 0) - { - return result; - } - - if ((result = - pthread_mutex_lock (&(rwl->mtxSharedAccessCompleted))) != 0) - { - (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess)); - return result; - } - - /* - * Check whether any threads own/wait for the lock (wait for ex.access); - * report "BUSY" if so. - */ - if (rwl->nExclusiveAccessCount > 0 - || rwl->nSharedAccessCount > rwl->nCompletedSharedAccessCount) - { - result = pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted)); - result1 = pthread_mutex_unlock (&(rwl->mtxExclusiveAccess)); - result2 = EBUSY; - } - else - { - rwl->nMagic = 0; - - if ((result = - pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted))) != 0) - { - pthread_mutex_unlock (&rwl->mtxExclusiveAccess); - return result; - } - - if ((result = - pthread_mutex_unlock (&(rwl->mtxExclusiveAccess))) != 0) - { - return result; - } - - *rwlock = NULL; /* Invalidate rwlock before anything else */ - result = pthread_cond_destroy (&(rwl->cndSharedAccessCompleted)); - result1 = pthread_mutex_destroy (&(rwl->mtxSharedAccessCompleted)); - result2 = pthread_mutex_destroy (&(rwl->mtxExclusiveAccess)); - (void) free (rwl); - } - } - else - { - ptw32_mcs_local_node_t node; - /* - * See notes in ptw32_rwlock_check_need_init() above also. - */ - ptw32_mcs_lock_acquire(&ptw32_rwlock_test_init_lock, &node); - - /* - * Check again. - */ - if (*rwlock == PTHREAD_RWLOCK_INITIALIZER) - { - /* - * This is all we need to do to destroy a statically - * initialised rwlock that has not yet been used (initialised). - * If we get to here, another thread - * waiting to initialise this rwlock will get an EINVAL. - */ - *rwlock = NULL; - } - else - { - /* - * The rwlock has been initialised while we were waiting - * so assume it's in use. - */ - result = EBUSY; - } - - ptw32_mcs_lock_release(&node); - } - - return ((result != 0) ? result : ((result1 != 0) ? result1 : result2)); -} diff --git a/dependencies/win32_pthread/src/pthread_rwlock_init.c b/dependencies/win32_pthread/src/pthread_rwlock_init.c deleted file mode 100644 index 90a66946..00000000 --- a/dependencies/win32_pthread/src/pthread_rwlock_init.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - * pthread_rwlock_init.c - * - * Description: - * This translation unit implements read/write lock primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include "pthread.h" -#include "implement.h" - -int -pthread_rwlock_init (pthread_rwlock_t * rwlock, - const pthread_rwlockattr_t * attr) -{ - int result; - pthread_rwlock_t rwl = 0; - - if (rwlock == NULL) - { - return EINVAL; - } - - if (attr != NULL && *attr != NULL) - { - result = EINVAL; /* Not supported */ - goto DONE; - } - - rwl = (pthread_rwlock_t) calloc (1, sizeof (*rwl)); - - if (rwl == NULL) - { - result = ENOMEM; - goto DONE; - } - - rwl->nSharedAccessCount = 0; - rwl->nExclusiveAccessCount = 0; - rwl->nCompletedSharedAccessCount = 0; - - result = pthread_mutex_init (&rwl->mtxExclusiveAccess, NULL); - if (result != 0) - { - goto FAIL0; - } - - result = pthread_mutex_init (&rwl->mtxSharedAccessCompleted, NULL); - if (result != 0) - { - goto FAIL1; - } - - result = pthread_cond_init (&rwl->cndSharedAccessCompleted, NULL); - if (result != 0) - { - goto FAIL2; - } - - rwl->nMagic = PTW32_RWLOCK_MAGIC; - - result = 0; - goto DONE; - -FAIL2: - (void) pthread_mutex_destroy (&(rwl->mtxSharedAccessCompleted)); - -FAIL1: - (void) pthread_mutex_destroy (&(rwl->mtxExclusiveAccess)); - -FAIL0: - (void) free (rwl); - rwl = NULL; - -DONE: - *rwlock = rwl; - - return result; -} diff --git a/dependencies/win32_pthread/src/pthread_rwlock_rdlock.c b/dependencies/win32_pthread/src/pthread_rwlock_rdlock.c deleted file mode 100644 index 4d0d393c..00000000 --- a/dependencies/win32_pthread/src/pthread_rwlock_rdlock.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * pthread_rwlock_rdlock.c - * - * Description: - * This translation unit implements read/write lock primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include "pthread.h" -#include "implement.h" - -int -pthread_rwlock_rdlock (pthread_rwlock_t * rwlock) -{ - int result; - pthread_rwlock_t rwl; - - if (rwlock == NULL || *rwlock == NULL) - { - return EINVAL; - } - - /* - * We do a quick check to see if we need to do more work - * to initialise a static rwlock. We check - * again inside the guarded section of ptw32_rwlock_check_need_init() - * to avoid race conditions. - */ - if (*rwlock == PTHREAD_RWLOCK_INITIALIZER) - { - result = ptw32_rwlock_check_need_init (rwlock); - - if (result != 0 && result != EBUSY) - { - return result; - } - } - - rwl = *rwlock; - - if (rwl->nMagic != PTW32_RWLOCK_MAGIC) - { - return EINVAL; - } - - if ((result = pthread_mutex_lock (&(rwl->mtxExclusiveAccess))) != 0) - { - return result; - } - - if (++rwl->nSharedAccessCount == INT_MAX) - { - if ((result = - pthread_mutex_lock (&(rwl->mtxSharedAccessCompleted))) != 0) - { - (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess)); - return result; - } - - rwl->nSharedAccessCount -= rwl->nCompletedSharedAccessCount; - rwl->nCompletedSharedAccessCount = 0; - - if ((result = - pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted))) != 0) - { - (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess)); - return result; - } - } - - return (pthread_mutex_unlock (&(rwl->mtxExclusiveAccess))); -} diff --git a/dependencies/win32_pthread/src/pthread_rwlock_timedrdlock.c b/dependencies/win32_pthread/src/pthread_rwlock_timedrdlock.c deleted file mode 100644 index ed281f3d..00000000 --- a/dependencies/win32_pthread/src/pthread_rwlock_timedrdlock.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - * pthread_rwlock_timedrdlock.c - * - * Description: - * This translation unit implements read/write lock primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include "pthread.h" -#include "implement.h" - -int -pthread_rwlock_timedrdlock (pthread_rwlock_t * rwlock, - const struct timespec *abstime) -{ - int result; - pthread_rwlock_t rwl; - - if (rwlock == NULL || *rwlock == NULL) - { - return EINVAL; - } - - /* - * We do a quick check to see if we need to do more work - * to initialise a static rwlock. We check - * again inside the guarded section of ptw32_rwlock_check_need_init() - * to avoid race conditions. - */ - if (*rwlock == PTHREAD_RWLOCK_INITIALIZER) - { - result = ptw32_rwlock_check_need_init (rwlock); - - if (result != 0 && result != EBUSY) - { - return result; - } - } - - rwl = *rwlock; - - if (rwl->nMagic != PTW32_RWLOCK_MAGIC) - { - return EINVAL; - } - - if ((result = - pthread_mutex_timedlock (&(rwl->mtxExclusiveAccess), abstime)) != 0) - { - return result; - } - - if (++rwl->nSharedAccessCount == INT_MAX) - { - if ((result = - pthread_mutex_timedlock (&(rwl->mtxSharedAccessCompleted), - abstime)) != 0) - { - if (result == ETIMEDOUT) - { - ++rwl->nCompletedSharedAccessCount; - } - (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess)); - return result; - } - - rwl->nSharedAccessCount -= rwl->nCompletedSharedAccessCount; - rwl->nCompletedSharedAccessCount = 0; - - if ((result = - pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted))) != 0) - { - (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess)); - return result; - } - } - - return (pthread_mutex_unlock (&(rwl->mtxExclusiveAccess))); -} diff --git a/dependencies/win32_pthread/src/pthread_rwlock_timedwrlock.c b/dependencies/win32_pthread/src/pthread_rwlock_timedwrlock.c deleted file mode 100644 index 7622d97f..00000000 --- a/dependencies/win32_pthread/src/pthread_rwlock_timedwrlock.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - * pthread_rwlock_timedwrlock.c - * - * Description: - * This translation unit implements read/write lock primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include "pthread.h" -#include "implement.h" - -int -pthread_rwlock_timedwrlock (pthread_rwlock_t * rwlock, - const struct timespec *abstime) -{ - int result; - pthread_rwlock_t rwl; - - if (rwlock == NULL || *rwlock == NULL) - { - return EINVAL; - } - - /* - * We do a quick check to see if we need to do more work - * to initialise a static rwlock. We check - * again inside the guarded section of ptw32_rwlock_check_need_init() - * to avoid race conditions. - */ - if (*rwlock == PTHREAD_RWLOCK_INITIALIZER) - { - result = ptw32_rwlock_check_need_init (rwlock); - - if (result != 0 && result != EBUSY) - { - return result; - } - } - - rwl = *rwlock; - - if (rwl->nMagic != PTW32_RWLOCK_MAGIC) - { - return EINVAL; - } - - if ((result = - pthread_mutex_timedlock (&(rwl->mtxExclusiveAccess), abstime)) != 0) - { - return result; - } - - if ((result = - pthread_mutex_timedlock (&(rwl->mtxSharedAccessCompleted), - abstime)) != 0) - { - (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess)); - return result; - } - - if (rwl->nExclusiveAccessCount == 0) - { - if (rwl->nCompletedSharedAccessCount > 0) - { - rwl->nSharedAccessCount -= rwl->nCompletedSharedAccessCount; - rwl->nCompletedSharedAccessCount = 0; - } - - if (rwl->nSharedAccessCount > 0) - { - rwl->nCompletedSharedAccessCount = -rwl->nSharedAccessCount; - - /* - * This routine may be a cancellation point - * according to POSIX 1003.1j section 18.1.2. - */ -#if defined(PTW32_CONFIG_MSVC7) -#pragma inline_depth(0) -#endif - pthread_cleanup_push (ptw32_rwlock_cancelwrwait, (void *) rwl); - - do - { - result = - pthread_cond_timedwait (&(rwl->cndSharedAccessCompleted), - &(rwl->mtxSharedAccessCompleted), - abstime); - } - while (result == 0 && rwl->nCompletedSharedAccessCount < 0); - - pthread_cleanup_pop ((result != 0) ? 1 : 0); -#if defined(PTW32_CONFIG_MSVC7) -#pragma inline_depth() -#endif - - if (result == 0) - { - rwl->nSharedAccessCount = 0; - } - } - } - - if (result == 0) - { - rwl->nExclusiveAccessCount++; - } - - return result; -} diff --git a/dependencies/win32_pthread/src/pthread_rwlock_tryrdlock.c b/dependencies/win32_pthread/src/pthread_rwlock_tryrdlock.c deleted file mode 100644 index 5660b5ad..00000000 --- a/dependencies/win32_pthread/src/pthread_rwlock_tryrdlock.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * pthread_rwlock_tryrdlock.c - * - * Description: - * This translation unit implements read/write lock primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include "pthread.h" -#include "implement.h" - -int -pthread_rwlock_tryrdlock (pthread_rwlock_t * rwlock) -{ - int result; - pthread_rwlock_t rwl; - - if (rwlock == NULL || *rwlock == NULL) - { - return EINVAL; - } - - /* - * We do a quick check to see if we need to do more work - * to initialise a static rwlock. We check - * again inside the guarded section of ptw32_rwlock_check_need_init() - * to avoid race conditions. - */ - if (*rwlock == PTHREAD_RWLOCK_INITIALIZER) - { - result = ptw32_rwlock_check_need_init (rwlock); - - if (result != 0 && result != EBUSY) - { - return result; - } - } - - rwl = *rwlock; - - if (rwl->nMagic != PTW32_RWLOCK_MAGIC) - { - return EINVAL; - } - - if ((result = pthread_mutex_trylock (&(rwl->mtxExclusiveAccess))) != 0) - { - return result; - } - - if (++rwl->nSharedAccessCount == INT_MAX) - { - if ((result = - pthread_mutex_lock (&(rwl->mtxSharedAccessCompleted))) != 0) - { - (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess)); - return result; - } - - rwl->nSharedAccessCount -= rwl->nCompletedSharedAccessCount; - rwl->nCompletedSharedAccessCount = 0; - - if ((result = - pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted))) != 0) - { - (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess)); - return result; - } - } - - return (pthread_mutex_unlock (&rwl->mtxExclusiveAccess)); -} diff --git a/dependencies/win32_pthread/src/pthread_rwlock_trywrlock.c b/dependencies/win32_pthread/src/pthread_rwlock_trywrlock.c deleted file mode 100644 index f12df055..00000000 --- a/dependencies/win32_pthread/src/pthread_rwlock_trywrlock.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - * pthread_rwlock_trywrlock.c - * - * Description: - * This translation unit implements read/write lock primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include "pthread.h" -#include "implement.h" - -int -pthread_rwlock_trywrlock (pthread_rwlock_t * rwlock) -{ - int result, result1; - pthread_rwlock_t rwl; - - if (rwlock == NULL || *rwlock == NULL) - { - return EINVAL; - } - - /* - * We do a quick check to see if we need to do more work - * to initialise a static rwlock. We check - * again inside the guarded section of ptw32_rwlock_check_need_init() - * to avoid race conditions. - */ - if (*rwlock == PTHREAD_RWLOCK_INITIALIZER) - { - result = ptw32_rwlock_check_need_init (rwlock); - - if (result != 0 && result != EBUSY) - { - return result; - } - } - - rwl = *rwlock; - - if (rwl->nMagic != PTW32_RWLOCK_MAGIC) - { - return EINVAL; - } - - if ((result = pthread_mutex_trylock (&(rwl->mtxExclusiveAccess))) != 0) - { - return result; - } - - if ((result = - pthread_mutex_trylock (&(rwl->mtxSharedAccessCompleted))) != 0) - { - result1 = pthread_mutex_unlock (&(rwl->mtxExclusiveAccess)); - return ((result1 != 0) ? result1 : result); - } - - if (rwl->nExclusiveAccessCount == 0) - { - if (rwl->nCompletedSharedAccessCount > 0) - { - rwl->nSharedAccessCount -= rwl->nCompletedSharedAccessCount; - rwl->nCompletedSharedAccessCount = 0; - } - - if (rwl->nSharedAccessCount > 0) - { - if ((result = - pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted))) != 0) - { - (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess)); - return result; - } - - if ((result = - pthread_mutex_unlock (&(rwl->mtxExclusiveAccess))) == 0) - { - result = EBUSY; - } - } - else - { - rwl->nExclusiveAccessCount = 1; - } - } - else - { - result = EBUSY; - } - - return result; -} diff --git a/dependencies/win32_pthread/src/pthread_rwlock_unlock.c b/dependencies/win32_pthread/src/pthread_rwlock_unlock.c deleted file mode 100644 index 63feac3e..00000000 --- a/dependencies/win32_pthread/src/pthread_rwlock_unlock.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * pthread_rwlock_unlock.c - * - * Description: - * This translation unit implements read/write lock primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include "pthread.h" -#include "implement.h" - -int -pthread_rwlock_unlock (pthread_rwlock_t * rwlock) -{ - int result, result1; - pthread_rwlock_t rwl; - - if (rwlock == NULL || *rwlock == NULL) - { - return (EINVAL); - } - - if (*rwlock == PTHREAD_RWLOCK_INITIALIZER) - { - /* - * Assume any race condition here is harmless. - */ - return 0; - } - - rwl = *rwlock; - - if (rwl->nMagic != PTW32_RWLOCK_MAGIC) - { - return EINVAL; - } - - if (rwl->nExclusiveAccessCount == 0) - { - if ((result = - pthread_mutex_lock (&(rwl->mtxSharedAccessCompleted))) != 0) - { - return result; - } - - if (++rwl->nCompletedSharedAccessCount == 0) - { - result = pthread_cond_signal (&(rwl->cndSharedAccessCompleted)); - } - - result1 = pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted)); - } - else - { - rwl->nExclusiveAccessCount--; - - result = pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted)); - result1 = pthread_mutex_unlock (&(rwl->mtxExclusiveAccess)); - - } - - return ((result != 0) ? result : result1); -} diff --git a/dependencies/win32_pthread/src/pthread_rwlock_wrlock.c b/dependencies/win32_pthread/src/pthread_rwlock_wrlock.c deleted file mode 100644 index 722a673f..00000000 --- a/dependencies/win32_pthread/src/pthread_rwlock_wrlock.c +++ /dev/null @@ -1,138 +0,0 @@ -/* - * pthread_rwlock_wrlock.c - * - * Description: - * This translation unit implements read/write lock primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include "pthread.h" -#include "implement.h" - -int -pthread_rwlock_wrlock (pthread_rwlock_t * rwlock) -{ - int result; - pthread_rwlock_t rwl; - - if (rwlock == NULL || *rwlock == NULL) - { - return EINVAL; - } - - /* - * We do a quick check to see if we need to do more work - * to initialise a static rwlock. We check - * again inside the guarded section of ptw32_rwlock_check_need_init() - * to avoid race conditions. - */ - if (*rwlock == PTHREAD_RWLOCK_INITIALIZER) - { - result = ptw32_rwlock_check_need_init (rwlock); - - if (result != 0 && result != EBUSY) - { - return result; - } - } - - rwl = *rwlock; - - if (rwl->nMagic != PTW32_RWLOCK_MAGIC) - { - return EINVAL; - } - - if ((result = pthread_mutex_lock (&(rwl->mtxExclusiveAccess))) != 0) - { - return result; - } - - if ((result = pthread_mutex_lock (&(rwl->mtxSharedAccessCompleted))) != 0) - { - (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess)); - return result; - } - - if (rwl->nExclusiveAccessCount == 0) - { - if (rwl->nCompletedSharedAccessCount > 0) - { - rwl->nSharedAccessCount -= rwl->nCompletedSharedAccessCount; - rwl->nCompletedSharedAccessCount = 0; - } - - if (rwl->nSharedAccessCount > 0) - { - rwl->nCompletedSharedAccessCount = -rwl->nSharedAccessCount; - - /* - * This routine may be a cancellation point - * according to POSIX 1003.1j section 18.1.2. - */ -#if defined(PTW32_CONFIG_MSVC7) -#pragma inline_depth(0) -#endif - pthread_cleanup_push (ptw32_rwlock_cancelwrwait, (void *) rwl); - - do - { - result = pthread_cond_wait (&(rwl->cndSharedAccessCompleted), - &(rwl->mtxSharedAccessCompleted)); - } - while (result == 0 && rwl->nCompletedSharedAccessCount < 0); - - pthread_cleanup_pop ((result != 0) ? 1 : 0); -#if defined(PTW32_CONFIG_MSVC7) -#pragma inline_depth() -#endif - - if (result == 0) - { - rwl->nSharedAccessCount = 0; - } - } - } - - if (result == 0) - { - rwl->nExclusiveAccessCount++; - } - - return result; -} diff --git a/dependencies/win32_pthread/src/pthread_rwlockattr_destroy.c b/dependencies/win32_pthread/src/pthread_rwlockattr_destroy.c deleted file mode 100644 index e9e3407b..00000000 --- a/dependencies/win32_pthread/src/pthread_rwlockattr_destroy.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * pthread_rwlockattr_destroy.c - * - * Description: - * This translation unit implements read/write lock primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include "pthread.h" -#include "implement.h" - -int -pthread_rwlockattr_destroy (pthread_rwlockattr_t * attr) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * Destroys a rwlock attributes object. The object can - * no longer be used. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_rwlockattr_t - * - * - * DESCRIPTION - * Destroys a rwlock attributes object. The object can - * no longer be used. - * - * NOTES: - * 1) Does not affect rwlockss created using 'attr' - * - * RESULTS - * 0 successfully released attr, - * EINVAL 'attr' is invalid. - * - * ------------------------------------------------------ - */ -{ - int result = 0; - - if (attr == NULL || *attr == NULL) - { - result = EINVAL; - } - else - { - pthread_rwlockattr_t rwa = *attr; - - *attr = NULL; - free (rwa); - } - - return (result); -} /* pthread_rwlockattr_destroy */ diff --git a/dependencies/win32_pthread/src/pthread_rwlockattr_getpshared.c b/dependencies/win32_pthread/src/pthread_rwlockattr_getpshared.c deleted file mode 100644 index 4de7d30e..00000000 --- a/dependencies/win32_pthread/src/pthread_rwlockattr_getpshared.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * pthread_rwlockattr_getpshared.c - * - * Description: - * This translation unit implements read/write lock primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include "pthread.h" -#include "implement.h" - -int -pthread_rwlockattr_getpshared (const pthread_rwlockattr_t * attr, - int *pshared) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * Determine whether rwlocks created with 'attr' can be - * shared between processes. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_rwlockattr_t - * - * pshared - * will be set to one of: - * - * PTHREAD_PROCESS_SHARED - * May be shared if in shared memory - * - * PTHREAD_PROCESS_PRIVATE - * Cannot be shared. - * - * - * DESCRIPTION - * Rwlocks creatd with 'attr' can be shared between - * processes if pthread_rwlock_t variable is allocated - * in memory shared by these processes. - * NOTES: - * 1) pshared rwlocks MUST be allocated in shared - * memory. - * 2) The following macro is defined if shared rwlocks - * are supported: - * _POSIX_THREAD_PROCESS_SHARED - * - * RESULTS - * 0 successfully retrieved attribute, - * EINVAL 'attr' is invalid, - * - * ------------------------------------------------------ - */ -{ - int result; - - if ((attr != NULL && *attr != NULL) && (pshared != NULL)) - { - *pshared = (*attr)->pshared; - result = 0; - } - else - { - result = EINVAL; - } - - return (result); - -} /* pthread_rwlockattr_getpshared */ diff --git a/dependencies/win32_pthread/src/pthread_rwlockattr_init.c b/dependencies/win32_pthread/src/pthread_rwlockattr_init.c deleted file mode 100644 index 994b7ec0..00000000 --- a/dependencies/win32_pthread/src/pthread_rwlockattr_init.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * pthread_rwlockattr_init.c - * - * Description: - * This translation unit implements read/write lock primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include "pthread.h" -#include "implement.h" - -int -pthread_rwlockattr_init (pthread_rwlockattr_t * attr) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * Initializes a rwlock attributes object with default - * attributes. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_rwlockattr_t - * - * - * DESCRIPTION - * Initializes a rwlock attributes object with default - * attributes. - * - * RESULTS - * 0 successfully initialized attr, - * ENOMEM insufficient memory for attr. - * - * ------------------------------------------------------ - */ -{ - int result = 0; - pthread_rwlockattr_t rwa; - - rwa = (pthread_rwlockattr_t) calloc (1, sizeof (*rwa)); - - if (rwa == NULL) - { - result = ENOMEM; - } - else - { - rwa->pshared = PTHREAD_PROCESS_PRIVATE; - } - - *attr = rwa; - - return (result); -} /* pthread_rwlockattr_init */ diff --git a/dependencies/win32_pthread/src/pthread_rwlockattr_setpshared.c b/dependencies/win32_pthread/src/pthread_rwlockattr_setpshared.c deleted file mode 100644 index 0263c11f..00000000 --- a/dependencies/win32_pthread/src/pthread_rwlockattr_setpshared.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * pthread_rwlockattr_setpshared.c - * - * Description: - * This translation unit implements read/write lock primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include "pthread.h" -#include "implement.h" - -int -pthread_rwlockattr_setpshared (pthread_rwlockattr_t * attr, int pshared) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * Rwlocks created with 'attr' can be shared between - * processes if pthread_rwlock_t variable is allocated - * in memory shared by these processes. - * - * PARAMETERS - * attr - * pointer to an instance of pthread_rwlockattr_t - * - * pshared - * must be one of: - * - * PTHREAD_PROCESS_SHARED - * May be shared if in shared memory - * - * PTHREAD_PROCESS_PRIVATE - * Cannot be shared. - * - * DESCRIPTION - * Rwlocks creatd with 'attr' can be shared between - * processes if pthread_rwlock_t variable is allocated - * in memory shared by these processes. - * - * NOTES: - * 1) pshared rwlocks MUST be allocated in shared - * memory. - * - * 2) The following macro is defined if shared rwlocks - * are supported: - * _POSIX_THREAD_PROCESS_SHARED - * - * RESULTS - * 0 successfully set attribute, - * EINVAL 'attr' or pshared is invalid, - * ENOSYS PTHREAD_PROCESS_SHARED not supported, - * - * ------------------------------------------------------ - */ -{ - int result; - - if ((attr != NULL && *attr != NULL) && - ((pshared == PTHREAD_PROCESS_SHARED) || - (pshared == PTHREAD_PROCESS_PRIVATE))) - { - if (pshared == PTHREAD_PROCESS_SHARED) - { - -#if !defined( _POSIX_THREAD_PROCESS_SHARED ) - - result = ENOSYS; - pshared = PTHREAD_PROCESS_PRIVATE; - -#else - - result = 0; - -#endif /* _POSIX_THREAD_PROCESS_SHARED */ - - } - else - { - result = 0; - } - - (*attr)->pshared = pshared; - } - else - { - result = EINVAL; - } - - return (result); - -} /* pthread_rwlockattr_setpshared */ diff --git a/dependencies/win32_pthread/src/pthread_self.c b/dependencies/win32_pthread/src/pthread_self.c deleted file mode 100644 index 4b52025b..00000000 --- a/dependencies/win32_pthread/src/pthread_self.c +++ /dev/null @@ -1,177 +0,0 @@ -/* - * pthread_self.c - * - * Description: - * This translation unit implements miscellaneous thread functions. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -pthread_t -pthread_self (void) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function returns a reference to the current running - * thread. - * - * PARAMETERS - * N/A - * - * - * DESCRIPTION - * This function returns a reference to the current running - * thread. - * - * RESULTS - * pthread_t reference to the current thread - * - * ------------------------------------------------------ - */ -{ - pthread_t self; - DWORD_PTR vThreadMask, vProcessMask, vSystemMask; - pthread_t nil = {NULL, 0}; - ptw32_thread_t * sp; - - if (!ptw32_processInitialize()) - return nil; - -#if defined(_UWIN) - if (!ptw32_selfThreadKey) - return nil; -#endif - - sp = (ptw32_thread_t *) pthread_getspecific (ptw32_selfThreadKey); - - if (sp != NULL) - { - self = sp->ptHandle; - } - else - { - int fail = PTW32_FALSE; - /* - * Need to create an implicit 'self' for the currently - * executing thread. - */ - self = ptw32_new (); - sp = (ptw32_thread_t *) self.p; - - if (sp != NULL) - { - /* - * This is a non-POSIX thread which has chosen to call - * a POSIX threads function for some reason. We assume that - * it isn't joinable, but we do assume that it's - * (deferred) cancelable. - */ - sp->implicit = 1; - sp->detachState = PTHREAD_CREATE_DETACHED; - sp->thread = GetCurrentThreadId (); - -#if defined(NEED_DUPLICATEHANDLE) - /* - * DuplicateHandle does not exist on WinCE. - * - * NOTE: - * GetCurrentThread only returns a pseudo-handle - * which is only valid in the current thread context. - * Therefore, you should not pass the handle to - * other threads for whatever purpose. - */ - sp->threadH = GetCurrentThread (); -#else - if (!DuplicateHandle (GetCurrentProcess (), - GetCurrentThread (), - GetCurrentProcess (), - &sp->threadH, - 0, FALSE, DUPLICATE_SAME_ACCESS)) - { - fail = PTW32_TRUE; - } -#endif - /* - * Get this threads CPU affinity by temporarily setting the threads - * affinity to that of the process to get the old thread affinity, - * then reset to the old affinity. - */ - if (!fail) - { - if (GetProcessAffinityMask(GetCurrentProcess(), &vProcessMask, &vSystemMask)) - { - vThreadMask = SetThreadAffinityMask(sp->threadH, vProcessMask); - if (vThreadMask) - { - if (SetThreadAffinityMask(sp->threadH, vThreadMask)) - { - sp->cpuset = (size_t) vThreadMask; - } - else fail = PTW32_TRUE; - } - else fail = PTW32_TRUE; - } - else fail = PTW32_TRUE; - - /* - * No need to explicitly serialise access to sched_priority - * because the new handle is not yet public. - */ - sp->sched_priority = GetThreadPriority (sp->threadH); - pthread_setspecific (ptw32_selfThreadKey, (void *) sp); - } - } - - if (fail) - { - /* - * Thread structs are never freed but are reused so if this - * continues to fail at least we don't leak memory. - */ - sp->threadH = 0; // [i_a] - ptw32_threadReusePush (self); - /* - * As this is a win32 thread calling us and we have failed, - * return a value that makes sense to win32. - */ - return nil; - } - } - - return (self); -} diff --git a/dependencies/win32_pthread/src/pthread_setaffinity.c b/dependencies/win32_pthread/src/pthread_setaffinity.c deleted file mode 100644 index 81d2e734..00000000 --- a/dependencies/win32_pthread/src/pthread_setaffinity.c +++ /dev/null @@ -1,225 +0,0 @@ -/* - * pthread_setaffinity.c - * - * Description: - * This translation unit implements thread cpu affinity setting. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -int -pthread_setaffinity_np (pthread_t thread, size_t cpusetsize, - const cpu_set_t *cpuset) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * The pthread_setaffinity_np() function sets the CPU affinity mask - * of the thread thread to the CPU set pointed to by cpuset. If the - * call is successful, and the thread is not currently running on one - * of the CPUs in cpuset, then it is migrated to one of those CPUs. - * - * PARAMETERS - * thread - * The target thread - * - * cpusetsize - * Ignored in pthreads4w. - * Usually set to sizeof(cpu_set_t) - * - * cpuset - * The new cpu set mask. - * - * The set of CPUs on which the thread will actually run - * is the intersection of the set specified in the cpuset - * argument and the set of CPUs actually present for - * the process. - * - * DESCRIPTION - * The pthread_setaffinity_np() function sets the CPU affinity mask - * of the thread thread to the CPU set pointed to by cpuset. If the - * call is successful, and the thread is not currently running on one - * of the CPUs in cpuset, then it is migrated to one of those CPUs. - * - * RESULTS - * 0 Success - * ESRCH Thread does not exist - * EFAULT pcuset is NULL - * EAGAIN The thread affinity could not be set - * - * ------------------------------------------------------ - */ -{ - int result = 0; - ptw32_thread_t * tp; - ptw32_mcs_local_node_t node; - cpu_set_t processCpuset; - - ptw32_mcs_lock_acquire (&ptw32_thread_reuse_lock, &node); - - tp = (ptw32_thread_t *) thread.p; - - if (NULL == tp || thread.x != tp->ptHandle.x || NULL == tp->threadH) - { - result = ESRCH; - } - else - { - if (cpuset) - { - if (sched_getaffinity(0, sizeof(cpu_set_t), &processCpuset)) - { - result = PTW32_GET_ERRNO(); - } - else - { - /* - * Result is the intersection of available CPUs and the mask. - */ - cpu_set_t newMask; - - CPU_AND(&newMask, &processCpuset, cpuset); - - if (((_sched_cpu_set_vector_*)&newMask)->_cpuset) - { - if (SetThreadAffinityMask (tp->threadH, ((_sched_cpu_set_vector_*)&newMask)->_cpuset)) - { - /* - * We record the intersection of the process affinity - * and the thread affinity cpusets so that - * pthread_getaffinity_np() returns the actual thread - * CPU set. - */ - tp->cpuset = ((_sched_cpu_set_vector_*)&newMask)->_cpuset; - } - else - { - result = EAGAIN; - } - } - else - { - result = EINVAL; - } - } - } - else - { - result = EFAULT; - } - } - - ptw32_mcs_lock_release (&node); - - return result; -} - -int -pthread_getaffinity_np (pthread_t thread, size_t cpusetsize, cpu_set_t *cpuset) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * The pthread_getaffinity_np() function returns the CPU affinity mask - * of the thread thread in the CPU set pointed to by cpuset. - * - * PARAMETERS - * thread - * The target thread - * - * cpusetsize - * Ignored in pthreads4w. - * Usually set to sizeof(cpu_set_t) - * - * cpuset - * The location where the current cpu set - * will be returned. - * - * - * DESCRIPTION - * The pthread_getaffinity_np() function returns the CPU affinity mask - * of the thread thread in the CPU set pointed to by cpuset. - * - * RESULTS - * 0 Success - * ESRCH thread does not exist - * EFAULT cpuset is NULL - * - * ------------------------------------------------------ - */ -{ - int result = 0; - ptw32_thread_t * tp; - ptw32_mcs_local_node_t node; - - ptw32_mcs_lock_acquire(&ptw32_thread_reuse_lock, &node); - - tp = (ptw32_thread_t *) thread.p; - - if (NULL == tp || thread.x != tp->ptHandle.x || NULL == tp->threadH) - { - result = ESRCH; - } - else - { - if (cpuset) - { - if (tp->cpuset) - { - /* - * The application may have set thread affinity independently - * via SetThreadAffinityMask(). If so, we adjust our record of the threads - * affinity and try to do so in a reasonable way. - */ - DWORD_PTR vThreadMask = SetThreadAffinityMask(tp->threadH, tp->cpuset); - if (vThreadMask && vThreadMask != tp->cpuset) - { - (void) SetThreadAffinityMask(tp->threadH, vThreadMask); - tp->cpuset = vThreadMask; - } - } - ((_sched_cpu_set_vector_*)cpuset)->_cpuset = tp->cpuset; - } - else - { - result = EFAULT; - } - } - - ptw32_mcs_lock_release(&node); - - return result; -} diff --git a/dependencies/win32_pthread/src/pthread_setcancelstate.c b/dependencies/win32_pthread/src/pthread_setcancelstate.c deleted file mode 100644 index 15268257..00000000 --- a/dependencies/win32_pthread/src/pthread_setcancelstate.c +++ /dev/null @@ -1,130 +0,0 @@ -/* - * pthread_setcancelstate.c - * - * Description: - * POSIX thread functions related to thread cancellation. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_setcancelstate (int state, int *oldstate) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function atomically sets the calling thread's - * cancelability state to 'state' and returns the previous - * cancelability state at the location referenced by - * 'oldstate' - * - * PARAMETERS - * state, - * oldstate - * PTHREAD_CANCEL_ENABLE - * cancellation is enabled, - * - * PTHREAD_CANCEL_DISABLE - * cancellation is disabled - * - * - * DESCRIPTION - * This function atomically sets the calling thread's - * cancelability state to 'state' and returns the previous - * cancelability state at the location referenced by - * 'oldstate'. - * - * NOTES: - * 1) Use to disable cancellation around 'atomic' code that - * includes cancellation points - * - * COMPATIBILITY ADDITIONS - * If 'oldstate' is NULL then the previous state is not returned - * but the function still succeeds. (Solaris) - * - * RESULTS - * 0 successfully set cancelability type, - * EINVAL 'state' is invalid - * - * ------------------------------------------------------ - */ -{ - ptw32_mcs_local_node_t stateLock; - int result = 0; - pthread_t self = pthread_self (); - ptw32_thread_t * sp = (ptw32_thread_t *) self.p; - - if (sp == NULL - || (state != PTHREAD_CANCEL_ENABLE && state != PTHREAD_CANCEL_DISABLE)) - { - return EINVAL; - } - - /* - * Lock for async-cancel safety. - */ - ptw32_mcs_lock_acquire (&sp->stateLock, &stateLock); - - if (oldstate != NULL) - { - *oldstate = sp->cancelState; - } - - sp->cancelState = state; - - /* - * Check if there is a pending asynchronous cancel - */ - if (state == PTHREAD_CANCEL_ENABLE - && sp->cancelType == PTHREAD_CANCEL_ASYNCHRONOUS - && WaitForSingleObject (sp->cancelEvent, 0) == WAIT_OBJECT_0) - { - sp->state = PThreadStateCanceling; - sp->cancelState = PTHREAD_CANCEL_DISABLE; - ResetEvent (sp->cancelEvent); - ptw32_mcs_lock_release (&stateLock); - ptw32_throw (PTW32_EPS_CANCEL); - - /* Never reached */ - } - - ptw32_mcs_lock_release (&stateLock); - - return (result); - -} /* pthread_setcancelstate */ diff --git a/dependencies/win32_pthread/src/pthread_setcanceltype.c b/dependencies/win32_pthread/src/pthread_setcanceltype.c deleted file mode 100644 index 41ecfe0d..00000000 --- a/dependencies/win32_pthread/src/pthread_setcanceltype.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * pthread_setcanceltype.c - * - * Description: - * POSIX thread functions related to thread cancellation. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_setcanceltype (int type, int *oldtype) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function atomically sets the calling thread's - * cancelability type to 'type' and returns the previous - * cancelability type at the location referenced by - * 'oldtype' - * - * PARAMETERS - * type, - * oldtype - * PTHREAD_CANCEL_DEFERRED - * only deferred cancellation is allowed, - * - * PTHREAD_CANCEL_ASYNCHRONOUS - * Asynchronous cancellation is allowed - * - * - * DESCRIPTION - * This function atomically sets the calling thread's - * cancelability type to 'type' and returns the previous - * cancelability type at the location referenced by - * 'oldtype' - * - * NOTES: - * 1) Use with caution; most code is not safe for use - * with asynchronous cancelability. - * - * COMPATIBILITY ADDITIONS - * If 'oldtype' is NULL then the previous type is not returned - * but the function still succeeds. (Solaris) - * - * RESULTS - * 0 successfully set cancelability type, - * EINVAL 'type' is invalid - * - * ------------------------------------------------------ - */ -{ - ptw32_mcs_local_node_t stateLock; - int result = 0; - pthread_t self = pthread_self (); - ptw32_thread_t * sp = (ptw32_thread_t *) self.p; - - if (sp == NULL - || (type != PTHREAD_CANCEL_DEFERRED - && type != PTHREAD_CANCEL_ASYNCHRONOUS)) - { - return EINVAL; - } - - /* - * Lock for async-cancel safety. - */ - ptw32_mcs_lock_acquire (&sp->stateLock, &stateLock); - - if (oldtype != NULL) - { - *oldtype = sp->cancelType; - } - - sp->cancelType = type; - - /* - * Check if there is a pending asynchronous cancel - */ - if (sp->cancelState == PTHREAD_CANCEL_ENABLE - && type == PTHREAD_CANCEL_ASYNCHRONOUS - && WaitForSingleObject (sp->cancelEvent, 0) == WAIT_OBJECT_0) - { - sp->state = PThreadStateCanceling; - sp->cancelState = PTHREAD_CANCEL_DISABLE; - ResetEvent (sp->cancelEvent); - ptw32_mcs_lock_release (&stateLock); - ptw32_throw (PTW32_EPS_CANCEL); - - /* Never reached */ - } - - ptw32_mcs_lock_release (&stateLock); - - return (result); - -} /* pthread_setcanceltype */ diff --git a/dependencies/win32_pthread/src/pthread_setconcurrency.c b/dependencies/win32_pthread/src/pthread_setconcurrency.c deleted file mode 100644 index 1861f96e..00000000 --- a/dependencies/win32_pthread/src/pthread_setconcurrency.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * pthread_setconcurrency.c - * - * Description: - * This translation unit implements miscellaneous thread functions. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_setconcurrency (int level) -{ - if (level < 0) - { - return EINVAL; - } - else - { - ptw32_concurrency = level; - return 0; - } -} diff --git a/dependencies/win32_pthread/src/pthread_setschedparam.c b/dependencies/win32_pthread/src/pthread_setschedparam.c deleted file mode 100644 index f0576d4f..00000000 --- a/dependencies/win32_pthread/src/pthread_setschedparam.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * sched_setschedparam.c - * - * Description: - * POSIX thread functions that deal with thread scheduling. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" -#include "sched.h" - -int -pthread_setschedparam (pthread_t thread, int policy, - const struct sched_param *param) -{ - int result; - - /* Validate the thread id. */ - result = pthread_kill (thread, 0); - if (0 != result) - { - return result; - } - - /* Validate the scheduling policy. */ - if (policy < SCHED_MIN || policy > SCHED_MAX) - { - return EINVAL; - } - - /* Ensure the policy is SCHED_OTHER. */ - if (policy != SCHED_OTHER) - { - return ENOTSUP; - } - - return (ptw32_setthreadpriority (thread, policy, param->sched_priority)); -} - - -int -ptw32_setthreadpriority (pthread_t thread, int policy, int priority) -{ - int prio; - ptw32_mcs_local_node_t threadLock; - int result = 0; - ptw32_thread_t * tp = (ptw32_thread_t *) thread.p; - - prio = priority; - - /* Validate priority level. */ - if (prio < sched_get_priority_min (policy) || - prio > sched_get_priority_max (policy)) - { - return EINVAL; - } - -#if (THREAD_PRIORITY_LOWEST > THREAD_PRIORITY_NORMAL) -/* WinCE */ -#else -/* Everything else */ - - if (THREAD_PRIORITY_IDLE < prio && THREAD_PRIORITY_LOWEST > prio) - { - prio = THREAD_PRIORITY_LOWEST; - } - else if (THREAD_PRIORITY_TIME_CRITICAL > prio - && THREAD_PRIORITY_HIGHEST < prio) - { - prio = THREAD_PRIORITY_HIGHEST; - } - -#endif - - ptw32_mcs_lock_acquire (&tp->threadLock, &threadLock); - - /* If this fails, the current priority is unchanged. */ - if (0 == SetThreadPriority (tp->threadH, prio)) - { - result = EINVAL; - } - else - { - /* - * Must record the thread's sched_priority as given, - * not as finally adjusted. - */ - tp->sched_priority = priority; - } - - ptw32_mcs_lock_release (&threadLock); - - return result; -} diff --git a/dependencies/win32_pthread/src/pthread_setspecific.c b/dependencies/win32_pthread/src/pthread_setspecific.c deleted file mode 100644 index 044308b8..00000000 --- a/dependencies/win32_pthread/src/pthread_setspecific.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - * pthread_setspecific.c - * - * Description: - * POSIX thread functions which implement thread-specific data (TSD). - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_setspecific (pthread_key_t key, const void *value) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function sets the value of the thread specific - * key in the calling thread. - * - * PARAMETERS - * key - * an instance of pthread_key_t - * value - * the value to set key to - * - * - * DESCRIPTION - * This function sets the value of the thread specific - * key in the calling thread. - * - * RESULTS - * 0 successfully set value - * EAGAIN could not set value - * ENOENT SERIOUS!! - * - * ------------------------------------------------------ - */ -{ - pthread_t self; - int result = 0; - - if (key != ptw32_selfThreadKey) - { - /* - * Using pthread_self will implicitly create - * an instance of pthread_t for the current - * thread if one wasn't explicitly created - */ - self = pthread_self (); - if (self.p == NULL) - { - return ENOENT; - } - } - else - { - /* - * Resolve catch-22 of registering thread with selfThread - * key - */ - ptw32_thread_t * sp = (ptw32_thread_t *) pthread_getspecific (ptw32_selfThreadKey); - - if (sp == NULL) - { - if (value == NULL) - { - return ENOENT; - } - self = *((pthread_t *) value); - } - else - { - self = sp->ptHandle; - } - } - - result = 0; - - if (key != NULL) - { - if (self.p != NULL && key->destructor != NULL && value != NULL) - { - ptw32_mcs_local_node_t keyLock; - ptw32_mcs_local_node_t threadLock; - ptw32_thread_t * sp = (ptw32_thread_t *) self.p; - /* - * Only require associations if we have to - * call user destroy routine. - * Don't need to locate an existing association - * when setting data to NULL for WIN32 since the - * data is stored with the operating system; not - * on the association; setting assoc to NULL short - * circuits the search. - */ - ThreadKeyAssoc *assoc; - - ptw32_mcs_lock_acquire(&(key->keyLock), &keyLock); - ptw32_mcs_lock_acquire(&(sp->threadLock), &threadLock); - - assoc = (ThreadKeyAssoc *) sp->keys; - /* - * Locate existing association - */ - while (assoc != NULL) - { - if (assoc->key == key) - { - /* - * Association already exists - */ - break; - } - assoc = assoc->nextKey; - } - - /* - * create an association if not found - */ - if (assoc == NULL) - { - result = ptw32_tkAssocCreate (sp, key); - } - - ptw32_mcs_lock_release(&threadLock); - ptw32_mcs_lock_release(&keyLock); - } - - if (result == 0) - { - if (!TlsSetValue (key->key, (LPVOID) value)) - { - result = EAGAIN; - } - } - } - - return (result); -} /* pthread_setspecific */ diff --git a/dependencies/win32_pthread/src/pthread_spin_destroy.c b/dependencies/win32_pthread/src/pthread_spin_destroy.c deleted file mode 100644 index 8309a090..00000000 --- a/dependencies/win32_pthread/src/pthread_spin_destroy.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * pthread_spin_destroy.c - * - * Description: - * This translation unit implements spin lock primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_spin_destroy (pthread_spinlock_t * lock) -{ - register pthread_spinlock_t s; - int result = 0; - - if (lock == NULL || *lock == NULL) - { - return EINVAL; - } - - if ((s = *lock) != PTHREAD_SPINLOCK_INITIALIZER) - { - if (s->interlock == PTW32_SPIN_USE_MUTEX) - { - result = pthread_mutex_destroy (&(s->u.mutex)); - } - else if ((PTW32_INTERLOCKED_LONG) PTW32_SPIN_UNLOCKED != - PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG ((PTW32_INTERLOCKED_LONGPTR) &s->interlock, - (PTW32_INTERLOCKED_LONG) PTW32_SPIN_INVALID, - (PTW32_INTERLOCKED_LONG) PTW32_SPIN_UNLOCKED)) - { - result = EINVAL; - } - - if (0 == result) - { - /* - * We are relying on the application to ensure that all other threads - * have finished with the spinlock before destroying it. - */ - *lock = NULL; - (void) free (s); - } - } - else - { - /* - * See notes in ptw32_spinlock_check_need_init() above also. - */ - ptw32_mcs_local_node_t node; - - ptw32_mcs_lock_acquire(&ptw32_spinlock_test_init_lock, &node); - - /* - * Check again. - */ - if (*lock == PTHREAD_SPINLOCK_INITIALIZER) - { - /* - * This is all we need to do to destroy a statically - * initialised spinlock that has not yet been used (initialised). - * If we get to here, another thread - * waiting to initialise this mutex will get an EINVAL. - */ - *lock = NULL; - } - else - { - /* - * The spinlock has been initialised while we were waiting - * so assume it's in use. - */ - result = EBUSY; - } - - ptw32_mcs_lock_release(&node); - } - - return (result); -} diff --git a/dependencies/win32_pthread/src/pthread_spin_init.c b/dependencies/win32_pthread/src/pthread_spin_init.c deleted file mode 100644 index ae3406f6..00000000 --- a/dependencies/win32_pthread/src/pthread_spin_init.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * pthread_spin_init.c - * - * Description: - * This translation unit implements spin lock primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_spin_init (pthread_spinlock_t * lock, int pshared) -{ - pthread_spinlock_t s; - int cpus = 0; - int result = 0; - - if (lock == NULL) - { - return EINVAL; - } - - if (0 != ptw32_getprocessors (&cpus)) - { - cpus = 1; - } - - if (cpus > 1) - { - if (pshared == PTHREAD_PROCESS_SHARED) - { - /* - * Creating spinlock that can be shared between - * processes. - */ -#if _POSIX_THREAD_PROCESS_SHARED >= 0 - - /* - * Not implemented yet. - */ - -#error ERROR [__FILE__, line __LINE__]: Process shared spin locks are not supported yet. - -#else - - return ENOSYS; - -#endif /* _POSIX_THREAD_PROCESS_SHARED */ - - } - } - - s = (pthread_spinlock_t) calloc (1, sizeof (*s)); - - if (s == NULL) - { - return ENOMEM; - } - - if (cpus > 1) - { - s->u.cpus = cpus; - s->interlock = PTW32_SPIN_UNLOCKED; - } - else - { - pthread_mutexattr_t ma; - result = pthread_mutexattr_init (&ma); - - if (0 == result) - { - ma->pshared = pshared; - result = pthread_mutex_init (&(s->u.mutex), &ma); - if (0 == result) - { - s->interlock = PTW32_SPIN_USE_MUTEX; - } - } - (void) pthread_mutexattr_destroy (&ma); - } - - if (0 == result) - { - *lock = s; - } - else - { - (void) free (s); - *lock = NULL; - } - - return (result); -} diff --git a/dependencies/win32_pthread/src/pthread_spin_lock.c b/dependencies/win32_pthread/src/pthread_spin_lock.c deleted file mode 100644 index 300ce97c..00000000 --- a/dependencies/win32_pthread/src/pthread_spin_lock.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * pthread_spin_lock.c - * - * Description: - * This translation unit implements spin lock primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_spin_lock (pthread_spinlock_t * lock) -{ - register pthread_spinlock_t s; - - if (NULL == lock || NULL == *lock) - { - return (EINVAL); - } - - if (*lock == PTHREAD_SPINLOCK_INITIALIZER) - { - int result; - - if ((result = ptw32_spinlock_check_need_init (lock)) != 0) - { - return (result); - } - } - - s = *lock; - - while ((PTW32_INTERLOCKED_LONG) PTW32_SPIN_LOCKED == - PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG ((PTW32_INTERLOCKED_LONGPTR) &s->interlock, - (PTW32_INTERLOCKED_LONG) PTW32_SPIN_LOCKED, - (PTW32_INTERLOCKED_LONG) PTW32_SPIN_UNLOCKED)) - { - } - - if (s->interlock == PTW32_SPIN_LOCKED) - { - return 0; - } - else if (s->interlock == PTW32_SPIN_USE_MUTEX) - { - return pthread_mutex_lock (&(s->u.mutex)); - } - - return EINVAL; -} diff --git a/dependencies/win32_pthread/src/pthread_spin_trylock.c b/dependencies/win32_pthread/src/pthread_spin_trylock.c deleted file mode 100644 index 51fc879e..00000000 --- a/dependencies/win32_pthread/src/pthread_spin_trylock.c +++ /dev/null @@ -1,82 +0,0 @@ -/* - * pthread_spin_trylock.c - * - * Description: - * This translation unit implements spin lock primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_spin_trylock (pthread_spinlock_t * lock) -{ - register pthread_spinlock_t s; - - if (NULL == lock || NULL == *lock) - { - return (EINVAL); - } - - if (*lock == PTHREAD_SPINLOCK_INITIALIZER) - { - int result; - - if ((result = ptw32_spinlock_check_need_init (lock)) != 0) - { - return (result); - } - } - - s = *lock; - - switch ((long) - PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG ((PTW32_INTERLOCKED_LONGPTR) &s->interlock, - (PTW32_INTERLOCKED_LONG) PTW32_SPIN_LOCKED, - (PTW32_INTERLOCKED_LONG) PTW32_SPIN_UNLOCKED)) - { - case PTW32_SPIN_UNLOCKED: - return 0; - case PTW32_SPIN_LOCKED: - return EBUSY; - case PTW32_SPIN_USE_MUTEX: - return pthread_mutex_trylock (&(s->u.mutex)); - } - - return EINVAL; -} diff --git a/dependencies/win32_pthread/src/pthread_spin_unlock.c b/dependencies/win32_pthread/src/pthread_spin_unlock.c deleted file mode 100644 index 762584ce..00000000 --- a/dependencies/win32_pthread/src/pthread_spin_unlock.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * pthread_spin_unlock.c - * - * Description: - * This translation unit implements spin lock primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -pthread_spin_unlock (pthread_spinlock_t * lock) -{ - register pthread_spinlock_t s; - - if (NULL == lock || NULL == *lock) - { - return (EINVAL); - } - - s = *lock; - - if (s == PTHREAD_SPINLOCK_INITIALIZER) - { - return EPERM; - } - - switch ((long) - PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG ((PTW32_INTERLOCKED_LONGPTR) &s->interlock, - (PTW32_INTERLOCKED_LONG) PTW32_SPIN_UNLOCKED, - (PTW32_INTERLOCKED_LONG) PTW32_SPIN_LOCKED)) - { - case PTW32_SPIN_LOCKED: - case PTW32_SPIN_UNLOCKED: - return 0; - case PTW32_SPIN_USE_MUTEX: - return pthread_mutex_unlock (&(s->u.mutex)); - } - - return EINVAL; -} diff --git a/dependencies/win32_pthread/src/pthread_testcancel.c b/dependencies/win32_pthread/src/pthread_testcancel.c deleted file mode 100644 index f6958563..00000000 --- a/dependencies/win32_pthread/src/pthread_testcancel.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * pthread_testcancel.c - * - * Description: - * POSIX thread functions related to thread cancellation. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -void -pthread_testcancel (void) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function creates a deferred cancellation point - * in the calling thread. The call has no effect if the - * current cancelability state is - * PTHREAD_CANCEL_DISABLE - * - * PARAMETERS - * N/A - * - * - * DESCRIPTION - * This function creates a deferred cancellation point - * in the calling thread. The call has no effect if the - * current cancelability state is - * PTHREAD_CANCEL_DISABLE - * - * NOTES: - * 1) Cancellation is asynchronous. Use pthread_join - * to wait for termination of thread if necessary - * - * RESULTS - * N/A - * - * ------------------------------------------------------ - */ -{ - ptw32_mcs_local_node_t stateLock; - pthread_t self = pthread_self (); - ptw32_thread_t * sp = (ptw32_thread_t *) self.p; - - if (sp == NULL) - { - return; - } - - /* - * Pthread_cancel() will have set sp->state to PThreadStateCancelPending - * and set an event, so no need to enter kernel space if - * sp->state != PThreadStateCancelPending - that only slows us down. - */ - if (sp->state != PThreadStateCancelPending) - { - return; - } - - ptw32_mcs_lock_acquire (&sp->stateLock, &stateLock); - - if (sp->cancelState != PTHREAD_CANCEL_DISABLE) - { - ResetEvent(sp->cancelEvent); - sp->state = PThreadStateCanceling; - sp->cancelState = PTHREAD_CANCEL_DISABLE; - ptw32_mcs_lock_release (&stateLock); - ptw32_throw (PTW32_EPS_CANCEL); - /* Never returns here */ - } - - ptw32_mcs_lock_release (&stateLock); -} /* pthread_testcancel */ diff --git a/dependencies/win32_pthread/src/pthread_timechange_handler_np.c b/dependencies/win32_pthread/src/pthread_timechange_handler_np.c deleted file mode 100644 index 98934e3c..00000000 --- a/dependencies/win32_pthread/src/pthread_timechange_handler_np.c +++ /dev/null @@ -1,113 +0,0 @@ -/* - * pthread_timechange_handler_np.c - * - * Description: - * This translation unit implements miscellaneous thread functions. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -/* - * Notes on handling system time adjustments (especially negative ones). - * --------------------------------------------------------------------- - * - * This solution was suggested by Alexander Terekhov, but any errors - * in the implementation are mine - [Ross Johnson] - * - * 1) The problem: threads doing a timedwait on a CV may expect to timeout - * at a specific absolute time according to a system timer. If the - * system clock is adjusted backwards then those threads sleep longer than - * expected. Also, pthreads-win32 converts absolute times to intervals in - * order to make use of the underlying Win32, and so waiting threads may - * awake before their proper abstimes. - * - * 2) We aren't able to distinquish between threads on timed or untimed waits, - * so we wake them all at the time of the adjustment so that they can - * re-evaluate their conditions and re-compute their timeouts. - * - * 3) We rely on correctly written applications for this to work. Specifically, - * they must be able to deal properly with spurious wakeups. That is, - * they must re-test their condition upon wakeup and wait again if - * the condition is not satisfied. - */ - -void * -pthread_timechange_handler_np (void *arg) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * Broadcasts all CVs to force re-evaluation and - * new timeouts if required. - * - * PARAMETERS - * NONE - * - * - * DESCRIPTION - * Broadcasts all CVs to force re-evaluation and - * new timeouts if required. - * - * This routine may be passed directly to pthread_create() - * as a new thread in order to run asynchronously. - * - * - * RESULTS - * 0 successfully broadcast all CVs - * EAGAIN Not all CVs were broadcast - * - * ------------------------------------------------------ - */ -{ - int result = 0; - pthread_cond_t cv; - ptw32_mcs_local_node_t node; - - ptw32_mcs_lock_acquire(&ptw32_cond_list_lock, &node); - - cv = ptw32_cond_list_head; - - while (cv != NULL && 0 == result) - { - result = pthread_cond_broadcast (&cv); - cv = cv->next; - } - - ptw32_mcs_lock_release(&node); - - return (void *) (size_t) (result != 0 ? EAGAIN : 0); -} diff --git a/dependencies/win32_pthread/src/pthread_timedjoin_np.c b/dependencies/win32_pthread/src/pthread_timedjoin_np.c deleted file mode 100644 index cee1b0a4..00000000 --- a/dependencies/win32_pthread/src/pthread_timedjoin_np.c +++ /dev/null @@ -1,188 +0,0 @@ -/* - * pthread_timedjoin_np.c - * - * Description: - * This translation unit implements functions related to thread - * synchronisation. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -/* - * Not needed yet, but defining it should indicate clashes with build target - * environment that should be fixed. - */ -#if !defined(WINCE) -# include -#endif - - -int -pthread_timedjoin_np (pthread_t thread, void **value_ptr, const struct timespec *abstime) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function waits for 'thread' to terminate and - * returns the thread's exit value if 'value_ptr' is not - * NULL or until 'abstime' passes and returns an - * error. If 'abstime' is NULL then the function waits - * forever, i.e. reverts to pthread_join behaviour. - * This function detaches the thread on successful - * completion. - * - * PARAMETERS - * thread - * an instance of pthread_t - * - * value_ptr - * pointer to an instance of pointer to void - * - * abstime - * pointer to an instance of struct timespec - * representing an absolute time value - * - * - * DESCRIPTION - * This function waits for 'thread' to terminate and - * returns the thread's exit value if 'value_ptr' is not - * NULL or until 'abstime' passes and returns an - * error. If 'abstime' is NULL then the function waits - * forever, i.e. reverts to pthread_join behaviour. - * This function detaches the thread on successful - * completion. - * NOTE: Detached threads cannot be joined or canceled. - * In this implementation 'abstime' will be - * resolved to the nearest millisecond. - * - * RESULTS - * 0 'thread' has completed - * ETIMEDOUT abstime passed - * EINVAL thread is not a joinable thread, - * ESRCH no thread could be found with ID 'thread', - * ENOENT thread couldn't find it's own valid handle, - * EDEADLK attempt to join thread with self - * - * ------------------------------------------------------ - */ -{ - int result; - pthread_t self; - DWORD milliseconds; - ptw32_thread_t * tp = (ptw32_thread_t *) thread.p; - ptw32_mcs_local_node_t node; - - if (abstime == NULL) - { - milliseconds = INFINITE; - } - else - { - /* - * Calculate timeout as milliseconds from current system time. - */ - milliseconds = ptw32_relmillisecs (abstime); - } - - ptw32_mcs_lock_acquire(&ptw32_thread_reuse_lock, &node); - - if (NULL == tp - || thread.x != tp->ptHandle.x) - { - result = ESRCH; - } - else if (PTHREAD_CREATE_DETACHED == tp->detachState) - { - result = EINVAL; - } - else - { - result = 0; - } - - ptw32_mcs_lock_release(&node); - - if (result == 0) - { - /* - * The target thread is joinable and can't be reused before we join it. - */ - self = pthread_self(); - - if (NULL == self.p) - { - result = ENOENT; - } - else if (pthread_equal (self, thread)) - { - result = EDEADLK; - } - else - { - /* - * Pthread_join is a cancellation point. - * If we are canceled then our target thread must not be - * detached (destroyed). This is guaranteed because - * pthreadCancelableTimedWait will not return if we - * are canceled. - */ - result = pthreadCancelableTimedWait (tp->threadH, milliseconds); - - if (0 == result) - { - if (value_ptr != NULL) - { - *value_ptr = tp->exitStatus; - } - - /* - * The result of making multiple simultaneous calls to - * pthread_join() or pthread_timedjoin_np() or pthread_detach() - * specifying the same target is undefined. - */ - result = pthread_detach (thread); - } - else if (ETIMEDOUT != result) - { - result = ESRCH; - } - } - } - - return (result); - -} diff --git a/dependencies/win32_pthread/src/pthread_tryjoin_np.c b/dependencies/win32_pthread/src/pthread_tryjoin_np.c deleted file mode 100644 index c78f3803..00000000 --- a/dependencies/win32_pthread/src/pthread_tryjoin_np.c +++ /dev/null @@ -1,173 +0,0 @@ -/* - * pthread_tryjoin_np.c - * - * Description: - * This translation unit implements functions related to thread - * synchronisation. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -/* - * Not needed yet, but defining it should indicate clashes with build target - * environment that should be fixed. - */ -#if !defined(WINCE) -# include -#endif - - -int -pthread_tryjoin_np (pthread_t thread, void **value_ptr) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function checks if 'thread' has terminated and - * returns the thread's exit value if 'value_ptr' is not - * NULL or until 'abstime' passes and returns an - * error. If the thread has not exited the function returns - * immediately. This function detaches the thread on successful - * completion. - * - * PARAMETERS - * thread - * an instance of pthread_t - * - * value_ptr - * pointer to an instance of pointer to void - * - * - * DESCRIPTION - * This function checks if 'thread' has terminated and - * returns the thread's exit value if 'value_ptr' is not - * NULL or until 'abstime' passes and returns an - * error. If the thread has not exited the function returns - * immediately. This function detaches the thread on successful - * completion. - * NOTE: Detached threads cannot be joined or canceled. - * In this implementation 'abstime' will be - * resolved to the nearest millisecond. - * - * RESULTS - * 0 'thread' has completed - * EBUSY 'thread' is still live - * EINVAL thread is not a joinable thread, - * ESRCH no thread could be found with ID 'thread', - * ENOENT thread couldn't find it's own valid handle, - * EDEADLK attempt to join thread with self - * - * ------------------------------------------------------ - */ -{ - int result; - pthread_t self; - ptw32_thread_t * tp = (ptw32_thread_t *) thread.p; - ptw32_mcs_local_node_t node; - - ptw32_mcs_lock_acquire(&ptw32_thread_reuse_lock, &node); - - if (NULL == tp - || thread.x != tp->ptHandle.x) - { - result = ESRCH; - } - else if (PTHREAD_CREATE_DETACHED == tp->detachState) - { - result = EINVAL; - } - else - { - result = 0; - } - - ptw32_mcs_lock_release(&node); - - if (result == 0) - { - /* - * The target thread is joinable and can't be reused before we join it. - */ - self = pthread_self(); - - if (NULL == self.p) - { - result = ENOENT; - } - else if (pthread_equal (self, thread)) - { - result = EDEADLK; - } - else - { - /* - * Pthread_join is a cancellation point. - * If we are canceled then our target thread must not be - * detached (destroyed). This is guaranteed because - * pthreadCancelableTimedWait will not return if we - * are canceled. - */ - result = pthreadCancelableTimedWait (tp->threadH, 0); - - if (0 == result) - { - if (value_ptr != NULL) - { - *value_ptr = tp->exitStatus; - } - - /* - * The result of making multiple simultaneous calls to - * pthread_join(), pthread_timedjoin_np(), pthread_tryjoin_np() - * or pthread_detach() specifying the same target is undefined. - */ - result = pthread_detach (thread); - } - else if (ETIMEDOUT == result) - { - result = EBUSY; - } - else - { - result = ESRCH; - } - } - } - - return (result); - -} diff --git a/dependencies/win32_pthread/src/pthread_win32_attach_detach_np.c b/dependencies/win32_pthread/src/pthread_win32_attach_detach_np.c deleted file mode 100644 index e4e64d59..00000000 --- a/dependencies/win32_pthread/src/pthread_win32_attach_detach_np.c +++ /dev/null @@ -1,268 +0,0 @@ -/* - * pthread_win32_attach_detach_np.c - * - * Description: - * This translation unit implements non-portable thread functions. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -/* - * Handle to quserex.dll - */ -static HINSTANCE ptw32_h_quserex; - -BOOL -pthread_win32_process_attach_np () -{ - TCHAR QuserExDLLPathBuf[1024]; - BOOL result = TRUE; - const UINT QuserExDLLPathBufSize = sizeof(QuserExDLLPathBuf) / sizeof(QuserExDLLPathBuf[0]); - - result = ptw32_processInitialize (); - -#if defined(_UWIN) - pthread_count++; -#endif - -#if defined(__GNUC__) - ptw32_features = 0; -#else - /* - * This is obsolete now. - */ - ptw32_features = PTW32_SYSTEM_INTERLOCKED_COMPARE_EXCHANGE; -#endif - - /* - * Load QUSEREX.DLL and try to get address of QueueUserAPCEx. - * Because QUSEREX.DLL requires a driver to be installed we will - * assume the DLL is in the system directory. - * - * This should take care of any security issues. - */ -#if defined(__GNUC__) || defined(PTW32_CONFIG_MSVC7) - if(GetSystemDirectory(QuserExDLLPathBuf, QuserExDLLPathBufSize)) - { - (void) strncat(QuserExDLLPathBuf, - "\\QUSEREX.DLL", - QuserExDLLPathBufSize - strlen(QuserExDLLPathBuf) - 1); - ptw32_h_quserex = LoadLibrary(QuserExDLLPathBuf); - } -#else - /* strncat is secure - this is just to avoid a warning */ - if(GetSystemDirectory(QuserExDLLPathBuf, QuserExDLLPathBufSize) && - 0 == _tcsncat_s(QuserExDLLPathBuf, QuserExDLLPathBufSize, _T("\\QUSEREX.DLL"), 12)) - { - ptw32_h_quserex = LoadLibrary(QuserExDLLPathBuf); - } -#endif - - if (ptw32_h_quserex != NULL) - { - ptw32_register_cancellation = (DWORD (*)(PAPCFUNC, HANDLE, DWORD)) -#if defined(NEED_UNICODE_CONSTS) - GetProcAddress (ptw32_h_quserex, - (const TCHAR *) TEXT ("QueueUserAPCEx")); -#else - GetProcAddress (ptw32_h_quserex, (LPCSTR) "QueueUserAPCEx"); -#endif - } - - if (NULL == ptw32_register_cancellation) - { - ptw32_register_cancellation = ptw32_RegisterCancellation; - - if (ptw32_h_quserex != NULL) - { - (void) FreeLibrary (ptw32_h_quserex); - } - ptw32_h_quserex = 0; - } - else - { - /* Initialise QueueUserAPCEx */ - BOOL (*queue_user_apc_ex_init) (VOID); - - queue_user_apc_ex_init = (BOOL (*)(VOID)) -#if defined(NEED_UNICODE_CONSTS) - GetProcAddress (ptw32_h_quserex, - (const TCHAR *) TEXT ("QueueUserAPCEx_Init")); -#else - GetProcAddress (ptw32_h_quserex, (LPCSTR) "QueueUserAPCEx_Init"); -#endif - - if (queue_user_apc_ex_init == NULL || !queue_user_apc_ex_init ()) - { - ptw32_register_cancellation = ptw32_RegisterCancellation; - - (void) FreeLibrary (ptw32_h_quserex); - ptw32_h_quserex = 0; - } - } - - if (ptw32_h_quserex) - { - ptw32_features |= PTW32_ALERTABLE_ASYNC_CANCEL; - } - - return result; -} - - -BOOL -pthread_win32_process_detach_np () -{ - if (ptw32_processInitialized) - { - ptw32_thread_t * sp = (ptw32_thread_t *) pthread_getspecific (ptw32_selfThreadKey); - - if (sp != NULL) - { - /* - * Detached threads have their resources automatically - * cleaned up upon exit (others must be 'joined'). - */ - if (sp->detachState == PTHREAD_CREATE_DETACHED) - { - ptw32_threadDestroy (sp->ptHandle); - if (ptw32_selfThreadKey) - { - TlsSetValue (ptw32_selfThreadKey->key, NULL); - } - } - } - - /* - * The DLL is being unmapped from the process's address space - */ - ptw32_processTerminate (); - - if (ptw32_h_quserex) - { - /* Close QueueUserAPCEx */ - BOOL (*queue_user_apc_ex_fini) (VOID); - - queue_user_apc_ex_fini = (BOOL (*)(VOID)) -#if defined(NEED_UNICODE_CONSTS) - GetProcAddress (ptw32_h_quserex, - (const TCHAR *) TEXT ("QueueUserAPCEx_Fini")); -#else - GetProcAddress (ptw32_h_quserex, (LPCSTR) "QueueUserAPCEx_Fini"); -#endif - - if (queue_user_apc_ex_fini != NULL) - { - (void) queue_user_apc_ex_fini (); - } - (void) FreeLibrary (ptw32_h_quserex); - } - } - - return TRUE; -} - -BOOL -pthread_win32_thread_attach_np () -{ - return TRUE; -} - -BOOL -pthread_win32_thread_detach_np () -{ - if (ptw32_processInitialized) - { - /* - * Don't use pthread_self() - to avoid creating an implicit POSIX thread handle - * unnecessarily. - */ - ptw32_thread_t * sp = (ptw32_thread_t *) pthread_getspecific (ptw32_selfThreadKey); - - if (sp != NULL) // otherwise Win32 thread with no implicit POSIX handle. - { - ptw32_mcs_local_node_t stateLock; - ptw32_callUserDestroyRoutines (sp->ptHandle); - - ptw32_mcs_lock_acquire (&sp->stateLock, &stateLock); - sp->state = PThreadStateLast; - /* - * If the thread is joinable at this point then it MUST be joined - * or detached explicitly by the application. - */ - ptw32_mcs_lock_release (&stateLock); - - /* - * Robust Mutexes - */ - while (sp->robustMxList != NULL) - { - pthread_mutex_t mx = sp->robustMxList->mx; - ptw32_robust_mutex_remove(&mx, sp); - (void) PTW32_INTERLOCKED_EXCHANGE_LONG( - (PTW32_INTERLOCKED_LONGPTR)&mx->robustNode->stateInconsistent, - (PTW32_INTERLOCKED_LONG)-1); - /* - * If there are no waiters then the next thread to block will - * sleep, wake up immediately and then go back to sleep. - * See pthread_mutex_lock.c. - */ - SetEvent(mx->event); - } - - - if (sp->detachState == PTHREAD_CREATE_DETACHED) - { - ptw32_threadDestroy (sp->ptHandle); - - if (ptw32_selfThreadKey) - { - TlsSetValue (ptw32_selfThreadKey->key, NULL); - } - } - } - } - - return TRUE; -} - -BOOL -pthread_win32_test_features_np (int feature_mask) -{ - return ((ptw32_features & feature_mask) == feature_mask); -} diff --git a/dependencies/win32_pthread/src/ptw32_MCS_lock.c b/dependencies/win32_pthread/src/ptw32_MCS_lock.c deleted file mode 100644 index ff0745f4..00000000 --- a/dependencies/win32_pthread/src/ptw32_MCS_lock.c +++ /dev/null @@ -1,283 +0,0 @@ -/* - * ptw32_MCS_lock.c - * - * Description: - * This translation unit implements queue-based locks. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -/* - * About MCS locks: - * - * MCS locks are queue-based locks, where the queue nodes are local to the - * thread. The 'lock' is nothing more than a global pointer that points to - * the last node in the queue, or is NULL if the queue is empty. - * - * Originally designed for use as spin locks requiring no kernel resources - * for synchronisation or blocking, the implementation below has adapted - * the MCS spin lock for use as a general mutex that will suspend threads - * when there is lock contention. - * - * Because the queue nodes are thread-local, most of the memory read/write - * operations required to add or remove nodes from the queue do not trigger - * cache-coherence updates. - * - * Like 'named' mutexes, MCS locks consume system resources transiently - - * they are able to acquire and free resources automatically - but MCS - * locks do not require any unique 'name' to identify the lock to all - * threads using it. - * - * Usage of MCS locks: - * - * - you need a global ptw32_mcs_lock_t instance initialised to 0 or NULL. - * - you need a local thread-scope ptw32_mcs_local_node_t instance, which - * may serve several different locks but you need at least one node for - * every lock held concurrently by a thread. - * - * E.g.: - * - * ptw32_mcs_lock_t lock1 = 0; - * ptw32_mcs_lock_t lock2 = 0; - * - * void *mythread(void *arg) - * { - * ptw32_mcs_local_node_t node; - * - * ptw32_mcs_acquire (&lock1, &node); - * ptw32_mcs_lock_release (&node); - * - * ptw32_mcs_lock_acquire (&lock2, &node); - * ptw32_mcs_lock_release (&node); - * { - * ptw32_mcs_local_node_t nodex; - * - * ptw32_mcs_lock_acquire (&lock1, &node); - * ptw32_mcs_lock_acquire (&lock2, &nodex); - * - * ptw32_mcs_lock_release (&nodex); - * ptw32_mcs_lock_release (&node); - * } - * return (void *)0; - * } - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "sched.h" -#include "implement.h" - -/* - * ptw32_mcs_flag_set -- notify another thread about an event. - * - * Set event if an event handle has been stored in the flag, and - * set flag to -1 otherwise. Note that -1 cannot be a valid handle value. - */ -INLINE void -ptw32_mcs_flag_set (HANDLE * flag) -{ - HANDLE e = (HANDLE)(PTW32_INTERLOCKED_SIZE)PTW32_INTERLOCKED_COMPARE_EXCHANGE_SIZE( - (PTW32_INTERLOCKED_SIZEPTR)flag, - (PTW32_INTERLOCKED_SIZE)-1, - (PTW32_INTERLOCKED_SIZE)0); - if ((HANDLE)0 != e) - { - /* another thread has already stored an event handle in the flag */ - SetEvent(e); - } -} - -/* - * ptw32_mcs_flag_wait -- wait for notification from another. - * - * Store an event handle in the flag and wait on it if the flag has not been - * set, and proceed without creating an event otherwise. - */ -INLINE void -ptw32_mcs_flag_wait (HANDLE * flag) -{ - if ((PTW32_INTERLOCKED_SIZE)0 == - PTW32_INTERLOCKED_EXCHANGE_ADD_SIZE((PTW32_INTERLOCKED_SIZEPTR)flag, - (PTW32_INTERLOCKED_SIZE)0)) /* MBR fence */ - { - /* the flag is not set. create event. */ - - HANDLE e = CreateEvent(NULL, PTW32_FALSE, PTW32_FALSE, NULL); - - if ((PTW32_INTERLOCKED_SIZE)0 == PTW32_INTERLOCKED_COMPARE_EXCHANGE_SIZE( - (PTW32_INTERLOCKED_SIZEPTR)flag, - (PTW32_INTERLOCKED_SIZE)e, - (PTW32_INTERLOCKED_SIZE)0)) - { - /* stored handle in the flag. wait on it now. */ - WaitForSingleObject(e, INFINITE); - } - - CloseHandle(e); - } -} - -/* - * ptw32_mcs_lock_acquire -- acquire an MCS lock. - * - * See: - * J. M. Mellor-Crummey and M. L. Scott. - * Algorithms for Scalable Synchronization on Shared-Memory Multiprocessors. - * ACM Transactions on Computer Systems, 9(1):21-65, Feb. 1991. - */ -#if defined(PTW32_BUILD_INLINED) -INLINE -#endif /* PTW32_BUILD_INLINED */ -void -ptw32_mcs_lock_acquire (ptw32_mcs_lock_t * lock, ptw32_mcs_local_node_t * node) -{ - ptw32_mcs_local_node_t *pred; - - node->lock = lock; - node->nextFlag = 0; - node->readyFlag = 0; - node->next = 0; /* initially, no successor */ - - /* queue for the lock */ - pred = (ptw32_mcs_local_node_t *)PTW32_INTERLOCKED_EXCHANGE_PTR((PTW32_INTERLOCKED_PVOID_PTR)lock, - (PTW32_INTERLOCKED_PVOID)node); - - if (0 != pred) - { - /* the lock was not free. link behind predecessor. */ - pred->next = node; - ptw32_mcs_flag_set(&pred->nextFlag); - ptw32_mcs_flag_wait(&node->readyFlag); - } -} - -/* - * ptw32_mcs_lock_release -- release an MCS lock. - * - * See: - * J. M. Mellor-Crummey and M. L. Scott. - * Algorithms for Scalable Synchronization on Shared-Memory Multiprocessors. - * ACM Transactions on Computer Systems, 9(1):21-65, Feb. 1991. - */ -#if defined(PTW32_BUILD_INLINED) -INLINE -#endif /* PTW32_BUILD_INLINED */ -void PTW32_CDECL -ptw32_mcs_lock_release (ptw32_mcs_local_node_t * node) -{ - ptw32_mcs_lock_t *lock = node->lock; - ptw32_mcs_local_node_t *next = - (ptw32_mcs_local_node_t *) - PTW32_INTERLOCKED_EXCHANGE_ADD_SIZE((PTW32_INTERLOCKED_SIZEPTR)&node->next, (PTW32_INTERLOCKED_SIZE)0); /* MBR fence */ - - if (0 == next) - { - /* no known successor */ - - if (node == (ptw32_mcs_local_node_t *) - PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR((PTW32_INTERLOCKED_PVOID_PTR)lock, - (PTW32_INTERLOCKED_PVOID)0, - (PTW32_INTERLOCKED_PVOID)node)) - { - /* no successor, lock is free now */ - return; - } - - /* wait for successor */ - ptw32_mcs_flag_wait(&node->nextFlag); - next = (ptw32_mcs_local_node_t *) - PTW32_INTERLOCKED_EXCHANGE_ADD_SIZE((PTW32_INTERLOCKED_SIZEPTR)&node->next, (PTW32_INTERLOCKED_SIZE)0); /* MBR fence */ - } - - /* pass the lock */ - ptw32_mcs_flag_set(&next->readyFlag); -} - -/* - * ptw32_mcs_lock_try_acquire - */ -#if defined(PTW32_BUILD_INLINED) -INLINE -#endif /* PTW32_BUILD_INLINED */ -int -ptw32_mcs_lock_try_acquire (ptw32_mcs_lock_t * lock, ptw32_mcs_local_node_t * node) -{ - node->lock = lock; - node->nextFlag = 0; - node->readyFlag = 0; - node->next = 0; /* initially, no successor */ - - return ((PTW32_INTERLOCKED_PVOID)PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR((PTW32_INTERLOCKED_PVOID_PTR)lock, - (PTW32_INTERLOCKED_PVOID)node, - (PTW32_INTERLOCKED_PVOID)0) - == (PTW32_INTERLOCKED_PVOID)0) ? 0 : EBUSY; -} - -/* - * ptw32_mcs_node_transfer -- move an MCS lock local node, usually from thread - * space to, for example, global space so that another thread can release - * the lock on behalf of the current lock owner. - * - * Example: used in pthread_barrier_wait where we want the last thread out of - * the barrier to release the lock owned by the last thread to enter the barrier - * (the one that releases all threads but not necessarily the last to leave). - * - * Should only be called by the thread that has the lock. - */ -#if defined(PTW32_BUILD_INLINED) -INLINE -#endif /* PTW32_BUILD_INLINED */ -void -ptw32_mcs_node_transfer (ptw32_mcs_local_node_t * new_node, ptw32_mcs_local_node_t * old_node) -{ - new_node->lock = old_node->lock; - new_node->nextFlag = 0; /* Not needed - used only in initial Acquire */ - new_node->readyFlag = 0; /* Not needed - we were waiting on this */ - new_node->next = 0; - - if ((ptw32_mcs_local_node_t *)PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR((PTW32_INTERLOCKED_PVOID_PTR)new_node->lock, - (PTW32_INTERLOCKED_PVOID)new_node, - (PTW32_INTERLOCKED_PVOID)old_node) - != old_node) - { - /* - * A successor has queued after us, so wait for them to link to us - */ - while (old_node->next == 0) - { - sched_yield(); - } - new_node->next = old_node->next; - } -} diff --git a/dependencies/win32_pthread/src/ptw32_callUserDestroyRoutines.c b/dependencies/win32_pthread/src/ptw32_callUserDestroyRoutines.c deleted file mode 100644 index 88325dc9..00000000 --- a/dependencies/win32_pthread/src/ptw32_callUserDestroyRoutines.c +++ /dev/null @@ -1,237 +0,0 @@ -/* - * ptw32_callUserDestroyRoutines.c - * - * Description: - * This translation unit implements routines which are private to - * the implementation and may be used throughout it. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -#if defined(__CLEANUP_CXX) -# if defined(_MSC_VER) -# include -# elif defined(__WATCOMC__) -# include -# include -# else -# if defined(__GNUC__) && __GNUC__ < 3 -# include -# else -# include - using - std::terminate; -# endif -# endif -#endif - -void -ptw32_callUserDestroyRoutines (pthread_t thread) - /* - * ------------------------------------------------------------------- - * DOCPRIVATE - * - * This the routine runs through all thread keys and calls - * the destroy routines on the user's data for the current thread. - * It simulates the behaviour of POSIX Threads. - * - * PARAMETERS - * thread - * an instance of pthread_t - * - * RETURNS - * N/A - * ------------------------------------------------------------------- - */ -{ - ThreadKeyAssoc * assoc; - - if (thread.p != NULL) - { - ptw32_mcs_local_node_t threadLock; - ptw32_mcs_local_node_t keyLock; - int assocsRemaining; - int iterations = 0; - ptw32_thread_t * sp = (ptw32_thread_t *) thread.p; - - /* - * Run through all Thread<-->Key associations - * for the current thread. - * - * Do this process at most PTHREAD_DESTRUCTOR_ITERATIONS times. - */ - do - { - assocsRemaining = 0; - iterations++; - - ptw32_mcs_lock_acquire(&(sp->threadLock), &threadLock); - /* - * The pointer to the next assoc is stored in the thread struct so that - * the assoc destructor in pthread_key_delete can adjust it - * if it deletes this assoc. This can happen if we fail to acquire - * both locks below, and are forced to release all of our locks, - * leaving open the opportunity for pthread_key_delete to get in - * before us. - */ - sp->nextAssoc = sp->keys; - ptw32_mcs_lock_release(&threadLock); - - for (;;) - { - void * value; - pthread_key_t k; - void (*destructor) (void *); - - /* - * First we need to serialise with pthread_key_delete by locking - * both assoc guards, but in the reverse order to our convention, - * so we must be careful to avoid deadlock. - */ - ptw32_mcs_lock_acquire(&(sp->threadLock), &threadLock); - - if ((assoc = (ThreadKeyAssoc *)sp->nextAssoc) == NULL) - { - /* Finished */ - ptw32_mcs_lock_release(&threadLock); - break; - } - else - { - /* - * assoc->key must be valid because assoc can't change or be - * removed from our chain while we hold at least one lock. If - * the assoc was on our key chain then the key has not been - * deleted yet. - * - * Now try to acquire the second lock without deadlocking. - * If we fail, we need to relinquish the first lock and the - * processor and then try to acquire them all again. - */ - if (ptw32_mcs_lock_try_acquire(&(assoc->key->keyLock), &keyLock) == EBUSY) - { - ptw32_mcs_lock_release(&threadLock); - Sleep(0); - /* - * Go around again. - * If pthread_key_delete has removed this assoc in the meantime, - * sp->nextAssoc will point to a new assoc. - */ - continue; - } - } - - /* We now hold both locks */ - - sp->nextAssoc = assoc->nextKey; - - /* - * Key still active; pthread_key_delete - * will block on these same mutexes before - * it can release actual key; therefore, - * key is valid and we can call the destroy - * routine; - */ - k = assoc->key; - destructor = k->destructor; - value = TlsGetValue(k->key); - TlsSetValue (k->key, NULL); - - // Every assoc->key exists and has a destructor - if (value != NULL && iterations <= PTHREAD_DESTRUCTOR_ITERATIONS) - { - /* - * Unlock both locks before the destructor runs. - * POSIX says pthread_key_delete can be run from destructors, - * and that probably includes with this key as target. - * pthread_setspecific can also be run from destructors and - * also needs to be able to access the assocs. - */ - ptw32_mcs_lock_release(&threadLock); - ptw32_mcs_lock_release(&keyLock); - - assocsRemaining++; - -#if defined(__cplusplus) - - try - { - /* - * Run the caller's cleanup routine. - */ - destructor (value); - } - catch (...) - { - /* - * A system unexpected exception has occurred - * running the user's destructor. - * We get control back within this block in case - * the application has set up it's own terminate - * handler. Since we are leaving the thread we - * should not get any internal pthreads - * exceptions. - */ - terminate (); - } - -#else /* __cplusplus */ - - /* - * Run the caller's cleanup routine. - */ - destructor (value); - -#endif /* __cplusplus */ - - } - else - { - /* - * Remove association from both the key and thread chains - * and reclaim it's memory resources. - */ - ptw32_tkAssocDestroy (assoc); - ptw32_mcs_lock_release(&threadLock); - ptw32_mcs_lock_release(&keyLock); - } - } - } - while (assocsRemaining); - } -} /* ptw32_callUserDestroyRoutines */ diff --git a/dependencies/win32_pthread/src/ptw32_calloc.c b/dependencies/win32_pthread/src/ptw32_calloc.c deleted file mode 100644 index b01c335e..00000000 --- a/dependencies/win32_pthread/src/ptw32_calloc.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * ptw32_calloc.c - * - * Description: - * This translation unit implements miscellaneous thread functions. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -#if defined(NEED_CALLOC) -void * -ptw32_calloc (size_t n, size_t s) -{ - unsigned int m = n * s; - void *p; - - p = malloc (m); - if (p == NULL) - return NULL; - - memset (p, 0, m); - - return p; -} -#endif diff --git a/dependencies/win32_pthread/src/ptw32_cond_check_need_init.c b/dependencies/win32_pthread/src/ptw32_cond_check_need_init.c deleted file mode 100644 index 251678cc..00000000 --- a/dependencies/win32_pthread/src/ptw32_cond_check_need_init.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * ptw32_cond_check_need_init.c - * - * Description: - * This translation unit implements condition variables and their primitives. - * - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -INLINE int -ptw32_cond_check_need_init (pthread_cond_t * cond) -{ - int result = 0; - ptw32_mcs_local_node_t node; - - /* - * The following guarded test is specifically for statically - * initialised condition variables (via PTHREAD_OBJECT_INITIALIZER). - */ - ptw32_mcs_lock_acquire(&ptw32_cond_test_init_lock, &node); - - /* - * We got here possibly under race - * conditions. Check again inside the critical section. - * If a static cv has been destroyed, the application can - * re-initialise it only by calling pthread_cond_init() - * explicitly. - */ - if (*cond == PTHREAD_COND_INITIALIZER) - { - result = pthread_cond_init (cond, NULL); - } - else if (*cond == NULL) - { - /* - * The cv has been destroyed while we were waiting to - * initialise it, so the operation that caused the - * auto-initialisation should fail. - */ - result = EINVAL; - } - - ptw32_mcs_lock_release(&node); - - return result; -} diff --git a/dependencies/win32_pthread/src/ptw32_getprocessors.c b/dependencies/win32_pthread/src/ptw32_getprocessors.c deleted file mode 100644 index 4ac3cce9..00000000 --- a/dependencies/win32_pthread/src/ptw32_getprocessors.c +++ /dev/null @@ -1,96 +0,0 @@ -/* - * ptw32_getprocessors.c - * - * Description: - * This translation unit implements routines which are private to - * the implementation and may be used throughout it. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -/* - * ptw32_getprocessors() - * - * Get the number of CPUs available to the process. - * - * If the available number of CPUs is 1 then pthread_spin_lock() - * will block rather than spin if the lock is already owned. - * - * pthread_spin_init() calls this routine when initialising - * a spinlock. If the number of available processors changes - * (after a call to SetProcessAffinityMask()) then only - * newly initialised spinlocks will notice. - */ -int -ptw32_getprocessors (int *count) -{ - DWORD_PTR vProcessCPUs; - DWORD_PTR vSystemCPUs; - int result = 0; - -#if defined(NEED_PROCESS_AFFINITY_MASK) - - *count = 1; - -#else - - if (GetProcessAffinityMask (GetCurrentProcess (), - &vProcessCPUs, &vSystemCPUs)) - { - DWORD_PTR bit; - int CPUs = 0; - - for (bit = 1; bit != 0; bit <<= 1) - { - if (vProcessCPUs & bit) - { - CPUs++; - } - } - *count = CPUs; - } - else - { - result = EAGAIN; - } - -#endif - - return (result); -} diff --git a/dependencies/win32_pthread/src/ptw32_is_attr.c b/dependencies/win32_pthread/src/ptw32_is_attr.c deleted file mode 100644 index 80917cfb..00000000 --- a/dependencies/win32_pthread/src/ptw32_is_attr.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * ptw32_is_attr.c - * - * Description: - * This translation unit implements operations on thread attribute objects. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -int -ptw32_is_attr (const pthread_attr_t * attr) -{ - /* Return 0 if the attr object is valid, non-zero otherwise. */ - - return (attr == NULL || - *attr == NULL || (*attr)->valid != PTW32_ATTR_VALID); -} diff --git a/dependencies/win32_pthread/src/ptw32_mutex_check_need_init.c b/dependencies/win32_pthread/src/ptw32_mutex_check_need_init.c deleted file mode 100644 index 846a4b7c..00000000 --- a/dependencies/win32_pthread/src/ptw32_mutex_check_need_init.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * ptw32_mutex_check_need_init.c - * - * Description: - * This translation unit implements mutual exclusion (mutex) primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -static struct pthread_mutexattr_t_ ptw32_recursive_mutexattr_s = - {PTHREAD_PROCESS_PRIVATE, PTHREAD_MUTEX_RECURSIVE, PTHREAD_MUTEX_STALLED}; -static struct pthread_mutexattr_t_ ptw32_errorcheck_mutexattr_s = - {PTHREAD_PROCESS_PRIVATE, PTHREAD_MUTEX_ERRORCHECK, PTHREAD_MUTEX_STALLED}; -static pthread_mutexattr_t ptw32_recursive_mutexattr = &ptw32_recursive_mutexattr_s; -static pthread_mutexattr_t ptw32_errorcheck_mutexattr = &ptw32_errorcheck_mutexattr_s; - - -INLINE int -ptw32_mutex_check_need_init (pthread_mutex_t * mutex) -{ - register int result = 0; - register pthread_mutex_t mtx; - ptw32_mcs_local_node_t node; - - ptw32_mcs_lock_acquire(&ptw32_mutex_test_init_lock, &node); - - /* - * We got here possibly under race - * conditions. Check again inside the critical section - * and only initialise if the mutex is valid (not been destroyed). - * If a static mutex has been destroyed, the application can - * re-initialise it only by calling pthread_mutex_init() - * explicitly. - */ - mtx = *mutex; - - if (mtx == PTHREAD_MUTEX_INITIALIZER) - { - result = pthread_mutex_init (mutex, NULL); - } - else if (mtx == PTHREAD_RECURSIVE_MUTEX_INITIALIZER) - { - result = pthread_mutex_init (mutex, &ptw32_recursive_mutexattr); - } - else if (mtx == PTHREAD_ERRORCHECK_MUTEX_INITIALIZER) - { - result = pthread_mutex_init (mutex, &ptw32_errorcheck_mutexattr); - } - else if (mtx == NULL) - { - /* - * The mutex has been destroyed while we were waiting to - * initialise it, so the operation that caused the - * auto-initialisation should fail. - */ - result = EINVAL; - } - - ptw32_mcs_lock_release(&node); - - return (result); -} diff --git a/dependencies/win32_pthread/src/ptw32_new.c b/dependencies/win32_pthread/src/ptw32_new.c deleted file mode 100644 index bd0a34fc..00000000 --- a/dependencies/win32_pthread/src/ptw32_new.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * ptw32_new.c - * - * Description: - * This translation unit implements miscellaneous thread functions. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -pthread_t -ptw32_new (void) -{ - pthread_t t; - pthread_t nil = {NULL, 0}; - ptw32_thread_t * tp; - - /* - * If there's a reusable pthread_t then use it. - */ - t = ptw32_threadReusePop (); - - if (NULL != t.p) - { - tp = (ptw32_thread_t *) t.p; - } - else - { - /* No reuse threads available */ - tp = (ptw32_thread_t *) calloc (1, sizeof(ptw32_thread_t)); - - if (tp == NULL) - { - return nil; - } - - /* ptHandle.p needs to point to it's parent ptw32_thread_t. */ - t.p = tp->ptHandle.p = tp; - t.x = tp->ptHandle.x = 0; - } - - /* Set default state. */ - tp->seqNumber = ++ptw32_threadSeqNumber; - tp->sched_priority = THREAD_PRIORITY_NORMAL; - tp->detachState = PTHREAD_CREATE_JOINABLE; - tp->cancelState = PTHREAD_CANCEL_ENABLE; - tp->cancelType = PTHREAD_CANCEL_DEFERRED; - tp->stateLock = 0; - tp->threadLock = 0; - tp->robustMxListLock = 0; - tp->robustMxList = NULL; - CPU_ZERO((cpu_set_t*)&tp->cpuset); - tp->cancelEvent = CreateEvent (0, (int) PTW32_TRUE, /* manualReset */ - (int) PTW32_FALSE, /* setSignaled */ - NULL); - - if (tp->cancelEvent == NULL) - { - ptw32_threadReusePush (tp->ptHandle); - return nil; - } - - return t; -} diff --git a/dependencies/win32_pthread/src/ptw32_processInitialize.c b/dependencies/win32_pthread/src/ptw32_processInitialize.c deleted file mode 100644 index 74deda03..00000000 --- a/dependencies/win32_pthread/src/ptw32_processInitialize.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * ptw32_processInitialize.c - * - * Description: - * This translation unit implements routines which are private to - * the implementation and may be used throughout it. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -ptw32_processInitialize (void) - /* - * ------------------------------------------------------ - * DOCPRIVATE - * This function performs process wide initialization for - * the pthread library. - * - * PARAMETERS - * N/A - * - * DESCRIPTION - * This function performs process wide initialization for - * the pthread library. - * If successful, this routine sets the global variable - * ptw32_processInitialized to TRUE. - * - * RESULTS - * TRUE if successful, - * FALSE otherwise - * - * ------------------------------------------------------ - */ -{ - if (ptw32_processInitialized) - { - /* - * Ignore if already initialized. this is useful for - * programs that uses a non-dll pthread - * library. Such programs must call ptw32_processInitialize() explicitly, - * since this initialization routine is automatically called only when - * the dll is loaded. - */ - return PTW32_TRUE; - } - - ptw32_processInitialized = PTW32_TRUE; - - /* - * Initialize Keys - */ - if ((pthread_key_create (&ptw32_selfThreadKey, NULL) != 0) || - (pthread_key_create (&ptw32_cleanupKey, NULL) != 0)) - { - ptw32_processTerminate (); - } - - return (ptw32_processInitialized); -} /* processInitialize */ diff --git a/dependencies/win32_pthread/src/ptw32_processTerminate.c b/dependencies/win32_pthread/src/ptw32_processTerminate.c deleted file mode 100644 index c7402185..00000000 --- a/dependencies/win32_pthread/src/ptw32_processTerminate.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * ptw32_processTerminate.c - * - * Description: - * This translation unit implements routines which are private to - * the implementation and may be used throughout it. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -void -ptw32_processTerminate (void) - /* - * ------------------------------------------------------ - * DOCPRIVATE - * This function performs process wide termination for - * the pthread library. - * - * PARAMETERS - * N/A - * - * DESCRIPTION - * This function performs process wide termination for - * the pthread library. - * This routine sets the global variable - * ptw32_processInitialized to FALSE - * - * RESULTS - * N/A - * - * ------------------------------------------------------ - */ -{ - if (ptw32_processInitialized) - { - ptw32_thread_t * tp, * tpNext; - ptw32_mcs_local_node_t node; - - if (ptw32_selfThreadKey != NULL) - { - /* - * Release ptw32_selfThreadKey - */ - pthread_key_delete (ptw32_selfThreadKey); - - ptw32_selfThreadKey = NULL; - } - - if (ptw32_cleanupKey != NULL) - { - /* - * Release ptw32_cleanupKey - */ - pthread_key_delete (ptw32_cleanupKey); - - ptw32_cleanupKey = NULL; - } - - ptw32_mcs_lock_acquire(&ptw32_thread_reuse_lock, &node); - - tp = ptw32_threadReuseTop; - while (tp != PTW32_THREAD_REUSE_EMPTY) - { - tpNext = tp->prevReuse; - free (tp); - tp = tpNext; - } - - ptw32_threadReuseTop = PTW32_THREAD_REUSE_EMPTY; - ptw32_threadReuseBottom = PTW32_THREAD_REUSE_EMPTY; - - ptw32_mcs_lock_release(&node); - - /* ptw32_cond_list_head = NULL; */ - /* ptw32_cond_list_tail = NULL; */ - - /* reset the thread sequence number. */ - ptw32_threadSeqNumber = 0; - - ptw32_processInitialized = PTW32_FALSE; - } - -} /* processTerminate */ diff --git a/dependencies/win32_pthread/src/ptw32_relmillisecs.c b/dependencies/win32_pthread/src/ptw32_relmillisecs.c deleted file mode 100644 index 34a855c1..00000000 --- a/dependencies/win32_pthread/src/ptw32_relmillisecs.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * ptw32_relmillisecs.c - * - * Description: - * This translation unit implements miscellaneous thread functions. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" -#if !defined(NEED_FTIME) -#include -#endif - - -#if defined(PTW32_BUILD_INLINED) -INLINE -#endif /* PTW32_BUILD_INLINED */ -DWORD -ptw32_relmillisecs (const struct timespec * abstime) -{ - const int64_t NANOSEC_PER_MILLISEC = 1000000; - const int64_t MILLISEC_PER_SEC = 1000; - DWORD milliseconds; - int64_t tmpAbsMilliseconds; - int64_t tmpCurrMilliseconds; -#if defined(NEED_FTIME) - struct timespec currSysTime; - FILETIME ft; - SYSTEMTIME st; -#else /* ! NEED_FTIME */ -#if ( defined(_MSC_VER) && _MSC_VER >= 1300 ) /* MSVC7+ */ || \ - ( defined(PTW32_CONFIG_MINGW) && __MSVCRT_VERSION__ >= 0x0601 ) - struct __timeb64 currSysTime; -#else - struct _timeb currSysTime; -#endif -#endif /* NEED_FTIME */ - - - /* - * Calculate timeout as milliseconds from current system time. - */ - - /* - * subtract current system time from abstime in a way that checks - * that abstime is never in the past, or is never equivalent to the - * defined INFINITE value (0xFFFFFFFF). - * - * Assume all integers are unsigned, i.e. cannot test if less than 0. - */ - tmpAbsMilliseconds = (int64_t)abstime->tv_sec * MILLISEC_PER_SEC; - tmpAbsMilliseconds += ((int64_t)abstime->tv_nsec + (NANOSEC_PER_MILLISEC/2)) / NANOSEC_PER_MILLISEC; - - /* get current system time */ - -#if defined(NEED_FTIME) - - GetSystemTime(&st); - SystemTimeToFileTime(&st, &ft); - /* - * GetSystemTimeAsFileTime(&ft); would be faster, - * but it does not exist on WinCE - */ - - ptw32_filetime_to_timespec(&ft, &currSysTime); - - tmpCurrMilliseconds = (int64_t)currSysTime.tv_sec * MILLISEC_PER_SEC; - tmpCurrMilliseconds += ((int64_t)currSysTime.tv_nsec + (NANOSEC_PER_MILLISEC/2)) - / NANOSEC_PER_MILLISEC; - -#else /* ! NEED_FTIME */ - -#if defined(_MSC_VER) && _MSC_VER >= 1400 /* MSVC8+ */ - _ftime64_s(&currSysTime); -#elif ( defined(_MSC_VER) && _MSC_VER >= 1300 ) /* MSVC7+ */ || \ - ( defined(PTW32_CONFIG_MINGW) && __MSVCRT_VERSION__ >= 0x0601 ) - _ftime64(&currSysTime); -#else - _ftime(&currSysTime); -#endif - - tmpCurrMilliseconds = (int64_t) currSysTime.time * MILLISEC_PER_SEC; - tmpCurrMilliseconds += (int64_t) currSysTime.millitm; - -#endif /* NEED_FTIME */ - - if (tmpAbsMilliseconds > tmpCurrMilliseconds) - { - milliseconds = (DWORD) (tmpAbsMilliseconds - tmpCurrMilliseconds); - if (milliseconds == INFINITE) - { - /* Timeouts must be finite */ - milliseconds--; - } - } - else - { - /* The abstime given is in the past */ - milliseconds = 0; - } - - return milliseconds; -} diff --git a/dependencies/win32_pthread/src/ptw32_reuse.c b/dependencies/win32_pthread/src/ptw32_reuse.c deleted file mode 100644 index 3efc6122..00000000 --- a/dependencies/win32_pthread/src/ptw32_reuse.c +++ /dev/null @@ -1,156 +0,0 @@ -/* - * ptw32_threadReuse.c - * - * Description: - * This translation unit implements miscellaneous thread functions. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -/* - * How it works: - * A pthread_t is a struct (2x32 bit scalar types on IA-32, 2x64 bit on IA-64) - * which is normally passed/returned by value to/from pthreads routines. - * Applications are therefore storing a copy of the struct as it is at that - * time. - * - * The original pthread_t struct plus all copies of it contain the address of - * the thread state struct ptw32_thread_t_ (p), plus a reuse counter (x). Each - * ptw32_thread_t contains the original copy of it's pthread_t. - * Once malloced, a ptw32_thread_t_ struct is not freed until the process exits. - * - * The thread reuse stack is a simple LILO stack managed through a singly - * linked list element in the ptw32_thread_t. - * - * Each time a thread is destroyed, the ptw32_thread_t address is pushed onto the - * reuse stack after it's ptHandle's reuse counter has been incremented. - * - * The following can now be said from this: - * - two pthread_t's are identical if their ptw32_thread_t reference pointers - * are equal and their reuse counters are equal. That is, - * - * equal = (a.p == b.p && a.x == b.x) - * - * - a pthread_t copy refers to a destroyed thread if the reuse counter in - * the copy is not equal to the reuse counter in the original. - * - * threadDestroyed = (copy.x != ((ptw32_thread_t *)copy.p)->ptHandle.x) - * - */ - -/* - * Pop a clean pthread_t struct off the reuse stack. - */ -pthread_t -ptw32_threadReusePop (void) -{ - pthread_t t = {NULL, 0}; - ptw32_mcs_local_node_t node; - - ptw32_mcs_lock_acquire(&ptw32_thread_reuse_lock, &node); - - if (PTW32_THREAD_REUSE_EMPTY != ptw32_threadReuseTop) - { - ptw32_thread_t * tp; - - tp = ptw32_threadReuseTop; - - ptw32_threadReuseTop = tp->prevReuse; - - if (PTW32_THREAD_REUSE_EMPTY == ptw32_threadReuseTop) - { - ptw32_threadReuseBottom = PTW32_THREAD_REUSE_EMPTY; - } - - tp->prevReuse = PTW32_THREAD_REUSE_EMPTY; - - t = tp->ptHandle; - } - - ptw32_mcs_lock_release(&node); - - return t; -} - -/* - * Push a clean pthread_t struct onto the reuse stack. - * Must be re-initialised when reused. - * All object elements (mutexes, events etc) must have been either - * destroyed before this, or never initialised. - */ -void -ptw32_threadReusePush (pthread_t thread) -{ - ptw32_thread_t * tp = (ptw32_thread_t *) thread.p; - pthread_t t; - ptw32_mcs_local_node_t node; - - ptw32_mcs_lock_acquire(&ptw32_thread_reuse_lock, &node); - - t = tp->ptHandle; - memset(tp, 0, sizeof(ptw32_thread_t)); - - /* Must restore the original POSIX handle that we just wiped. */ - tp->ptHandle = t; - - /* Bump the reuse counter now */ -#if defined(PTW32_THREAD_ID_REUSE_INCREMENT) - tp->ptHandle.x += PTW32_THREAD_ID_REUSE_INCREMENT; -#else - tp->ptHandle.x++; -#endif - - tp->state = PThreadStateReuse; - - tp->prevReuse = PTW32_THREAD_REUSE_EMPTY; - - if (PTW32_THREAD_REUSE_EMPTY != ptw32_threadReuseBottom) - { - ptw32_threadReuseBottom->prevReuse = tp; - } - else - { - ptw32_threadReuseTop = tp; - } - - ptw32_threadReuseBottom = tp; - - ptw32_mcs_lock_release(&node); -} - diff --git a/dependencies/win32_pthread/src/ptw32_rwlock_cancelwrwait.c b/dependencies/win32_pthread/src/ptw32_rwlock_cancelwrwait.c deleted file mode 100644 index 74e8a870..00000000 --- a/dependencies/win32_pthread/src/ptw32_rwlock_cancelwrwait.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * ptw32_rwlock_cancelwrwait.c - * - * Description: - * This translation unit implements read/write lock primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -void PTW32_CDECL -ptw32_rwlock_cancelwrwait (void *arg) -{ - pthread_rwlock_t rwl = (pthread_rwlock_t) arg; - - rwl->nSharedAccessCount = -rwl->nCompletedSharedAccessCount; - rwl->nCompletedSharedAccessCount = 0; - - (void) pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted)); - (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess)); -} diff --git a/dependencies/win32_pthread/src/ptw32_rwlock_check_need_init.c b/dependencies/win32_pthread/src/ptw32_rwlock_check_need_init.c deleted file mode 100644 index 8e24da88..00000000 --- a/dependencies/win32_pthread/src/ptw32_rwlock_check_need_init.c +++ /dev/null @@ -1,82 +0,0 @@ -/* - * pthread_rwlock_check_need_init.c - * - * Description: - * This translation unit implements read/write lock primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -INLINE int -ptw32_rwlock_check_need_init (pthread_rwlock_t * rwlock) -{ - int result = 0; - ptw32_mcs_local_node_t node; - - /* - * The following guarded test is specifically for statically - * initialised rwlocks (via PTHREAD_RWLOCK_INITIALIZER). - */ - ptw32_mcs_lock_acquire(&ptw32_rwlock_test_init_lock, &node); - - /* - * We got here possibly under race - * conditions. Check again inside the critical section - * and only initialise if the rwlock is valid (not been destroyed). - * If a static rwlock has been destroyed, the application can - * re-initialise it only by calling pthread_rwlock_init() - * explicitly. - */ - if (*rwlock == PTHREAD_RWLOCK_INITIALIZER) - { - result = pthread_rwlock_init (rwlock, NULL); - } - else if (*rwlock == NULL) - { - /* - * The rwlock has been destroyed while we were waiting to - * initialise it, so the operation that caused the - * auto-initialisation should fail. - */ - result = EINVAL; - } - - ptw32_mcs_lock_release(&node); - - return result; -} diff --git a/dependencies/win32_pthread/src/ptw32_semwait.c b/dependencies/win32_pthread/src/ptw32_semwait.c deleted file mode 100644 index f01d8bc7..00000000 --- a/dependencies/win32_pthread/src/ptw32_semwait.c +++ /dev/null @@ -1,140 +0,0 @@ -/* - * ptw32_semwait.c - * - * Description: - * This translation unit implements mutual exclusion (mutex) primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#if !defined(_UWIN) -/*# include */ -#endif -#include "pthread.h" -#include "implement.h" - - -int -ptw32_semwait (sem_t * sem) - /* - * ------------------------------------------------------ - * DESCRIPTION - * This function waits on a POSIX semaphore. If the - * semaphore value is greater than zero, it decreases - * its value by one. If the semaphore value is zero, then - * the calling thread (or process) is blocked until it can - * successfully decrease the value. - * - * Unlike sem_wait(), this routine is non-cancelable. - * - * RESULTS - * 0 successfully decreased semaphore, - * -1 failed, error in errno. - * ERRNO - * EINVAL 'sem' is not a valid semaphore, - * ENOSYS semaphores are not supported, - * EINTR the function was interrupted by a signal, - * EDEADLK a deadlock condition was detected. - * - * ------------------------------------------------------ - */ -{ - int result = 0; - sem_t s = *sem; - - if (s == NULL) - { - result = EINVAL; - } - else - { - if ((result = pthread_mutex_lock (&s->lock)) == 0) - { - int v; - - /* See sem_destroy.c - */ - if (*sem == NULL) - { - (void) pthread_mutex_unlock (&s->lock); - PTW32_SET_ERRNO(EINVAL); - return -1; - } - - v = --s->value; - (void) pthread_mutex_unlock (&s->lock); - - if (v < 0) - { - /* Must wait */ - if (WaitForSingleObject (s->sem, INFINITE) == WAIT_OBJECT_0) - { -#if defined(NEED_SEM) - if (pthread_mutex_lock (&s->lock) == 0) - { - if (*sem == NULL) - { - (void) pthread_mutex_unlock (&s->lock); - PTW32_SET_ERRNO(EINVAL); - return -1; - } - - if (s->leftToUnblock > 0) - { - --s->leftToUnblock; - SetEvent(s->sem); - } - (void) pthread_mutex_unlock (&s->lock); - } -#endif - return 0; - } - } - else - { - return 0; - } - } - } - - if (result != 0) - { - PTW32_SET_ERRNO(result); - return -1; - } - - return 0; - -} /* ptw32_semwait */ diff --git a/dependencies/win32_pthread/src/ptw32_spinlock_check_need_init.c b/dependencies/win32_pthread/src/ptw32_spinlock_check_need_init.c deleted file mode 100644 index 1cd0ff3f..00000000 --- a/dependencies/win32_pthread/src/ptw32_spinlock_check_need_init.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * ptw32_spinlock_check_need_init.c - * - * Description: - * This translation unit implements spin lock primitives. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -INLINE int -ptw32_spinlock_check_need_init (pthread_spinlock_t * lock) -{ - int result = 0; - ptw32_mcs_local_node_t node; - - /* - * The following guarded test is specifically for statically - * initialised spinlocks (via PTHREAD_SPINLOCK_INITIALIZER). - */ - ptw32_mcs_lock_acquire(&ptw32_spinlock_test_init_lock, &node); - - /* - * We got here possibly under race - * conditions. Check again inside the critical section - * and only initialise if the spinlock is valid (not been destroyed). - * If a static spinlock has been destroyed, the application can - * re-initialise it only by calling pthread_spin_init() - * explicitly. - */ - if (*lock == PTHREAD_SPINLOCK_INITIALIZER) - { - result = pthread_spin_init (lock, PTHREAD_PROCESS_PRIVATE); - } - else if (*lock == NULL) - { - /* - * The spinlock has been destroyed while we were waiting to - * initialise it, so the operation that caused the - * auto-initialisation should fail. - */ - result = EINVAL; - } - - ptw32_mcs_lock_release(&node); - - return (result); -} diff --git a/dependencies/win32_pthread/src/ptw32_threadDestroy.c b/dependencies/win32_pthread/src/ptw32_threadDestroy.c deleted file mode 100644 index 701a4406..00000000 --- a/dependencies/win32_pthread/src/ptw32_threadDestroy.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * ptw32_threadDestroy.c - * - * Description: - * This translation unit implements routines which are private to - * the implementation and may be used throughout it. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -void -ptw32_threadDestroy (pthread_t thread) -{ - ptw32_thread_t * tp = (ptw32_thread_t *) thread.p; - ptw32_thread_t threadCopy; - - if (tp != NULL) - { - /* - * Copy thread state so that the thread can be atomically NULLed. - */ - memcpy (&threadCopy, tp, sizeof (threadCopy)); - - /* - * Thread ID structs are never freed. They're NULLed and reused. - * This also sets the thread to PThreadStateInitial (invalid). - */ - ptw32_threadReusePush (thread); - - /* Now work on the copy. */ - if (threadCopy.cancelEvent != NULL) - { - CloseHandle (threadCopy.cancelEvent); - } - -#if ! defined(PTW32_CONFIG_MINGW) || defined (__MSVCRT__) || defined (__DMC__) - /* - * See documentation for endthread vs endthreadex. - */ - if (threadCopy.threadH != 0) - { - CloseHandle (threadCopy.threadH); - } -#endif - - } -} /* ptw32_threadDestroy */ - diff --git a/dependencies/win32_pthread/src/ptw32_threadStart.c b/dependencies/win32_pthread/src/ptw32_threadStart.c deleted file mode 100644 index 32143e5d..00000000 --- a/dependencies/win32_pthread/src/ptw32_threadStart.c +++ /dev/null @@ -1,330 +0,0 @@ -/* - * ptw32_threadStart.c - * - * Description: - * This translation unit implements routines which are private to - * the implementation and may be used throughout it. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" -#include - -#if defined(__CLEANUP_C) -# include -#endif - -#if defined(__CLEANUP_SEH) - -static DWORD -ExceptionFilter (EXCEPTION_POINTERS * ep, ULONG_PTR * ei) -{ - switch (ep->ExceptionRecord->ExceptionCode) - { - case EXCEPTION_PTW32_SERVICES: - { - DWORD param; - DWORD numParams = ep->ExceptionRecord->NumberParameters; - - numParams = (numParams > 3) ? 3 : numParams; - - for (param = 0; param < numParams; param++) - { - ei[param] = (DWORD) ep->ExceptionRecord->ExceptionInformation[param]; - } - - return EXCEPTION_EXECUTE_HANDLER; - break; - } - default: - { - /* - * A system unexpected exception has occurred running the user's - * routine. We need to cleanup before letting the exception - * out of thread scope. - */ - pthread_t self = pthread_self (); - - ptw32_callUserDestroyRoutines (self); - - return EXCEPTION_CONTINUE_SEARCH; - break; - } - } -} - -#elif defined(__CLEANUP_CXX) - -#if defined(_MSC_VER) -# include -#elif defined(__WATCOMC__) -# include -# include -#else -# if defined(__GNUC__) && __GNUC__ < 3 -# include -# else -# include -using - std::terminate; -using - std::set_terminate; -# endif -#endif - -#endif /* __CLEANUP_CXX */ - -/* - * MSVC6 does not optimize ptw32_threadStart() safely - * (i.e. tests/context1.c fails with "abnormal program - * termination" in some configurations), and there's no - * point to optimizing this routine anyway - */ -#ifdef _MSC_VER -# pragma optimize("g", off) -# pragma warning( disable : 4748 ) -#endif - -#if ! defined (PTW32_CONFIG_MINGW) || (defined (__MSVCRT__) && ! defined (__DMC__)) -unsigned - __stdcall -#else -void -#endif -ptw32_threadStart (void *vthreadParms) -{ - ThreadParms * threadParms = (ThreadParms *) vthreadParms; - pthread_t self; - ptw32_thread_t * sp; - void * (PTW32_CDECL *start) (void *); - void * arg; - -#if defined(__CLEANUP_SEH) - ULONG_PTR - ei[] = { 0, 0, 0 }; -#endif - -#if defined(__CLEANUP_C) - int setjmp_rc; -#endif - - ptw32_mcs_local_node_t stateLock; - void * status = (void *) 0; - - self = threadParms->tid; - sp = (ptw32_thread_t *) self.p; - start = threadParms->start; - arg = threadParms->arg; - - free (threadParms); - -#if defined (PTW32_CONFIG_MINGW) && ! defined (__MSVCRT__) - /* - * beginthread does not return the thread id and is running - * before it returns us the thread handle, and so we do it here. - */ - sp->thread = GetCurrentThreadId (); - /* - * Here we're using stateLock as a general-purpose lock - * to make the new thread wait until the creating thread - * has the new handle. - */ - ptw32_mcs_lock_acquire (&sp->stateLock, &stateLock); - pthread_setspecific (ptw32_selfThreadKey, sp); -#else - pthread_setspecific (ptw32_selfThreadKey, sp); - ptw32_mcs_lock_acquire (&sp->stateLock, &stateLock); -#endif - - sp->state = PThreadStateRunning; - ptw32_mcs_lock_release (&stateLock); - -#if defined(__CLEANUP_SEH) - - __try - { - /* - * Run the caller's routine; - */ - status = sp->exitStatus = (*start) (arg); - sp->state = PThreadStateExiting; - -#if defined(_UWIN) - if (--pthread_count <= 0) - exit (0); -#endif - - } - __except (ExceptionFilter (GetExceptionInformation (), ei)) - { - switch (ei[0]) - { - case PTW32_EPS_CANCEL: - status = sp->exitStatus = PTHREAD_CANCELED; -#if defined(_UWIN) - if (--pthread_count <= 0) - exit (0); -#endif - break; - case PTW32_EPS_EXIT: - status = sp->exitStatus; - break; - default: - status = sp->exitStatus = PTHREAD_CANCELED; - break; - } - } - -#else /* __CLEANUP_SEH */ - -#if defined(__CLEANUP_C) - - setjmp_rc = setjmp (sp->start_mark); - - if (0 == setjmp_rc) - { - /* - * Run the caller's routine; - */ - status = sp->exitStatus = (*start) (arg); - sp->state = PThreadStateExiting; - } - else - { - switch (setjmp_rc) - { - case PTW32_EPS_CANCEL: - status = sp->exitStatus = PTHREAD_CANCELED; - break; - case PTW32_EPS_EXIT: - status = sp->exitStatus; - break; - default: - status = sp->exitStatus = PTHREAD_CANCELED; - break; - } - } - -#else /* __CLEANUP_C */ - -#if defined(__CLEANUP_CXX) - - try - { - status = sp->exitStatus = (*start) (arg); - sp->state = PThreadStateExiting; - } - catch (ptw32_exception_cancel &) - { - /* - * Thread was canceled. - */ - status = sp->exitStatus = PTHREAD_CANCELED; - } - catch (ptw32_exception_exit &) - { - /* - * Thread was exited via pthread_exit(). - */ - status = sp->exitStatus; - } - catch (...) - { - /* - * Some other exception occurred. Clean up while we have - * the opportunity, and call the terminate handler. - */ - (void) pthread_win32_thread_detach_np (); - terminate (); - } - -#else - -#error ERROR [__FILE__, line __LINE__]: Cleanup type undefined. - -#endif /* __CLEANUP_CXX */ -#endif /* __CLEANUP_C */ -#endif /* __CLEANUP_SEH */ - -#if defined(PTW32_STATIC_LIB) - /* - * We need to cleanup the pthread now if we have - * been statically linked, in which case the cleanup - * in DllMain won't get done. Joinable threads will - * only be partially cleaned up and must be fully cleaned - * up by pthread_join() or pthread_detach(). - * - * Note: if this library has been statically linked, - * implicitly created pthreads (those created - * for Win32 threads which have called pthreads routines) - * must be cleaned up explicitly by the application - * by calling pthread_exit(). - * For the dll, DllMain will do the cleanup automatically. - */ - (void) pthread_win32_thread_detach_np (); -#endif - -#if ! defined (PTW32_CONFIG_MINGW) || defined (__MSVCRT__) || defined (__DMC__) - _endthreadex ((unsigned)(size_t) status); -#else - _endthread (); -#endif - - /* - * Never reached. - */ - -#if ! defined (PTW32_CONFIG_MINGW) || defined (__MSVCRT__) || defined (__DMC__) - return (unsigned)(size_t) status; -#endif - -} /* ptw32_threadStart */ - -/* - * Reset optimization - */ -#ifdef _MSC_VER -# pragma optimize("", on) -#endif - -#if defined (PTW32_USES_SEPARATE_CRT) && defined (__cplusplus) -ptw32_terminate_handler -pthread_win32_set_terminate_np(ptw32_terminate_handler termFunction) -{ - return set_terminate(termFunction); -} -#endif diff --git a/dependencies/win32_pthread/src/ptw32_throw.c b/dependencies/win32_pthread/src/ptw32_throw.c deleted file mode 100644 index d79328db..00000000 --- a/dependencies/win32_pthread/src/ptw32_throw.c +++ /dev/null @@ -1,194 +0,0 @@ -/* - * ptw32_throw.c - * - * Description: - * This translation unit implements routines which are private to - * the implementation and may be used throughout it. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -#if defined(__CLEANUP_C) -# include -#endif - -/* - * ptw32_throw - * - * All canceled and explicitly exited POSIX threads go through - * here. This routine knows how to exit both POSIX initiated threads and - * 'implicit' POSIX threads for each of the possible language modes (C, - * C++, and SEH). - */ -#if defined(_MSC_VER) -/* - * Ignore the warning: - * "C++ exception specification ignored except to indicate that - * the function is not __declspec(nothrow)." - */ -#pragma warning(disable:4290) -#endif -void -ptw32_throw (DWORD exception) -#if defined(__CLEANUP_CXX) - throw(ptw32_exception_cancel,ptw32_exception_exit) -#endif -{ - /* - * Don't use pthread_self() to avoid creating an implicit POSIX thread handle - * unnecessarily. - */ - ptw32_thread_t * sp = (ptw32_thread_t *) pthread_getspecific (ptw32_selfThreadKey); - -#if defined(__CLEANUP_SEH) - ULONG_PTR exceptionInformation[3]; -#endif - - sp->state = PThreadStateExiting; - - if (exception != PTW32_EPS_CANCEL && exception != PTW32_EPS_EXIT) - { - /* Should never enter here */ - exit (1); - } - - if (NULL == sp || sp->implicit) - { - /* - * We're inside a non-POSIX initialised Win32 thread - * so there is no point to jump or throw back to. Just do an - * explicit thread exit here after cleaning up POSIX - * residue (i.e. cleanup handlers, POSIX thread handle etc). - */ -#if ! defined (PTW32_CONFIG_MINGW) || defined (__MSVCRT__) || defined (__DMC__) - unsigned exitCode = 0; - - switch (exception) - { - case PTW32_EPS_CANCEL: - exitCode = (unsigned)(size_t) PTHREAD_CANCELED; - break; - case PTW32_EPS_EXIT: - if (NULL != sp) - { - exitCode = (unsigned)(size_t) sp->exitStatus; - } - break; - } -#endif - -#if defined(PTW32_STATIC_LIB) - - pthread_win32_thread_detach_np (); - -#endif - -#if ! defined (PTW32_CONFIG_MINGW) || defined (__MSVCRT__) || defined (__DMC__) - _endthreadex (exitCode); -#else - _endthread (); -#endif - - } - -#if defined(__CLEANUP_SEH) - - - exceptionInformation[0] = (ULONG_PTR) (exception); - exceptionInformation[1] = (ULONG_PTR) (0); - exceptionInformation[2] = (ULONG_PTR) (0); - - RaiseException (EXCEPTION_PTW32_SERVICES, 0, 3, (ULONG_PTR *) exceptionInformation); - -#else /* __CLEANUP_SEH */ - -#if defined(__CLEANUP_C) - - ptw32_pop_cleanup_all (1); - longjmp (sp->start_mark, exception); - -#else /* __CLEANUP_C */ - -#if defined(__CLEANUP_CXX) - - switch (exception) - { - case PTW32_EPS_CANCEL: - throw ptw32_exception_cancel (); - break; - case PTW32_EPS_EXIT: - throw ptw32_exception_exit (); - break; - } - -#else - -#error ERROR [__FILE__, line __LINE__]: Cleanup type undefined. - -#endif /* __CLEANUP_CXX */ - -#endif /* __CLEANUP_C */ - -#endif /* __CLEANUP_SEH */ - - /* Never reached */ -} - - -void -ptw32_pop_cleanup_all (int execute) -{ - while (NULL != ptw32_pop_cleanup (execute)) - { - } -} - - -DWORD -ptw32_get_exception_services_code (void) -{ -#if defined(__CLEANUP_SEH) - - return EXCEPTION_PTW32_SERVICES; - -#else - - return (DWORD)0; - -#endif -} diff --git a/dependencies/win32_pthread/src/ptw32_timespec.c b/dependencies/win32_pthread/src/ptw32_timespec.c deleted file mode 100644 index 5d4e38ca..00000000 --- a/dependencies/win32_pthread/src/ptw32_timespec.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * ptw32_timespec.c - * - * Description: - * This translation unit implements routines which are private to - * the implementation and may be used throughout it. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -#if defined(NEED_FTIME) - -/* - * time between jan 1, 1601 and jan 1, 1970 in units of 100 nanoseconds - */ -#define PTW32_TIMESPEC_TO_FILETIME_OFFSET \ - ( ((int64_t) 27111902 << 32) + (int64_t) 3577643008 ) - -INLINE void -ptw32_timespec_to_filetime (const struct timespec *ts, FILETIME * ft) - /* - * ------------------------------------------------------------------- - * converts struct timespec - * where the time is expressed in seconds and nanoseconds from Jan 1, 1970. - * into FILETIME (as set by GetSystemTimeAsFileTime), where the time is - * expressed in 100 nanoseconds from Jan 1, 1601, - * ------------------------------------------------------------------- - */ -{ - *(int64_t *) ft = ts->tv_sec * 10000000 - + (ts->tv_nsec + 50) / 100 + PTW32_TIMESPEC_TO_FILETIME_OFFSET; -} - -INLINE void -ptw32_filetime_to_timespec (const FILETIME * ft, struct timespec *ts) - /* - * ------------------------------------------------------------------- - * converts FILETIME (as set by GetSystemTimeAsFileTime), where the time is - * expressed in 100 nanoseconds from Jan 1, 1601, - * into struct timespec - * where the time is expressed in seconds and nanoseconds from Jan 1, 1970. - * ------------------------------------------------------------------- - */ -{ - ts->tv_sec = - (int) ((*(int64_t *) ft - PTW32_TIMESPEC_TO_FILETIME_OFFSET) / 10000000); - ts->tv_nsec = - (int) ((*(int64_t *) ft - PTW32_TIMESPEC_TO_FILETIME_OFFSET - - ((int64_t) ts->tv_sec * (int64_t) 10000000)) * 100); -} - -#endif /* NEED_FTIME */ diff --git a/dependencies/win32_pthread/src/ptw32_tkAssocCreate.c b/dependencies/win32_pthread/src/ptw32_tkAssocCreate.c deleted file mode 100644 index 85569be3..00000000 --- a/dependencies/win32_pthread/src/ptw32_tkAssocCreate.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - * ptw32_tkAssocCreate.c - * - * Description: - * This translation unit implements routines which are private to - * the implementation and may be used throughout it. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -int -ptw32_tkAssocCreate (ptw32_thread_t * sp, pthread_key_t key) - /* - * ------------------------------------------------------------------- - * This routine creates an association that - * is unique for the given (thread,key) combination.The association - * is referenced by both the thread and the key. - * This association allows us to determine what keys the - * current thread references and what threads a given key - * references. - * See the detailed description - * at the beginning of this file for further details. - * - * Notes: - * 1) New associations are pushed to the beginning of the - * chain so that the internal ptw32_selfThreadKey association - * is always last, thus allowing selfThreadExit to - * be implicitly called last by pthread_exit. - * 2) - * - * Parameters: - * thread - * current running thread. - * key - * key on which to create an association. - * Returns: - * 0 - if successful, - * ENOMEM - not enough memory to create assoc or other object - * EINVAL - an internal error occurred - * ENOSYS - an internal error occurred - * ------------------------------------------------------------------- - */ -{ - ThreadKeyAssoc *assoc; - - /* - * Have to create an association and add it - * to both the key and the thread. - * - * Both key->keyLock and thread->threadLock are locked before - * entry to this routine. - */ - assoc = (ThreadKeyAssoc *) calloc (1, sizeof (*assoc)); - - if (assoc == NULL) - { - return ENOMEM; - } - - assoc->thread = sp; - assoc->key = key; - - /* - * Register assoc with key - */ - assoc->prevThread = NULL; - assoc->nextThread = (ThreadKeyAssoc *) key->threads; - if (assoc->nextThread != NULL) - { - assoc->nextThread->prevThread = assoc; - } - key->threads = (void *) assoc; - - /* - * Register assoc with thread - */ - assoc->prevKey = NULL; - assoc->nextKey = (ThreadKeyAssoc *) sp->keys; - if (assoc->nextKey != NULL) - { - assoc->nextKey->prevKey = assoc; - } - sp->keys = (void *) assoc; - - return (0); - -} /* ptw32_tkAssocCreate */ diff --git a/dependencies/win32_pthread/src/ptw32_tkAssocDestroy.c b/dependencies/win32_pthread/src/ptw32_tkAssocDestroy.c deleted file mode 100644 index 87f78abe..00000000 --- a/dependencies/win32_pthread/src/ptw32_tkAssocDestroy.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * ptw32_tkAssocDestroy.c - * - * Description: - * This translation unit implements routines which are private to - * the implementation and may be used throughout it. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -void -ptw32_tkAssocDestroy (ThreadKeyAssoc * assoc) - /* - * ------------------------------------------------------------------- - * This routine releases all resources for the given ThreadKeyAssoc - * once it is no longer being referenced - * ie) either the key or thread has stopped referencing it. - * - * Parameters: - * assoc - * an instance of ThreadKeyAssoc. - * Returns: - * N/A - * ------------------------------------------------------------------- - */ -{ - - /* - * Both key->keyLock and thread->threadLock are locked before - * entry to this routine. - */ - if (assoc != NULL) - { - ThreadKeyAssoc * prev, * next; - - /* Remove assoc from thread's keys chain */ - prev = assoc->prevKey; - next = assoc->nextKey; - if (prev != NULL) - { - prev->nextKey = next; - } - if (next != NULL) - { - next->prevKey = prev; - } - - if (assoc->thread->keys == assoc) - { - /* We're at the head of the thread's keys chain */ - assoc->thread->keys = next; - } - if (assoc->thread->nextAssoc == assoc) - { - /* - * Thread is exiting and we're deleting the assoc to be processed next. - * Hand thread the assoc after this one. - */ - assoc->thread->nextAssoc = next; - } - - /* Remove assoc from key's threads chain */ - prev = assoc->prevThread; - next = assoc->nextThread; - if (prev != NULL) - { - prev->nextThread = next; - } - if (next != NULL) - { - next->prevThread = prev; - } - - if (assoc->key->threads == assoc) - { - /* We're at the head of the key's threads chain */ - assoc->key->threads = next; - } - - free (assoc); - } - -} /* ptw32_tkAssocDestroy */ diff --git a/dependencies/win32_pthread/src/sched_get_priority_max.c b/dependencies/win32_pthread/src/sched_get_priority_max.c deleted file mode 100644 index e05867b7..00000000 --- a/dependencies/win32_pthread/src/sched_get_priority_max.c +++ /dev/null @@ -1,139 +0,0 @@ -/* - * sched_get_priority_max.c - * - * Description: - * POSIX thread functions that deal with thread scheduling. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" -#include "sched.h" - -/* - * On Windows98, THREAD_PRIORITY_LOWEST is (-2) and - * THREAD_PRIORITY_HIGHEST is 2, and everything works just fine. - * - * On WinCE 3.0, it so happen that THREAD_PRIORITY_LOWEST is 5 - * and THREAD_PRIORITY_HIGHEST is 1 (yes, I know, it is funny: - * highest priority use smaller numbers) and the following happens: - * - * sched_get_priority_min() returns 5 - * sched_get_priority_max() returns 1 - * - * The following table shows the base priority levels for combinations - * of priority class and priority value in Win32. - * - * Process Priority Class Thread Priority Level - * ----------------------------------------------------------------- - * 1 IDLE_PRIORITY_CLASS THREAD_PRIORITY_IDLE - * 1 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_IDLE - * 1 NORMAL_PRIORITY_CLASS THREAD_PRIORITY_IDLE - * 1 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_IDLE - * 1 HIGH_PRIORITY_CLASS THREAD_PRIORITY_IDLE - * 2 IDLE_PRIORITY_CLASS THREAD_PRIORITY_LOWEST - * 3 IDLE_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL - * 4 IDLE_PRIORITY_CLASS THREAD_PRIORITY_NORMAL - * 4 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_LOWEST - * 5 IDLE_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL - * 5 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL - * 5 Background NORMAL_PRIORITY_CLASS THREAD_PRIORITY_LOWEST - * 6 IDLE_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST - * 6 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_NORMAL - * 6 Background NORMAL_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL - * 7 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL - * 7 Background NORMAL_PRIORITY_CLASS THREAD_PRIORITY_NORMAL - * 7 Foreground NORMAL_PRIORITY_CLASS THREAD_PRIORITY_LOWEST - * 8 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST - * 8 NORMAL_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL - * 8 Foreground NORMAL_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL - * 8 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_LOWEST - * 9 NORMAL_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST - * 9 Foreground NORMAL_PRIORITY_CLASS THREAD_PRIORITY_NORMAL - * 9 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL - * 10 Foreground NORMAL_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL - * 10 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_NORMAL - * 11 Foreground NORMAL_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST - * 11 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL - * 11 HIGH_PRIORITY_CLASS THREAD_PRIORITY_LOWEST - * 12 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST - * 12 HIGH_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL - * 13 HIGH_PRIORITY_CLASS THREAD_PRIORITY_NORMAL - * 14 HIGH_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL - * 15 HIGH_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST - * 15 HIGH_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL - * 15 IDLE_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL - * 15 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL - * 15 NORMAL_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL - * 15 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL - * 16 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_IDLE - * 17 REALTIME_PRIORITY_CLASS -7 - * 18 REALTIME_PRIORITY_CLASS -6 - * 19 REALTIME_PRIORITY_CLASS -5 - * 20 REALTIME_PRIORITY_CLASS -4 - * 21 REALTIME_PRIORITY_CLASS -3 - * 22 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_LOWEST - * 23 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL - * 24 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_NORMAL - * 25 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL - * 26 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST - * 27 REALTIME_PRIORITY_CLASS 3 - * 28 REALTIME_PRIORITY_CLASS 4 - * 29 REALTIME_PRIORITY_CLASS 5 - * 30 REALTIME_PRIORITY_CLASS 6 - * 31 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL - * - * Windows NT: Values -7, -6, -5, -4, -3, 3, 4, 5, and 6 are not supported. - */ - - -int -sched_get_priority_max (int policy) -{ - if (policy < SCHED_MIN || policy > SCHED_MAX) - { - PTW32_SET_ERRNO(EINVAL); - return -1; - } - -#if (THREAD_PRIORITY_LOWEST > THREAD_PRIORITY_NORMAL) - /* WinCE? */ - return PTW32_MAX (THREAD_PRIORITY_IDLE, THREAD_PRIORITY_TIME_CRITICAL); -#else - /* This is independent of scheduling policy in Win32. */ - return PTW32_MAX (THREAD_PRIORITY_IDLE, THREAD_PRIORITY_TIME_CRITICAL); -#endif -} diff --git a/dependencies/win32_pthread/src/sched_get_priority_min.c b/dependencies/win32_pthread/src/sched_get_priority_min.c deleted file mode 100644 index 2c8a6560..00000000 --- a/dependencies/win32_pthread/src/sched_get_priority_min.c +++ /dev/null @@ -1,140 +0,0 @@ -/* - * sched_get_priority_min.c - * - * Description: - * POSIX thread functions that deal with thread scheduling. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" -#include "sched.h" - -/* - * On Windows98, THREAD_PRIORITY_LOWEST is (-2) and - * THREAD_PRIORITY_HIGHEST is 2, and everything works just fine. - * - * On WinCE 3.0, it so happen that THREAD_PRIORITY_LOWEST is 5 - * and THREAD_PRIORITY_HIGHEST is 1 (yes, I know, it is funny: - * highest priority use smaller numbers) and the following happens: - * - * sched_get_priority_min() returns 5 - * sched_get_priority_max() returns 1 - * - * The following table shows the base priority levels for combinations - * of priority class and priority value in Win32. - * - * Process Priority Class Thread Priority Level - * ----------------------------------------------------------------- - * 1 IDLE_PRIORITY_CLASS THREAD_PRIORITY_IDLE - * 1 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_IDLE - * 1 NORMAL_PRIORITY_CLASS THREAD_PRIORITY_IDLE - * 1 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_IDLE - * 1 HIGH_PRIORITY_CLASS THREAD_PRIORITY_IDLE - * 2 IDLE_PRIORITY_CLASS THREAD_PRIORITY_LOWEST - * 3 IDLE_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL - * 4 IDLE_PRIORITY_CLASS THREAD_PRIORITY_NORMAL - * 4 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_LOWEST - * 5 IDLE_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL - * 5 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL - * 5 Background NORMAL_PRIORITY_CLASS THREAD_PRIORITY_LOWEST - * 6 IDLE_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST - * 6 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_NORMAL - * 6 Background NORMAL_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL - * 7 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL - * 7 Background NORMAL_PRIORITY_CLASS THREAD_PRIORITY_NORMAL - * 7 Foreground NORMAL_PRIORITY_CLASS THREAD_PRIORITY_LOWEST - * 8 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST - * 8 NORMAL_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL - * 8 Foreground NORMAL_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL - * 8 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_LOWEST - * 9 NORMAL_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST - * 9 Foreground NORMAL_PRIORITY_CLASS THREAD_PRIORITY_NORMAL - * 9 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL - * 10 Foreground NORMAL_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL - * 10 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_NORMAL - * 11 Foreground NORMAL_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST - * 11 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL - * 11 HIGH_PRIORITY_CLASS THREAD_PRIORITY_LOWEST - * 12 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST - * 12 HIGH_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL - * 13 HIGH_PRIORITY_CLASS THREAD_PRIORITY_NORMAL - * 14 HIGH_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL - * 15 HIGH_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST - * 15 HIGH_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL - * 15 IDLE_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL - * 15 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL - * 15 NORMAL_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL - * 15 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL - * 16 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_IDLE - * 17 REALTIME_PRIORITY_CLASS -7 - * 18 REALTIME_PRIORITY_CLASS -6 - * 19 REALTIME_PRIORITY_CLASS -5 - * 20 REALTIME_PRIORITY_CLASS -4 - * 21 REALTIME_PRIORITY_CLASS -3 - * 22 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_LOWEST - * 23 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL - * 24 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_NORMAL - * 25 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL - * 26 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST - * 27 REALTIME_PRIORITY_CLASS 3 - * 28 REALTIME_PRIORITY_CLASS 4 - * 29 REALTIME_PRIORITY_CLASS 5 - * 30 REALTIME_PRIORITY_CLASS 6 - * 31 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL - * - * Windows NT: Values -7, -6, -5, -4, -3, 3, 4, 5, and 6 are not supported. - * - */ - - -int -sched_get_priority_min (int policy) -{ - if (policy < SCHED_MIN || policy > SCHED_MAX) - { - PTW32_SET_ERRNO(EINVAL); - return -1; - } - -#if (THREAD_PRIORITY_LOWEST > THREAD_PRIORITY_NORMAL) - /* WinCE? */ - return PTW32_MIN (THREAD_PRIORITY_IDLE, THREAD_PRIORITY_TIME_CRITICAL); -#else - /* This is independent of scheduling policy in Win32. */ - return PTW32_MIN (THREAD_PRIORITY_IDLE, THREAD_PRIORITY_TIME_CRITICAL); -#endif -} diff --git a/dependencies/win32_pthread/src/sched_getscheduler.c b/dependencies/win32_pthread/src/sched_getscheduler.c deleted file mode 100644 index a6b7c84f..00000000 --- a/dependencies/win32_pthread/src/sched_getscheduler.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * sched_getscheduler.c - * - * Description: - * POSIX thread functions that deal with thread scheduling. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" -#include "sched.h" - -int -sched_getscheduler (pid_t pid) -{ - /* - * Win32 only has one policy which we call SCHED_OTHER. - * However, we try to provide other valid side-effects - * such as EPERM and ESRCH errors. - */ - if (0 != pid) - { - pid_t selfPid = (pid_t) GetCurrentProcessId (); - - if (pid != selfPid) - { - HANDLE h = - OpenProcess (PROCESS_QUERY_INFORMATION, PTW32_FALSE, (DWORD) pid); - - if (NULL == h) - { - PTW32_SET_ERRNO(((0xFF & ERROR_ACCESS_DENIED) == GetLastError()) ? EPERM : ESRCH); - return -1; - } - else - CloseHandle(h); - } - } - - return SCHED_OTHER; -} diff --git a/dependencies/win32_pthread/src/sched_setaffinity.c b/dependencies/win32_pthread/src/sched_setaffinity.c deleted file mode 100644 index 520d4d51..00000000 --- a/dependencies/win32_pthread/src/sched_setaffinity.c +++ /dev/null @@ -1,352 +0,0 @@ -/* - * sched_setaffinity.c - * - * Description: - * POSIX scheduling functions that deal with CPU affinity. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" -#include "sched.h" - -int -sched_setaffinity (pid_t pid, size_t cpusetsize, cpu_set_t *set) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * Sets the CPU affinity mask of the process whose ID is pid - * to the value specified by mask. If pid is zero, then the - * calling process is used. The argument cpusetsize is the - * length (in bytes) of the data pointed to by mask. Normally - * this argument would be specified as sizeof(cpu_set_t). - * - * If the process specified by pid is not currently running on - * one of the CPUs specified in mask, then that process is - * migrated to one of the CPUs specified in mask. - * - * PARAMETERS - * pid - * Process ID - * - * cpusetsize - * Currently ignored in pthreads4w. - * Usually set to sizeof(cpu_set_t) - * - * mask - * Pointer to the CPU mask to set (cpu_set_t). - * - * DESCRIPTION - * Sets the CPU affinity mask of the process whose ID is pid - * to the value specified by mask. If pid is zero, then the - * calling process is used. The argument cpusetsize is the - * length (in bytes) of the data pointed to by mask. Normally - * this argument would be specified as sizeof(cpu_set_t). - * - * If the process specified by pid is not currently running on - * one of the CPUs specified in mask, then that process is - * migrated to one of the CPUs specified in mask. - * - * RESULTS - * 0 successfully created semaphore, - * EFAULT 'mask' is a NULL pointer. - * EINVAL '*mask' contains no CPUs in the set - * of available CPUs. - * EAGAIN The system available CPUs could not - * be obtained. - * EPERM The process referred to by 'pid' is - * not modifiable by us. - * ESRCH The process referred to by 'pid' was - * not found. - * ENOSYS Function not supported. - * - * ------------------------------------------------------ - */ -{ -#if ! defined(NEED_PROCESS_AFFINITY_MASK) - - DWORD_PTR vProcessMask; - DWORD_PTR vSystemMask; - HANDLE h; - int targetPid = (int)(size_t) pid; - int result = 0; - - if (NULL == set) - { - result = EFAULT; - } - else - { - if (0 == targetPid) - { - targetPid = (int) GetCurrentProcessId (); - } - - h = OpenProcess (PROCESS_QUERY_INFORMATION|PROCESS_SET_INFORMATION, PTW32_FALSE, (DWORD) targetPid); - - if (NULL == h) - { - result = (((0xFF & ERROR_ACCESS_DENIED) == GetLastError()) ? EPERM : ESRCH); - } - else - { - if (GetProcessAffinityMask (h, &vProcessMask, &vSystemMask)) - { - /* - * Result is the intersection of available CPUs and the mask. - */ - DWORD_PTR newMask = vSystemMask & ((_sched_cpu_set_vector_*)set)->_cpuset; - - if (newMask) - { - if (SetProcessAffinityMask(h, newMask) == 0) - { - switch (GetLastError()) - { - case (0xFF & ERROR_ACCESS_DENIED): - result = EPERM; - break; - case (0xFF & ERROR_INVALID_PARAMETER): - result = EINVAL; - break; - default: - result = EAGAIN; - break; - } - } - } - else - { - /* - * Mask does not contain any CPUs currently available on the system. - */ - result = EINVAL; - } - } - else - { - result = EAGAIN; - } - } - CloseHandle(h); - } - - if (result != 0) - { - PTW32_SET_ERRNO(result); - return -1; - } - else - { - return 0; - } - -#else - - PTW32_SET_ERRNO(ENOSYS); - return -1; - -#endif -} - - -int -sched_getaffinity (pid_t pid, size_t cpusetsize, cpu_set_t *set) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * Gets the CPU affinity mask of the process whose ID is pid - * to the value specified by mask. If pid is zero, then the - * calling process is used. The argument cpusetsize is the - * length (in bytes) of the data pointed to by mask. Normally - * this argument would be specified as sizeof(cpu_set_t). - * - * PARAMETERS - * pid - * Process ID - * - * cpusetsize - * Currently ignored in pthreads4w. - * Usually set to sizeof(cpu_set_t) - * - * mask - * Pointer to the CPU mask to set (cpu_set_t). - * - * DESCRIPTION - * Sets the CPU affinity mask of the process whose ID is pid - * to the value specified by mask. If pid is zero, then the - * calling process is used. The argument cpusetsize is the - * length (in bytes) of the data pointed to by mask. Normally - * this argument would be specified as sizeof(cpu_set_t). - * - * RESULTS - * 0 successfully created semaphore, - * EFAULT 'mask' is a NULL pointer. - * EAGAIN The system available CPUs could not - * be obtained. - * EPERM The process referred to by 'pid' is - * not modifiable by us. - * ESRCH The process referred to by 'pid' was - * not found. - * - * ------------------------------------------------------ - */ -{ - DWORD_PTR vProcessMask; - DWORD_PTR vSystemMask; - HANDLE h; - int targetPid = (int)(size_t) pid; - int result = 0; - - if (NULL == set) - { - result = EFAULT; - } - else - { - -#if ! defined(NEED_PROCESS_AFFINITY_MASK) - - if (0 == targetPid) - { - targetPid = (int) GetCurrentProcessId (); - } - - h = OpenProcess (PROCESS_QUERY_INFORMATION, PTW32_FALSE, (DWORD) targetPid); - - if (NULL == h) - { - result = (((0xFF & ERROR_ACCESS_DENIED) == GetLastError()) ? EPERM : ESRCH); - } - else - { - if (GetProcessAffinityMask (h, &vProcessMask, &vSystemMask)) - { - ((_sched_cpu_set_vector_*)set)->_cpuset = vProcessMask; - } - else - { - result = EAGAIN; - } - } - CloseHandle(h); - -#else - ((_sched_cpu_set_vector_*)set)->_cpuset = (size_t)0x1; -#endif - - } - - if (result != 0) - { - PTW32_SET_ERRNO(result); - return -1; - } - else - { - return 0; - } -} - -/* - * Support routines for cpu_set_t - */ -int _sched_affinitycpucount (const cpu_set_t *set) -{ - size_t tset; - int count; - - /* - * Relies on tset being unsigned, otherwise the right-shift will - * be arithmetic rather than logical and the 'for' will loop forever. - */ - for (count = 0, tset = ((_sched_cpu_set_vector_*)set)->_cpuset; tset; tset >>= 1) - { - if (tset & (size_t)1) - { - count++; - } - } - return count; -} - -void _sched_affinitycpuzero (cpu_set_t *pset) -{ - ((_sched_cpu_set_vector_*)pset)->_cpuset = (size_t)0; -} - -void _sched_affinitycpuset (int cpu, cpu_set_t *pset) -{ - ((_sched_cpu_set_vector_*)pset)->_cpuset |= ((size_t)1 << cpu); -} - -void _sched_affinitycpuclr (int cpu, cpu_set_t *pset) -{ - ((_sched_cpu_set_vector_*)pset)->_cpuset &= ~((size_t)1 << cpu); -} - -int _sched_affinitycpuisset (int cpu, const cpu_set_t *pset) -{ - return ((((_sched_cpu_set_vector_*)pset)->_cpuset & - ((size_t)1 << cpu)) != (size_t)0); -} - -void _sched_affinitycpuand(cpu_set_t *pdestset, const cpu_set_t *psrcset1, const cpu_set_t *psrcset2) -{ - ((_sched_cpu_set_vector_*)pdestset)->_cpuset = - (((_sched_cpu_set_vector_*)psrcset1)->_cpuset & - ((_sched_cpu_set_vector_*)psrcset2)->_cpuset); -} - -void _sched_affinitycpuor(cpu_set_t *pdestset, const cpu_set_t *psrcset1, const cpu_set_t *psrcset2) -{ - ((_sched_cpu_set_vector_*)pdestset)->_cpuset = - (((_sched_cpu_set_vector_*)psrcset1)->_cpuset | - ((_sched_cpu_set_vector_*)psrcset2)->_cpuset); -} - -void _sched_affinitycpuxor(cpu_set_t *pdestset, const cpu_set_t *psrcset1, const cpu_set_t *psrcset2) -{ - ((_sched_cpu_set_vector_*)pdestset)->_cpuset = - (((_sched_cpu_set_vector_*)psrcset1)->_cpuset ^ - ((_sched_cpu_set_vector_*)psrcset2)->_cpuset); -} - -int _sched_affinitycpuequal (const cpu_set_t *pset1, const cpu_set_t *pset2) -{ - return (((_sched_cpu_set_vector_*)pset1)->_cpuset == - ((_sched_cpu_set_vector_*)pset2)->_cpuset); -} diff --git a/dependencies/win32_pthread/src/sched_setscheduler.c b/dependencies/win32_pthread/src/sched_setscheduler.c deleted file mode 100644 index 7f5204bc..00000000 --- a/dependencies/win32_pthread/src/sched_setscheduler.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * sched_setscheduler.c - * - * Description: - * POSIX thread functions that deal with thread scheduling. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" -#include "sched.h" - -int -sched_setscheduler (pid_t pid, int policy) -{ - /* - * Win32 only has one policy which we call SCHED_OTHER. - * However, we try to provide other valid side-effects - * such as EPERM and ESRCH errors. Choosing to check - * for a valid policy last allows us to get the most value out - * of this function. - */ - if (0 != pid) - { - pid_t selfPid = (pid_t) GetCurrentProcessId (); - - if (pid != selfPid) - { - HANDLE h = - OpenProcess (PROCESS_SET_INFORMATION, PTW32_FALSE, (DWORD) pid); - - if (NULL == h) - { - PTW32_SET_ERRNO((GetLastError () == (0xFF & ERROR_ACCESS_DENIED)) ? EPERM : ESRCH); - return -1; - } - else - CloseHandle(h); - } - } - - if (SCHED_OTHER != policy) - { - PTW32_SET_ERRNO(ENOSYS); - return -1; - } - - /* - * Don't set anything because there is nothing to set. - * Just return the current (the only possible) value. - */ - return SCHED_OTHER; -} diff --git a/dependencies/win32_pthread/src/sched_yield.c b/dependencies/win32_pthread/src/sched_yield.c deleted file mode 100644 index 30de449b..00000000 --- a/dependencies/win32_pthread/src/sched_yield.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * sched_yield.c - * - * Description: - * POSIX thread functions that deal with thread scheduling. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" -#include "sched.h" - -int -sched_yield (void) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function indicates that the calling thread is - * willing to give up some time slices to other threads. - * - * PARAMETERS - * N/A - * - * - * DESCRIPTION - * This function indicates that the calling thread is - * willing to give up some time slices to other threads. - * NOTE: Since this is part of POSIX 1003.1b - * (realtime extensions), it is defined as returning - * -1 if an error occurs and sets errno to the actual - * error. - * - * RESULTS - * 0 successfully created semaphore, - * ENOSYS sched_yield not supported, - * - * ------------------------------------------------------ - */ -{ - Sleep (0); - - return 0; -} diff --git a/dependencies/win32_pthread/src/sem_close.c b/dependencies/win32_pthread/src/sem_close.c deleted file mode 100644 index 5e86ae82..00000000 --- a/dependencies/win32_pthread/src/sem_close.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * ------------------------------------------------------------- - * - * Module: sem_close.c - * - * Purpose: - * Semaphores aren't actually part of the PThreads standard. - * They are defined by the POSIX Standard: - * - * POSIX 1003.1b-1993 (POSIX.1b) - * - * ------------------------------------------------------------- - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "semaphore.h" -#include "implement.h" - -/* ignore warning "unreferenced formal parameter" */ -#if defined(_MSC_VER) -#pragma warning( disable : 4100 ) -#endif - -int -sem_close (sem_t * sem) -{ - PTW32_SET_ERRNO(ENOSYS); - return -1; -} /* sem_close */ diff --git a/dependencies/win32_pthread/src/sem_destroy.c b/dependencies/win32_pthread/src/sem_destroy.c deleted file mode 100644 index 243ba8d3..00000000 --- a/dependencies/win32_pthread/src/sem_destroy.c +++ /dev/null @@ -1,149 +0,0 @@ -/* - * ------------------------------------------------------------- - * - * Module: sem_destroy.c - * - * Purpose: - * Semaphores aren't actually part of the PThreads standard. - * They are defined by the POSIX Standard: - * - * POSIX 1003.1b-1993 (POSIX.1b) - * - * ------------------------------------------------------------- - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "semaphore.h" -#include "implement.h" - - -int -sem_destroy (sem_t * sem) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function destroys an unnamed semaphore. - * - * PARAMETERS - * sem - * pointer to an instance of sem_t - * - * DESCRIPTION - * This function destroys an unnamed semaphore. - * - * RESULTS - * 0 successfully destroyed semaphore, - * -1 failed, error in errno - * ERRNO - * EINVAL 'sem' is not a valid semaphore, - * ENOSYS semaphores are not supported, - * EBUSY threads (or processes) are currently - * blocked on 'sem' - * - * ------------------------------------------------------ - */ -{ - int result = 0; - sem_t s = NULL; - - if (sem == NULL || *sem == NULL) - { - result = EINVAL; - } - else - { - s = *sem; - - if ((result = pthread_mutex_lock (&s->lock)) == 0) - { - if (s->value < 0) - { - (void) pthread_mutex_unlock (&s->lock); - result = EBUSY; - } - else - { - /* There are no threads currently blocked on this semaphore. */ - - if (!CloseHandle (s->sem)) - { - (void) pthread_mutex_unlock (&s->lock); - result = EINVAL; - } - else - { - /* - * Invalidate the semaphore handle when we have the lock. - * Other sema operations should test this after acquiring the lock - * to check that the sema is still valid, i.e. before performing any - * operations. This may only be necessary before the sema op routine - * returns so that the routine can return EINVAL - e.g. if setting - * s->value to SEM_VALUE_MAX below does force a fall-through. - */ - *sem = NULL; - - /* Prevent anyone else actually waiting on or posting this sema. - */ - s->value = SEM_VALUE_MAX; - - (void) pthread_mutex_unlock (&s->lock); - - do - { - /* Give other threads a chance to run and exit any sema op - * routines. Due to the SEM_VALUE_MAX value, if sem_post or - * sem_wait were blocked by us they should fall through. - */ - Sleep(0); - } - while (pthread_mutex_destroy (&s->lock) == EBUSY); - } - } - } - } - - if (result != 0) - { - PTW32_SET_ERRNO(result); - return -1; - } - - free (s); - - return 0; - -} /* sem_destroy */ diff --git a/dependencies/win32_pthread/src/sem_getvalue.c b/dependencies/win32_pthread/src/sem_getvalue.c deleted file mode 100644 index 704af126..00000000 --- a/dependencies/win32_pthread/src/sem_getvalue.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * ------------------------------------------------------------- - * - * Module: sem_getvalue.c - * - * Purpose: - * Semaphores aren't actually part of PThreads. - * They are defined by the POSIX Standard: - * - * POSIX 1003.1-2001 - * - * ------------------------------------------------------------- - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "semaphore.h" -#include "implement.h" - - -int -sem_getvalue (sem_t * sem, int *sval) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function stores the current count value of the - * semaphore. - * RESULTS - * - * Return value - * - * 0 sval has been set. - * -1 failed, error in errno - * - * in global errno - * - * EINVAL 'sem' is not a valid semaphore, - * ENOSYS this function is not supported, - * - * - * PARAMETERS - * - * sem pointer to an instance of sem_t - * - * sval pointer to int. - * - * DESCRIPTION - * This function stores the current count value of the semaphore - * pointed to by sem in the int pointed to by sval. - */ -{ - int result = 0; - - if (NULL == sem || NULL == *sem || NULL == sval) - { - result = EINVAL; - } - else - { - register sem_t s = *sem; - - if ((result = pthread_mutex_lock(&s->lock)) == 0) - { - /* - * See sem_destroy.c - */ - if (*sem == NULL /* don't test 's' here */) - { - result = EINVAL; - } - else - { - *sval = s->value; - } - (void) pthread_mutex_unlock (&s->lock); - } - } - - if (result != 0) - { - PTW32_SET_ERRNO(result); - return -1; - } - - return 0; -} /* sem_getvalue */ diff --git a/dependencies/win32_pthread/src/sem_init.c b/dependencies/win32_pthread/src/sem_init.c deleted file mode 100644 index 176f87a3..00000000 --- a/dependencies/win32_pthread/src/sem_init.c +++ /dev/null @@ -1,173 +0,0 @@ -/* - * ------------------------------------------------------------- - * - * Module: sem_init.c - * - * Purpose: - * Semaphores aren't actually part of PThreads. - * They are defined by the POSIX Standard: - * - * POSIX 1003.1-2001 - * - * ------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "semaphore.h" -#include "implement.h" - -int -sem_init (sem_t * sem, int pshared, unsigned int value) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function initializes a semaphore. The - * initial value of the semaphore is 'value' - * - * PARAMETERS - * sem - * pointer to an instance of sem_t - * - * pshared - * if zero, this semaphore may only be shared between - * threads in the same process. - * if nonzero, the semaphore can be shared between - * processes - * - * value - * initial value of the semaphore counter - * - * DESCRIPTION - * This function initializes a semaphore. The - * initial value of the semaphore is set to 'value'. - * - * RESULTS - * 0 successfully created semaphore, - * -1 failed, error in errno - * ERRNO - * EINVAL 'sem' is not a valid semaphore, or - * 'value' >= SEM_VALUE_MAX - * ENOMEM out of memory, - * ENOSPC a required resource has been exhausted, - * ENOSYS semaphores are not supported, - * EPERM the process lacks appropriate privilege - * - * ------------------------------------------------------ - */ -{ - int result = 0; - sem_t s = NULL; - - if (pshared != 0) - { - /* - * Creating a semaphore that can be shared between - * processes - */ - result = EPERM; - } - else if (value > (unsigned int)SEM_VALUE_MAX) - { - result = EINVAL; - } - else - { - s = (sem_t) calloc (1, sizeof (*s)); - - if (NULL == s) - { - result = ENOMEM; - } - else - { - - s->value = value; - if (pthread_mutex_init(&s->lock, NULL) == 0) - { - -#if defined(NEED_SEM) - - s->sem = CreateEvent (NULL, - PTW32_FALSE, /* auto (not manual) reset */ - PTW32_FALSE, /* initial state is unset */ - NULL); - - if (0 == s->sem) - { - (void) pthread_mutex_destroy(&s->lock); - result = ENOSPC; - } - else - { - s->leftToUnblock = 0; - } - -#else /* NEED_SEM */ - - if ((s->sem = CreateSemaphore (NULL, /* Always NULL */ - (long) 0, /* Force threads to wait */ - (long) SEM_VALUE_MAX, /* Maximum value */ - NULL)) == 0) /* Name */ - { - (void) pthread_mutex_destroy(&s->lock); - result = ENOSPC; - } - -#endif /* NEED_SEM */ - - } - else - { - result = ENOSPC; - } - - if (result != 0) - { - free(s); - } - } - } - - if (result != 0) - { - PTW32_SET_ERRNO(result); - return -1; - } - - *sem = s; - - return 0; - -} /* sem_init */ diff --git a/dependencies/win32_pthread/src/sem_open.c b/dependencies/win32_pthread/src/sem_open.c deleted file mode 100644 index 60316e66..00000000 --- a/dependencies/win32_pthread/src/sem_open.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * ------------------------------------------------------------- - * - * Module: sem_open.c - * - * Purpose: - * Semaphores aren't actually part of the PThreads standard. - * They are defined by the POSIX Standard: - * - * POSIX 1003.1b-1993 (POSIX.1b) - * - * ------------------------------------------------------------- - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "semaphore.h" -#include "implement.h" - -/* ignore warning "unreferenced formal parameter" */ -#if defined(_MSC_VER) -#pragma warning( disable : 4100 ) -#endif - -int -sem_open (const char *name, int oflag, mode_t mode, unsigned int value) -{ - PTW32_SET_ERRNO(ENOSYS); - return -1; -} /* sem_open */ diff --git a/dependencies/win32_pthread/src/sem_post.c b/dependencies/win32_pthread/src/sem_post.c deleted file mode 100644 index b495420b..00000000 --- a/dependencies/win32_pthread/src/sem_post.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * ------------------------------------------------------------- - * - * Module: sem_post.c - * - * Purpose: - * Semaphores aren't actually part of the PThreads standard. - * They are defined by the POSIX Standard: - * - * POSIX 1003.1b-1993 (POSIX.1b) - * - * ------------------------------------------------------------- - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "semaphore.h" -#include "implement.h" - - -int -sem_post (sem_t * sem) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function posts a wakeup to a semaphore. - * - * PARAMETERS - * sem - * pointer to an instance of sem_t - * - * DESCRIPTION - * This function posts a wakeup to a semaphore. If there - * are waiting threads (or processes), one is awakened; - * otherwise, the semaphore value is incremented by one. - * - * RESULTS - * 0 successfully posted semaphore, - * -1 failed, error in errno - * ERRNO - * EINVAL 'sem' is not a valid semaphore, - * ENOSYS semaphores are not supported, - * ERANGE semaphore count is too big - * - * ------------------------------------------------------ - */ -{ - int result = 0; - - if (NULL == sem || NULL == *sem) - { - result = EINVAL; - } - else - { - sem_t s = *sem; - - if ((result = pthread_mutex_lock (&s->lock)) == 0) - { - /* - * See sem_destroy.c - */ - if (NULL == *sem /* don't test 's' here */) - { - result = EINVAL; - } - else - { - if (s->value < SEM_VALUE_MAX) - { -#if defined(NEED_SEM) - if (++s->value <= 0 - && !SetEvent(s->sem)) - { - s->value--; - result = EINVAL; - } -#else - if (++s->value <= 0 - && !ReleaseSemaphore (s->sem, 1, NULL)) - { - s->value--; - result = EINVAL; - } -#endif /* NEED_SEM */ - } - else - { - result = ERANGE; - } - } - (void) pthread_mutex_unlock (&s->lock); - } - } - - if (result != 0) - { - PTW32_SET_ERRNO(result); - return -1; - } - - return 0; -} diff --git a/dependencies/win32_pthread/src/sem_post_multiple.c b/dependencies/win32_pthread/src/sem_post_multiple.c deleted file mode 100644 index 01d8bb54..00000000 --- a/dependencies/win32_pthread/src/sem_post_multiple.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * ------------------------------------------------------------- - * - * Module: sem_post_multiple.c - * - * Purpose: - * Semaphores aren't actually part of the PThreads standard. - * They are defined by the POSIX Standard: - * - * POSIX 1003.1b-1993 (POSIX.1b) - * - * ------------------------------------------------------------- - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "semaphore.h" -#include "implement.h" - - -int -sem_post_multiple (sem_t * sem, int count) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function posts multiple wakeups to a semaphore. - * - * PARAMETERS - * sem - * pointer to an instance of sem_t - * - * count - * counter, must be greater than zero. - * - * DESCRIPTION - * This function posts multiple wakeups to a semaphore. If there - * are waiting threads (or processes), n <= count are awakened; - * the semaphore value is incremented by count - n. - * - * RESULTS - * 0 successfully posted semaphore, - * -1 failed, error in errno - * ERRNO - * EINVAL 'sem' is not a valid semaphore - * or count is less than or equal to zero. - * ERANGE semaphore count is too big - * - * ------------------------------------------------------ - */ -{ - int result = 0; - long waiters; - sem_t s = *sem; - - if (s == NULL || count <= 0) - { - result = EINVAL; - } - else if ((result = pthread_mutex_lock (&s->lock)) == 0) - { - /* See sem_destroy.c - */ - if (*sem == NULL) - { - (void) pthread_mutex_unlock (&s->lock); - result = EINVAL; - return -1; - } - - if (s->value <= (SEM_VALUE_MAX - count)) - { - waiters = -s->value; - s->value += count; - if (waiters > 0) - { -#if defined(NEED_SEM) - if (SetEvent(s->sem)) - { - waiters--; - s->leftToUnblock += count - 1; - if (s->leftToUnblock > waiters) - { - s->leftToUnblock = waiters; - } - } -#else - if (ReleaseSemaphore (s->sem, (waiters<=count)?waiters:count, 0)) - { - /* No action */ - } -#endif - else - { - s->value -= count; - result = EINVAL; - } - } - } - else - { - result = ERANGE; - } - (void) pthread_mutex_unlock (&s->lock); - } - - if (result != 0) - { - PTW32_SET_ERRNO(result); - return -1; - } - - return 0; - -} /* sem_post_multiple */ diff --git a/dependencies/win32_pthread/src/sem_timedwait.c b/dependencies/win32_pthread/src/sem_timedwait.c deleted file mode 100644 index 36dedf57..00000000 --- a/dependencies/win32_pthread/src/sem_timedwait.c +++ /dev/null @@ -1,243 +0,0 @@ -/* - * ------------------------------------------------------------- - * - * Module: sem_timedwait.c - * - * Purpose: - * Semaphores aren't actually part of the PThreads standard. - * They are defined by the POSIX Standard: - * - * POSIX 1003.1b-1993 (POSIX.1b) - * - * ------------------------------------------------------------- - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "semaphore.h" -#include "implement.h" - - -typedef struct { - sem_t sem; - int * resultPtr; -} sem_timedwait_cleanup_args_t; - - -static void PTW32_CDECL -ptw32_sem_timedwait_cleanup (void * args) -{ - sem_timedwait_cleanup_args_t * a = (sem_timedwait_cleanup_args_t *)args; - sem_t s = a->sem; - - if (pthread_mutex_lock (&s->lock) == 0) - { - /* - * We either timed out or were cancelled. - * If someone has posted between then and now we try to take the semaphore. - * Otherwise the semaphore count may be wrong after we - * return. In the case of a cancellation, it is as if we - * were cancelled just before we return (after taking the semaphore) - * which is ok. - */ - if (WaitForSingleObject(s->sem, 0) == WAIT_OBJECT_0) - { - /* We got the semaphore on the second attempt */ - *(a->resultPtr) = 0; - } - else - { - /* Indicate we're no longer waiting */ - s->value++; -#if defined(NEED_SEM) - if (s->value > 0) - { - s->leftToUnblock = 0; - } -#else - /* - * Don't release the W32 sema, it doesn't need adjustment - * because it doesn't record the number of waiters. - */ -#endif - } - (void) pthread_mutex_unlock (&s->lock); - } -} - - -int -sem_timedwait (sem_t * sem, const struct timespec *abstime) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function waits on a semaphore possibly until - * 'abstime' time. - * - * PARAMETERS - * sem - * pointer to an instance of sem_t - * - * abstime - * pointer to an instance of struct timespec - * - * DESCRIPTION - * This function waits on a semaphore. If the - * semaphore value is greater than zero, it decreases - * its value by one. If the semaphore value is zero, then - * the calling thread (or process) is blocked until it can - * successfully decrease the value or until interrupted by - * a signal. - * - * If 'abstime' is a NULL pointer then this function will - * block until it can successfully decrease the value or - * until interrupted by a signal. - * - * RESULTS - * 0 successfully decreased semaphore, - * -1 failed, error in errno - * ERRNO - * EINVAL 'sem' is not a valid semaphore, - * ENOSYS semaphores are not supported, - * EINTR the function was interrupted by a signal, - * EDEADLK a deadlock condition was detected. - * ETIMEDOUT abstime elapsed before success. - * - * ------------------------------------------------------ - */ -{ - int result = 0; - sem_t s = *sem; - - pthread_testcancel(); - - if (sem == NULL) - { - result = EINVAL; - } - else - { - DWORD milliseconds; - - if (abstime == NULL) - { - milliseconds = INFINITE; - } - else - { - /* - * Calculate timeout as milliseconds from current system time. - */ - milliseconds = ptw32_relmillisecs (abstime); - } - - if ((result = pthread_mutex_lock (&s->lock)) == 0) - { - int v; - - /* See sem_destroy.c - */ - if (*sem == NULL) - { - (void) pthread_mutex_unlock (&s->lock); - PTW32_SET_ERRNO(EINVAL); - return -1; - } - - v = --s->value; - (void) pthread_mutex_unlock (&s->lock); - - if (v < 0) - { -#if defined(NEED_SEM) - int timedout; -#endif - sem_timedwait_cleanup_args_t cleanup_args; - - cleanup_args.sem = s; - cleanup_args.resultPtr = &result; - -#if defined(PTW32_CONFIG_MSVC7) -#pragma inline_depth(0) -#endif - /* Must wait */ - pthread_cleanup_push(ptw32_sem_timedwait_cleanup, (void *) &cleanup_args); -#if defined(NEED_SEM) - timedout = -#endif - result = pthreadCancelableTimedWait (s->sem, milliseconds); - pthread_cleanup_pop(result); -#if defined(PTW32_CONFIG_MSVC7) -#pragma inline_depth() -#endif - -#if defined(NEED_SEM) - - if (!timedout && pthread_mutex_lock (&s->lock) == 0) - { - if (*sem == NULL) - { - (void) pthread_mutex_unlock (&s->lock); - PTW32_SET_ERRNO(EINVAL); - return -1; - } - - if (s->leftToUnblock > 0) - { - --s->leftToUnblock; - SetEvent(s->sem); - } - (void) pthread_mutex_unlock (&s->lock); - } - -#endif /* NEED_SEM */ - - } - } - - } - - if (result != 0) - { - - PTW32_SET_ERRNO(result); - return -1; - - } - - return 0; - -} /* sem_timedwait */ diff --git a/dependencies/win32_pthread/src/sem_trywait.c b/dependencies/win32_pthread/src/sem_trywait.c deleted file mode 100644 index 3147ff3e..00000000 --- a/dependencies/win32_pthread/src/sem_trywait.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * ------------------------------------------------------------- - * - * Module: sem_trywait.c - * - * Purpose: - * Semaphores aren't actually part of the PThreads standard. - * They are defined by the POSIX Standard: - * - * POSIX 1003.1b-1993 (POSIX.1b) - * - * ------------------------------------------------------------- - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "semaphore.h" -#include "implement.h" - - -int -sem_trywait (sem_t * sem) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function tries to wait on a semaphore. - * - * PARAMETERS - * sem - * pointer to an instance of sem_t - * - * DESCRIPTION - * This function tries to wait on a semaphore. If the - * semaphore value is greater than zero, it decreases - * its value by one. If the semaphore value is zero, then - * this function returns immediately with the error EAGAIN - * - * RESULTS - * 0 successfully decreased semaphore, - * -1 failed, error in errno - * ERRNO - * EAGAIN the semaphore was already locked, - * EINVAL 'sem' is not a valid semaphore, - * ENOTSUP sem_trywait is not supported, - * EINTR the function was interrupted by a signal, - * EDEADLK a deadlock condition was detected. - * - * ------------------------------------------------------ - */ -{ - int result = 0; - sem_t s = *sem; - - if (s == NULL) - { - result = EINVAL; - } - else if ((result = pthread_mutex_lock (&s->lock)) == 0) - { - /* See sem_destroy.c - */ - if (*sem == NULL) - { - (void) pthread_mutex_unlock (&s->lock); - PTW32_SET_ERRNO(EINVAL); - return -1; - } - - if (s->value > 0) - { - s->value--; - } - else - { - result = EAGAIN; - } - - (void) pthread_mutex_unlock (&s->lock); - } - - if (result != 0) - { - PTW32_SET_ERRNO(result); - return -1; - } - - return 0; - -} /* sem_trywait */ diff --git a/dependencies/win32_pthread/src/sem_unlink.c b/dependencies/win32_pthread/src/sem_unlink.c deleted file mode 100644 index 26bc442c..00000000 --- a/dependencies/win32_pthread/src/sem_unlink.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * ------------------------------------------------------------- - * - * Module: sem_unlink.c - * - * Purpose: - * Semaphores aren't actually part of the PThreads standard. - * They are defined by the POSIX Standard: - * - * POSIX 1003.1b-1993 (POSIX.1b) - * - * ------------------------------------------------------------- - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "semaphore.h" -#include "implement.h" - -/* ignore warning "unreferenced formal parameter" */ -#if defined(_MSC_VER) -#pragma warning( disable : 4100 ) -#endif - -int -sem_unlink (const char *name) -{ - PTW32_SET_ERRNO(ENOSYS); - return -1; -} /* sem_unlink */ diff --git a/dependencies/win32_pthread/src/sem_wait.c b/dependencies/win32_pthread/src/sem_wait.c deleted file mode 100644 index 46ee172e..00000000 --- a/dependencies/win32_pthread/src/sem_wait.c +++ /dev/null @@ -1,191 +0,0 @@ -/* - * ------------------------------------------------------------- - * - * Module: sem_wait.c - * - * Purpose: - * Semaphores aren't actually part of the PThreads standard. - * They are defined by the POSIX Standard: - * - * POSIX 1003.1b-1993 (POSIX.1b) - * - * ------------------------------------------------------------- - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "semaphore.h" -#include "implement.h" - - -static void PTW32_CDECL -ptw32_sem_wait_cleanup(void * sem) -{ - sem_t s = (sem_t) sem; - - if (pthread_mutex_lock (&s->lock) == 0) - { - /* - * If sema is destroyed do nothing, otherwise:- - * If the sema is posted between us being cancelled and us locking - * the sema again above then we need to consume that post but cancel - * anyway. If we don't get the semaphore we indicate that we're no - * longer waiting. - */ - if (*((sem_t *)sem) != NULL && !(WaitForSingleObject(s->sem, 0) == WAIT_OBJECT_0)) - { - ++s->value; -#if defined(NEED_SEM) - if (s->value > 0) - { - s->leftToUnblock = 0; - } -#else - /* - * Don't release the W32 sema, it doesn't need adjustment - * because it doesn't record the number of waiters. - */ -#endif /* NEED_SEM */ - } - (void) pthread_mutex_unlock (&s->lock); - } -} - -int -sem_wait (sem_t * sem) - /* - * ------------------------------------------------------ - * DOCPUBLIC - * This function waits on a semaphore. - * - * PARAMETERS - * sem - * pointer to an instance of sem_t - * - * DESCRIPTION - * This function waits on a semaphore. If the - * semaphore value is greater than zero, it decreases - * its value by one. If the semaphore value is zero, then - * the calling thread (or process) is blocked until it can - * successfully decrease the value or until interrupted by - * a signal. - * - * RESULTS - * 0 successfully decreased semaphore, - * -1 failed, error in errno - * ERRNO - * EINVAL 'sem' is not a valid semaphore, - * ENOSYS semaphores are not supported, - * EINTR the function was interrupted by a signal, - * EDEADLK a deadlock condition was detected. - * - * ------------------------------------------------------ - */ -{ - int result = 0; - sem_t s = *sem; - - pthread_testcancel(); - - if (s == NULL) - { - result = EINVAL; - } - else - { - if ((result = pthread_mutex_lock (&s->lock)) == 0) - { - int v; - - /* See sem_destroy.c - */ - if (*sem == NULL) - { - (void) pthread_mutex_unlock (&s->lock); - PTW32_SET_ERRNO(EINVAL); - return -1; - } - - v = --s->value; - (void) pthread_mutex_unlock (&s->lock); - - if (v < 0) - { -#if defined(PTW32_CONFIG_MSVC7) -#pragma inline_depth(0) -#endif - /* Must wait */ - pthread_cleanup_push(ptw32_sem_wait_cleanup, (void *) s); - result = pthreadCancelableWait (s->sem); - /* Cleanup if we're canceled or on any other error */ - pthread_cleanup_pop(result); -#if defined(PTW32_CONFIG_MSVC7) -#pragma inline_depth() -#endif - } -#if defined(NEED_SEM) - - if (!result && pthread_mutex_lock (&s->lock) == 0) - { - if (*sem == NULL) - { - (void) pthread_mutex_unlock (&s->lock); - PTW32_SET_ERRNO(EINVAL); - return -1; - } - - if (s->leftToUnblock > 0) - { - --s->leftToUnblock; - SetEvent(s->sem); - } - (void) pthread_mutex_unlock (&s->lock); - } - -#endif /* NEED_SEM */ - - } - - } - - if (result != 0) - { - PTW32_SET_ERRNO(result); - return -1; - } - - return 0; -} /* sem_wait */ diff --git a/dependencies/win32_pthread/src/signal.c b/dependencies/win32_pthread/src/signal.c deleted file mode 100644 index 845019d3..00000000 --- a/dependencies/win32_pthread/src/signal.c +++ /dev/null @@ -1,184 +0,0 @@ -/* - * signal.c - * - * Description: - * Thread-aware signal functions. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -/* - * Possible future strategy for implementing pthread_kill() - * ======================================================== - * - * Win32 does not implement signals. - * Signals are simply software interrupts. - * pthread_kill() asks the system to deliver a specified - * signal (interrupt) to a specified thread in the same - * process. - * Signals are always asynchronous (no deferred signals). - * Pthread-win32 has an async cancellation mechanism. - * A similar system can be written to deliver signals - * within the same process (on ix86 processors at least). - * - * Each thread maintains information about which - * signals it will respond to. Handler routines - * are set on a per-process basis - not per-thread. - * When signalled, a thread will check it's sigmask - * and, if the signal is not being ignored, call the - * handler routine associated with the signal. The - * thread must then (except for some signals) return to - * the point where it was interrupted. - * - * Ideally the system itself would check the target thread's - * mask before possibly needlessly bothering the thread - * itself. This could be done by pthread_kill(), that is, - * in the signaling thread since it has access to - * all pthread_t structures. It could also retrieve - * the handler routine address to minimise the target - * threads response overhead. This may also simplify - * serialisation of the access to the per-thread signal - * structures. - * - * pthread_kill() eventually calls a routine similar to - * ptw32_cancel_thread() which manipulates the target - * threads processor context to cause the thread to - * run the handler launcher routine. pthread_kill() must - * save the target threads current context so that the - * handler launcher routine can restore the context after - * the signal handler has returned. Some handlers will not - * return, eg. the default SIGKILL handler may simply - * call pthread_exit(). - * - * The current context is saved in the target threads - * pthread_t structure. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - -#if defined(HAVE_SIGSET_T) - -static void -ptw32_signal_thread () -{ -} - -static void -ptw32_signal_callhandler () -{ -} - -int -pthread_sigmask (int how, sigset_t const *set, sigset_t * oset) -{ - pthread_t thread = pthread_self (); - - if (thread.p == NULL) - { - return ENOENT; - } - - /* Validate the `how' argument. */ - if (set != NULL) - { - switch (how) - { - case SIG_BLOCK: - break; - case SIG_UNBLOCK: - break; - case SIG_SETMASK: - break; - default: - /* Invalid `how' argument. */ - return EINVAL; - } - } - - /* Copy the old mask before modifying it. */ - if (oset != NULL) - { - memcpy (oset, &(thread.p->sigmask), sizeof (sigset_t)); - } - - if (set != NULL) - { - unsigned int i; - - /* FIXME: this code assumes that sigmask is an even multiple of - the size of a long integer. */ - - unsigned long *src = (unsigned long const *) set; - unsigned long *dest = (unsigned long *) &(thread.p->sigmask); - - switch (how) - { - case SIG_BLOCK: - for (i = 0; i < (sizeof (sigset_t) / sizeof (unsigned long)); i++) - { - /* OR the bit field longword-wise. */ - *dest++ |= *src++; - } - break; - case SIG_UNBLOCK: - for (i = 0; i < (sizeof (sigset_t) / sizeof (unsigned long)); i++) - { - /* XOR the bitfield longword-wise. */ - *dest++ ^= *src++; - } - case SIG_SETMASK: - /* Replace the whole sigmask. */ - memcpy (&(thread.p->sigmask), set, sizeof (sigset_t)); - break; - } - } - - return 0; -} - -int -sigwait (const sigset_t * set, int *sig) -{ - /* This routine is a cancellation point */ - pthread_test_cancel(); -} - -int -sigaction (int signum, const struct sigaction *act, struct sigaction *oldact) -{ -} - -#endif /* HAVE_SIGSET_T */ diff --git a/dependencies/win32_pthread/src/version.rc b/dependencies/win32_pthread/src/version.rc deleted file mode 100644 index 87a9a757..00000000 --- a/dependencies/win32_pthread/src/version.rc +++ /dev/null @@ -1,406 +0,0 @@ -/* This is an implementation of the threads API of POSIX 1003.1-2001. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include "pthread.h" - -/* - * Note: the correct __CLEANUP_* macro must be defined corresponding to - * the definition used for the object file builds. This is done in the - * relevent makefiles for the command line builds, but users should ensure - * that their resource compiler knows what it is too. - * If using the default (no __CLEANUP_* defined), pthread.h will define it - * as __CLEANUP_C. - */ - -#if defined(PTW32_RC_MSC) -# if defined(PTW32_ARCHx64) -# define PTW32_ARCH "x64" -# elif defined(PTW32_ARCHx86) -# define PTW32_ARCH "x86" -# else -# error "PTW32_ARCHx64 / PTW32_ARCHx86 has not been defined" -# endif -# if defined(__CLEANUP_C) -# define PTW32_VERSIONINFO_NAME "pthreadVC2.DLL\0" -# define PTW32_VERSIONINFO_DESCRIPTION "MS C " PTW32_ARCH "\0" -# elif defined(__CLEANUP_CXX) -# define PTW32_VERSIONINFO_NAME "pthreadVCE2.DLL\0" -# define PTW32_VERSIONINFO_DESCRIPTION "MS C++ " PTW32_ARCH "\0" -# elif defined(__CLEANUP_SEH) -# define PTW32_VERSIONINFO_NAME "pthreadVSE2.DLL\0" -# define PTW32_VERSIONINFO_DESCRIPTION "MS C SEH " PTW32_ARCH "\0" -# else -# error Resource compiler doesn't know which cleanup style you're using - see version.rc -# endif -#elif defined(__GNUC__) -# if defined(_M_X64) -# define PTW32_ARCH "x64 (mingw64)" -# else -# define PTW32_ARCH "x86 (mingw32)" -# endif -# if defined(__CLEANUP_C) -# define PTW32_VERSIONINFO_NAME "pthreadGC2.DLL\0" -# define PTW32_VERSIONINFO_DESCRIPTION "GNU C " PTW32_ARCH "\0" -# elif defined(__CLEANUP_CXX) -# define PTW32_VERSIONINFO_NAME "pthreadGCE2.DLL\0" -# define PTW32_VERSIONINFO_DESCRIPTION "GNU C++ " PTW32_ARCH "\0" -# else -# error Resource compiler doesn't know which cleanup style you're using - see version.rc -# endif -#elif defined(__BORLANDC__) -# if defined(_M_X64) -# define PTW32_ARCH "x64 (Borland)" -# else -# define PTW32_ARCH "x86 (Borland)" -# endif -# if defined(__CLEANUP_C) -# define PTW32_VERSIONINFO_NAME "pthreadBC2.DLL\0" -# define PTW32_VERSIONINFO_DESCRIPTION "BORLAND C " PTW32_ARCH "\0" -# elif defined(__CLEANUP_CXX) -# define PTW32_VERSIONINFO_NAME "pthreadBCE2.DLL\0" -# define PTW32_VERSIONINFO_DESCRIPTION "BORLAND C++ " PTW32_ARCH "\0" -# else -# error Resource compiler doesn't know which cleanup style you're using - see version.rc -# endif -#elif defined(__WATCOMC__) -# if defined(_M_X64) -# define PTW32_ARCH "x64 (Watcom)" -# else -# define PTW32_ARCH "x86 (Watcom)" -# endif -# if defined(__CLEANUP_C) -# define PTW32_VERSIONINFO_NAME "pthreadWC2.DLL\0" -# define PTW32_VERSIONINFO_DESCRIPTION "WATCOM C " PTW32_ARCH "\0" -# elif defined(__CLEANUP_CXX) -# define PTW32_VERSIONINFO_NAME "pthreadWCE2.DLL\0" -# define PTW32_VERSIONINFO_DESCRIPTION "WATCOM C++ " PTW32_ARCH "\0" -# else -# error Resource compiler doesn't know which cleanup style you're using - see version.rc -# endif -#else -# error Resource compiler doesn't know which compiler you're using - see version.rc -#endif - - -VS_VERSION_INFO VERSIONINFO - FILEVERSION PTW32_VERSION - PRODUCTVERSION PTW32_VERSION - FILEFLAGSMASK VS_FFI_FILEFLAGSMASK - FILEFLAGS 0 - FILEOS VOS__WINDOWS32 - FILETYPE VFT_DLL -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904b0" - BEGIN - VALUE "ProductName", "POSIX Threads for Windows LPGL\0" - VALUE "ProductVersion", PTW32_VERSION_STRING - VALUE "FileVersion", PTW32_VERSION_STRING - VALUE "FileDescription", PTW32_VERSIONINFO_DESCRIPTION - VALUE "InternalName", PTW32_VERSIONINFO_NAME - VALUE "OriginalFilename", PTW32_VERSIONINFO_NAME - VALUE "CompanyName", "Open Source Software community LGPL\0" - VALUE "LegalCopyright", "Copyright (C) Project contributors 2012\0" - VALUE "Comments", "http://sourceware.org/pthreads-win32/\0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1200 - END -END - -/* -VERSIONINFO Resource - -The VERSIONINFO resource-definition statement creates a version-information -resource. The resource contains such information about the file as its -version number, its intended operating system, and its original filename. -The resource is intended to be used with the Version Information functions. - -versionID VERSIONINFO fixed-info { block-statement...} - -versionID - Version-information resource identifier. This value must be 1. - -fixed-info - Version information, such as the file version and the intended operating - system. This parameter consists of the following statements. - - - Statement Description - -------------------------------------------------------------------------- - FILEVERSION - version Binary version number for the file. The version - consists of two 32-bit integers, defined by four - 16-bit integers. For example, "FILEVERSION 3,10,0,61" - is translated into two doublewords: 0x0003000a and - 0x0000003d, in that order. Therefore, if version is - defined by the DWORD values dw1 and dw2, they need - to appear in the FILEVERSION statement as follows: - HIWORD(dw1), LOWORD(dw1), HIWORD(dw2), LOWORD(dw2). - PRODUCTVERSION - version Binary version number for the product with which the - file is distributed. The version parameter is two - 32-bit integers, defined by four 16-bit integers. - For more information about version, see the - FILEVERSION description. - FILEFLAGSMASK - fileflagsmask Bits in the FILEFLAGS statement are valid. If a bit - is set, the corresponding bit in FILEFLAGS is valid. - FILEFLAGSfileflags Attributes of the file. The fileflags parameter must - be the combination of all the file flags that are - valid at compile time. For 16-bit Windows, this - value is 0x3f. - FILEOSfileos Operating system for which this file was designed. - The fileos parameter can be one of the operating - system values given in the Remarks section. - FILETYPEfiletype General type of file. The filetype parameter can be - one of the file type values listed in the Remarks - section. - FILESUBTYPE - subtype Function of the file. The subtype parameter is zero - unless the type parameter in the FILETYPE statement - is VFT_DRV, VFT_FONT, or VFT_VXD. For a list of file - subtype values, see the Remarks section. - -block-statement - Specifies one or more version-information blocks. A block can contain - string information or variable information. For more information, see - StringFileInfo Block or VarFileInfo Block. - -Remarks - -To use the constants specified with the VERSIONINFO statement, you must -include the Winver.h or Windows.h header file in the resource-definition file. - -The following list describes the parameters used in the VERSIONINFO statement: - -fileflags - A combination of the following values. - - Value Description - - VS_FF_DEBUG File contains debugging information or is compiled - with debugging features enabled. - VS_FF_PATCHED File has been modified and is not identical to the - original shipping file of the same version number. - VS_FF_PRERELEASE File is a development version, not a commercially - released product. - VS_FF_PRIVATEBUILD File was not built using standard release procedures. - If this value is given, the StringFileInfo block must - contain a PrivateBuild string. - VS_FF_SPECIALBUILD File was built by the original company using standard - release procedures but is a variation of the standard - file of the same version number. If this value is - given, the StringFileInfo block must contain a - SpecialBuild string. - -fileos - One of the following values. - - Value Description - - VOS_UNKNOWN The operating system for which the file was designed - is unknown. - VOS_DOS File was designed for MS-DOS. - VOS_NT File was designed for Windows Server 2003 family, - Windows XP, Windows 2000, or Windows NT. - VOS__WINDOWS16 File was designed for 16-bit Windows. - VOS__WINDOWS32 File was designed for 32-bit Windows. - VOS_DOS_WINDOWS16 File was designed for 16-bit Windows running with - MS-DOS. - VOS_DOS_WINDOWS32 File was designed for 32-bit Windows running with - MS-DOS. - VOS_NT_WINDOWS32 File was designed for Windows Server 2003 family, - Windows XP, Windows 2000, or Windows NT. - - The values 0x00002L, 0x00003L, 0x20000L and 0x30000L are reserved. - -filetype - One of the following values. - - Value Description - - VFT_UNKNOWN File type is unknown. - VFT_APP File contains an application. - VFT_DLL File contains a dynamic-link library (DLL). - VFT_DRV File contains a device driver. If filetype is - VFT_DRV, subtype contains a more specific - description of the driver. - VFT_FONT File contains a font. If filetype is VFT_FONT, - subtype contains a more specific description of the - font. - VFT_VXD File contains a virtual device. - VFT_STATIC_LIB File contains a static-link library. - - All other values are reserved for use by Microsoft. - -subtype - Additional information about the file type. - - If filetype specifies VFT_DRV, this parameter can be one of the - following values. - - Value Description - - VFT2_UNKNOWN Driver type is unknown. - VFT2_DRV_COMM File contains a communications driver. - VFT2_DRV_PRINTER File contains a printer driver. - VFT2_DRV_KEYBOARD File contains a keyboard driver. - VFT2_DRV_LANGUAGE File contains a language driver. - VFT2_DRV_DISPLAY File contains a display driver. - VFT2_DRV_MOUSE File contains a mouse driver. - VFT2_DRV_NETWORK File contains a network driver. - VFT2_DRV_SYSTEM File contains a system driver. - VFT2_DRV_INSTALLABLE File contains an installable driver. - VFT2_DRV_SOUND File contains a sound driver. - VFT2_DRV_VERSIONED_PRINTER File contains a versioned printer driver. - - If filetype specifies VFT_FONT, this parameter can be one of the - following values. - - Value Description - - VFT2_UNKNOWN Font type is unknown. - VFT2_FONT_RASTER File contains a raster font. - VFT2_FONT_VECTOR File contains a vector font. - VFT2_FONT_TRUETYPE File contains a TrueType font. - - If filetype specifies VFT_VXD, this parameter must be the virtual-device - identifier included in the virtual-device control block. - - All subtype values not listed here are reserved for use by Microsoft. - -langID - One of the following language codes. - - Code Language Code Language - - 0x0401 Arabic 0x0415 Polish - 0x0402 Bulgarian 0x0416 Portuguese (Brazil) - 0x0403 Catalan 0x0417 Rhaeto-Romanic - 0x0404 Traditional Chinese 0x0418 Romanian - 0x0405 Czech 0x0419 Russian - 0x0406 Danish 0x041A Croato-Serbian (Latin) - 0x0407 German 0x041B Slovak - 0x0408 Greek 0x041C Albanian - 0x0409 U.S. English 0x041D Swedish - 0x040A Castilian Spanish 0x041E Thai - 0x040B Finnish 0x041F Turkish - 0x040C French 0x0420 Urdu - 0x040D Hebrew 0x0421 Bahasa - 0x040E Hungarian 0x0804 Simplified Chinese - 0x040F Icelandic 0x0807 Swiss German - 0x0410 Italian 0x0809 U.K. English - 0x0411 Japanese 0x080A Mexican Spanish - 0x0412 Korean 0x080C Belgian French - 0x0413 Dutch 0x0C0C Canadian French - 0x0414 Norwegian ā€“ Bokmal 0x100C Swiss French - 0x0810 Swiss Italian 0x0816 Portuguese (Portugal) - 0x0813 Belgian Dutch 0x081A Serbo-Croatian (Cyrillic) - 0x0814 Norwegian ā€“ Nynorsk - -charsetID - One of the following character-set identifiers. - - Identifier Character Set - - 0 7-bit ASCII - 932 Japan (Shift %Gā€“%@ JIS X-0208) - 949 Korea (Shift %Gā€“%@ KSC 5601) - 950 Taiwan (Big5) - 1200 Unicode - 1250 Latin-2 (Eastern European) - 1251 Cyrillic - 1252 Multilingual - 1253 Greek - 1254 Turkish - 1255 Hebrew - 1256 Arabic - -string-name - One of the following predefined names. - - Name Description - - Comments Additional information that should be displayed for - diagnostic purposes. - CompanyName Company that produced the file%Gā€”%@for example, - "Microsoft Corporation" or "Standard Microsystems - Corporation, Inc." This string is required. - FileDescription File description to be presented to users. This - string may be displayed in a list box when the user - is choosing files to install%Gā€”%@for example, - "Keyboard Driver for AT-Style Keyboards". This - string is required. - FileVersion Version number of the file%Gā€”%@for example, - "3.10" or "5.00.RC2". This string is required. - InternalName Internal name of the file, if one exists ā€” for - example, a module name if the file is a dynamic-link - library. If the file has no internal name, this - string should be the original filename, without - extension. This string is required. - LegalCopyright Copyright notices that apply to the file. This - should include the full text of all notices, legal - symbols, copyright dates, and so on ā€” for example, - "Copyright (C) Microsoft Corporation 1990ā€“1999". - This string is optional. - LegalTrademarks Trademarks and registered trademarks that apply to - the file. This should include the full text of all - notices, legal symbols, trademark numbers, and so on. - This string is optional. - OriginalFilename Original name of the file, not including a path. - This information enables an application to determine - whether a file has been renamed by a user. The - format of the name depends on the file system for - which the file was created. This string is required. - PrivateBuild Information about a private version of the file ā€” for - example, "Built by TESTER1 on \TESTBED". This string - should be present only if VS_FF_PRIVATEBUILD is - specified in the fileflags parameter of the root - block. - ProductName Name of the product with which the file is - distributed. This string is required. - ProductVersion Version of the product with which the file is - distributed ā€” for example, "3.10" or "5.00.RC2". - This string is required. - SpecialBuild Text that indicates how this version of the file - differs from the standard version ā€” for example, - "Private build for TESTER1 solving mouse problems - on M250 and M250E computers". This string should be - present only if VS_FF_SPECIALBUILD is specified in - the fileflags parameter of the root block. - */ diff --git a/dependencies/win32_pthread/src/w32_CancelableWait.c b/dependencies/win32_pthread/src/w32_CancelableWait.c deleted file mode 100644 index b30d65e3..00000000 --- a/dependencies/win32_pthread/src/w32_CancelableWait.c +++ /dev/null @@ -1,166 +0,0 @@ -/* - * w32_CancelableWait.c - * - * Description: - * This translation unit implements miscellaneous thread functions. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2012 Pthreads-win32 contributors - * - * Homepage1: http://sourceware.org/pthreads-win32/ - * Homepage2: http://sourceforge.net/projects/pthreads4w/ - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "pthread.h" -#include "implement.h" - - -static INLINE int -ptw32_cancelable_wait (HANDLE waitHandle, DWORD timeout) - /* - * ------------------------------------------------------------------- - * This provides an extra hook into the pthread_cancel - * mechanism that will allow you to wait on a Windows handle and make it a - * cancellation point. This function blocks until the given WIN32 handle is - * signaled or pthread_cancel has been called. It is implemented using - * WaitForMultipleObjects on 'waitHandle' and a manually reset WIN32 - * event used to implement pthread_cancel. - * - * Given this hook it would be possible to implement more of the cancellation - * points. - * ------------------------------------------------------------------- - */ -{ - int result; - pthread_t self; - ptw32_thread_t * sp; - HANDLE handles[2]; - DWORD nHandles = 1; - DWORD status; - - handles[0] = waitHandle; - - self = pthread_self(); - sp = (ptw32_thread_t *) self.p; - - if (sp != NULL) - { - /* - * Get cancelEvent handle - */ - if (sp->cancelState == PTHREAD_CANCEL_ENABLE) - { - - if ((handles[1] = sp->cancelEvent) != NULL) - { - nHandles++; - } - } - } - else - { - handles[1] = NULL; - } - - status = WaitForMultipleObjects (nHandles, handles, PTW32_FALSE, timeout); - - switch (status - WAIT_OBJECT_0) - { - case 0: - /* - * Got the handle. - * In the event that both handles are signalled, the smallest index - * value (us) is returned. As it has been arranged, this ensures that - * we don't drop a signal that we should act on (i.e. semaphore, - * mutex, or condition variable etc). - */ - result = 0; - break; - - case 1: - /* - * Got cancel request. - * In the event that both handles are signaled, the cancel will - * be ignored (see case 0 comment). - */ - ResetEvent (handles[1]); - - if (sp != NULL) - { - ptw32_mcs_local_node_t stateLock; - /* - * Should handle POSIX and implicit POSIX threads.. - * Make sure we haven't been async-canceled in the meantime. - */ - ptw32_mcs_lock_acquire (&sp->stateLock, &stateLock); - if (sp->state < PThreadStateCanceling) - { - sp->state = PThreadStateCanceling; - sp->cancelState = PTHREAD_CANCEL_DISABLE; - ptw32_mcs_lock_release (&stateLock); - ptw32_throw (PTW32_EPS_CANCEL); - - /* Never reached */ - } - ptw32_mcs_lock_release (&stateLock); - } - - /* Should never get to here. */ - result = EINVAL; - break; - - default: - if (status == WAIT_TIMEOUT) - { - result = ETIMEDOUT; - } - else - { - result = EINVAL; - } - break; - } - - return (result); - -} /* CancelableWait */ - -int -pthreadCancelableWait (HANDLE waitHandle) -{ - return (ptw32_cancelable_wait (waitHandle, INFINITE)); -} - -int -pthreadCancelableTimedWait (HANDLE waitHandle, DWORD timeout) -{ - return (ptw32_cancelable_wait (waitHandle, timeout)); -} diff --git a/source/server/CMakeLists.txt b/source/server/CMakeLists.txt index 2508cefa..df093ed6 100644 --- a/source/server/CMakeLists.txt +++ b/source/server/CMakeLists.txt @@ -21,11 +21,10 @@ if (RORSERVER_WITH_ANGELSCRIPT) endif () IF (WIN32) - target_compile_definitions(${PROJECT_NAME} PRIVATE PTW32_STATIC_LIB) - target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/dependencies/win32_pthread/include) - target_link_libraries(${PROJECT_NAME} PRIVATE mysocketw jsoncpp pthread) + target_link_libraries(${PROJECT_NAME} PRIVATE mysocketw jsoncpp) ELSEIF (UNIX) #add_definitions("-DAS_MAX_PORTABILITY") + #NOTE: pthread is needed for AngelScript to link. target_link_libraries(${PROJECT_NAME} PRIVATE mysocketw pthread dl jsoncpp) ELSEIF (APPLE) ENDIF (WIN32) diff --git a/source/server/mutexutils.cpp b/source/server/mutexutils.cpp deleted file mode 100644 index e58ccc5a..00000000 --- a/source/server/mutexutils.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/* -This file is part of "Rigs of Rods Server" (Relay mode) - -Copyright 2007 Pierre-Michel Ricordel -Copyright 2014+ Rigs of Rods Community - -"Rigs of Rods Server" 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. - -"Rigs of Rods Server" 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 Foobar. If not, see . -*/ - -#include "mutexutils.h" - -#include "logger.h" - -#include -#include - -Condition::Condition() { pthread_cond_init(&cond, NULL); } - -Condition::~Condition() { pthread_cond_destroy(&cond); } - -void Condition::signal() { pthread_cond_signal(&cond); } - -Mutex::Mutex(bool recursive /*= false*/) -{ - pthread_mutexattr_t attr; - pthread_mutexattr_init(&attr); - if (recursive) - { - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - } - pthread_mutex_init(&m, &attr); -} - -Mutex::~Mutex() { pthread_mutex_destroy(&m); } - -void Mutex::lock() { - pthread_mutex_lock(&m); -} - -void Mutex::unlock() { - pthread_mutex_unlock(&m); -} - -void Mutex::wait(Condition &c) { pthread_cond_wait(&(c.cond), &m); } - -MutexLocker::MutexLocker(Mutex &pm) : m(pm) { m.lock(); } - -MutexLocker::~MutexLocker() { m.unlock(); } - - -pthread_key_t ThreadID::key; -pthread_once_t ThreadID::key_once = PTHREAD_ONCE_INIT; -unsigned int ThreadID::tuid = 1; - -unsigned int ThreadID::getID() { - ThreadID *ptr = NULL; - pthread_once(&key_once, ThreadID::make_key); - ptr = (ThreadID *) pthread_getspecific(key); - - if (!ptr) { - ptr = new ThreadID(); - pthread_setspecific(key, (void *) ptr); - } - - return ptr->thread_id; -} - -ThreadID::ThreadID() : thread_id(tuid) { tuid++; } - -void ThreadID::make_key() { pthread_key_create(&key, NULL); } - -namespace Threading { - - bool SimpleCond::Initialize() { - assert(m_value == INACTIVE); - - int result = pthread_mutex_init(&m_mutex, nullptr); - if (result != 0) { - Logger::Log(LOG_ERROR, - "Internal error: Failed to initialize mutex, error code: %d [in SimpleCond::Initialize()]", - result); - return false; - } - int cond_result = pthread_cond_init(&m_cond, nullptr); - if (cond_result != 0) { - Logger::Log(LOG_ERROR, - "Internal error: Failed to initialize condition variable, error code: %d [in SimpleCond::Initialize()]", - cond_result); - return false; - } - m_value = 0; - return true; - } - - bool SimpleCond::Destroy() { - assert(m_value != INACTIVE); - - int result = pthread_mutex_destroy(&m_mutex); - if (result != 0) { - Logger::Log(LOG_WARN, "Internal: Failed to destroy mutex, error code: %d [in SimpleCond::Destroy()]", - result); - return false; - } - int cond_result = pthread_cond_destroy(&m_cond); - if (cond_result != 0) { - Logger::Log(LOG_WARN, - "Internal: Failed to destroy condition variable, error code: %d [in SimpleCond::Destroy()]", - cond_result); - return false; - } - m_value = INACTIVE; - return true; - } - - bool SimpleCond::Wait(int *out_value) { - assert(out_value != nullptr); - - if (!this->Lock("SimpleCond::Wait()")) { - return false; - } - - while (m_value == 0) { - int wait_result = pthread_cond_wait(&m_cond, &m_mutex); - if (wait_result != 0) { - Logger::Log(LOG_ERROR, - "Internal error: Failed to wait on condition variable, error code: %d [in SimpleCond::Wait()]", - wait_result); - pthread_mutex_unlock(&m_mutex); - return false; - } - } - *out_value = m_value; - - if (!this->Unlock("SimpleCond::Wait()")) { - return false; - } - return true; - } - - bool SimpleCond::Signal(int value) { - assert(m_value != INACTIVE); - - if (!this->Lock("SimpleCond::Signal()")) { - return false; - } - - m_value = value; - int signal_result = pthread_cond_signal(&m_cond); - if (signal_result != 0) { - Logger::Log(LOG_ERROR, - "Internal error: Failed to signal condition variable, error code: %d [in SimpleCond::Signal()]", - signal_result); - pthread_mutex_unlock(&m_mutex); - return false; - } - - if (!this->Unlock("SimpleCond::Signal()")) { - return false; - } - return true; - } - - bool SimpleCond::Lock(const char *log_location) { - int lock_result = pthread_mutex_lock(&m_mutex); - if (lock_result != 0) { - Logger::Log(LOG_ERROR, "Internal: Failed to acquire lock, error code: %d [in %s]", lock_result, - log_location); - return false; - } - return true; - } - - bool SimpleCond::Unlock(const char *log_location) { - int unlock_result = pthread_mutex_unlock(&m_mutex); - if (unlock_result != 0) { - Logger::Log(LOG_ERROR, "Internal: Failed to remove lock, error code: %d [in %s]", unlock_result, - log_location); - return false; - } - return true; - } - -} - diff --git a/source/server/mutexutils.h b/source/server/mutexutils.h deleted file mode 100644 index cc347124..00000000 --- a/source/server/mutexutils.h +++ /dev/null @@ -1,113 +0,0 @@ -/* -This file is part of "Rigs of Rods Server" (Relay mode) - -Copyright 2007 Pierre-Michel Ricordel -Copyright 2014+ Rigs of Rods Community - -"Rigs of Rods Server" 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. - -"Rigs of Rods Server" 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 Foobar. If not, see . -*/ - -#pragma once - -#include - -#define USE_THREADID - -namespace Threading { - - class SimpleCond { - public: - static const int INACTIVE = 0xFEFEFEFE; - - SimpleCond() : m_value(INACTIVE) {} - - bool Initialize(); - - bool Destroy(); - - bool Wait(int *out_value); - - bool Signal(int value); - - private: - bool Lock(const char *log_location); - - bool Unlock(const char *log_location); - - pthread_cond_t m_cond; - pthread_mutex_t m_mutex; - int m_value; - }; - -} - -class Condition { - friend class Mutex; - -public: - Condition(); - - ~Condition(); - - void signal(); - -private: - pthread_cond_t cond; -}; - - -class Mutex { -public: - Mutex(bool recursive = false); - - ~Mutex(); - - void lock(); - - void unlock(); - - void wait(Condition &c); - - pthread_mutex_t *getRaw() { return &m; }; - -private: - pthread_mutex_t m; -}; - - -class MutexLocker { -public: - MutexLocker(Mutex &pm); - - ~MutexLocker(); - -private: - Mutex &m; -}; - -class ThreadID { - -public: - static unsigned int getID(); - -private: - ThreadID(); - - static void make_key(); - - unsigned int thread_id; - static pthread_key_t key; - static pthread_once_t key_once; - static unsigned int tuid; -};