Refactor workthread.hpp and threadtypes.hpp (renamed to threads.hpp)
Also rename all variables and fields named "mutex" (gdb does not like that name).
This commit is contained in:
parent
2823958ffb
commit
4f0e636b9b
64 changed files with 581 additions and 561 deletions
|
@ -16,7 +16,7 @@
|
|||
#include <map>
|
||||
#include <list>
|
||||
#include "library/controller-data.hpp"
|
||||
#include "library/threadtypes.hpp"
|
||||
#include "library/threads.hpp"
|
||||
|
||||
/**
|
||||
* Controllers state.
|
||||
|
@ -227,7 +227,7 @@ private:
|
|||
controller_frame _committed;
|
||||
std::map<std::string, controller_macro> all_macros;
|
||||
std::list<std::pair<uint64_t, controller_macro*>> active_macros;
|
||||
mutex_class macro_lock;
|
||||
threads::lock macro_lock;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef _filedownload__hpp__included__
|
||||
#define _filedownload__hpp__included__
|
||||
|
||||
#include "library/threadtypes.hpp"
|
||||
#include "library/threads.hpp"
|
||||
#include "library/httpreq.hpp"
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
@ -23,8 +23,8 @@ struct file_download
|
|||
std::string errormsg;
|
||||
http_async_request req;
|
||||
std::string statusmsg();
|
||||
cv_class cond;
|
||||
mutex_class m;
|
||||
threads::cv cond;
|
||||
threads::lock m;
|
||||
//Internal.
|
||||
void _do_async();
|
||||
std::string tempname;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef _fileupload__hpp__included__
|
||||
#define _fileupload__hpp__included__
|
||||
|
||||
#include "library/threadtypes.hpp"
|
||||
#include "library/threads.hpp"
|
||||
#include "library/httpreq.hpp"
|
||||
#include "library/httpauth.hpp"
|
||||
#include <string>
|
||||
|
@ -35,7 +35,7 @@ struct file_upload
|
|||
dh25519_http_auth* dh25519;
|
||||
http_async_request* req;
|
||||
std::list<std::string> msgs;
|
||||
mutex_class m;
|
||||
threads::lock m;
|
||||
void add_msg(const std::string& msg);
|
||||
};
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
private:
|
||||
triplebuffer_logic(triplebuffer_logic&);
|
||||
triplebuffer_logic& operator=(triplebuffer_logic&);
|
||||
mutex_class mut;
|
||||
threads::lock mut;
|
||||
unsigned read_active;
|
||||
unsigned write_active;
|
||||
unsigned read_active_slot;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define _multitrack__hpp__included__
|
||||
|
||||
#include <map>
|
||||
#include "library/threadtypes.hpp"
|
||||
#include "library/threads.hpp"
|
||||
#include "library/controller-data.hpp"
|
||||
|
||||
class multitrack_edit
|
||||
|
@ -25,7 +25,7 @@ public:
|
|||
void process_frame(controller_frame& input);
|
||||
bool any_records();
|
||||
private:
|
||||
mutex_class mutex;
|
||||
threads::lock mlock;
|
||||
bool enabled;
|
||||
std::map<std::pair<unsigned, unsigned>, state> controllerstate;
|
||||
};
|
||||
|
|
|
@ -178,7 +178,7 @@ struct platform
|
|||
/**
|
||||
* Get message buffer lock.
|
||||
*/
|
||||
static mutex_class& msgbuf_lock() throw();
|
||||
static threads::lock& msgbuf_lock() throw();
|
||||
/**
|
||||
* Adds a messages to mesage queue to be shown.
|
||||
*
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include "interface/controller.hpp"
|
||||
#include "interface/setting.hpp"
|
||||
#include "library/framebuffer.hpp"
|
||||
#include "library/threadtypes.hpp"
|
||||
#include "library/threads.hpp"
|
||||
|
||||
struct core_region;
|
||||
struct core_type;
|
||||
|
@ -531,7 +531,7 @@ private:
|
|||
std::vector<port_type*> port_types;
|
||||
bool hidden;
|
||||
std::map<std::string, interface_action> actions;
|
||||
mutex_class actions_lock;
|
||||
threads::lock actions_lock;
|
||||
};
|
||||
|
||||
struct core_type
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <set>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include "threadtypes.hpp"
|
||||
#include "threads.hpp"
|
||||
|
||||
namespace command
|
||||
{
|
||||
|
@ -68,7 +68,7 @@ private:
|
|||
std::map<std::string, base*> commands;
|
||||
std::set<std::string> command_stack;
|
||||
std::map<std::string, std::list<std::string>> aliases;
|
||||
mutex_class int_mutex;
|
||||
threads::lock int_mutex;
|
||||
std::ostream* output;
|
||||
void (*oom_panic_routine)();
|
||||
base* builtin[1];
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
#include <set>
|
||||
#include <list>
|
||||
#include <functional>
|
||||
#include "threadtypes.hpp"
|
||||
#include "threads.hpp"
|
||||
|
||||
namespace dispatch
|
||||
{
|
||||
mutex_class& global_init_lock();
|
||||
threads::lock& global_init_lock();
|
||||
|
||||
template<typename... T> struct source;
|
||||
|
||||
|
@ -107,7 +107,7 @@ template<typename... T> struct source
|
|||
void connect(target<T...>& target)
|
||||
{
|
||||
init();
|
||||
umutex_class h(*lck);
|
||||
threads::alock h(*lck);
|
||||
targets()[next_cbseq++] = ⌖
|
||||
target.set_source(this);
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ template<typename... T> struct source
|
|||
init();
|
||||
if(!lck)
|
||||
return;
|
||||
umutex_class h(*lck);
|
||||
threads::alock h(*lck);
|
||||
for(auto i = targets().begin(); i != targets().end(); i++)
|
||||
if(i->second == &target) {
|
||||
targets().erase(i);
|
||||
|
@ -143,17 +143,17 @@ private:
|
|||
{
|
||||
if(inited)
|
||||
return;
|
||||
umutex_class h(global_init_lock());
|
||||
threads::alock h(global_init_lock());
|
||||
if(inited)
|
||||
return;
|
||||
errstrm = &std::cerr;
|
||||
next_cbseq = 0;
|
||||
name = "(unknown)";
|
||||
_targets = NULL;
|
||||
lck = new mutex_class;
|
||||
lck = new threads::lock;
|
||||
inited = true;
|
||||
}
|
||||
mutex_class* lck;
|
||||
threads::lock* lck;
|
||||
std::map<uint64_t, target<T...>*>& targets()
|
||||
{
|
||||
if(!_targets) _targets = new std::map<uint64_t, target<T...>*>;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef _library__emustatus__hpp__included__
|
||||
#define _library__emustatus__hpp__included__
|
||||
|
||||
#include "threadtypes.hpp"
|
||||
#include "threads.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
@ -92,7 +92,7 @@ public:
|
|||
private:
|
||||
emulator_status(const emulator_status&);
|
||||
emulator_status& operator=(const emulator_status&);
|
||||
mutex_class lock;
|
||||
threads::lock lock;
|
||||
std::map<std::string, std::u32string> content;
|
||||
};
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <cstdint>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include "threadtypes.hpp"
|
||||
#include "threads.hpp"
|
||||
|
||||
namespace fileimage
|
||||
{
|
||||
|
@ -61,8 +61,8 @@ private:
|
|||
void resolve_error(unsigned id, const std::string& err);
|
||||
|
||||
friend class hash;
|
||||
mutable mutex_class mutex;
|
||||
mutable cv_class condition;
|
||||
mutable threads::lock mlock;
|
||||
mutable threads::cv condition;
|
||||
bool is_ready;
|
||||
unsigned cbid;
|
||||
uint64_t prefixv;
|
||||
|
@ -120,9 +120,9 @@ private:
|
|||
};
|
||||
hash(const hash&);
|
||||
hash& operator=(const hash&);
|
||||
thread_class* hash_thread;
|
||||
mutex_class mutex;
|
||||
cv_class condition;
|
||||
threads::thread* hash_thread;
|
||||
threads::lock mlock;
|
||||
threads::cv condition;
|
||||
std::list<queue_job> queue;
|
||||
std::list<queue_job>::iterator current_job;
|
||||
hashval* first_future;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <map>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include "threadtypes.hpp"
|
||||
#include "threads.hpp"
|
||||
|
||||
#define CLUSTER_SIZE 8192
|
||||
#define CLUSTERS_PER_SUPER (CLUSTER_SIZE / 4)
|
||||
|
@ -88,7 +88,7 @@ public:
|
|||
ref()
|
||||
{
|
||||
refcnt = NULL;
|
||||
mutex = NULL;
|
||||
mlock = NULL;
|
||||
fs = NULL;
|
||||
}
|
||||
/**
|
||||
|
@ -99,14 +99,14 @@ public:
|
|||
ref(const std::string& backingfile)
|
||||
{
|
||||
refcnt = NULL;
|
||||
mutex = NULL;
|
||||
mlock = NULL;
|
||||
try {
|
||||
refcnt = new unsigned;
|
||||
mutex = new mutex_class;
|
||||
mlock = new threads::lock;
|
||||
fs = new filesystem(backingfile);
|
||||
} catch(...) {
|
||||
delete refcnt;
|
||||
delete mutex;
|
||||
delete mlock;
|
||||
throw;
|
||||
}
|
||||
*refcnt = 1;
|
||||
|
@ -116,16 +116,16 @@ public:
|
|||
*/
|
||||
~ref()
|
||||
{
|
||||
mutex_class* mtodelete = NULL;
|
||||
if(!mutex)
|
||||
threads::lock* mtodelete = NULL;
|
||||
if(!mlock)
|
||||
return;
|
||||
{
|
||||
umutex_class m(*mutex);
|
||||
threads::alock m(*mlock);
|
||||
--*refcnt;
|
||||
if(!*refcnt) {
|
||||
delete fs;
|
||||
delete refcnt;
|
||||
mtodelete = mutex;
|
||||
mtodelete = mlock;
|
||||
}
|
||||
}
|
||||
if(mtodelete)
|
||||
|
@ -136,10 +136,10 @@ public:
|
|||
*/
|
||||
ref(const ref& r)
|
||||
{
|
||||
umutex_class m(*r.mutex);
|
||||
threads::alock m(*r.mlock);
|
||||
++*(r.refcnt);
|
||||
refcnt = r.refcnt;
|
||||
mutex = r.mutex;
|
||||
mlock = r.mlock;
|
||||
fs = r.fs;
|
||||
}
|
||||
/**
|
||||
|
@ -153,7 +153,7 @@ public:
|
|||
*/
|
||||
uint32_t allocate_cluster()
|
||||
{
|
||||
umutex_class m(*mutex);
|
||||
threads::alock m(*mlock);
|
||||
return fs->allocate_cluster();
|
||||
}
|
||||
/**
|
||||
|
@ -163,7 +163,7 @@ public:
|
|||
*/
|
||||
void free_cluster_chain(uint32_t cluster)
|
||||
{
|
||||
umutex_class m(*mutex);
|
||||
threads::alock m(*mlock);
|
||||
fs->free_cluster_chain(cluster);
|
||||
}
|
||||
/**
|
||||
|
@ -173,7 +173,7 @@ public:
|
|||
*/
|
||||
size_t skip_data(uint32_t& cluster, uint32_t& ptr, uint32_t length)
|
||||
{
|
||||
umutex_class m(*mutex);
|
||||
threads::alock m(*mlock);
|
||||
return fs->skip_data(cluster, ptr, length);
|
||||
}
|
||||
/**
|
||||
|
@ -183,7 +183,7 @@ public:
|
|||
*/
|
||||
size_t read_data(uint32_t& cluster, uint32_t& ptr, void* data, uint32_t length)
|
||||
{
|
||||
umutex_class m(*mutex);
|
||||
threads::alock m(*mlock);
|
||||
return fs->read_data(cluster, ptr, data, length);
|
||||
}
|
||||
/**
|
||||
|
@ -194,13 +194,13 @@ public:
|
|||
void write_data(uint32_t& cluster, uint32_t& ptr, const void* data, uint32_t length,
|
||||
uint32_t& real_cluster, uint32_t& real_ptr)
|
||||
{
|
||||
umutex_class m(*mutex);
|
||||
threads::alock m(*mlock);
|
||||
fs->write_data(cluster, ptr, data, length, real_cluster, real_ptr);
|
||||
}
|
||||
private:
|
||||
filesystem* fs;
|
||||
unsigned* refcnt;
|
||||
mutex_class* mutex;
|
||||
threads::lock* mlock;
|
||||
};
|
||||
private:
|
||||
filesystem(const filesystem&);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <cstdint>
|
||||
#include <set>
|
||||
#include "json.hpp"
|
||||
#include "threadtypes.hpp"
|
||||
#include "threads.hpp"
|
||||
|
||||
namespace gamepad
|
||||
{
|
||||
|
@ -108,7 +108,7 @@ private:
|
|||
unsigned next_button;
|
||||
unsigned next_hat;
|
||||
unsigned jid;
|
||||
mutex_class mutex;
|
||||
threads::lock mlock;
|
||||
};
|
||||
|
||||
class set
|
||||
|
@ -136,7 +136,7 @@ private:
|
|||
std::function<void(unsigned jnum, unsigned num, int mode, double tolerance)> amode_fn;
|
||||
std::function<void(unsigned jnum, unsigned num, int type)> newitem_fn;
|
||||
std::vector<pad*> _gamepads;
|
||||
mutex_class mutex;
|
||||
threads::lock mlock;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <cstdlib>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "threadtypes.hpp"
|
||||
#include "threads.hpp"
|
||||
|
||||
class http_request
|
||||
{
|
||||
|
@ -147,9 +147,9 @@ struct http_async_request
|
|||
std::string errormsg; //Final error (OUTPUT).
|
||||
long http_code; //HTTP error code (OUTPUT).
|
||||
volatile bool finished; //Finished flag (semi-transient).
|
||||
cv_class finished_cond; //This condition variable is fired on finish.
|
||||
threads::cv finished_cond; //This condition variable is fired on finish.
|
||||
http_request* req; //The HTTP request object (TRANSIENT).
|
||||
mutex_class m; //Lock protecting the object (TRANSIENT).
|
||||
threads::lock m; //Lock protecting the object (TRANSIENT).
|
||||
void get_xfer_status(int64_t& dnow, int64_t& dtotal, int64_t& unow, int64_t& utotal);
|
||||
void lauch_async(); //Lauch asynchronous request.
|
||||
void cancel(); //Cancel request in flight.
|
||||
|
|
|
@ -217,7 +217,7 @@ private:
|
|||
std::set<key*> listening;
|
||||
keyboard& kbd;
|
||||
command::group& domain;
|
||||
mutex_class mutex;
|
||||
threads::lock mlock;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -273,7 +273,7 @@ private:
|
|||
std::string cmd;
|
||||
std::string oname;
|
||||
std::vector<keyspec> specs;
|
||||
mutex_class mutex;
|
||||
threads::lock mlock;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -337,7 +337,7 @@ private:
|
|||
std::string oname;
|
||||
std::vector<std::pair<key*, unsigned>> keys;
|
||||
bool axis;
|
||||
mutex_class mutex;
|
||||
threads::lock mlock;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define _library__keyboard__hpp__included__
|
||||
|
||||
#include "register-queue.hpp"
|
||||
#include "threadtypes.hpp"
|
||||
#include "threads.hpp"
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
@ -120,7 +120,7 @@ private:
|
|||
keyboard& operator=(const keyboard&);
|
||||
std::map<std::string, modifier*> modifiers;
|
||||
std::map<std::string, key*> keys;
|
||||
mutex_class mutex;
|
||||
threads::lock mlock;
|
||||
key* current_key;
|
||||
};
|
||||
|
||||
|
@ -583,7 +583,7 @@ protected:
|
|||
/**
|
||||
* Mutex protecting state.
|
||||
*/
|
||||
mutable mutex_class mutex;
|
||||
mutable threads::lock mlock;
|
||||
private:
|
||||
key(key&);
|
||||
key& operator=(key&);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <map>
|
||||
#include "threadtypes.hpp"
|
||||
#include "threads.hpp"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#include <windows.h>
|
||||
|
@ -12,7 +12,7 @@
|
|||
|
||||
namespace loadlib
|
||||
{
|
||||
mutex_class& global_mutex();
|
||||
threads::lock& global_mutex();
|
||||
|
||||
/**
|
||||
* A loaded library.
|
||||
|
@ -43,7 +43,7 @@ public:
|
|||
*/
|
||||
~library() throw()
|
||||
{
|
||||
umutex_class h(global_mutex());
|
||||
threads::alock h(global_mutex());
|
||||
if(lib && !--lib->refs)
|
||||
delete lib;
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public:
|
|||
*/
|
||||
void* operator[](const std::string& symbol) const throw(std::bad_alloc, std::runtime_error)
|
||||
{
|
||||
umutex_class h(global_mutex());
|
||||
threads::alock h(global_mutex());
|
||||
if(!lib) throw std::runtime_error("Symbol '" + symbol + "' not found");
|
||||
return (*lib)[symbol];
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ public:
|
|||
*/
|
||||
library(const library& r)
|
||||
{
|
||||
umutex_class h(global_mutex());
|
||||
threads::alock h(global_mutex());
|
||||
lib = r.lib;
|
||||
if(lib) ++lib->refs;
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ public:
|
|||
{
|
||||
if(lib == r.lib)
|
||||
return *this;
|
||||
umutex_class h(global_mutex());
|
||||
threads::alock h(global_mutex());
|
||||
if(lib && !--lib->refs)
|
||||
delete lib;
|
||||
lib = r.lib;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include "threadtypes.hpp"
|
||||
#include "threads.hpp"
|
||||
#include "arch-detect.hpp"
|
||||
|
||||
/**
|
||||
|
@ -243,7 +243,7 @@ public:
|
|||
*/
|
||||
void read_all_linear_memory(uint8_t* buffer);
|
||||
private:
|
||||
mutex_class mutex;
|
||||
threads::lock mlock;
|
||||
std::vector<memory_region*> u_regions;
|
||||
std::vector<memory_region*> u_lregions;
|
||||
std::vector<uint64_t> linear_bases;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef _library__register_queue__hpp__included__
|
||||
#define _library__register_queue__hpp__included__
|
||||
|
||||
#include "threadtypes.hpp"
|
||||
#include "threads.hpp"
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <set>
|
||||
|
@ -23,7 +23,7 @@ public:
|
|||
static void do_register(G& group, const std::string& name, O& object)
|
||||
{
|
||||
{
|
||||
umutex_class h(get_mutex());
|
||||
threads::alock h(get_mutex());
|
||||
if(get_ready().count(&group)) {
|
||||
group.do_register(name, object);
|
||||
return;
|
||||
|
@ -44,7 +44,7 @@ public:
|
|||
*/
|
||||
static void do_unregister(G& group, const std::string& name)
|
||||
{
|
||||
umutex_class h(get_mutex());
|
||||
threads::alock h(get_mutex());
|
||||
auto& x = get_pending();
|
||||
auto i = x.begin();
|
||||
O* obj = NULL;
|
||||
|
@ -65,7 +65,7 @@ public:
|
|||
static void do_ready(G& group, bool ready)
|
||||
{
|
||||
{
|
||||
umutex_class h(get_mutex());
|
||||
threads::alock h(get_mutex());
|
||||
if(ready)
|
||||
get_ready().insert(&group);
|
||||
else
|
||||
|
@ -91,18 +91,18 @@ private:
|
|||
static std::list<queue_entry<G, O>> x;
|
||||
return x;
|
||||
}
|
||||
static mutex_class& get_mutex()
|
||||
static threads::lock& get_mutex()
|
||||
{
|
||||
static bool init = false;
|
||||
static mutex_class* x;
|
||||
static threads::lock* x;
|
||||
if(!init)
|
||||
x = new mutex_class;
|
||||
x = new threads::lock;
|
||||
init = true;
|
||||
return *x;
|
||||
}
|
||||
static void run()
|
||||
{
|
||||
umutex_class h(get_mutex());
|
||||
threads::alock h(get_mutex());
|
||||
auto& x = get_pending();
|
||||
auto i = x.begin();
|
||||
while(i != x.end()) {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <string>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include "threadtypes.hpp"
|
||||
#include "threads.hpp"
|
||||
#include "string.hpp"
|
||||
#include <string>
|
||||
|
||||
|
@ -74,7 +74,7 @@ public:
|
|||
private:
|
||||
std::map<std::string, class base*> settings;
|
||||
std::set<struct listener*> listeners;
|
||||
mutex_class lock;
|
||||
threads::lock lock;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -126,7 +126,7 @@ public:
|
|||
std::runtime_error);
|
||||
private:
|
||||
group& grp;
|
||||
mutex_class lock;
|
||||
threads::lock lock;
|
||||
std::map<std::string, std::string> badcache;
|
||||
};
|
||||
|
||||
|
@ -211,7 +211,7 @@ protected:
|
|||
group& sgroup;
|
||||
std::string iname;
|
||||
std::string hname;
|
||||
mutable mutex_class lock;
|
||||
mutable threads::lock lock;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -244,7 +244,7 @@ public:
|
|||
void str(const std::string& val) throw(std::runtime_error, std::bad_alloc)
|
||||
{
|
||||
{
|
||||
umutex_class h(lock);
|
||||
threads::alock h(lock);
|
||||
value = model::read(val);
|
||||
}
|
||||
sgroup.fire_listener(*this);
|
||||
|
@ -254,7 +254,7 @@ public:
|
|||
*/
|
||||
std::string str() const throw(std::runtime_error, std::bad_alloc)
|
||||
{
|
||||
umutex_class h(lock);
|
||||
threads::alock h(lock);
|
||||
return model::write(value);
|
||||
}
|
||||
/**
|
||||
|
@ -263,7 +263,7 @@ public:
|
|||
void set(valtype_t _value) throw(std::runtime_error, std::bad_alloc)
|
||||
{
|
||||
{
|
||||
umutex_class h(lock);
|
||||
threads::alock h(lock);
|
||||
if(!model::valid(value))
|
||||
throw std::runtime_error("Invalid value");
|
||||
value = _value;
|
||||
|
@ -275,7 +275,7 @@ public:
|
|||
*/
|
||||
valtype_t get() throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class h(lock);
|
||||
threads::alock h(lock);
|
||||
return model::transform(value);
|
||||
}
|
||||
/**
|
||||
|
|
50
include/library/threads.hpp
Normal file
50
include/library/threads.hpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
#ifndef _library_threads__hpp__included__
|
||||
#define _library_threads__hpp__included__
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#ifdef NATIVE_THREADS
|
||||
#include <thread>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#else
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
#endif
|
||||
|
||||
namespace threads
|
||||
{
|
||||
#ifdef NATIVE_THREADS
|
||||
typedef std::thread thread;
|
||||
typedef std::condition_variable cv;
|
||||
typedef std::mutex lock;
|
||||
typedef std::unique_lock<std::mutex> alock;
|
||||
typedef std::chrono::microseconds ustime;
|
||||
typedef std::thread::id id;
|
||||
inline void cv_timed_wait(cv& c, alock& m, const ustime& t)
|
||||
{
|
||||
c.wait_for(m, t);
|
||||
}
|
||||
inline id this_id()
|
||||
{
|
||||
return std::this_thread::get_id();
|
||||
}
|
||||
#else
|
||||
typedef boost::thread thread;
|
||||
typedef boost::condition_variable cv;
|
||||
typedef boost::mutex lock;
|
||||
typedef boost::unique_lock<boost::mutex> alock;
|
||||
typedef boost::posix_time::microseconds ustime;
|
||||
typedef boost::thread::id id;
|
||||
inline void cv_timed_wait(cv& c, alock& m, const ustime& t)
|
||||
{
|
||||
c.timed_wait(m, t);
|
||||
}
|
||||
inline id this_id()
|
||||
{
|
||||
return boost::this_thread::get_id();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,45 +0,0 @@
|
|||
#ifndef _library_threadtypes__hpp__included__
|
||||
#define _library_threadtypes__hpp__included__
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#ifdef NATIVE_THREADS
|
||||
#include <thread>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
typedef std::thread thread_class;
|
||||
typedef std::condition_variable cv_class;
|
||||
typedef std::mutex mutex_class;
|
||||
typedef std::unique_lock<std::mutex> umutex_class;
|
||||
typedef std::chrono::microseconds microsec_class;
|
||||
typedef std::thread::id threadid_class;
|
||||
typedef std::thread thread_class;
|
||||
inline void cv_timed_wait(cv_class& c, umutex_class& m, const microsec_class& t)
|
||||
{
|
||||
c.wait_for(m, t);
|
||||
}
|
||||
inline threadid_class this_thread_id()
|
||||
{
|
||||
return std::this_thread::get_id();
|
||||
}
|
||||
#else
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
typedef boost::thread thread_class;
|
||||
typedef boost::condition_variable cv_class;
|
||||
typedef boost::mutex mutex_class;
|
||||
typedef boost::unique_lock<boost::mutex> umutex_class;
|
||||
typedef boost::posix_time::microseconds microsec_class;
|
||||
typedef boost::thread::id threadid_class;
|
||||
typedef boost::thread thread_class;
|
||||
inline void cv_timed_wait(cv_class& c, umutex_class& m, const microsec_class& t)
|
||||
{
|
||||
c.timed_wait(m, t);
|
||||
}
|
||||
inline threadid_class this_thread_id()
|
||||
{
|
||||
return boost::this_thread::get_id();
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -2,28 +2,30 @@
|
|||
#define _library_workthread__hpp__included__
|
||||
|
||||
#include <cstdint>
|
||||
#include "threadtypes.hpp"
|
||||
#include "threads.hpp"
|
||||
|
||||
#define WORKFLAG_QUIT_REQUEST 0x80000000U
|
||||
namespace workthread
|
||||
{
|
||||
class reflector;
|
||||
|
||||
class worker_thread_reflector;
|
||||
extern const uint32_t quit_request;
|
||||
|
||||
/**
|
||||
* A worker thread.
|
||||
*
|
||||
* Note: All methods (except entrypoints) are thread-safe.
|
||||
*/
|
||||
class worker_thread
|
||||
class worker
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
worker_thread();
|
||||
worker();
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~worker_thread();
|
||||
virtual ~worker();
|
||||
/**
|
||||
* Request quit. Sets quit request workflag.
|
||||
*/
|
||||
|
@ -89,10 +91,10 @@ protected:
|
|||
*/
|
||||
void fire();
|
||||
private:
|
||||
thread_class* thread;
|
||||
worker_thread_reflector* reflector;
|
||||
cv_class condition;
|
||||
mutex_class mutex;
|
||||
threads::thread* thread;
|
||||
workthread::reflector* reflector;
|
||||
threads::cv condition;
|
||||
threads::lock mlock;
|
||||
volatile bool joined;
|
||||
volatile uint32_t workflag;
|
||||
volatile bool busy;
|
||||
|
@ -102,5 +104,6 @@ private:
|
|||
volatile uint64_t waitamt_work;
|
||||
std::string exception_text;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "library/lua-class.hpp"
|
||||
#include "library/lua-params.hpp"
|
||||
#include "library/framebuffer.hpp"
|
||||
#include "library/threadtypes.hpp"
|
||||
#include "library/threads.hpp"
|
||||
#include "library/string.hpp"
|
||||
|
||||
struct lua_palette
|
||||
|
@ -17,7 +17,7 @@ struct lua_palette
|
|||
std::vector<framebuffer::color> colors;
|
||||
lua_palette(lua::state& L);
|
||||
~lua_palette();
|
||||
mutex_class palette_mutex;
|
||||
threads::lock palette_mutex;
|
||||
std::string print();
|
||||
static int create(lua::state& L, lua::parameters& P);
|
||||
static int load(lua::state& L, lua::parameters& P);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
#include "library/threadtypes.hpp"
|
||||
#include "library/threads.hpp"
|
||||
|
||||
/**
|
||||
* Sample queue.
|
||||
|
@ -42,12 +42,13 @@ public:
|
|||
*/
|
||||
size_t available();
|
||||
private:
|
||||
size_t _available();
|
||||
std::vector<int16_t> data;
|
||||
bool blank;
|
||||
size_t rptr;
|
||||
size_t wptr;
|
||||
size_t size;
|
||||
mutex_class lock;
|
||||
threads::lock mlock;
|
||||
};
|
||||
|
||||
struct frame_object
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "core/dispatch.hpp"
|
||||
#include "core/framerate.hpp"
|
||||
#include "library/minmax.hpp"
|
||||
#include "library/threadtypes.hpp"
|
||||
#include "library/threads.hpp"
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
@ -65,7 +65,7 @@ namespace
|
|||
};
|
||||
|
||||
dummy_cb_proc* dummy_cb_proc_obj;
|
||||
thread_class* dummy_cb_thread;
|
||||
threads::thread* dummy_cb_thread;
|
||||
|
||||
|
||||
// | -1 1 -1 1 | 1 0 0 0 |
|
||||
|
@ -345,7 +345,7 @@ void audioapi_init()
|
|||
dummy_cb_active_record = true;
|
||||
dummy_cb_quit = false;
|
||||
dummy_cb_proc_obj = new dummy_cb_proc;
|
||||
dummy_cb_thread = new thread_class(*dummy_cb_proc_obj);
|
||||
dummy_cb_thread = new threads::thread(*dummy_cb_proc_obj);
|
||||
}
|
||||
|
||||
void audioapi_quit()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "core/command.hpp"
|
||||
#include "core/keymapper.hpp"
|
||||
#include "library/globalwrap.hpp"
|
||||
#include "library/threadtypes.hpp"
|
||||
#include "library/threads.hpp"
|
||||
#include "core/misc.hpp"
|
||||
#include "core/window.hpp"
|
||||
|
||||
|
@ -12,13 +12,13 @@ command::group lsnes_cmd;
|
|||
|
||||
namespace
|
||||
{
|
||||
mutex_class alias_ibind_mutex;
|
||||
threads::lock alias_ibind_mutex;
|
||||
std::map<std::string, keyboard::invbind*> alias_binds;
|
||||
}
|
||||
|
||||
void refresh_alias_binds()
|
||||
{
|
||||
umutex_class h(alias_ibind_mutex);
|
||||
threads::alock h(alias_ibind_mutex);
|
||||
auto a = lsnes_cmd.get_aliases();
|
||||
for(auto i : alias_binds) {
|
||||
if(!a.count(i.first)) {
|
||||
|
|
|
@ -216,7 +216,7 @@ bool controller_state::is_present(unsigned port, unsigned controller) throw()
|
|||
void controller_state::erase_macro(const std::string& macro)
|
||||
{
|
||||
{
|
||||
umutex_class h(macro_lock);
|
||||
threads::alock h(macro_lock);
|
||||
if(!all_macros.count(macro))
|
||||
return;
|
||||
auto m = &all_macros[macro];
|
||||
|
@ -238,7 +238,7 @@ void controller_state::erase_macro(const std::string& macro)
|
|||
|
||||
std::set<std::string> controller_state::enumerate_macro()
|
||||
{
|
||||
umutex_class h(macro_lock);
|
||||
threads::alock h(macro_lock);
|
||||
std::set<std::string> r;
|
||||
for(auto i : all_macros)
|
||||
r.insert(i.first);
|
||||
|
@ -247,7 +247,7 @@ std::set<std::string> controller_state::enumerate_macro()
|
|||
|
||||
controller_macro& controller_state::get_macro(const std::string& macro)
|
||||
{
|
||||
umutex_class h(macro_lock);
|
||||
threads::alock h(macro_lock);
|
||||
if(!all_macros.count(macro))
|
||||
throw std::runtime_error("No such macro");
|
||||
return all_macros[macro];
|
||||
|
@ -256,7 +256,7 @@ controller_macro& controller_state::get_macro(const std::string& macro)
|
|||
void controller_state::set_macro(const std::string& macro, const controller_macro& m)
|
||||
{
|
||||
{
|
||||
umutex_class h(macro_lock);
|
||||
threads::alock h(macro_lock);
|
||||
controller_macro* old = NULL;
|
||||
if(all_macros.count(macro))
|
||||
old = &all_macros[macro];
|
||||
|
@ -278,21 +278,21 @@ void controller_state::set_macro(const std::string& macro, const controller_macr
|
|||
|
||||
void controller_state::apply_macro(controller_frame& f)
|
||||
{
|
||||
umutex_class h(macro_lock);
|
||||
threads::alock h(macro_lock);
|
||||
for(auto i : active_macros)
|
||||
i.second->write(f, i.first);
|
||||
}
|
||||
|
||||
void controller_state::advance_macros()
|
||||
{
|
||||
umutex_class h(macro_lock);
|
||||
threads::alock h(macro_lock);
|
||||
for(auto& i : active_macros)
|
||||
i.first++;
|
||||
}
|
||||
|
||||
std::map<std::string, uint64_t> controller_state::get_macro_frames()
|
||||
{
|
||||
umutex_class h(macro_lock);
|
||||
threads::alock h(macro_lock);
|
||||
std::map<std::string, uint64_t> r;
|
||||
for(auto i : active_macros) {
|
||||
for(auto& j : all_macros)
|
||||
|
@ -305,7 +305,7 @@ std::map<std::string, uint64_t> controller_state::get_macro_frames()
|
|||
|
||||
void controller_state::set_macro_frames(const std::map<std::string, uint64_t>& f)
|
||||
{
|
||||
umutex_class h(macro_lock);
|
||||
threads::alock h(macro_lock);
|
||||
std::list<std::pair<uint64_t, controller_macro*>> new_active_macros;
|
||||
for(auto i : f)
|
||||
if(all_macros.count(i.first))
|
||||
|
@ -318,7 +318,7 @@ void controller_state::set_macro_frames(const std::map<std::string, uint64_t>& f
|
|||
void controller_state::rename_macro(const std::string& old, const std::string& newn)
|
||||
{
|
||||
{
|
||||
umutex_class h(macro_lock);
|
||||
threads::alock h(macro_lock);
|
||||
if(!all_macros.count(old))
|
||||
throw std::runtime_error("Old macro doesn't exist");
|
||||
if(all_macros.count(newn))
|
||||
|
@ -345,7 +345,7 @@ void controller_state::rename_macro(const std::string& old, const std::string& n
|
|||
|
||||
void controller_state::do_macro(const std::string& a, int mode) {
|
||||
{
|
||||
umutex_class h(macro_lock);
|
||||
threads::alock h(macro_lock);
|
||||
if(!all_macros.count(a)) {
|
||||
if(mode & 1) messages << "No such macro '" << a << "'" << std::endl;
|
||||
return;
|
||||
|
@ -366,7 +366,7 @@ end:
|
|||
|
||||
std::set<std::string> controller_state::active_macro_set()
|
||||
{
|
||||
umutex_class h(macro_lock);
|
||||
threads::alock h(macro_lock);
|
||||
std::set<std::string> r;
|
||||
for(auto i : active_macros) {
|
||||
for(auto& j : all_macros)
|
||||
|
|
|
@ -67,10 +67,10 @@ void file_download::do_async()
|
|||
req.url = url;
|
||||
try {
|
||||
req.lauch_async();
|
||||
(new thread_class(file_download_thread_trampoline, this))->detach();
|
||||
(new threads::thread(file_download_thread_trampoline, this))->detach();
|
||||
} catch(std::exception& e) {
|
||||
req.cancel();
|
||||
umutex_class h(m);
|
||||
threads::alock h(m);
|
||||
errormsg = e.what();
|
||||
finished = true;
|
||||
cond.notify_all();
|
||||
|
@ -96,13 +96,13 @@ std::string file_download::statusmsg()
|
|||
void file_download::_do_async()
|
||||
{
|
||||
while(!req.finished) {
|
||||
umutex_class h(req.m);
|
||||
threads::alock h(req.m);
|
||||
req.finished_cond.wait(h);
|
||||
if(!req.finished)
|
||||
continue;
|
||||
if(req.errormsg != "") {
|
||||
remove(tempname.c_str());
|
||||
umutex_class h(m);
|
||||
threads::alock h(m);
|
||||
errormsg = req.errormsg;
|
||||
finished = true;
|
||||
cond.notify_all();
|
||||
|
@ -112,7 +112,7 @@ void file_download::_do_async()
|
|||
delete req.ohandler;
|
||||
req.ohandler = NULL;
|
||||
if(req.http_code > 299) {
|
||||
umutex_class h(m);
|
||||
threads::alock h(m);
|
||||
errormsg = (stringfmt() << "Got HTTP error " << req.http_code).str();
|
||||
finished = true;
|
||||
cond.notify_all();
|
||||
|
@ -162,14 +162,14 @@ void file_download::_do_async()
|
|||
remove(tempname2.c_str());
|
||||
} catch(std::exception& e) {
|
||||
remove(tempname2.c_str());
|
||||
umutex_class h(m);
|
||||
threads::alock h(m);
|
||||
errormsg = e.what();
|
||||
finished = true;
|
||||
cond.notify_all();
|
||||
return;
|
||||
}
|
||||
//We are done!
|
||||
umutex_class h(m);
|
||||
threads::alock h(m);
|
||||
finished = true;
|
||||
cond.notify_all();
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ file_upload::~file_upload()
|
|||
|
||||
void file_upload::do_async()
|
||||
{
|
||||
(new thread_class(file_upload_trampoline, this))->detach();
|
||||
(new threads::thread(file_upload_trampoline, this))->detach();
|
||||
}
|
||||
|
||||
void file_upload::_do_async()
|
||||
|
@ -138,7 +138,7 @@ void file_upload::_do_async()
|
|||
{
|
||||
http_async_request obtainkey;
|
||||
{
|
||||
umutex_class h(m);
|
||||
threads::alock h(m);
|
||||
req = &obtainkey;
|
||||
}
|
||||
http_request::null_input_handler nullinput;
|
||||
|
@ -154,34 +154,34 @@ void file_upload::_do_async()
|
|||
add_msg("Obtaining short-term credentials...");
|
||||
obtainkey.lauch_async();
|
||||
while(!obtainkey.finished) {
|
||||
umutex_class hx(obtainkey.m);
|
||||
threads::alock hx(obtainkey.m);
|
||||
obtainkey.finished_cond.wait(hx);
|
||||
}
|
||||
if(obtainkey.errormsg != "") {
|
||||
add_msg((stringfmt() << "Failed: " << obtainkey.errormsg).str());
|
||||
{ umutex_class h(m); req = NULL; }
|
||||
{ threads::alock h(m); req = NULL; }
|
||||
finished = true;
|
||||
return;
|
||||
}
|
||||
if(obtainkey.http_code != 401) {
|
||||
add_msg((stringfmt() << "Failed: Expected 401, got " << obtainkey.http_code).str());
|
||||
{ umutex_class h(m); req = NULL; }
|
||||
{ threads::alock h(m); req = NULL; }
|
||||
finished = true;
|
||||
return;
|
||||
}
|
||||
if(!dh25519->is_ready()) {
|
||||
add_msg((stringfmt() << "Failed: Authenticator is not ready!").str());
|
||||
{ umutex_class h(m); req = NULL; }
|
||||
{ threads::alock h(m); req = NULL; }
|
||||
finished = true;
|
||||
return;
|
||||
}
|
||||
add_msg("Got short-term credentials.");
|
||||
{ umutex_class h(m); req = NULL; }
|
||||
{ threads::alock h(m); req = NULL; }
|
||||
}
|
||||
{
|
||||
http_async_request upload;
|
||||
{
|
||||
umutex_class h(m);
|
||||
threads::alock h(m);
|
||||
req = &upload;
|
||||
}
|
||||
property_upload_request input;
|
||||
|
@ -211,39 +211,39 @@ void file_upload::_do_async()
|
|||
add_msg("Uploading file...");
|
||||
upload.lauch_async();
|
||||
while(!upload.finished) {
|
||||
umutex_class hx(upload.m);
|
||||
threads::alock hx(upload.m);
|
||||
upload.finished_cond.wait(hx);
|
||||
}
|
||||
output.flush();
|
||||
if(upload.errormsg != "") {
|
||||
add_msg((stringfmt() << "Failed: " << upload.errormsg).str());
|
||||
finished = true;
|
||||
{ umutex_class h(m); req = NULL; }
|
||||
{ threads::alock h(m); req = NULL; }
|
||||
return;
|
||||
}
|
||||
if(upload.http_code != 201) {
|
||||
add_msg((stringfmt() << "Failed: Expected 201, got " << upload.http_code).str());
|
||||
finished = true;
|
||||
{ umutex_class h(m); req = NULL; }
|
||||
{ threads::alock h(m); req = NULL; }
|
||||
return;
|
||||
}
|
||||
add_msg((stringfmt() << "Sucessful! URL: " << output.get_location()).str());
|
||||
final_url = output.get_location();
|
||||
finished = true;
|
||||
success = true;
|
||||
{ umutex_class h(m); req = NULL; }
|
||||
{ threads::alock h(m); req = NULL; }
|
||||
}
|
||||
}
|
||||
|
||||
void file_upload::cancel()
|
||||
{
|
||||
umutex_class h(m);
|
||||
threads::alock h(m);
|
||||
if(req) req->cancel();
|
||||
}
|
||||
|
||||
std::list<std::string> file_upload::get_messages()
|
||||
{
|
||||
umutex_class h(m);
|
||||
threads::alock h(m);
|
||||
std::list<std::string> x = msgs;
|
||||
msgs.clear();
|
||||
return x;
|
||||
|
@ -251,7 +251,7 @@ std::list<std::string> file_upload::get_messages()
|
|||
|
||||
int file_upload::get_progress_ppm()
|
||||
{
|
||||
umutex_class h(m);
|
||||
threads::alock h(m);
|
||||
int ppm = -1;
|
||||
if(req) {
|
||||
int64_t dnow, dtotal, unow, utotal;
|
||||
|
@ -264,7 +264,7 @@ int file_upload::get_progress_ppm()
|
|||
|
||||
void file_upload::add_msg(const std::string& msg)
|
||||
{
|
||||
umutex_class h(m);
|
||||
threads::alock h(m);
|
||||
msgs.push_back(msg);
|
||||
}
|
||||
|
||||
|
|
|
@ -274,7 +274,7 @@ triplebuffer_logic::~triplebuffer_logic() throw()
|
|||
|
||||
unsigned triplebuffer_logic::start_write() throw()
|
||||
{
|
||||
umutex_class h(mut);
|
||||
threads::alock h(mut);
|
||||
if(!write_active) {
|
||||
//We need to avoid hitting last complete slot or slot that is active for read.
|
||||
if(last_complete_slot != 0 && read_active_slot != 0)
|
||||
|
@ -290,14 +290,14 @@ unsigned triplebuffer_logic::start_write() throw()
|
|||
|
||||
void triplebuffer_logic::end_write() throw()
|
||||
{
|
||||
umutex_class h(mut);
|
||||
threads::alock h(mut);
|
||||
if(!--write_active)
|
||||
last_complete_slot = write_active_slot;
|
||||
}
|
||||
|
||||
unsigned triplebuffer_logic::start_read() throw()
|
||||
{
|
||||
umutex_class h(mut);
|
||||
threads::alock h(mut);
|
||||
if(!read_active)
|
||||
read_active_slot = last_complete_slot;
|
||||
read_active++;
|
||||
|
@ -306,7 +306,7 @@ unsigned triplebuffer_logic::start_read() throw()
|
|||
|
||||
void triplebuffer_logic::end_read() throw()
|
||||
{
|
||||
umutex_class h(mut);
|
||||
threads::alock h(mut);
|
||||
read_active--;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace
|
|||
//Framerate.
|
||||
double nominal_framerate = 60;
|
||||
double multiplier_framerate = 1;
|
||||
mutex_class framerate_lock;
|
||||
threads::lock framerate_lock;
|
||||
bool turboed = false;
|
||||
|
||||
uint64_t get_time(uint64_t curtime, bool update)
|
||||
|
@ -64,7 +64,7 @@ namespace
|
|||
{
|
||||
double n, m;
|
||||
{
|
||||
umutex_class h(framerate_lock);
|
||||
threads::alock h(framerate_lock);
|
||||
n = nominal_framerate;
|
||||
m = multiplier_framerate;
|
||||
}
|
||||
|
@ -100,14 +100,14 @@ namespace
|
|||
//Set the speed multiplier. Note that INFINITE is a valid multiplier.
|
||||
void set_speed_multiplier(double multiplier) throw()
|
||||
{
|
||||
umutex_class h(framerate_lock);
|
||||
threads::alock h(framerate_lock);
|
||||
multiplier_framerate = multiplier;
|
||||
}
|
||||
|
||||
//Get the speed multiplier. Note that this may be INFINITE.
|
||||
double get_speed_multiplier() throw()
|
||||
{
|
||||
umutex_class h(framerate_lock);
|
||||
threads::alock h(framerate_lock);
|
||||
return multiplier_framerate;
|
||||
}
|
||||
|
||||
|
@ -126,13 +126,13 @@ void unfreeze_time(uint64_t curtime)
|
|||
|
||||
void set_nominal_framerate(double fps) throw()
|
||||
{
|
||||
umutex_class h(framerate_lock);
|
||||
threads::alock h(framerate_lock);
|
||||
nominal_framerate = fps;
|
||||
}
|
||||
|
||||
double get_realized_multiplier() throw()
|
||||
{
|
||||
umutex_class h(framerate_lock);
|
||||
threads::alock h(framerate_lock);
|
||||
return get_realized_fps() / nominal_framerate;
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ namespace
|
|||
//Last seen rate.
|
||||
double last_rate = 0;
|
||||
//Mutex protecting current_time and time_jump.
|
||||
mutex_class time_mutex;
|
||||
threads::lock time_mutex;
|
||||
//The current time.
|
||||
uint64_t current_time;
|
||||
//Time jump flag. Set if time jump is detected.
|
||||
|
@ -83,13 +83,13 @@ namespace
|
|||
//are started.
|
||||
bool time_jump;
|
||||
//Lock protecting active_playback_streams.
|
||||
mutex_class active_playback_streams_lock;
|
||||
threads::lock active_playback_streams_lock;
|
||||
//List of streams currently playing.
|
||||
std::list<opus_playback_stream*> active_playback_streams;
|
||||
//The collection of streams.
|
||||
stream_collection* current_collection;
|
||||
//Lock protecting current collection.
|
||||
mutex_class current_collection_lock;
|
||||
threads::lock current_collection_lock;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//Bitrate tracker.
|
||||
|
@ -275,9 +275,9 @@ namespace
|
|||
//Unlock a stream.
|
||||
void unlock() { locked = false; }
|
||||
//Increment reference count.
|
||||
void get_ref() { umutex_class m(reflock); refcount++; }
|
||||
void get_ref() { threads::alock m(reflock); refcount++; }
|
||||
//Decrement reference count, destroying object if it hits zero.
|
||||
void put_ref() { umutex_class m(reflock); refcount--; if(!refcount) destroy(); }
|
||||
void put_ref() { threads::alock m(reflock); refcount--; if(!refcount) destroy(); }
|
||||
//Add new packet into stream.
|
||||
//Not safe to call simultaneously with packet_length() or packet().
|
||||
//Can throw.
|
||||
|
@ -309,7 +309,7 @@ namespace
|
|||
uint32_t postgap_length;
|
||||
int16_t gain;
|
||||
bool locked;
|
||||
mutex_class reflock;
|
||||
threads::lock reflock;
|
||||
unsigned refcount;
|
||||
bool deleting;
|
||||
};
|
||||
|
@ -970,7 +970,7 @@ out:
|
|||
//Get stream with given index (NULL if not found).
|
||||
opus_stream* get_stream(uint64_t index)
|
||||
{
|
||||
umutex_class m(mutex);
|
||||
threads::alock m(mlock);
|
||||
if(streams.count(index)) {
|
||||
streams[index]->get_ref();
|
||||
return streams[index];
|
||||
|
@ -994,7 +994,7 @@ out:
|
|||
filesystem::ref fs;
|
||||
uint64_t next_index;
|
||||
unsigned next_stream;
|
||||
mutex_class mutex;
|
||||
threads::lock mlock;
|
||||
std::set<uint64_t> free_indices;
|
||||
std::map<uint64_t, uint64_t> entries;
|
||||
std::multimap<uint64_t, uint64_t> streams_by_time;
|
||||
|
@ -1038,7 +1038,7 @@ out:
|
|||
|
||||
stream_collection::~stream_collection()
|
||||
{
|
||||
umutex_class m(mutex);
|
||||
threads::alock m(mlock);
|
||||
for(auto i : streams)
|
||||
i.second->put_ref();
|
||||
streams.clear();
|
||||
|
@ -1046,7 +1046,7 @@ out:
|
|||
|
||||
std::list<uint64_t> stream_collection::streams_at(uint64_t point)
|
||||
{
|
||||
umutex_class m(mutex);
|
||||
threads::alock m(mlock);
|
||||
std::list<uint64_t> s;
|
||||
for(auto i : streams) {
|
||||
uint64_t start = i.second->timebase();
|
||||
|
@ -1063,7 +1063,7 @@ out:
|
|||
{
|
||||
uint64_t idx;
|
||||
try {
|
||||
umutex_class m(mutex);
|
||||
threads::alock m(mlock);
|
||||
//Lock the added stream so it doesn't start playing back immediately.
|
||||
stream.lock();
|
||||
idx = next_index++;
|
||||
|
@ -1096,14 +1096,14 @@ out:
|
|||
|
||||
void stream_collection::unlock_all()
|
||||
{
|
||||
umutex_class m(mutex);
|
||||
threads::alock m(mlock);
|
||||
for(auto i : streams)
|
||||
i.second->unlock();
|
||||
}
|
||||
|
||||
void stream_collection::delete_stream(uint64_t index)
|
||||
{
|
||||
umutex_class m(mutex);
|
||||
threads::alock m(mlock);
|
||||
if(!entries.count(index))
|
||||
return;
|
||||
uint64_t entry_number = entries[index];
|
||||
|
@ -1127,7 +1127,7 @@ out:
|
|||
void stream_collection::alter_stream_timebase(uint64_t index, uint64_t newts)
|
||||
{
|
||||
try {
|
||||
umutex_class m(mutex);
|
||||
threads::alock m(mlock);
|
||||
if(!streams.count(index))
|
||||
return;
|
||||
if(entries.count(index)) {
|
||||
|
@ -1156,7 +1156,7 @@ out:
|
|||
void stream_collection::alter_stream_gain(uint64_t index, uint16_t newgain)
|
||||
{
|
||||
try {
|
||||
umutex_class m(mutex);
|
||||
threads::alock m(mlock);
|
||||
if(!streams.count(index))
|
||||
return;
|
||||
streams[index]->set_gain(newgain);
|
||||
|
@ -1168,7 +1168,7 @@ out:
|
|||
|
||||
std::list<uint64_t> stream_collection::all_streams()
|
||||
{
|
||||
umutex_class m(mutex);
|
||||
threads::alock m(mlock);
|
||||
std::list<uint64_t> s;
|
||||
for(auto i : streams_by_time)
|
||||
s.push_back(i.second);
|
||||
|
@ -1276,16 +1276,16 @@ out:
|
|||
void start_management_stream(opus_stream& s)
|
||||
{
|
||||
opus_playback_stream* p = new opus_playback_stream(s);
|
||||
umutex_class m(active_playback_streams_lock);
|
||||
threads::alock m(active_playback_streams_lock);
|
||||
active_playback_streams.push_back(p);
|
||||
}
|
||||
|
||||
void advance_time(uint64_t newtime)
|
||||
{
|
||||
umutex_class m2(current_collection_lock);
|
||||
threads::alock m2(current_collection_lock);
|
||||
if(!current_collection) {
|
||||
//Clear all.
|
||||
umutex_class m(active_playback_streams_lock);
|
||||
threads::alock m(active_playback_streams_lock);
|
||||
for(auto i : active_playback_streams)
|
||||
delete i;
|
||||
active_playback_streams.clear();
|
||||
|
@ -1297,7 +1297,7 @@ out:
|
|||
if(!i)
|
||||
continue;
|
||||
//Don't play locked streams in order to avoid double playing.
|
||||
umutex_class m(active_playback_streams_lock);
|
||||
threads::alock m(active_playback_streams_lock);
|
||||
try {
|
||||
if(!i->islocked())
|
||||
active_playback_streams.push_back(new opus_playback_stream(*i));
|
||||
|
@ -1310,10 +1310,10 @@ out:
|
|||
|
||||
void jump_time(uint64_t newtime)
|
||||
{
|
||||
umutex_class m2(current_collection_lock);
|
||||
threads::alock m2(current_collection_lock);
|
||||
if(!current_collection) {
|
||||
//Clear all.
|
||||
umutex_class m(active_playback_streams_lock);
|
||||
threads::alock m(active_playback_streams_lock);
|
||||
for(auto i : active_playback_streams)
|
||||
delete i;
|
||||
active_playback_streams.clear();
|
||||
|
@ -1321,7 +1321,7 @@ out:
|
|||
}
|
||||
//Close all currently playing streams.
|
||||
{
|
||||
umutex_class m(active_playback_streams_lock);
|
||||
threads::alock m(active_playback_streams_lock);
|
||||
for(auto i : active_playback_streams)
|
||||
delete i;
|
||||
active_playback_streams.clear();
|
||||
|
@ -1346,7 +1346,7 @@ out:
|
|||
if(!s)
|
||||
continue;
|
||||
s->skip(p);
|
||||
umutex_class m(active_playback_streams_lock);
|
||||
threads::alock m(active_playback_streams_lock);
|
||||
active_playback_streams.push_back(s);
|
||||
}
|
||||
}
|
||||
|
@ -1429,7 +1429,7 @@ out:
|
|||
uint64_t sampletime;
|
||||
bool jumping;
|
||||
{
|
||||
umutex_class m(time_mutex);
|
||||
threads::alock m(time_mutex);
|
||||
sampletime = current_time;
|
||||
jumping = time_jump;
|
||||
time_jump = false;
|
||||
|
@ -1450,7 +1450,7 @@ out:
|
|||
//is held.
|
||||
std::list<opus_playback_stream*> stmp;
|
||||
{
|
||||
umutex_class m(active_playback_streams_lock);
|
||||
threads::alock m(active_playback_streams_lock);
|
||||
stmp = active_playback_streams;
|
||||
}
|
||||
std::set<opus_playback_stream*> toerase;
|
||||
|
@ -1469,7 +1469,7 @@ out:
|
|||
toerase.insert(i);
|
||||
}
|
||||
{
|
||||
umutex_class m(active_playback_streams_lock);
|
||||
threads::alock m(active_playback_streams_lock);
|
||||
for(auto i = active_playback_streams.begin(); i != active_playback_streams.end();) {
|
||||
if(toerase.count(*i)) {
|
||||
auto toerase = i;
|
||||
|
@ -1484,7 +1484,7 @@ out:
|
|||
|
||||
void handle_tangent_positive_edge(opus::encoder& e, opus_stream*& active_stream, bitrate_tracker& brtrack)
|
||||
{
|
||||
umutex_class m2(current_collection_lock);
|
||||
threads::alock m2(current_collection_lock);
|
||||
if(!current_collection)
|
||||
return;
|
||||
try {
|
||||
|
@ -1493,7 +1493,7 @@ out:
|
|||
brtrack.reset();
|
||||
uint64_t ctime;
|
||||
{
|
||||
umutex_class m(time_mutex);
|
||||
threads::alock m(time_mutex);
|
||||
ctime = current_time;
|
||||
}
|
||||
active_stream = NULL;
|
||||
|
@ -1509,7 +1509,7 @@ out:
|
|||
|
||||
void handle_tangent_negative_edge(opus_stream*& active_stream, bitrate_tracker& brtrack)
|
||||
{
|
||||
umutex_class m2(current_collection_lock);
|
||||
threads::alock m2(current_collection_lock);
|
||||
messages << "Tangent disenaged: " << brtrack;
|
||||
try {
|
||||
active_stream->write_trailier();
|
||||
|
@ -1529,7 +1529,7 @@ out:
|
|||
active_stream = NULL;
|
||||
}
|
||||
|
||||
class inthread_th : public worker_thread
|
||||
class inthread_th : public workthread::worker
|
||||
{
|
||||
public:
|
||||
inthread_th()
|
||||
|
@ -1543,7 +1543,7 @@ out:
|
|||
{
|
||||
quit = true;
|
||||
{
|
||||
umutex_class h(lmut);
|
||||
threads::alock h(lmut);
|
||||
lcond.notify_all();
|
||||
}
|
||||
while(!quit_ack)
|
||||
|
@ -1566,11 +1566,11 @@ out:
|
|||
{
|
||||
//Wait for libopus to load...
|
||||
size_t cbh = opus::add_callback([this]() {
|
||||
umutex_class h(this->lmut);
|
||||
threads::alock h(this->lmut);
|
||||
this->lcond.notify_all();
|
||||
});
|
||||
while(true) {
|
||||
umutex_class h(lmut);
|
||||
threads::alock h(lmut);
|
||||
if(opus::libopus_loaded() || quit)
|
||||
break;
|
||||
lcond.wait(h);
|
||||
|
@ -1598,7 +1598,7 @@ out:
|
|||
|
||||
drain_input();
|
||||
while(1) {
|
||||
if(clear_workflag(WORKFLAG_QUIT_REQUEST) & WORKFLAG_QUIT_REQUEST) {
|
||||
if(clear_workflag(workthread::quit_request) & workthread::quit_request) {
|
||||
if(!active_flag && active_stream)
|
||||
handle_tangent_negative_edge(active_stream, brtrack);
|
||||
break;
|
||||
|
@ -1652,7 +1652,7 @@ out:
|
|||
if(ticks_spent < ITERATION_TIME)
|
||||
usleep(ITERATION_TIME - ticks_spent);
|
||||
}
|
||||
umutex_class h(current_collection_lock);
|
||||
threads::alock h(current_collection_lock);
|
||||
delete current_collection;
|
||||
current_collection = NULL;
|
||||
}
|
||||
|
@ -1661,8 +1661,8 @@ out:
|
|||
double position;
|
||||
volatile bool quit;
|
||||
volatile bool quit_ack;
|
||||
mutex_class lmut;
|
||||
cv_class lcond;
|
||||
threads::lock lmut;
|
||||
threads::cv lcond;
|
||||
};
|
||||
|
||||
//The tangent function.
|
||||
|
@ -1685,7 +1685,7 @@ void voice_frame_number(uint64_t newframe, double rate)
|
|||
{
|
||||
if(rate == last_rate && last_frame_number == newframe)
|
||||
return;
|
||||
umutex_class m(time_mutex);
|
||||
threads::alock m(time_mutex);
|
||||
current_time = newframe / rate * OPUS_SAMPLERATE;
|
||||
if(fabs(rate - last_rate) > 1e-6 || last_frame_number + 1 != newframe)
|
||||
time_jump = true;
|
||||
|
@ -1717,13 +1717,13 @@ uint64_t voicesub_parse_timebase(const std::string& n)
|
|||
|
||||
bool voicesub_collection_loaded()
|
||||
{
|
||||
umutex_class m2(current_collection_lock);
|
||||
threads::alock m2(current_collection_lock);
|
||||
return (current_collection != NULL);
|
||||
}
|
||||
|
||||
std::list<playback_stream_info> voicesub_get_stream_info()
|
||||
{
|
||||
umutex_class m2(current_collection_lock);
|
||||
threads::alock m2(current_collection_lock);
|
||||
std::list<playback_stream_info> in;
|
||||
if(!current_collection)
|
||||
return in;
|
||||
|
@ -1746,7 +1746,7 @@ std::list<playback_stream_info> voicesub_get_stream_info()
|
|||
|
||||
void voicesub_play_stream(uint64_t id)
|
||||
{
|
||||
umutex_class m2(current_collection_lock);
|
||||
threads::alock m2(current_collection_lock);
|
||||
if(!current_collection)
|
||||
throw std::runtime_error("No collection loaded");
|
||||
opus_stream* s = current_collection->get_stream(id);
|
||||
|
@ -1763,7 +1763,7 @@ void voicesub_play_stream(uint64_t id)
|
|||
|
||||
void voicesub_export_stream(uint64_t id, const std::string& filename, external_stream_format fmt)
|
||||
{
|
||||
umutex_class m2(current_collection_lock);
|
||||
threads::alock m2(current_collection_lock);
|
||||
if(!current_collection)
|
||||
throw std::runtime_error("No collection loaded");
|
||||
opus_stream* st = current_collection->get_stream(id);
|
||||
|
@ -1785,7 +1785,7 @@ void voicesub_export_stream(uint64_t id, const std::string& filename, external_s
|
|||
|
||||
uint64_t voicesub_import_stream(uint64_t ts, const std::string& filename, external_stream_format fmt)
|
||||
{
|
||||
umutex_class m2(current_collection_lock);
|
||||
threads::alock m2(current_collection_lock);
|
||||
if(!current_collection)
|
||||
throw std::runtime_error("No collection loaded");
|
||||
|
||||
|
@ -1807,7 +1807,7 @@ uint64_t voicesub_import_stream(uint64_t ts, const std::string& filename, extern
|
|||
|
||||
void voicesub_delete_stream(uint64_t id)
|
||||
{
|
||||
umutex_class m2(current_collection_lock);
|
||||
threads::alock m2(current_collection_lock);
|
||||
if(!current_collection)
|
||||
throw std::runtime_error("No collection loaded");
|
||||
current_collection->delete_stream(id);
|
||||
|
@ -1816,7 +1816,7 @@ void voicesub_delete_stream(uint64_t id)
|
|||
|
||||
void voicesub_export_superstream(const std::string& filename)
|
||||
{
|
||||
umutex_class m2(current_collection_lock);
|
||||
threads::alock m2(current_collection_lock);
|
||||
if(!current_collection)
|
||||
throw std::runtime_error("No collection loaded");
|
||||
std::ofstream s(filename, std::ios_base::out | std::ios_base::binary);
|
||||
|
@ -1827,7 +1827,7 @@ void voicesub_export_superstream(const std::string& filename)
|
|||
|
||||
void voicesub_load_collection(const std::string& filename)
|
||||
{
|
||||
umutex_class m2(current_collection_lock);
|
||||
threads::alock m2(current_collection_lock);
|
||||
filesystem::ref newfs;
|
||||
stream_collection* newc;
|
||||
newfs = filesystem::ref(filename);
|
||||
|
@ -1840,7 +1840,7 @@ void voicesub_load_collection(const std::string& filename)
|
|||
|
||||
void voicesub_unload_collection()
|
||||
{
|
||||
umutex_class m2(current_collection_lock);
|
||||
threads::alock m2(current_collection_lock);
|
||||
if(current_collection)
|
||||
delete current_collection;
|
||||
current_collection = NULL;
|
||||
|
@ -1849,7 +1849,7 @@ void voicesub_unload_collection()
|
|||
|
||||
void voicesub_alter_timebase(uint64_t id, uint64_t ts)
|
||||
{
|
||||
umutex_class m2(current_collection_lock);
|
||||
threads::alock m2(current_collection_lock);
|
||||
if(!current_collection)
|
||||
throw std::runtime_error("No collection loaded");
|
||||
current_collection->alter_stream_timebase(id, ts);
|
||||
|
@ -1858,7 +1858,7 @@ void voicesub_alter_timebase(uint64_t id, uint64_t ts)
|
|||
|
||||
float voicesub_get_gain(uint64_t id)
|
||||
{
|
||||
umutex_class m2(current_collection_lock);
|
||||
threads::alock m2(current_collection_lock);
|
||||
if(!current_collection)
|
||||
throw std::runtime_error("No collection loaded");
|
||||
return current_collection->get_stream(id)->get_gain() / 256.0;
|
||||
|
@ -1866,7 +1866,7 @@ float voicesub_get_gain(uint64_t id)
|
|||
|
||||
void voicesub_set_gain(uint64_t id, float gain)
|
||||
{
|
||||
umutex_class m2(current_collection_lock);
|
||||
threads::alock m2(current_collection_lock);
|
||||
if(!current_collection)
|
||||
throw std::runtime_error("No collection loaded");
|
||||
int64_t _gain = gain * 256;
|
||||
|
|
|
@ -76,7 +76,7 @@ namespace
|
|||
};
|
||||
|
||||
//Our thread.
|
||||
threadid_class emulation_thread;
|
||||
threads::id emulation_thread;
|
||||
//Flags related to repeating advance.
|
||||
bool advanced_once;
|
||||
bool cancel_advance;
|
||||
|
@ -1185,7 +1185,7 @@ void main_loop(struct loaded_rom& rom, struct moviefile& initial, bool load_has_
|
|||
platform::system_thread_available(true);
|
||||
//Basic initialization.
|
||||
dispatch_set_error_streams(&messages.getstream());
|
||||
emulation_thread = this_thread_id();
|
||||
emulation_thread = threads::this_id();
|
||||
jukebox_size_listener jlistener;
|
||||
voicethread_task();
|
||||
init_special_screens();
|
||||
|
|
|
@ -44,7 +44,7 @@ namespace
|
|||
skein::prng prng;
|
||||
uint64_t rcounter = 0;
|
||||
bool reached_main_flag;
|
||||
mutex_class seed_mutex;
|
||||
threads::lock seed_mutex;
|
||||
|
||||
uint64_t arch_get_tsc()
|
||||
{
|
||||
|
@ -88,7 +88,7 @@ namespace
|
|||
static uint64_t last_reseed = 0;
|
||||
static uint64_t buf[slots + 1];
|
||||
buf[count++] = arch_get_tsc();
|
||||
umutex_class h(seed_mutex);
|
||||
threads::alock h(seed_mutex);
|
||||
if(count == 0) count = 1; //Shouldn't happen.
|
||||
if(count == slots || buf[count - 1] - last_reseed > 300000000) {
|
||||
last_reseed = buf[count - 1];
|
||||
|
@ -100,7 +100,7 @@ namespace
|
|||
|
||||
std::string get_random_hexstring_64(size_t index)
|
||||
{
|
||||
umutex_class h(seed_mutex);
|
||||
threads::alock h(seed_mutex);
|
||||
uint64_t buf[6];
|
||||
uint8_t out[32];
|
||||
buf[0] = time(NULL);
|
||||
|
@ -199,7 +199,7 @@ void set_random_seed(const std::string& seed) throw(std::bad_alloc)
|
|||
{
|
||||
std::vector<char> x(seed.begin(), seed.end());
|
||||
{
|
||||
umutex_class h(seed_mutex);
|
||||
threads::alock h(seed_mutex);
|
||||
prng.write(&x[0], x.size());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,13 +34,13 @@ namespace
|
|||
"Movie‣Saving‣Compression", 7);
|
||||
settingvar::variable<settingvar::model_bool<settingvar::yes_no>> readonly_load_preserves(lsnes_vset,
|
||||
"preserve_on_readonly_load", "Movie‣Loading‣Preserve on readonly load", true);
|
||||
mutex_class mprefix_lock;
|
||||
threads::lock mprefix_lock;
|
||||
std::string mprefix;
|
||||
bool mprefix_valid;
|
||||
|
||||
std::string get_mprefix()
|
||||
{
|
||||
umutex_class h(mprefix_lock);
|
||||
threads::alock h(mprefix_lock);
|
||||
if(!mprefix_valid)
|
||||
return "movieslot";
|
||||
else
|
||||
|
@ -80,7 +80,7 @@ namespace
|
|||
void set_mprefix(const std::string& pfx)
|
||||
{
|
||||
{
|
||||
umutex_class h(mprefix_lock);
|
||||
threads::alock h(mprefix_lock);
|
||||
mprefix_valid = (pfx != "");
|
||||
mprefix = pfx;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ bool multitrack_edit::is_enabled()
|
|||
void multitrack_edit::enable(bool state)
|
||||
{
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
enabled = state;
|
||||
controllerstate.clear();
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ void multitrack_edit::enable(bool state)
|
|||
void multitrack_edit::set(unsigned port, unsigned controller, state s)
|
||||
{
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
controllerstate[std::make_pair(port, controller)] = s;
|
||||
}
|
||||
update_movie_state();
|
||||
|
@ -75,7 +75,7 @@ void multitrack_edit::rotate(bool forward)
|
|||
|
||||
multitrack_edit::state multitrack_edit::get(unsigned port, unsigned controller)
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
auto key = std::make_pair(port, controller);
|
||||
if(controllerstate.count(key))
|
||||
return controllerstate[key];
|
||||
|
@ -84,7 +84,7 @@ multitrack_edit::state multitrack_edit::get(unsigned port, unsigned controller)
|
|||
|
||||
void multitrack_edit::config_altered()
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
controllerstate.clear();
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ void multitrack_edit::process_frame(controller_frame& input)
|
|||
{
|
||||
if(!movb || !movb.get_movie().readonly_mode())
|
||||
return;
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
bool any_need = false;
|
||||
if(!enabled)
|
||||
return;
|
||||
|
@ -154,7 +154,7 @@ bool multitrack_edit::any_records()
|
|||
{
|
||||
if(!movb || !movb.get_movie().readonly_mode())
|
||||
return true;
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
bool any_need = false;
|
||||
for(auto i : controllerstate)
|
||||
any_need = any_need || (i.second != MT_PRESERVE);
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include "library/framebuffer.hpp"
|
||||
#include "library/string.hpp"
|
||||
#include "library/minmax.hpp"
|
||||
#include "library/threadtypes.hpp"
|
||||
#include "library/threads.hpp"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
@ -235,7 +235,7 @@ messagebuffer platform::msgbuf(MAXMESSAGES, INIT_WIN_SIZE);
|
|||
|
||||
void platform::message(const std::string& msg) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class h(msgbuf_lock());
|
||||
threads::alock h(msgbuf_lock());
|
||||
for(auto& forlog : token_iterator_foreach(msg, {"\n"})) {
|
||||
msgbuf.add_message(forlog);
|
||||
if(system_log)
|
||||
|
@ -259,8 +259,8 @@ void platform::fatal_error() throw()
|
|||
|
||||
namespace
|
||||
{
|
||||
mutex_class queue_lock;
|
||||
cv_class queue_condition;
|
||||
threads::lock queue_lock;
|
||||
threads::cv queue_condition;
|
||||
std::deque<keypress> keypresses;
|
||||
std::deque<std::string> commands;
|
||||
std::deque<std::pair<void(*)(void*), void*>> functions;
|
||||
|
@ -338,9 +338,9 @@ void platform::dummy_event_loop() throw()
|
|||
{
|
||||
init_threading();
|
||||
while(!do_exit_dummy_event_loop) {
|
||||
umutex_class h(queue_lock);
|
||||
threads::alock h(queue_lock);
|
||||
internal_run_queues(true);
|
||||
cv_timed_wait(queue_condition, h, microsec_class(MAXWAIT));
|
||||
threads::cv_timed_wait(queue_condition, h, threads::ustime(MAXWAIT));
|
||||
random_mix_timing_entropy();
|
||||
}
|
||||
}
|
||||
|
@ -349,7 +349,7 @@ void platform::exit_dummy_event_loop() throw()
|
|||
{
|
||||
init_threading();
|
||||
do_exit_dummy_event_loop = true;
|
||||
umutex_class h(queue_lock);
|
||||
threads::alock h(queue_lock);
|
||||
queue_condition.notify_all();
|
||||
usleep(200000);
|
||||
}
|
||||
|
@ -373,7 +373,7 @@ void platform::flush_command_queue() throw()
|
|||
reload_lua_timers();
|
||||
run_idle = false;
|
||||
}
|
||||
umutex_class h(queue_lock);
|
||||
threads::alock h(queue_lock);
|
||||
internal_run_queues(true);
|
||||
if(!pausing_allowed)
|
||||
break;
|
||||
|
@ -394,7 +394,7 @@ void platform::flush_command_queue() throw()
|
|||
if(on_timer_time >= now)
|
||||
waitleft = min(waitleft, on_timer_time - now);
|
||||
if(waitleft > 0) {
|
||||
cv_timed_wait(queue_condition, h, microsec_class(waitleft));
|
||||
threads::cv_timed_wait(queue_condition, h, threads::ustime(waitleft));
|
||||
random_mix_timing_entropy();
|
||||
}
|
||||
} else
|
||||
|
@ -427,7 +427,7 @@ void platform::wait(uint64_t usec) throw()
|
|||
run_idle = false;
|
||||
reload_lua_timers();
|
||||
}
|
||||
umutex_class h(queue_lock);
|
||||
threads::alock h(queue_lock);
|
||||
internal_run_queues(true);
|
||||
if(queue_function_run)
|
||||
reload_lua_timers();
|
||||
|
@ -448,7 +448,7 @@ void platform::wait(uint64_t usec) throw()
|
|||
if(on_timer_time >= now)
|
||||
waitleft = min(waitleft, on_timer_time - now);
|
||||
if(waitleft > 0) {
|
||||
cv_timed_wait(queue_condition, h, microsec_class(waitleft));
|
||||
threads::cv_timed_wait(queue_condition, h, threads::ustime(waitleft));
|
||||
random_mix_timing_entropy();
|
||||
}
|
||||
} else
|
||||
|
@ -460,7 +460,7 @@ void platform::cancel_wait() throw()
|
|||
{
|
||||
init_threading();
|
||||
continue_time = 0;
|
||||
umutex_class h(queue_lock);
|
||||
threads::alock h(queue_lock);
|
||||
queue_condition.notify_all();
|
||||
}
|
||||
|
||||
|
@ -472,7 +472,7 @@ void platform::set_modal_pause(bool enable) throw()
|
|||
void platform::queue(const keypress& k) throw(std::bad_alloc)
|
||||
{
|
||||
init_threading();
|
||||
umutex_class h(queue_lock);
|
||||
threads::alock h(queue_lock);
|
||||
keypresses.push_back(k);
|
||||
queue_condition.notify_all();
|
||||
}
|
||||
|
@ -480,7 +480,7 @@ void platform::queue(const keypress& k) throw(std::bad_alloc)
|
|||
void platform::queue(const std::string& c) throw(std::bad_alloc)
|
||||
{
|
||||
init_threading();
|
||||
umutex_class h(queue_lock);
|
||||
threads::alock h(queue_lock);
|
||||
commands.push_back(c);
|
||||
queue_condition.notify_all();
|
||||
}
|
||||
|
@ -492,13 +492,13 @@ void platform::queue(void (*f)(void* arg), void* arg, bool sync) throw(std::bad_
|
|||
return;
|
||||
}
|
||||
init_threading();
|
||||
umutex_class h(queue_lock);
|
||||
threads::alock h(queue_lock);
|
||||
++next_function;
|
||||
functions.push_back(std::make_pair(f, arg));
|
||||
queue_condition.notify_all();
|
||||
if(sync)
|
||||
while(functions_executed < next_function && _system_thread_available) {
|
||||
cv_timed_wait(queue_condition, h, microsec_class(10000));
|
||||
threads::cv_timed_wait(queue_condition, h, threads::ustime(10000));
|
||||
random_mix_timing_entropy();
|
||||
}
|
||||
}
|
||||
|
@ -515,7 +515,7 @@ void platform::system_thread_available(bool av) throw()
|
|||
|
||||
namespace
|
||||
{
|
||||
mutex_class _msgbuf_lock;
|
||||
threads::lock _msgbuf_lock;
|
||||
framebuffer::fb<false>* our_screen;
|
||||
|
||||
struct painter_listener
|
||||
|
@ -533,7 +533,7 @@ namespace
|
|||
} x;
|
||||
}
|
||||
|
||||
mutex_class& platform::msgbuf_lock() throw()
|
||||
threads::lock& platform::msgbuf_lock() throw()
|
||||
{
|
||||
return _msgbuf_lock;
|
||||
}
|
||||
|
|
|
@ -548,7 +548,7 @@ unsigned core_core::action_flags(unsigned id)
|
|||
|
||||
std::set<const interface_action*> core_core::get_actions()
|
||||
{
|
||||
umutex_class h(actions_lock);
|
||||
threads::alock h(actions_lock);
|
||||
std::set<const interface_action*> r;
|
||||
for(auto& i : actions)
|
||||
r.insert(&i.second);
|
||||
|
|
|
@ -110,14 +110,14 @@ void group::invoke(const std::string& cmd) throw()
|
|||
std::string cmd2 = strip_CR(cmd);
|
||||
if(cmd2 == "?") {
|
||||
//The special ? command.
|
||||
umutex_class lock(int_mutex);
|
||||
threads::alock lock(int_mutex);
|
||||
for(auto i : commands)
|
||||
(*output) << i.first << ": " << i.second->get_short_help() << std::endl;
|
||||
return;
|
||||
}
|
||||
if(firstchar(cmd2) == '?') {
|
||||
//?command.
|
||||
umutex_class lock(int_mutex);
|
||||
threads::alock lock(int_mutex);
|
||||
std::string rcmd = cmd2.substr(1, min(cmd2.find_first_of(" \t"), cmd2.length()));
|
||||
if(firstchar(rcmd) != '*') {
|
||||
//This may be an alias.
|
||||
|
@ -146,7 +146,7 @@ void group::invoke(const std::string& cmd) throw()
|
|||
if(may_be_alias_expanded) {
|
||||
std::list<std::string> aexp;
|
||||
{
|
||||
umutex_class lock(int_mutex);
|
||||
threads::alock lock(int_mutex);
|
||||
if(!aliases.count(cmd))
|
||||
goto not_alias;
|
||||
aexp = aliases[cmd2];
|
||||
|
@ -162,7 +162,7 @@ not_alias:
|
|||
std::string args = cmd2.substr(min(cmd2.find_first_not_of(" \t", split), cmd2.length()));
|
||||
base* cmdh = NULL;
|
||||
{
|
||||
umutex_class lock(int_mutex);
|
||||
threads::alock lock(int_mutex);
|
||||
if(!commands.count(rcmd)) {
|
||||
(*output) << "Unknown command '" << rcmd << "'" << std::endl;
|
||||
return;
|
||||
|
@ -189,7 +189,7 @@ not_alias:
|
|||
|
||||
std::set<std::string> group::get_aliases() throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class lock(int_mutex);
|
||||
threads::alock lock(int_mutex);
|
||||
std::set<std::string> r;
|
||||
for(auto i : aliases)
|
||||
r.insert(i.first);
|
||||
|
@ -198,7 +198,7 @@ std::set<std::string> group::get_aliases() throw(std::bad_alloc)
|
|||
|
||||
std::string group::get_alias_for(const std::string& aname) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class lock(int_mutex);
|
||||
threads::alock lock(int_mutex);
|
||||
if(!valid_alias_name(aname))
|
||||
return "";
|
||||
if(aliases.count(aname)) {
|
||||
|
@ -212,7 +212,7 @@ std::string group::get_alias_for(const std::string& aname) throw(std::bad_alloc)
|
|||
|
||||
void group::set_alias_for(const std::string& aname, const std::string& avalue) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class lock(int_mutex);
|
||||
threads::alock lock(int_mutex);
|
||||
if(!valid_alias_name(aname))
|
||||
return;
|
||||
std::list<std::string> newlist;
|
||||
|
@ -241,7 +241,7 @@ bool group::valid_alias_name(const std::string& aliasname) throw(std::bad_alloc)
|
|||
|
||||
void group::do_register(const std::string& name, base& cmd) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class lock(int_mutex);
|
||||
threads::alock lock(int_mutex);
|
||||
if(commands.count(name))
|
||||
std::cerr << "WARNING: Command collision for " << name << "!" << std::endl;
|
||||
commands[name] = &cmd;
|
||||
|
@ -249,7 +249,7 @@ void group::do_register(const std::string& name, base& cmd) throw(std::bad_alloc
|
|||
|
||||
void group::do_unregister(const std::string& name, base* dummy) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class lock(int_mutex);
|
||||
threads::alock lock(int_mutex);
|
||||
commands.erase(name);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "controller-data.hpp"
|
||||
#include "threadtypes.hpp"
|
||||
#include "threads.hpp"
|
||||
#include "minmax.hpp"
|
||||
#include "globalwrap.hpp"
|
||||
#include "serialization.hpp"
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
namespace dispatch
|
||||
{
|
||||
mutex_class& global_init_lock()
|
||||
threads::lock& global_init_lock()
|
||||
{
|
||||
static mutex_class m;
|
||||
static threads::lock m;
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,31 +10,31 @@ emulator_status::~emulator_status() throw()
|
|||
|
||||
void emulator_status::set(const std::string& key, const std::string& value) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class h(lock);
|
||||
threads::alock h(lock);
|
||||
content[key] = utf8::to32(value);
|
||||
}
|
||||
|
||||
void emulator_status::set(const std::string& key, const std::u32string& value) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class h(lock);
|
||||
threads::alock h(lock);
|
||||
content[key] = value;
|
||||
}
|
||||
|
||||
bool emulator_status::haskey(const std::string& key) throw()
|
||||
{
|
||||
umutex_class h(lock);
|
||||
threads::alock h(lock);
|
||||
return (content.count(key) != 0);
|
||||
}
|
||||
|
||||
void emulator_status::erase(const std::string& key) throw()
|
||||
{
|
||||
umutex_class h(lock);
|
||||
threads::alock h(lock);
|
||||
content.erase(key);
|
||||
}
|
||||
|
||||
std::u32string emulator_status::get(const std::string& key) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class h(lock);
|
||||
threads::alock h(lock);
|
||||
return content[key];
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ emulator_status::iterator emulator_status::first() throw(std::bad_alloc)
|
|||
|
||||
bool emulator_status::next(iterator& itr) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class h(lock);
|
||||
threads::alock h(lock);
|
||||
std::map<std::string, std::u32string>::iterator j;
|
||||
if(itr.not_valid)
|
||||
j = content.lower_bound("");
|
||||
|
|
|
@ -13,12 +13,12 @@ namespace
|
|||
{
|
||||
std::map<std::string, std::pair<time_t, std::string>> cached_entries;
|
||||
|
||||
mutex_class& global_queue_mutex()
|
||||
threads::lock& global_queue_mutex()
|
||||
{
|
||||
static bool init = false;
|
||||
static mutex_class* m;
|
||||
static threads::lock* m;
|
||||
if(!init)
|
||||
m = new mutex_class();
|
||||
m = new threads::lock();
|
||||
init = true;
|
||||
return *m;
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ hashval::hashval(const std::string& _value, uint64_t _prefix)
|
|||
|
||||
hashval::hashval(hash& h, unsigned id)
|
||||
{
|
||||
umutex_class h2(global_queue_mutex());
|
||||
threads::alock h2(global_queue_mutex());
|
||||
is_ready = false;
|
||||
cbid = id;
|
||||
prev = next = NULL;
|
||||
|
@ -130,21 +130,21 @@ hashval::hashval(hash& h, unsigned id)
|
|||
|
||||
hashval::~hashval()
|
||||
{
|
||||
umutex_class h2(global_queue_mutex());
|
||||
umutex_class h(mutex);
|
||||
threads::alock h2(global_queue_mutex());
|
||||
threads::alock h(mlock);
|
||||
if(hasher)
|
||||
hasher->unlink(*this);
|
||||
}
|
||||
|
||||
bool hashval::ready() const
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
return is_ready;
|
||||
}
|
||||
|
||||
std::string hashval::read() const
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
while(!is_ready)
|
||||
condition.wait(h);
|
||||
if(error != "")
|
||||
|
@ -154,7 +154,7 @@ std::string hashval::read() const
|
|||
|
||||
uint64_t hashval::prefix() const
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
while(!is_ready)
|
||||
condition.wait(h);
|
||||
if(error != "")
|
||||
|
@ -164,8 +164,8 @@ uint64_t hashval::prefix() const
|
|||
|
||||
hashval::hashval(const hashval& f)
|
||||
{
|
||||
umutex_class h2(global_queue_mutex());
|
||||
umutex_class h(f.mutex);
|
||||
threads::alock h2(global_queue_mutex());
|
||||
threads::alock h(f.mlock);
|
||||
is_ready = f.is_ready;
|
||||
cbid = f.cbid;
|
||||
value = f.value;
|
||||
|
@ -181,13 +181,13 @@ hashval& hashval::operator=(const hashval& f)
|
|||
{
|
||||
if(this == &f)
|
||||
return *this;
|
||||
umutex_class h2(global_queue_mutex());
|
||||
threads::alock h2(global_queue_mutex());
|
||||
if((size_t)this < (size_t)&f) {
|
||||
mutex.lock();
|
||||
f.mutex.lock();
|
||||
mlock.lock();
|
||||
f.mlock.lock();
|
||||
} else {
|
||||
f.mutex.lock();
|
||||
mutex.lock();
|
||||
f.mlock.lock();
|
||||
mlock.lock();
|
||||
}
|
||||
|
||||
if(!is_ready && hasher)
|
||||
|
@ -201,13 +201,13 @@ hashval& hashval::operator=(const hashval& f)
|
|||
hasher = f.hasher;
|
||||
if(!is_ready && hasher)
|
||||
hasher->link(*this);
|
||||
mutex.unlock();
|
||||
f.mutex.unlock();
|
||||
mlock.unlock();
|
||||
f.mlock.unlock();
|
||||
}
|
||||
|
||||
void hashval::resolve(unsigned id, const std::string& hash, uint64_t _prefix)
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
hasher->unlink(*this);
|
||||
if(id != cbid)
|
||||
return;
|
||||
|
@ -219,7 +219,7 @@ void hashval::resolve(unsigned id, const std::string& hash, uint64_t _prefix)
|
|||
|
||||
void hashval::resolve_error(unsigned id, const std::string& err)
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
hasher->unlink(*this);
|
||||
if(id != cbid)
|
||||
return;
|
||||
|
@ -233,7 +233,7 @@ void hash::link(hashval& future)
|
|||
{
|
||||
//We assume caller holds global queue lock.
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
unsigned cbid = future.cbid;
|
||||
for(auto& i : queue)
|
||||
if(i.cbid == cbid)
|
||||
|
@ -252,7 +252,7 @@ void hash::unlink(hashval& future)
|
|||
{
|
||||
//We assume caller holds global queue lock.
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
unsigned cbid = future.cbid;
|
||||
for(auto& i : queue)
|
||||
if(i.cbid == cbid)
|
||||
|
@ -278,7 +278,7 @@ hashval hash::operator()(const std::string& filename, uint64_t prefixlen)
|
|||
j.interested = 1;
|
||||
hashval future(*this, j.cbid);
|
||||
queue.push_back(j);
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
total_work += j.size;
|
||||
work_size += j.size;
|
||||
condition.notify_all();
|
||||
|
@ -295,7 +295,7 @@ hashval hash::operator()(const std::string& filename, std::function<uint64_t(uin
|
|||
j.interested = 1;
|
||||
hashval future(*this, j.cbid);
|
||||
queue.push_back(j);
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
total_work += j.size;
|
||||
work_size += j.size;
|
||||
condition.notify_all();
|
||||
|
@ -304,7 +304,7 @@ hashval hash::operator()(const std::string& filename, std::function<uint64_t(uin
|
|||
|
||||
void hash::set_callback(std::function<void(uint64_t, uint64_t)> cb)
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
progresscb = cb;
|
||||
}
|
||||
|
||||
|
@ -317,19 +317,19 @@ hash::hash()
|
|||
total_work = 0;
|
||||
work_size = 0;
|
||||
progresscb = [](uint64_t x, uint64_t y) -> void {};
|
||||
hash_thread = new thread_class(thread_trampoline, this);
|
||||
hash_thread = new threads::thread(thread_trampoline, this);
|
||||
}
|
||||
|
||||
hash::~hash()
|
||||
{
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
quitting = true;
|
||||
condition.notify_all();
|
||||
}
|
||||
hash_thread->join();
|
||||
delete hash_thread;
|
||||
umutex_class h2(global_queue_mutex());
|
||||
threads::alock h2(global_queue_mutex());
|
||||
while(first_future)
|
||||
first_future->resolve_error(first_future->cbid, "Hasher deleted");
|
||||
}
|
||||
|
@ -340,7 +340,7 @@ void hash::entrypoint()
|
|||
while(true) {
|
||||
//Wait for work or quit signal.
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
while(!quitting && queue.empty()) {
|
||||
send_idle();
|
||||
condition.wait(h);
|
||||
|
@ -357,14 +357,14 @@ void hash::entrypoint()
|
|||
fp = NULL;
|
||||
cached_hash = lookup_cache(current_job->filename, current_job->prefix);
|
||||
if(cached_hash != "") {
|
||||
umutex_class h2(global_queue_mutex());
|
||||
threads::alock h2(global_queue_mutex());
|
||||
for(hashval* fut = first_future; fut != NULL; fut = fut->next)
|
||||
fut->resolve(current_job->cbid, cached_hash, current_job->prefix);
|
||||
goto finished;
|
||||
}
|
||||
fp = fopen(current_job->filename.c_str(), "rb");
|
||||
if(!fp) {
|
||||
umutex_class h2(global_queue_mutex());
|
||||
threads::alock h2(global_queue_mutex());
|
||||
for(hashval* fut = first_future; fut != NULL; fut = fut->next)
|
||||
fut->resolve_error(current_job->cbid, "Can't open file");
|
||||
} else {
|
||||
|
@ -372,7 +372,7 @@ void hash::entrypoint()
|
|||
uint64_t toskip = current_job->prefix;
|
||||
while(!feof(fp) && !ferror(fp)) {
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
if(!current_job->interested)
|
||||
goto finished; //Aborted.
|
||||
}
|
||||
|
@ -387,12 +387,12 @@ void hash::entrypoint()
|
|||
send_callback(progress);
|
||||
}
|
||||
if(ferror(fp)) {
|
||||
umutex_class h2(global_queue_mutex());
|
||||
threads::alock h2(global_queue_mutex());
|
||||
for(hashval* fut = first_future; fut != NULL; fut = fut->next)
|
||||
fut->resolve_error(current_job->cbid, "Can't read file");
|
||||
} else {
|
||||
std::string hval = hash.read();
|
||||
umutex_class h2(global_queue_mutex());
|
||||
threads::alock h2(global_queue_mutex());
|
||||
for(hashval* fut = first_future; fut != NULL; fut = fut->next)
|
||||
fut->resolve(current_job->cbid, hval, current_job->prefix);
|
||||
store_cache(current_job->filename, current_job->prefix, hval);
|
||||
|
@ -402,7 +402,7 @@ finished:
|
|||
if(fp) fclose(fp);
|
||||
//Okay, this work item is complete.
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
total_work -= current_job->size;
|
||||
queue.erase(current_job);
|
||||
}
|
||||
|
@ -414,7 +414,7 @@ void hash::send_callback(uint64_t this_completed)
|
|||
{
|
||||
uint64_t amount;
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
if(this_completed > total_work)
|
||||
amount = 0;
|
||||
else
|
||||
|
|
|
@ -291,41 +291,41 @@ filesystem::ref& filesystem::ref::operator=(const filesystem::ref& r)
|
|||
//This is tricky, due to having to lock two objects.
|
||||
size_t A = (size_t)this;
|
||||
size_t B = (size_t)&r;
|
||||
mutex_class* mtodelete = NULL;
|
||||
threads::lock* mtodelete = NULL;
|
||||
if(!refcnt) {
|
||||
//We just have to grab a ref and copy.
|
||||
umutex_class m(*r.mutex);
|
||||
threads::alock m(*r.mlock);
|
||||
++*(r.refcnt);
|
||||
refcnt = r.refcnt;
|
||||
mutex = r.mutex;
|
||||
mlock = r.mlock;
|
||||
fs = r.fs;
|
||||
} else if(A < B) {
|
||||
//Two-object case.
|
||||
umutex_class m1(*mutex);
|
||||
umutex_class m2(*r.mutex);
|
||||
threads::alock m1(*mlock);
|
||||
threads::alock m2(*r.mlock);
|
||||
--*refcnt;
|
||||
if(!*refcnt) {
|
||||
delete fs;
|
||||
delete refcnt;
|
||||
mtodelete = mutex;;
|
||||
mtodelete = mlock;
|
||||
}
|
||||
++*(r.refcnt);
|
||||
refcnt = r.refcnt;
|
||||
mutex = r.mutex;
|
||||
mlock = r.mlock;
|
||||
fs = r.fs;
|
||||
} else {
|
||||
//Two-object case.
|
||||
umutex_class m1(*r.mutex);
|
||||
umutex_class m2(*mutex);
|
||||
threads::alock m1(*r.mlock);
|
||||
threads::alock m2(*mlock);
|
||||
--*refcnt;
|
||||
if(!*refcnt) {
|
||||
delete fs;
|
||||
delete refcnt;
|
||||
mtodelete = mutex;;
|
||||
mtodelete = mlock;
|
||||
}
|
||||
++*(r.refcnt);
|
||||
refcnt = r.refcnt;
|
||||
mutex = r.mutex;
|
||||
mlock = r.mlock;
|
||||
fs = r.fs;
|
||||
}
|
||||
if(mtodelete)
|
||||
|
|
|
@ -98,7 +98,7 @@ void pad::set_online(bool status)
|
|||
std::list<unsigned> buttons_off;
|
||||
std::list<unsigned> hats_off;
|
||||
{
|
||||
umutex_class H(mutex);
|
||||
threads::alock H(mlock);
|
||||
if(status)
|
||||
online_flag = status;
|
||||
else {
|
||||
|
@ -134,7 +134,7 @@ unsigned pad::add_axis(uint64_t id, int64_t _min, int64_t _max, bool pressure, c
|
|||
{
|
||||
axis_info a;
|
||||
{
|
||||
umutex_class H(mutex);
|
||||
threads::alock H(mlock);
|
||||
if(_axes.count(id)) {
|
||||
_axes[id].name = xname;
|
||||
_axes[id].online = true;
|
||||
|
@ -163,7 +163,7 @@ unsigned pad::add_button(uint64_t id, const std::string& xname)
|
|||
{
|
||||
button_info b;
|
||||
{
|
||||
umutex_class H(mutex);
|
||||
threads::alock H(mlock);
|
||||
if(_buttons.count(id)) {
|
||||
_buttons[id].name = xname;
|
||||
_buttons[id].online = true;
|
||||
|
@ -184,7 +184,7 @@ unsigned pad::add_hat(uint64_t id, const std::string& xname)
|
|||
{
|
||||
hat_info h;
|
||||
{
|
||||
umutex_class H(mutex);
|
||||
threads::alock H(mlock);
|
||||
if(_hats.count(id)) {
|
||||
_hats[id].name = xname;
|
||||
_hats[id].online = true;
|
||||
|
@ -208,7 +208,7 @@ unsigned pad::add_hat(uint64_t idx, uint64_t idy, int64_t mindev, const std::str
|
|||
{
|
||||
hat_info h;
|
||||
{
|
||||
umutex_class H(mutex);
|
||||
threads::alock H(mlock);
|
||||
if(_axes_hat.count(idx)) {
|
||||
_axes_hat[idx]->name = xnamex;
|
||||
_axes_hat[idy]->name2 = xnamey;
|
||||
|
@ -231,7 +231,7 @@ unsigned pad::add_hat(uint64_t idx, uint64_t idy, int64_t mindev, const std::str
|
|||
|
||||
void pad::report_axis(uint64_t id, int64_t val)
|
||||
{
|
||||
mutex.lock();
|
||||
mlock.lock();
|
||||
if(_axes.count(id)) {
|
||||
axis_info& i = _axes[id];
|
||||
int16_t val2 = map_value(val, i.minus, i.zero, i.plus, i.neutral, i.pressure);
|
||||
|
@ -240,7 +240,7 @@ void pad::report_axis(uint64_t id, int64_t val)
|
|||
i.rstate = val;
|
||||
int16_t nstate = i.state;
|
||||
unsigned inum = i.num;
|
||||
mutex.unlock();
|
||||
mlock.unlock();
|
||||
if(ostate != nstate)
|
||||
axis_fn(jid, inum, nstate);
|
||||
} else if(_axes_hat.count(id)) {
|
||||
|
@ -254,18 +254,18 @@ void pad::report_axis(uint64_t id, int64_t val)
|
|||
if(is_y) { i.state = (val >= i.mindev) ? (i.state | 0x4) : (i.state & 0xB); }
|
||||
int16_t nstate = i.state;
|
||||
unsigned inum = i.num;
|
||||
mutex.unlock();
|
||||
mlock.unlock();
|
||||
if(ostate != nstate)
|
||||
hat_fn(jid, inum, nstate);
|
||||
} else
|
||||
mutex.unlock();
|
||||
mlock.unlock();
|
||||
}
|
||||
|
||||
void pad::report_button(uint64_t id, bool val)
|
||||
{
|
||||
mutex.lock();
|
||||
mlock.lock();
|
||||
if(!_buttons.count(id)) {
|
||||
mutex.unlock();
|
||||
mlock.unlock();
|
||||
return;
|
||||
}
|
||||
button_info& i = _buttons[id];
|
||||
|
@ -273,17 +273,17 @@ void pad::report_button(uint64_t id, bool val)
|
|||
i.state = val;
|
||||
int16_t nstate = i.state;
|
||||
unsigned inum = i.num;
|
||||
mutex.unlock();
|
||||
mlock.unlock();
|
||||
if(ostate != nstate)
|
||||
button_fn(jid, inum, nstate);
|
||||
}
|
||||
|
||||
void pad::report_hat(uint64_t id, int angle)
|
||||
{
|
||||
mutex.lock();
|
||||
mlock.lock();
|
||||
unsigned h = angle_to_bitmask(angle);
|
||||
if(!_hats.count(id)) {
|
||||
mutex.unlock();
|
||||
mlock.unlock();
|
||||
return;
|
||||
}
|
||||
hat_info& i = _hats[id];
|
||||
|
@ -291,14 +291,14 @@ void pad::report_hat(uint64_t id, int angle)
|
|||
i.state = h;
|
||||
int16_t nstate = i.state;
|
||||
unsigned inum = i.num;
|
||||
mutex.unlock();
|
||||
mlock.unlock();
|
||||
if(ostate != nstate)
|
||||
hat_fn(jid, inum, nstate);
|
||||
}
|
||||
|
||||
std::set<unsigned> pad::online_axes()
|
||||
{
|
||||
umutex_class H(mutex);
|
||||
threads::alock H(mlock);
|
||||
std::set<unsigned> r;
|
||||
for(auto i : _axes)
|
||||
if(i.second.online) r.insert(i.second.num);
|
||||
|
@ -307,7 +307,7 @@ std::set<unsigned> pad::online_axes()
|
|||
|
||||
std::set<unsigned> pad::online_buttons()
|
||||
{
|
||||
umutex_class H(mutex);
|
||||
threads::alock H(mlock);
|
||||
std::set<unsigned> r;
|
||||
for(auto i : _buttons)
|
||||
if(i.second.online) r.insert(i.second.num);
|
||||
|
@ -316,7 +316,7 @@ std::set<unsigned> pad::online_buttons()
|
|||
|
||||
std::set<unsigned> pad::online_hats()
|
||||
{
|
||||
umutex_class H(mutex);
|
||||
threads::alock H(mlock);
|
||||
std::set<unsigned> r;
|
||||
for(auto i : _hats)
|
||||
if(i.second.online) r.insert(i.second.num);
|
||||
|
@ -329,7 +329,7 @@ void pad::load(const JSON::node& state)
|
|||
{
|
||||
std::list<std::pair<unsigned, int>> notify_queue;
|
||||
{
|
||||
umutex_class H(mutex);
|
||||
threads::alock H(mlock);
|
||||
_name = state["name"].as_string8();
|
||||
const JSON::node& hat_data = state["hats"];
|
||||
|
||||
|
@ -409,7 +409,7 @@ void pad::load(const JSON::node& state)
|
|||
void pad::calibrate_axis(unsigned num, int64_t minus, int64_t zero, int64_t plus, int64_t neutral,
|
||||
double threshold, bool pressure, bool disabled)
|
||||
{
|
||||
mutex.lock();
|
||||
mlock.lock();
|
||||
for(auto& i : _axes) {
|
||||
if(i.second.num != num)
|
||||
continue;
|
||||
|
@ -431,21 +431,21 @@ void pad::calibrate_axis(unsigned num, int64_t minus, int64_t zero, int64_t plus
|
|||
if(a.state != 0)
|
||||
a.state = 0;
|
||||
}
|
||||
mutex.unlock();
|
||||
mlock.unlock();
|
||||
if(oldmode >= 0 && newmode < 0)
|
||||
try { axis_fn(jid, num, 0); } catch(...) {}
|
||||
if(oldmode != newmode || oldtolerance != newtreshold)
|
||||
try { amode_fn(jid, num, newmode, newtreshold); } catch(...) {}
|
||||
return;
|
||||
}
|
||||
mutex.unlock();
|
||||
mlock.unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
void pad::get_calibration(unsigned num, int64_t& minus, int64_t& zero, int64_t& plus, int64_t& neutral,
|
||||
double& threshold, bool& pressure, bool& disabled)
|
||||
{
|
||||
umutex_class H(mutex);
|
||||
threads::alock H(mlock);
|
||||
for(auto& i : _axes) {
|
||||
if(i.second.num != num)
|
||||
continue;
|
||||
|
@ -462,7 +462,7 @@ void pad::get_calibration(unsigned num, int64_t& minus, int64_t& zero, int64_t&
|
|||
|
||||
double pad::get_tolerance(unsigned num)
|
||||
{
|
||||
umutex_class H(mutex);
|
||||
threads::alock H(mlock);
|
||||
for(auto& i : _axes) {
|
||||
if(i.second.num != num)
|
||||
continue;
|
||||
|
@ -473,7 +473,7 @@ double pad::get_tolerance(unsigned num)
|
|||
|
||||
int pad::get_mode(unsigned num)
|
||||
{
|
||||
umutex_class H(mutex);
|
||||
threads::alock H(mlock);
|
||||
for(auto& i : _axes) {
|
||||
if(i.second.num != num)
|
||||
continue;
|
||||
|
@ -484,7 +484,7 @@ int pad::get_mode(unsigned num)
|
|||
|
||||
void pad::axis_status(unsigned num, int64_t& raw, int16_t& pct)
|
||||
{
|
||||
umutex_class H(mutex);
|
||||
threads::alock H(mlock);
|
||||
for(auto& i : _axes) {
|
||||
if(i.second.num != num || !i.second.online)
|
||||
continue;
|
||||
|
@ -501,7 +501,7 @@ void pad::axis_status(unsigned num, int64_t& raw, int16_t& pct)
|
|||
|
||||
int pad::button_status(unsigned num)
|
||||
{
|
||||
umutex_class H(mutex);
|
||||
threads::alock H(mlock);
|
||||
for(auto& i : _buttons) {
|
||||
if(i.second.num != num || !i.second.online)
|
||||
continue;
|
||||
|
@ -512,7 +512,7 @@ int pad::button_status(unsigned num)
|
|||
|
||||
int pad::hat_status(unsigned num)
|
||||
{
|
||||
umutex_class H(mutex);
|
||||
threads::alock H(mlock);
|
||||
for(auto& i : _hats) {
|
||||
if(i.second.num != num || !i.second.online)
|
||||
continue;
|
||||
|
@ -528,7 +528,7 @@ int pad::hat_status(unsigned num)
|
|||
|
||||
JSON::node pad::save()
|
||||
{
|
||||
umutex_class H(mutex);
|
||||
threads::alock H(mlock);
|
||||
JSON::node r(JSON::object);
|
||||
r.insert("name", JSON::string(_name));
|
||||
|
||||
|
@ -588,7 +588,7 @@ JSON::node pad::save()
|
|||
|
||||
std::string pad::get_summary()
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
std::ostringstream x;
|
||||
x << "joystick" << jid << ": " << _name << " " << (online_flag ? "" : " [Offline]") << std::endl;
|
||||
for(auto i : _axes) {
|
||||
|
@ -642,7 +642,7 @@ set::~set()
|
|||
void set::load(const JSON::node& state)
|
||||
{
|
||||
bool locked = true;
|
||||
mutex.lock();
|
||||
mlock.lock();
|
||||
for(auto i : _gamepads)
|
||||
delete i;
|
||||
_gamepads.clear();
|
||||
|
@ -660,23 +660,23 @@ void set::load(const JSON::node& state)
|
|||
gp->set_newitem_cb(newitem_fn);
|
||||
_gamepads.push_back(gp);
|
||||
locked = false;
|
||||
mutex.unlock();
|
||||
mlock.unlock();
|
||||
gp->load(gpn);
|
||||
mutex.lock();
|
||||
mlock.lock();
|
||||
locked = true;
|
||||
} catch(std::runtime_error& e) {
|
||||
std::cerr << "Can't load gamepad #" << i << " configuration: " << e.what() << std::endl;
|
||||
if(!locked)
|
||||
mutex.lock();
|
||||
mlock.lock();
|
||||
delete gp;
|
||||
}
|
||||
}
|
||||
mutex.unlock();
|
||||
mlock.unlock();
|
||||
}
|
||||
|
||||
JSON::node set::save()
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
JSON::node n(JSON::array);
|
||||
for(auto i : _gamepads)
|
||||
n.append(i->save());
|
||||
|
@ -685,13 +685,13 @@ JSON::node set::save()
|
|||
|
||||
unsigned set::gamepads()
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
return _gamepads.size();
|
||||
}
|
||||
|
||||
pad& set::operator[](unsigned gpnum)
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
if(gpnum >= _gamepads.size())
|
||||
throw std::runtime_error("Invalid gamepad index");
|
||||
return *_gamepads[gpnum];
|
||||
|
@ -699,7 +699,7 @@ pad& set::operator[](unsigned gpnum)
|
|||
|
||||
unsigned set::add(const std::string& name)
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
for(size_t i = 0; i < _gamepads.size(); i++) {
|
||||
if(!_gamepads[i]->online() && _gamepads[i]->name() == name) {
|
||||
_gamepads[i]->set_online(true);
|
||||
|
@ -725,7 +725,7 @@ unsigned set::add(const std::string& name)
|
|||
|
||||
void set::set_axis_cb(std::function<void(unsigned jnum, unsigned num, int16_t val)> fn)
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
axis_fn = fn;
|
||||
for(auto i : _gamepads)
|
||||
i->set_axis_cb(axis_fn);
|
||||
|
@ -733,7 +733,7 @@ void set::set_axis_cb(std::function<void(unsigned jnum, unsigned num, int16_t va
|
|||
|
||||
void set::set_button_cb(std::function<void(unsigned jnum, unsigned num, bool val)> fn)
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
button_fn = fn;
|
||||
for(auto i : _gamepads)
|
||||
i->set_button_cb(button_fn);
|
||||
|
@ -741,7 +741,7 @@ void set::set_button_cb(std::function<void(unsigned jnum, unsigned num, bool val
|
|||
|
||||
void set::set_hat_cb(std::function<void(unsigned jnum, unsigned num, unsigned val)> fn)
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
hat_fn = fn;
|
||||
for(auto i : _gamepads)
|
||||
i->set_hat_cb(hat_fn);
|
||||
|
@ -749,7 +749,7 @@ void set::set_hat_cb(std::function<void(unsigned jnum, unsigned num, unsigned va
|
|||
|
||||
void set::set_axismode_cb(std::function<void(unsigned jnum, unsigned num, int mode, double tolerance)> fn)
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
amode_fn = fn;
|
||||
for(auto i : _gamepads)
|
||||
i->set_axismode_cb(amode_fn);
|
||||
|
@ -757,7 +757,7 @@ void set::set_axismode_cb(std::function<void(unsigned jnum, unsigned num, int mo
|
|||
|
||||
void set::set_newitem_cb(std::function<void(unsigned jnum, unsigned num, int type)> fn)
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
newitem_fn = fn;
|
||||
for(auto i : _gamepads)
|
||||
i->set_newitem_cb(newitem_fn);
|
||||
|
@ -765,7 +765,7 @@ void set::set_newitem_cb(std::function<void(unsigned jnum, unsigned num, int typ
|
|||
|
||||
std::string set::get_summary()
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
std::ostringstream x;
|
||||
for(auto i : _gamepads)
|
||||
x << i->get_summary();
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "httpauth.hpp"
|
||||
#include "string.hpp"
|
||||
#include "minmax.hpp"
|
||||
#include "threadtypes.hpp"
|
||||
#include "threads.hpp"
|
||||
#include "streamcompress.hpp"
|
||||
#include <curl/curl.h>
|
||||
#include <cstring>
|
||||
|
@ -230,7 +230,7 @@ http_async_request::http_async_request()
|
|||
|
||||
void http_async_request::get_xfer_status(int64_t& dnow, int64_t& dtotal, int64_t& unow, int64_t& utotal)
|
||||
{
|
||||
umutex_class h(m);
|
||||
threads::alock h(m);
|
||||
if(req) {
|
||||
req->get_xfer_status(dnow, dtotal, unow, utotal);
|
||||
} else {
|
||||
|
@ -246,7 +246,7 @@ namespace
|
|||
try {
|
||||
r->req->do_transfer(r->ihandler, r->ohandler);
|
||||
} catch(std::exception& e) {
|
||||
umutex_class h(r->m);
|
||||
threads::alock h(r->m);
|
||||
r->finished_cond.notify_all();
|
||||
r->finished = true;
|
||||
delete r->req;
|
||||
|
@ -255,7 +255,7 @@ namespace
|
|||
return;
|
||||
}
|
||||
int64_t tmp1, tmp2;
|
||||
umutex_class h(r->m);
|
||||
threads::alock h(r->m);
|
||||
r->http_code = r->req->get_http_code();
|
||||
r->req->get_xfer_status(r->final_dl, tmp1, r->final_ul, tmp2);
|
||||
r->finished_cond.notify_all();
|
||||
|
@ -269,13 +269,13 @@ void http_async_request::lauch_async()
|
|||
{
|
||||
try {
|
||||
{
|
||||
umutex_class h(m);
|
||||
threads::alock h(m);
|
||||
req = new http_request(verb, url);
|
||||
if(authorization != "") req->set_authorization(authorization);
|
||||
}
|
||||
(new thread_class(async_http_trampoline, this))->detach();
|
||||
(new threads::thread(async_http_trampoline, this))->detach();
|
||||
} catch(std::exception& e) {
|
||||
umutex_class h(m);
|
||||
threads::alock h(m);
|
||||
finished_cond.notify_all();
|
||||
finished = true;
|
||||
delete req;
|
||||
|
|
|
@ -69,7 +69,7 @@ bool keyspec::operator!=(const keyspec& keyspec)
|
|||
|
||||
std::set<invbind*> mapper::get_inverses() throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
std::set<invbind*> r;
|
||||
for(auto i : ibinds)
|
||||
r.insert(i.second);
|
||||
|
@ -78,7 +78,7 @@ std::set<invbind*> mapper::get_inverses() throw(std::bad_alloc)
|
|||
|
||||
invbind* mapper::get_inverse(const std::string& command) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
if(ibinds.count(command))
|
||||
return ibinds[command];
|
||||
else
|
||||
|
@ -87,7 +87,7 @@ invbind* mapper::get_inverse(const std::string& command) throw(std::bad_alloc)
|
|||
|
||||
std::set<ctrlrkey*> mapper::get_controller_keys() throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
std::set<ctrlrkey*> r;
|
||||
for(auto i : ckeys)
|
||||
r.insert(i.second);
|
||||
|
@ -96,7 +96,7 @@ std::set<ctrlrkey*> mapper::get_controller_keys() throw(std::bad_alloc)
|
|||
|
||||
ctrlrkey* mapper::get_controllerkey(const std::string& command) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
if(ckeys.count(command))
|
||||
return ckeys[command];
|
||||
else
|
||||
|
@ -105,31 +105,31 @@ ctrlrkey* mapper::get_controllerkey(const std::string& command) throw(std::bad_a
|
|||
|
||||
void mapper::do_register(const std::string& name, invbind& ibind) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
ibinds[name] = &ibind;
|
||||
//Search for matches.
|
||||
for(auto i : bindings)
|
||||
if(i.second == ibind.cmd) {
|
||||
umutex_class u2(ibind.mutex);
|
||||
threads::alock u2(ibind.mlock);
|
||||
ibind.specs.push_back(i.first.as_keyspec());
|
||||
}
|
||||
}
|
||||
|
||||
void mapper::do_unregister(const std::string& name, invbind* dummy) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
ibinds.erase(name);
|
||||
}
|
||||
|
||||
void mapper::do_register(const std::string& name, ctrlrkey& ckey) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
ckeys[name] = &ckey;
|
||||
}
|
||||
|
||||
void mapper::do_unregister(const std::string& name, ctrlrkey* dummy) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
ckeys.erase(name);
|
||||
}
|
||||
|
||||
|
@ -223,7 +223,7 @@ keyspec mapper::triplet::as_keyspec() const throw(std::bad_alloc)
|
|||
|
||||
std::list<keyspec> mapper::get_bindings() throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
std::list<keyspec> r;
|
||||
for(auto i : bindings)
|
||||
r.push_back(i.first.as_keyspec());
|
||||
|
@ -243,7 +243,7 @@ void mapper::bind(std::string mod, std::string modmask, std::string keyname, std
|
|||
spec.mask = modmask;
|
||||
spec.key = keyname;
|
||||
triplet t(kbd, spec);
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
if(bindings.count(t))
|
||||
throw std::runtime_error("Key is already bound");
|
||||
if(!listening.count(t._key)) {
|
||||
|
@ -265,7 +265,7 @@ void mapper::unbind(std::string mod, std::string modmask, std::string keyname) t
|
|||
spec.mask = modmask;
|
||||
spec.key = keyname;
|
||||
triplet t(kbd, spec);
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
if(!bindings.count(t))
|
||||
throw std::runtime_error("Key is not bound");
|
||||
//No harm at leaving listeners listening.
|
||||
|
@ -279,7 +279,7 @@ void mapper::unbind(std::string mod, std::string modmask, std::string keyname) t
|
|||
std::string mapper::get(const keyspec& keyspec) throw(std::bad_alloc)
|
||||
{
|
||||
triplet t(kbd, keyspec);
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
if(!bindings.count(t))
|
||||
return "";
|
||||
return bindings[t];
|
||||
|
@ -290,18 +290,18 @@ void mapper::change_command(const keyspec& spec, const std::string& old, const s
|
|||
if(old != "" && ibinds.count(old)) {
|
||||
auto& i = ibinds[old];
|
||||
{
|
||||
umutex_class u2(i->mutex);
|
||||
threads::alock u2(i->mlock);
|
||||
i->specs.clear();
|
||||
}
|
||||
for(auto j : bindings)
|
||||
if(j.second == i->cmd && j.first.as_keyspec() != spec) {
|
||||
umutex_class u2(i->mutex);
|
||||
threads::alock u2(i->mlock);
|
||||
i->specs.push_back(j.first.as_keyspec());
|
||||
}
|
||||
}
|
||||
if(newc != "" && ibinds.count(newc)) {
|
||||
auto& i = ibinds[newc];
|
||||
umutex_class u2(i->mutex);
|
||||
threads::alock u2(i->mlock);
|
||||
i->specs.push_back(spec);
|
||||
}
|
||||
}
|
||||
|
@ -310,7 +310,7 @@ void mapper::set(const keyspec& keyspec, const std::string& cmd) throw(std::bad_
|
|||
std::runtime_error)
|
||||
{
|
||||
triplet t(kbd, keyspec);
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
if(!listening.count(t._key)) {
|
||||
t._key->add_listener(*this, false);
|
||||
listening.insert(t._key);
|
||||
|
@ -366,7 +366,7 @@ mapper::triplet::triplet(keyboard& k, const keyspec& spec)
|
|||
std::list<ctrlrkey*> mapper::get_controllerkeys_kbdkey(key* kbdkey)
|
||||
throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
std::list<ctrlrkey*> r;
|
||||
for(auto i : ckeys) {
|
||||
for(unsigned j = 0;; j++) {
|
||||
|
@ -394,7 +394,7 @@ invbind::~invbind() throw()
|
|||
|
||||
keyspec invbind::get(unsigned index) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
if(index >= specs.size())
|
||||
return keyspec();
|
||||
return specs[index];
|
||||
|
@ -404,7 +404,7 @@ void invbind::clear(unsigned index) throw(std::bad_alloc)
|
|||
{
|
||||
keyspec unbind;
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
if(index >= specs.size())
|
||||
return;
|
||||
unbind = specs[index];
|
||||
|
@ -438,7 +438,7 @@ ctrlrkey::~ctrlrkey() throw()
|
|||
|
||||
std::pair<key*, unsigned> ctrlrkey::get(unsigned index) throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
if(index >= keys.size())
|
||||
return std::make_pair(reinterpret_cast<key*>(NULL), 0);
|
||||
return keys[index];
|
||||
|
@ -457,7 +457,7 @@ std::string ctrlrkey::get_string(unsigned index) throw(std::bad_alloc)
|
|||
|
||||
void ctrlrkey::append(key* _key, unsigned _subkey) throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
//Search for duplicates.
|
||||
std::pair<key*, unsigned> mkey = std::make_pair(_key, _subkey);
|
||||
for(auto i : keys)
|
||||
|
@ -470,7 +470,7 @@ void ctrlrkey::append(key* _key, unsigned _subkey) throw()
|
|||
|
||||
void ctrlrkey::remove(key* _key, unsigned _subkey) throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
std::pair<key*, unsigned> mkey = std::make_pair(_key, _subkey);
|
||||
for(auto i = keys.begin(); i != keys.end(); i++) {
|
||||
if(*i == mkey) {
|
||||
|
|
|
@ -5,13 +5,13 @@ namespace keyboard
|
|||
{
|
||||
void keyboard::do_register(const std::string& name, modifier& mod) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
modifiers[name] = &mod;
|
||||
}
|
||||
|
||||
void keyboard::do_unregister(const std::string& name, modifier* mod) throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
modifiers.erase(name);
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ modifier& keyboard::lookup_modifier(const std::string& name) throw(std::runtime_
|
|||
|
||||
modifier* keyboard::try_lookup_modifier(const std::string& name) throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
if(!modifiers.count(name))
|
||||
return NULL;
|
||||
return modifiers[name];
|
||||
|
@ -33,7 +33,7 @@ modifier* keyboard::try_lookup_modifier(const std::string& name) throw()
|
|||
|
||||
std::list<modifier*> keyboard::all_modifiers() throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
std::list<modifier*> r;
|
||||
for(auto i : modifiers)
|
||||
r.push_back(i.second);
|
||||
|
@ -42,13 +42,13 @@ std::list<modifier*> keyboard::all_modifiers() throw(std::bad_alloc)
|
|||
|
||||
void keyboard::do_register(const std::string& name, key& key) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
keys[name] = &key;
|
||||
}
|
||||
|
||||
void keyboard::do_unregister(const std::string& name, key* dummy) throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
keys.erase(name);
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ key& keyboard::lookup_key(const std::string& name) throw(std::runtime_error)
|
|||
|
||||
key* keyboard::try_lookup_key(const std::string& name) throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
if(!keys.count(name))
|
||||
return NULL;
|
||||
return keys[name];
|
||||
|
@ -70,7 +70,7 @@ key* keyboard::try_lookup_key(const std::string& name) throw()
|
|||
|
||||
std::list<key*> keyboard::all_keys() throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
std::list<key*> r;
|
||||
for(auto i : keys)
|
||||
r.push_back(i.second);
|
||||
|
@ -79,20 +79,20 @@ std::list<key*> keyboard::all_keys() throw(std::bad_alloc)
|
|||
|
||||
void keyboard::set_exclusive(event_listener* listener) throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
for(auto i : keys)
|
||||
i.second->set_exclusive(listener);
|
||||
}
|
||||
|
||||
void keyboard::set_current_key(key* key) throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
current_key = key;
|
||||
}
|
||||
|
||||
key* keyboard::get_current_key() throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
return current_key;
|
||||
}
|
||||
|
||||
|
@ -323,7 +323,7 @@ void key::remove_listener(event_listener& listener) throw()
|
|||
|
||||
void key::set_exclusive(event_listener* listener) throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
exclusive_listener = listener;
|
||||
}
|
||||
|
||||
|
@ -331,9 +331,9 @@ void key::call_listeners(modifier_set& mods, event& event)
|
|||
{
|
||||
kbd.set_current_key(this);
|
||||
bool digital = (event.get_change_mask() & 0xAAAAAAAAUL) != 0;
|
||||
mutex.lock();
|
||||
mlock.lock();
|
||||
if(exclusive_listener) {
|
||||
mutex.unlock();
|
||||
mlock.unlock();
|
||||
exclusive_listener->on_key_event(mods, *this, event);
|
||||
kbd.set_current_key(NULL);
|
||||
return;
|
||||
|
@ -344,9 +344,9 @@ void key::call_listeners(modifier_set& mods, event& event)
|
|||
if(itr2 == digital_listeners.end())
|
||||
break;
|
||||
itr = *itr2;
|
||||
mutex.unlock();
|
||||
mlock.unlock();
|
||||
itr->on_key_event(mods, *this, event);
|
||||
mutex.lock();
|
||||
mlock.lock();
|
||||
}
|
||||
itr = NULL;
|
||||
while(true) {
|
||||
|
@ -354,11 +354,11 @@ void key::call_listeners(modifier_set& mods, event& event)
|
|||
if(itr2 == analog_listeners.end())
|
||||
break;
|
||||
itr = *itr2;
|
||||
mutex.unlock();
|
||||
mlock.unlock();
|
||||
itr->on_key_event(mods, *this, event);
|
||||
mutex.lock();
|
||||
mlock.lock();
|
||||
}
|
||||
mutex.unlock();
|
||||
mlock.unlock();
|
||||
kbd.set_current_key(NULL);
|
||||
}
|
||||
|
||||
|
@ -389,13 +389,13 @@ void key_key::set_state(modifier_set mods, int32_t _state) throw()
|
|||
{
|
||||
uint32_t change = _state ? 1 : 0;
|
||||
bool edge = false;
|
||||
mutex.lock();
|
||||
mlock.lock();
|
||||
if(state != _state) {
|
||||
state = _state;
|
||||
change |= 2;
|
||||
edge = true;
|
||||
}
|
||||
mutex.unlock();
|
||||
mlock.unlock();
|
||||
if(edge) {
|
||||
event_key e(change);
|
||||
call_listeners(mods, e);
|
||||
|
@ -425,7 +425,7 @@ void key_hat::set_state(modifier_set mods, int32_t _state) throw()
|
|||
state &= 15;
|
||||
uint32_t change = 0;
|
||||
bool edge = false;
|
||||
mutex.lock();
|
||||
mlock.lock();
|
||||
if(state != _state) {
|
||||
int32_t schange = state ^ _state;
|
||||
state = _state;
|
||||
|
@ -439,7 +439,7 @@ void key_hat::set_state(modifier_set mods, int32_t _state) throw()
|
|||
if(schange & 8) change |= 128;
|
||||
edge = true;
|
||||
}
|
||||
mutex.unlock();
|
||||
mlock.unlock();
|
||||
if(edge) {
|
||||
event_hat e(change);
|
||||
call_listeners(mods, e);
|
||||
|
@ -472,13 +472,13 @@ key_axis::~key_axis() throw() {}
|
|||
|
||||
int32_t key_axis::get_state() const throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
return rawstate;
|
||||
}
|
||||
|
||||
int32_t key_axis::get_state_digital() const throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
if(rawstate <= -32768 * last_tolerance)
|
||||
return -1;
|
||||
if(rawstate >= 32767 * last_tolerance)
|
||||
|
@ -488,13 +488,13 @@ int32_t key_axis::get_state_digital() const throw()
|
|||
|
||||
int key_axis::get_mode() const throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
return _mode;
|
||||
}
|
||||
|
||||
std::vector<std::string> key_axis::get_subkeys() throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
std::vector<std::string> r;
|
||||
if(_mode == 0)
|
||||
r.push_back("");
|
||||
|
@ -511,7 +511,7 @@ void key_axis::set_state(modifier_set mods, int32_t _rawstate) throw()
|
|||
int32_t state, ostate;
|
||||
uint32_t change = 0;
|
||||
int dold = 0, dnew = 0;
|
||||
mutex.lock();
|
||||
mlock.lock();
|
||||
if(rawstate != _rawstate) {
|
||||
ostate = rawstate;
|
||||
dold = digitalstate;
|
||||
|
@ -532,7 +532,7 @@ void key_axis::set_state(modifier_set mods, int32_t _rawstate) throw()
|
|||
change |= 8;
|
||||
edge = true;
|
||||
}
|
||||
mutex.unlock();
|
||||
mlock.unlock();
|
||||
if(edge) {
|
||||
event_axis e(state, change);
|
||||
call_listeners(mods, e);
|
||||
|
@ -541,7 +541,7 @@ void key_axis::set_state(modifier_set mods, int32_t _rawstate) throw()
|
|||
|
||||
void key_axis::set_mode(int mode, double tolerance) throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
_mode = mode;
|
||||
last_tolerance = tolerance;
|
||||
}
|
||||
|
@ -559,7 +559,7 @@ int32_t key_mouse::get_state_digital() const throw() { return 0; }
|
|||
|
||||
int32_t key_mouse::get_state() const throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
return cal.get_calibrated_value(rawstate);
|
||||
}
|
||||
|
||||
|
@ -570,7 +570,7 @@ std::vector<std::string> key_mouse::get_subkeys() throw(std::bad_alloc)
|
|||
|
||||
mouse_calibration key_mouse::get_calibration() const throw()
|
||||
{
|
||||
umutex_class u(mutex);
|
||||
threads::alock u(mlock);
|
||||
mouse_calibration tmp = cal;
|
||||
return tmp;
|
||||
}
|
||||
|
@ -580,14 +580,14 @@ void key_mouse::set_state(modifier_set mods, int32_t _rawstate) throw()
|
|||
bool edge = false;
|
||||
int32_t state;
|
||||
mouse_calibration _cal;
|
||||
mutex.lock();
|
||||
mlock.lock();
|
||||
if(rawstate != _rawstate) {
|
||||
rawstate = _rawstate;
|
||||
state = cal.get_calibrated_value(rawstate);
|
||||
_cal = cal;
|
||||
edge = true;
|
||||
}
|
||||
mutex.unlock();
|
||||
mlock.unlock();
|
||||
if(edge) {
|
||||
event_mouse e(state, _cal);
|
||||
call_listeners(mods, e);
|
||||
|
@ -596,10 +596,10 @@ void key_mouse::set_state(modifier_set mods, int32_t _rawstate) throw()
|
|||
|
||||
void key_mouse::set_calibration(mouse_calibration _cal) throw()
|
||||
{
|
||||
mutex.lock();
|
||||
mlock.lock();
|
||||
cal = _cal;
|
||||
int32_t state = cal.get_calibrated_value(rawstate);
|
||||
mutex.unlock();
|
||||
mlock.unlock();
|
||||
event_mouse e(state, _cal);
|
||||
modifier_set mods;
|
||||
call_listeners(mods, e);
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
|
||||
namespace loadlib
|
||||
{
|
||||
mutex_class& global_mutex()
|
||||
threads::lock& global_mutex()
|
||||
{
|
||||
static mutex_class m;
|
||||
static threads::lock m;
|
||||
return m;
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ module::module(std::initializer_list<symbol> _symbols, std::function<void(const
|
|||
symbols[i.name] = i.address;
|
||||
init = init_fn;
|
||||
if(init) {
|
||||
umutex_class h(global_mutex());
|
||||
threads::alock h(global_mutex());
|
||||
module_queue().push_back(this);
|
||||
}
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ module::module(library _lib)
|
|||
|
||||
module::~module()
|
||||
{
|
||||
umutex_class h(global_mutex());
|
||||
threads::alock h(global_mutex());
|
||||
for(auto i = module_queue().begin(); i != module_queue().end(); i++) {
|
||||
if(*i == this) {
|
||||
module_queue().erase(i);
|
||||
|
@ -163,7 +163,7 @@ module::module(const module& mod)
|
|||
symbols = mod.symbols;
|
||||
init = mod.init;
|
||||
if(init) {
|
||||
umutex_class h(global_mutex());
|
||||
threads::alock h(global_mutex());
|
||||
module_queue().push_back(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ bool memory_region::write(uint64_t offset, const void* buffer, size_t tsize)
|
|||
|
||||
std::pair<memory_region*, uint64_t> memory_space::lookup(uint64_t address)
|
||||
{
|
||||
umutex_class m(mutex);
|
||||
threads::alock m(mlock);
|
||||
size_t lb = 0;
|
||||
size_t ub = u_regions.size();
|
||||
while(lb < ub) {
|
||||
|
@ -122,7 +122,7 @@ std::pair<memory_region*, uint64_t> memory_space::lookup(uint64_t address)
|
|||
|
||||
std::pair<memory_region*, uint64_t> memory_space::lookup_linear(uint64_t linear)
|
||||
{
|
||||
umutex_class m(mutex);
|
||||
threads::alock m(mlock);
|
||||
if(linear >= linear_size)
|
||||
return std::make_pair(reinterpret_cast<memory_region*>(NULL), 0);
|
||||
size_t lb = 0;
|
||||
|
@ -245,7 +245,7 @@ bool memory_space::write_range_linear(uint64_t address, const void* buffer, size
|
|||
|
||||
memory_region* memory_space::lookup_n(size_t n)
|
||||
{
|
||||
umutex_class m(mutex);
|
||||
threads::alock m(mlock);
|
||||
if(n >= u_regions.size())
|
||||
return NULL;
|
||||
return u_regions[n];
|
||||
|
@ -254,7 +254,7 @@ memory_region* memory_space::lookup_n(size_t n)
|
|||
|
||||
std::list<memory_region*> memory_space::get_regions()
|
||||
{
|
||||
umutex_class m(mutex);
|
||||
threads::alock m(mlock);
|
||||
std::list<memory_region*> r;
|
||||
for(auto i : u_regions)
|
||||
r.push_back(i);
|
||||
|
@ -278,7 +278,7 @@ char* memory_space::get_physical_mapping(uint64_t base, uint64_t size)
|
|||
|
||||
void memory_space::set_regions(const std::list<memory_region*>& regions)
|
||||
{
|
||||
umutex_class m(mutex);
|
||||
threads::alock m(mlock);
|
||||
std::vector<memory_region*> n_regions;
|
||||
std::vector<memory_region*> n_lregions;
|
||||
std::vector<uint64_t> n_linear_bases;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "opus.hpp"
|
||||
#include "loadlib.hpp"
|
||||
#include "threadtypes.hpp"
|
||||
#include "threads.hpp"
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
|
@ -186,7 +186,7 @@ struct functions dummy_functions = {
|
|||
struct functions* opus_functions = &dummy_functions;
|
||||
|
||||
std::map<size_t, std::function<void()>> lcbs;
|
||||
mutex_class mut;
|
||||
threads::lock mut;
|
||||
|
||||
template<typename T> void CA(T& d, void* s)
|
||||
{
|
||||
|
@ -240,7 +240,7 @@ void load_libopus(const loadlib::module& lib)
|
|||
}
|
||||
|
||||
lfun = tmp;
|
||||
umutex_class h(mut);
|
||||
threads::alock h(mut);
|
||||
opus_functions = &lfun;
|
||||
for(auto i : lcbs)
|
||||
(i.second)();
|
||||
|
@ -248,13 +248,13 @@ void load_libopus(const loadlib::module& lib)
|
|||
|
||||
bool libopus_loaded()
|
||||
{
|
||||
umutex_class h(mut);
|
||||
threads::alock h(mut);
|
||||
return (opus_functions != &dummy_functions);
|
||||
}
|
||||
|
||||
size_t add_callback(std::function<void()> fun)
|
||||
{
|
||||
umutex_class h(mut);
|
||||
threads::alock h(mut);
|
||||
static size_t var = 0;
|
||||
size_t hd = 0;
|
||||
if(opus_functions != &dummy_functions)
|
||||
|
@ -266,7 +266,7 @@ size_t add_callback(std::function<void()> fun)
|
|||
|
||||
void cancel_callback(size_t handle)
|
||||
{
|
||||
umutex_class h(mut);
|
||||
threads::alock h(mut);
|
||||
lcbs.erase(handle);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ group::~group() throw()
|
|||
|
||||
std::set<std::string> group::get_settings_set() throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class(lock);
|
||||
threads::alock(lock);
|
||||
std::set<std::string> x;
|
||||
for(auto i : settings)
|
||||
x.insert(i.first);
|
||||
|
@ -33,7 +33,7 @@ std::set<std::string> group::get_settings_set() throw(std::bad_alloc)
|
|||
|
||||
base& group::operator[](const std::string& name)
|
||||
{
|
||||
umutex_class(lock);
|
||||
threads::alock(lock);
|
||||
if(!settings.count(name))
|
||||
throw std::runtime_error("No such setting");
|
||||
return *settings[name];
|
||||
|
@ -43,7 +43,7 @@ void group::fire_listener(base& var) throw()
|
|||
{
|
||||
std::set<listener*> l;
|
||||
{
|
||||
umutex_class h(lock);
|
||||
threads::alock h(lock);
|
||||
for(auto i : listeners)
|
||||
l.insert(i);
|
||||
}
|
||||
|
@ -56,25 +56,25 @@ void group::fire_listener(base& var) throw()
|
|||
|
||||
void group::add_listener(struct listener& listener) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class(lock);
|
||||
threads::alock(lock);
|
||||
listeners.insert(&listener);
|
||||
}
|
||||
|
||||
void group::remove_listener(struct listener& listener) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class(lock);
|
||||
threads::alock(lock);
|
||||
listeners.erase(&listener);
|
||||
}
|
||||
|
||||
void group::do_register(const std::string& name, base& _setting) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class h(lock);
|
||||
threads::alock h(lock);
|
||||
settings[name] = &_setting;
|
||||
}
|
||||
|
||||
void group::do_unregister(const std::string& name, base* dummy) throw(std::bad_alloc)
|
||||
{
|
||||
umutex_class h(lock);
|
||||
threads::alock h(lock);
|
||||
settings.erase(name);
|
||||
}
|
||||
|
||||
|
@ -116,13 +116,13 @@ void cache::set(const std::string& name, const std::string& value, bool allow_in
|
|||
{
|
||||
try {
|
||||
grp[name].str(value);
|
||||
umutex_class h(lock);
|
||||
threads::alock h(lock);
|
||||
badcache.erase(name);
|
||||
} catch(std::bad_alloc& e) {
|
||||
throw;
|
||||
} catch(std::exception& e) {
|
||||
if(allow_invalid) {
|
||||
umutex_class h(lock);
|
||||
threads::alock h(lock);
|
||||
badcache[name] = value;
|
||||
} else
|
||||
throw;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "string.hpp"
|
||||
#include "minmax.hpp"
|
||||
#include "threadtypes.hpp"
|
||||
#include "threads.hpp"
|
||||
#include "eatarg.hpp"
|
||||
#include <cctype>
|
||||
#include <boost/regex.hpp>
|
||||
|
@ -86,8 +86,8 @@ std::pair<size_t, size_t> regex_results::match(size_t i) const
|
|||
regex_results regex(const std::string& regexp, const std::string& str, const char* ex) throw(std::bad_alloc,
|
||||
std::runtime_error)
|
||||
{
|
||||
static mutex_class m;
|
||||
umutex_class h(m);
|
||||
static threads::lock m;
|
||||
threads::alock h(m);
|
||||
static std::map<std::string, map_pointer<boost::regex>> regexps;
|
||||
if(!regexps.count(regexp)) {
|
||||
boost::regex* y = NULL;
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
#include "workthread.hpp"
|
||||
#include <stdexcept>
|
||||
#include <sys/time.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace workthread
|
||||
{
|
||||
const uint32_t quit_request = 0x80000000U;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
@ -12,16 +17,16 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
struct worker_thread_reflector
|
||||
struct reflector
|
||||
{
|
||||
int operator()(worker_thread* x)
|
||||
int operator()(worker* x)
|
||||
{
|
||||
(*x)(42);
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
worker_thread::worker_thread()
|
||||
worker::worker()
|
||||
{
|
||||
thread = NULL;
|
||||
reflector = NULL;
|
||||
|
@ -34,44 +39,44 @@ worker_thread::worker_thread()
|
|||
joined = false;
|
||||
}
|
||||
|
||||
worker_thread::~worker_thread()
|
||||
worker::~worker()
|
||||
{
|
||||
set_workflag(WORKFLAG_QUIT_REQUEST);
|
||||
set_workflag(quit_request);
|
||||
if(!joined && thread)
|
||||
thread->join();
|
||||
delete thread;
|
||||
delete reflector;
|
||||
}
|
||||
|
||||
void worker_thread::request_quit()
|
||||
void worker::request_quit()
|
||||
{
|
||||
{
|
||||
//If the thread isn't there yet, wait for it.
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
if(!thread)
|
||||
condition.wait(h);
|
||||
}
|
||||
set_workflag(WORKFLAG_QUIT_REQUEST);
|
||||
set_workflag(quit_request);
|
||||
if(!joined)
|
||||
thread->join();
|
||||
joined = true;
|
||||
}
|
||||
|
||||
void worker_thread::set_busy()
|
||||
void worker::set_busy()
|
||||
{
|
||||
busy = true;
|
||||
}
|
||||
|
||||
void worker_thread::clear_busy()
|
||||
void worker::clear_busy()
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
busy = false;
|
||||
condition.notify_all();
|
||||
}
|
||||
|
||||
void worker_thread::wait_busy()
|
||||
void worker::wait_busy()
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
if(busy) {
|
||||
uint64_t tmp = ticks();
|
||||
while(busy)
|
||||
|
@ -80,7 +85,7 @@ void worker_thread::wait_busy()
|
|||
}
|
||||
}
|
||||
|
||||
void worker_thread::rethrow()
|
||||
void worker::rethrow()
|
||||
{
|
||||
if(exception_caught) {
|
||||
if(exception_oom)
|
||||
|
@ -90,24 +95,24 @@ void worker_thread::rethrow()
|
|||
}
|
||||
}
|
||||
|
||||
void worker_thread::set_workflag(uint32_t flag)
|
||||
void worker::set_workflag(uint32_t flag)
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
workflag |= flag;
|
||||
condition.notify_all();
|
||||
}
|
||||
|
||||
uint32_t worker_thread::clear_workflag(uint32_t flag)
|
||||
uint32_t worker::clear_workflag(uint32_t flag)
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
uint32_t tmp = workflag;
|
||||
workflag &= ~flag;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
uint32_t worker_thread::wait_workflag()
|
||||
uint32_t worker::wait_workflag()
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
if(!workflag) {
|
||||
uint64_t tmp = ticks();
|
||||
while(!workflag)
|
||||
|
@ -117,13 +122,13 @@ uint32_t worker_thread::wait_workflag()
|
|||
return workflag;
|
||||
}
|
||||
|
||||
std::pair<uint64_t, uint64_t> worker_thread::get_wait_count()
|
||||
std::pair<uint64_t, uint64_t> worker::get_wait_count()
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(mlock);
|
||||
return std::make_pair(waitamt_busy, waitamt_work);
|
||||
}
|
||||
|
||||
int worker_thread::operator()(int dummy)
|
||||
int worker::operator()(int dummy)
|
||||
{
|
||||
try {
|
||||
entry();
|
||||
|
@ -139,8 +144,9 @@ int worker_thread::operator()(int dummy)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void worker_thread::fire()
|
||||
void worker::fire()
|
||||
{
|
||||
reflector = new worker_thread_reflector;
|
||||
thread = new thread_class(*reflector, this);
|
||||
reflector = new workthread::reflector;
|
||||
thread = new threads::thread(*reflector, this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "library/string.hpp"
|
||||
#include "library/zip.hpp"
|
||||
#include "lua/bitmap.hpp"
|
||||
#include "library/threadtypes.hpp"
|
||||
#include "library/threads.hpp"
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
|
@ -805,7 +805,7 @@ int lua_palette::set(lua::state& L, lua::parameters& P)
|
|||
|
||||
P(P.skipped(), c, nc);
|
||||
|
||||
//The mutex lock protects only the internals of colors array.
|
||||
//The lock protects only the internals of colors array.
|
||||
if(this->colors.size() <= c) {
|
||||
this->palette_mutex.lock();
|
||||
this->colors.resize(static_cast<uint32_t>(c) + 1);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include "library/framebuffer.hpp"
|
||||
#include "library/png.hpp"
|
||||
#include "library/string.hpp"
|
||||
#include "library/threadtypes.hpp"
|
||||
#include "library/threads.hpp"
|
||||
#include "library/lua-framebuffer.hpp"
|
||||
#include "library/zip.hpp"
|
||||
#include "lua/bitmap.hpp"
|
||||
|
@ -33,7 +33,7 @@ namespace
|
|||
tilemap(lua::state& L, size_t _width, size_t _height, size_t _cwidth, size_t _cheight);
|
||||
~tilemap()
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(lock);
|
||||
render_kill_request(this);
|
||||
}
|
||||
static int create(lua::state& L, lua::parameters& P);
|
||||
|
@ -44,7 +44,7 @@ namespace
|
|||
|
||||
P(P.skipped(), x, y);
|
||||
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(lock);
|
||||
if(x >= width || y >= height)
|
||||
return 0;
|
||||
tilemap_entry& e = map[y * width + x];
|
||||
|
@ -65,7 +65,7 @@ namespace
|
|||
P(P.skipped(), x, y);
|
||||
int oidx = P.skip();
|
||||
|
||||
umutex_class h(mutex);
|
||||
threads::alock h(lock);
|
||||
if(x >= width || y >= height)
|
||||
return 0;
|
||||
tilemap_entry& e = map[y * width + x];
|
||||
|
@ -125,7 +125,7 @@ namespace
|
|||
P(P.skipped(), ox, oy, P.optional(x0, 0), P.optional(y0, 0), P.optional(w, width),
|
||||
P.optional(h, height), P.optional(circx, false), P.optional(circy, false));
|
||||
|
||||
umutex_class mh(mutex);
|
||||
threads::alock mh(lock);
|
||||
if(x0 > width || x0 + w > width || x0 + w < x0 || y0 > height || y0 + h > height ||
|
||||
y0 + h < y0)
|
||||
throw std::runtime_error("Scroll window out of range");
|
||||
|
@ -161,7 +161,7 @@ namespace
|
|||
size_t cwidth;
|
||||
size_t cheight;
|
||||
std::vector<tilemap_entry> map;
|
||||
mutex_class mutex;
|
||||
threads::lock lock;
|
||||
};
|
||||
|
||||
struct render_object_tilemap : public framebuffer::object
|
||||
|
@ -179,7 +179,7 @@ namespace
|
|||
template<bool T> void composite_op(struct framebuffer::fb<T>& scr) throw()
|
||||
{
|
||||
tilemap& _map = *map;
|
||||
umutex_class h(_map.mutex);
|
||||
threads::alock h(_map.lock);
|
||||
for(size_t ty = 0; ty < _map.height; ty++) {
|
||||
size_t basey = _map.cheight * ty;
|
||||
for(size_t tx = 0; tx < _map.width; tx++) {
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace
|
|||
bool was_enabled = false;
|
||||
int driver_id = 0;
|
||||
|
||||
class cb_thread : public worker_thread
|
||||
class cb_thread : public workthread::worker
|
||||
{
|
||||
public:
|
||||
cb_thread() { fire(); }
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "core/window.hpp"
|
||||
#include "interface/romtype.hpp"
|
||||
#include "library/string.hpp"
|
||||
#include "library/threadtypes.hpp"
|
||||
#include "library/threads.hpp"
|
||||
#include "library/utf8.hpp"
|
||||
#include "library/zip.hpp"
|
||||
|
||||
|
@ -59,14 +59,14 @@ bool wxwidgets_exiting = false;
|
|||
|
||||
namespace
|
||||
{
|
||||
threadid_class ui_thread;
|
||||
threads::id ui_thread;
|
||||
volatile bool panic_ack = false;
|
||||
std::string error_message_text;
|
||||
volatile bool modal_dialog_confirm;
|
||||
volatile bool modal_dialog_active;
|
||||
mutex_class ui_mutex;
|
||||
cv_class ui_condition;
|
||||
thread_class* joystick_thread_handle;
|
||||
threads::lock ui_mutex;
|
||||
threads::cv ui_condition;
|
||||
threads::thread* joystick_thread_handle;
|
||||
|
||||
void* joystick_thread(int _args)
|
||||
{
|
||||
|
@ -139,7 +139,7 @@ namespace
|
|||
queue_synchronous_fn_warning = true;
|
||||
back:
|
||||
{
|
||||
umutex_class h(ui_mutex);
|
||||
threads::alock h(ui_mutex);
|
||||
if(ui_queue.empty())
|
||||
goto end;
|
||||
i = ui_queue.begin();
|
||||
|
@ -428,7 +428,7 @@ bool lsnes_app::OnInit()
|
|||
|
||||
ui_services = new ui_services_type();
|
||||
|
||||
ui_thread = this_thread_id();
|
||||
ui_thread = threads::this_id();
|
||||
platform::init();
|
||||
|
||||
messages << "lsnes version: lsnes rr" << lsnes_version << std::endl;
|
||||
|
@ -456,8 +456,8 @@ bool lsnes_app::OnInit()
|
|||
if(settings_mode) {
|
||||
//We got to boot this up quite a bit to get the joystick driver working.
|
||||
//In practicular, we need joystick thread and emulator thread in pause.
|
||||
joystick_thread_handle = new thread_class(joystick_thread, 6);
|
||||
thread_class* dummy_loop = new thread_class(eloop_helper, 8);
|
||||
joystick_thread_handle = new threads::thread(joystick_thread, 6);
|
||||
threads::thread* dummy_loop = new threads::thread(eloop_helper, 8);
|
||||
display_settings_dialog(NULL, NULL);
|
||||
platform::exit_dummy_event_loop();
|
||||
joystick_driver_signal();
|
||||
|
@ -468,7 +468,7 @@ bool lsnes_app::OnInit()
|
|||
}
|
||||
init_lua();
|
||||
|
||||
joystick_thread_handle = new thread_class(joystick_thread, 7);
|
||||
joystick_thread_handle = new threads::thread(joystick_thread, 7);
|
||||
|
||||
msg_window = new wxwin_messages();
|
||||
msg_window->Show();
|
||||
|
@ -560,7 +560,7 @@ namespace
|
|||
},
|
||||
.fatal_error = []() -> void {
|
||||
//Fun: This can be called from any thread!
|
||||
if(ui_thread == this_thread_id()) {
|
||||
if(ui_thread == threads::this_id()) {
|
||||
//UI thread.
|
||||
platform::set_modal_pause(true);
|
||||
wxMessageBox(_T("Panic: Unrecoverable error, can't continue"), _T("Error"),
|
||||
|
@ -579,17 +579,17 @@ namespace
|
|||
.request_rom = [](rom_request& req)
|
||||
{
|
||||
rom_request* _req = &req;
|
||||
mutex_class lock;
|
||||
cv_class cv;
|
||||
threads::lock lock;
|
||||
threads::cv cv;
|
||||
bool done = false;
|
||||
umutex_class h(lock);
|
||||
threads::alock h(lock);
|
||||
runuifun([_req, &lock, &cv, &done]() -> void {
|
||||
try {
|
||||
main_window->request_rom(*_req);
|
||||
} catch(...) {
|
||||
_req->canceled = true;
|
||||
}
|
||||
umutex_class h(lock);
|
||||
threads::alock h(lock);
|
||||
done = true;
|
||||
cv.notify_all();
|
||||
});
|
||||
|
@ -607,7 +607,7 @@ void signal_core_change()
|
|||
|
||||
void _runuifun_async(void (*fn)(void*), void* arg)
|
||||
{
|
||||
umutex_class h(ui_mutex);
|
||||
threads::alock h(ui_mutex);
|
||||
ui_queue_entry e;
|
||||
e.fn = fn;
|
||||
e.arg = arg;
|
||||
|
|
|
@ -170,7 +170,7 @@ namespace
|
|||
uint64_t hashing_left = 0;
|
||||
uint64_t hashing_total = 0;
|
||||
int64_t last_update = 0;
|
||||
thread_class* emulation_thread;
|
||||
threads::thread* emulation_thread;
|
||||
|
||||
settingvar::variable<settingvar::model_bool<settingvar::yes_no>> background_audio(lsnes_vset,
|
||||
"background-audio", "GUI‣Enable background audio", true);
|
||||
|
@ -775,7 +775,7 @@ void boot_emulator(loaded_rom& rom, moviefile& movie, bool fscreen)
|
|||
a->initial = &movie;
|
||||
a->load_has_to_succeed = false;
|
||||
modal_pause_holder hld;
|
||||
emulation_thread = new thread_class(emulator_main, a);
|
||||
emulation_thread = new threads::thread(emulator_main, a);
|
||||
main_window = new wxwin_mainwindow(fscreen);
|
||||
main_window->Show();
|
||||
} catch(std::bad_alloc& e) {
|
||||
|
|
|
@ -37,12 +37,12 @@ void wxwin_messages::panel::on_mouse(wxMouseEvent& e)
|
|||
int unit = e.GetWheelDelta();
|
||||
scroll_acc += e.GetWheelRotation();
|
||||
while(scroll_acc <= -unit) {
|
||||
umutex_class h(platform::msgbuf_lock());
|
||||
threads::alock h(platform::msgbuf_lock());
|
||||
platform::msgbuf.scroll_down_line();
|
||||
scroll_acc += unit;
|
||||
}
|
||||
while(scroll_acc >= e.GetWheelDelta()) {
|
||||
umutex_class h(platform::msgbuf_lock());
|
||||
threads::alock h(platform::msgbuf_lock());
|
||||
platform::msgbuf.scroll_up_line();
|
||||
scroll_acc -= unit;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ void wxwin_messages::panel::on_mouse(wxMouseEvent& e)
|
|||
|
||||
uint64_t gfirst;
|
||||
{
|
||||
umutex_class h(platform::msgbuf_lock());
|
||||
threads::alock h(platform::msgbuf_lock());
|
||||
gfirst = platform::msgbuf.get_visible_first();
|
||||
}
|
||||
uint64_t local_line = e.GetY() / line_separation;
|
||||
|
@ -81,7 +81,7 @@ void wxwin_messages::panel::on_menu(wxCommandEvent& e)
|
|||
uint64_t M = max(line_clicked, line_declicked);
|
||||
size_t lines = 0;
|
||||
{
|
||||
umutex_class h(platform::msgbuf_lock());
|
||||
threads::alock h(platform::msgbuf_lock());
|
||||
for(uint64_t i = m; i <= M; i++) {
|
||||
try {
|
||||
std::string mline = platform::msgbuf.get_message(i);
|
||||
|
@ -190,7 +190,7 @@ void wxwin_messages::panel::prepare_paint()
|
|||
uint64_t xM = max(line_clicked, line_current);
|
||||
std::vector<std::string> msgs;
|
||||
{
|
||||
umutex_class h(platform::msgbuf_lock());
|
||||
threads::alock h(platform::msgbuf_lock());
|
||||
lines = platform::msgbuf.get_visible_count();
|
||||
first = platform::msgbuf.get_visible_first();
|
||||
msgs.resize(lines);
|
||||
|
@ -238,37 +238,37 @@ void wxwin_messages::reshow()
|
|||
|
||||
void wxwin_messages::on_scroll_home(wxCommandEvent& e)
|
||||
{
|
||||
umutex_class h(platform::msgbuf_lock());
|
||||
threads::alock h(platform::msgbuf_lock());
|
||||
platform::msgbuf.scroll_beginning();
|
||||
}
|
||||
|
||||
void wxwin_messages::on_scroll_pageup(wxCommandEvent& e)
|
||||
{
|
||||
umutex_class h(platform::msgbuf_lock());
|
||||
threads::alock h(platform::msgbuf_lock());
|
||||
platform::msgbuf.scroll_up_page();
|
||||
}
|
||||
|
||||
void wxwin_messages::on_scroll_lineup(wxCommandEvent& e)
|
||||
{
|
||||
umutex_class h(platform::msgbuf_lock());
|
||||
threads::alock h(platform::msgbuf_lock());
|
||||
platform::msgbuf.scroll_up_line();
|
||||
}
|
||||
|
||||
void wxwin_messages::on_scroll_linedown(wxCommandEvent& e)
|
||||
{
|
||||
umutex_class h(platform::msgbuf_lock());
|
||||
threads::alock h(platform::msgbuf_lock());
|
||||
platform::msgbuf.scroll_down_line();
|
||||
}
|
||||
|
||||
void wxwin_messages::on_scroll_pagedown(wxCommandEvent& e)
|
||||
{
|
||||
umutex_class h(platform::msgbuf_lock());
|
||||
threads::alock h(platform::msgbuf_lock());
|
||||
platform::msgbuf.scroll_down_page();
|
||||
}
|
||||
|
||||
void wxwin_messages::on_scroll_end(wxCommandEvent& e)
|
||||
{
|
||||
umutex_class h(platform::msgbuf_lock());
|
||||
threads::alock h(platform::msgbuf_lock());
|
||||
platform::msgbuf.scroll_end();
|
||||
}
|
||||
|
||||
|
|
|
@ -550,7 +550,7 @@ namespace
|
|||
bool broken;
|
||||
bool broken2;
|
||||
wxCheckBox* enabled;
|
||||
mutex_class buffer_mutex;
|
||||
threads::lock buffer_mutex;
|
||||
std::list<std::string> lines_waiting;
|
||||
bool unprocessed_lines;
|
||||
bool closing;
|
||||
|
@ -585,7 +585,7 @@ namespace
|
|||
void wxwin_tracelog::kill_debug_hooks()
|
||||
{
|
||||
debug_remove_callback(cpuid, DEBUG_TRACE, trace_handle);
|
||||
umutex_class h(buffer_mutex);
|
||||
threads::alock h(buffer_mutex);
|
||||
for(auto& i : rwx_breakpoints) {
|
||||
if(!i.second.handle)
|
||||
continue;
|
||||
|
@ -682,7 +682,7 @@ namespace
|
|||
|
||||
void wxwin_tracelog::process_lines()
|
||||
{
|
||||
umutex_class h(this->buffer_mutex);
|
||||
threads::alock h(this->buffer_mutex);
|
||||
size_t osize = panel->rows.size();
|
||||
if(broken) {
|
||||
panel->rows.push_back(std::string(120, '-'));
|
||||
|
@ -709,7 +709,7 @@ namespace
|
|||
bool enable = enabled->GetValue();
|
||||
runemufn([this, enable]() {
|
||||
if(enable) {
|
||||
umutex_class h(buffer_mutex);
|
||||
threads::alock h(buffer_mutex);
|
||||
broken = broken2;
|
||||
broken2 = true;
|
||||
for(auto& i : rwx_breakpoints) {
|
||||
|
@ -730,7 +730,7 @@ namespace
|
|||
if(!this->trace_active)
|
||||
return;
|
||||
//Got tracelog line, send it.
|
||||
umutex_class h(this->buffer_mutex);
|
||||
threads::alock h(this->buffer_mutex);
|
||||
lines_waiting.push_back(str);
|
||||
if(!this->unprocessed_lines) {
|
||||
this->unprocessed_lines = true;
|
||||
|
|
|
@ -133,7 +133,7 @@ namespace
|
|||
uint32_t max_frames;
|
||||
};
|
||||
|
||||
struct resample_worker : public worker_thread
|
||||
struct resample_worker : public workthread::worker
|
||||
{
|
||||
resample_worker(double _ratio, uint32_t _nch);
|
||||
~resample_worker();
|
||||
|
@ -151,7 +151,7 @@ namespace
|
|||
void* resampler;
|
||||
};
|
||||
|
||||
struct avi_worker : public worker_thread
|
||||
struct avi_worker : public workthread::worker
|
||||
{
|
||||
avi_worker(const struct avi_info& info);
|
||||
~avi_worker();
|
||||
|
@ -216,7 +216,7 @@ namespace
|
|||
{
|
||||
while(1) {
|
||||
wait_workflag();
|
||||
uint32_t work = clear_workflag(~WORKFLAG_QUIT_REQUEST);
|
||||
uint32_t work = clear_workflag(~workthread::quit_request);
|
||||
//Flush the queue first in order to provode backpressure.
|
||||
if(work & WORKFLAG_FLUSH) {
|
||||
clear_workflag(WORKFLAG_FLUSH);
|
||||
|
@ -256,7 +256,7 @@ namespace
|
|||
clear_workflag(WORKFLAG_END | WORKFLAG_FLUSH | WORKFLAG_QUEUE_FRAME);
|
||||
}
|
||||
//If signaled to quit and no more work, do so.
|
||||
if(work == WORKFLAG_QUIT_REQUEST) {
|
||||
if(work == workthread::quit_request) {
|
||||
if(!closed)
|
||||
aviout.close();
|
||||
closed = true;
|
||||
|
@ -551,7 +551,7 @@ again:
|
|||
{
|
||||
while(1) {
|
||||
wait_workflag();
|
||||
uint32_t work = clear_workflag(~WORKFLAG_QUIT_REQUEST);
|
||||
uint32_t work = clear_workflag(~workthread::quit_request);
|
||||
if(work & (WORKFLAG_QUEUE_FRAME | WORKFLAG_END)) {
|
||||
#ifdef WITH_SECRET_RABBIT_CODE
|
||||
again:
|
||||
|
@ -583,7 +583,7 @@ again:
|
|||
if(work & WORKFLAG_END)
|
||||
return;
|
||||
}
|
||||
if(work == WORKFLAG_QUIT_REQUEST)
|
||||
if(work == workthread::quit_request)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@ sample_queue::sample_queue()
|
|||
|
||||
void sample_queue::push(const int16_t* samples, size_t count)
|
||||
{
|
||||
umutex_class(mutex);
|
||||
size_t dsize = available();
|
||||
threads::alock h(mlock);
|
||||
size_t dsize = _available();
|
||||
if(dsize + count > size) {
|
||||
//Expand the buffer.
|
||||
std::vector<int16_t> newbuffer;
|
||||
|
@ -41,7 +41,7 @@ void sample_queue::push(const int16_t* samples, size_t count)
|
|||
|
||||
void sample_queue::pull(int16_t* samples, size_t count)
|
||||
{
|
||||
umutex_class(mutex);
|
||||
threads::alock h(mlock);
|
||||
while(count) {
|
||||
if(!blank) {
|
||||
*samples = data[rptr++];
|
||||
|
@ -58,7 +58,12 @@ void sample_queue::pull(int16_t* samples, size_t count)
|
|||
|
||||
size_t sample_queue::available()
|
||||
{
|
||||
umutex_class(mutex);
|
||||
threads::alock h(mlock);
|
||||
return _available();
|
||||
}
|
||||
|
||||
size_t sample_queue::_available()
|
||||
{
|
||||
if(blank)
|
||||
return 0;
|
||||
else if(rptr < wptr)
|
||||
|
|
Loading…
Add table
Reference in a new issue