X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fpbd%2Fpbd%2Fabstract_ui.h;h=dc5620b2ef76354358862d03e8a1fcd594fb1c42;hb=a882e96db1367c26660fd3d3079e9e3e19b1e149;hp=88c27aa0bce7c3787db8106bf2eee9a97d8983c6;hpb=6edccc3070b813157ffcd4014ec8dd7fa6ed9ce7;p=ardour.git diff --git a/libs/pbd/pbd/abstract_ui.h b/libs/pbd/pbd/abstract_ui.h index 88c27aa0bc..dc5620b2ef 100644 --- a/libs/pbd/pbd/abstract_ui.h +++ b/libs/pbd/pbd/abstract_ui.h @@ -1,5 +1,5 @@ /* - Copyright (C) 1998-99 Paul Barton-Davis + Copyright (C) 1998-2009 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,53 +24,85 @@ #include #include -#include +#include -#include +#include "pbd/libpbd_visibility.h" +#include "pbd/receiver.h" +#include "pbd/ringbufferNPT.h" +#include "pbd/signals.h" +#include "pbd/base_ui.h" + +/* We have a special case in libpbd of a template class that gets instantiated + * as the base class of several classes in other libraries. It is not possible + * to use LIBFOO_API to mark this visible, because the FOO in each case is + * different. So we define this generic visible/export/hidden/import pair + * of macros to try to deal with this special case. These should NEVER be + * used anywhere except AbstractUI (or similar cases if they arise. + * + * Note the assumption here that other libs are being built as DLLs if this one is. + */ + +#ifdef ABSTRACT_UI_EXPORTS +#define ABSTRACT_UI_API LIBPBD_DLL_EXPORT +#else +#define ABSTRACT_UI_API LIBPBD_DLL_IMPORT +#endif -#include -#include -#include class Touchable; -template -class AbstractUI : public BaseUI +template +class ABSTRACT_UI_API AbstractUI : public BaseUI { public: - AbstractUI (std::string name, bool with_signal_pipe); + AbstractUI (const std::string& name); virtual ~AbstractUI() {} - virtual bool caller_is_ui_thread() = 0; + void register_thread (std::string, pthread_t, std::string, uint32_t num_requests); + void call_slot (EventLoop::InvalidationRecord*, const boost::function&); + Glib::Threads::Mutex& slot_invalidation_mutex() { return request_buffer_map_lock; } - void call_slot (sigc::slot el_slot) { - RequestObject *req = get_request (BaseUI::CallSlot); - - if (req == 0) { - return; - } - - req->slot = el_slot; - send_request (req); - } - - void register_thread (pthread_t, std::string); - void register_thread_with_request_count (pthread_t, std::string, uint32_t num_requests); + Glib::Threads::Mutex request_buffer_map_lock; protected: - typedef RingBufferNPT RequestBuffer; + struct RequestBuffer : public PBD::RingBufferNPT { + bool dead; + AbstractUI& ui; + RequestBuffer (uint32_t size, AbstractUI& uir) + : PBD::RingBufferNPT (size) + , dead (false) + , ui (uir) {} + }; typedef typename RequestBuffer::rw_vector RequestBufferVector; - typedef typename std::map::iterator RequestBufferMapIterator; - Glib::Mutex request_buffer_map_lock; +#if defined(__MINGW32__) && !defined (__MINGW64__) + + struct pthread_cmp + { + bool operator() (const ptw32_handle_t& thread1, const ptw32_handle_t& thread2) + { + return thread1.p < thread2.p; + } + }; + typedef typename std::map::iterator RequestBufferMapIterator; + typedef std::map RequestBufferMap; +#else + typedef typename std::map::iterator RequestBufferMapIterator; typedef std::map RequestBufferMap; +#endif + RequestBufferMap request_buffers; - pthread_key_t thread_request_buffer_key; + static Glib::Threads::Private per_thread_request_buffer; + + Glib::Threads::Mutex request_list_lock; + std::list request_list; + RequestObject* get_request (RequestType); void handle_ui_requests (); void send_request (RequestObject *); virtual void do_request (RequestObject *) = 0; + PBD::ScopedConnection new_thread_connection; }; #endif /* __pbd_abstract_ui_h__ */