summaryrefslogtreecommitdiff
path: root/sql/my_apc.h
diff options
context:
space:
mode:
authorSergey Petrunya <psergey@askmonty.org>2011-08-23 19:28:32 +0400
committerSergey Petrunya <psergey@askmonty.org>2011-08-23 19:28:32 +0400
commit7e66213444a5af73879b57ad0b5bd7476b5c6f4d (patch)
tree6939d6b4b4cea99971b19fd7ad97e8096ad26ebf /sql/my_apc.h
parentd2206ad14920e85907c965256e1ce061633c36ee (diff)
downloadmariadb-git-7e66213444a5af73879b57ad0b5bd7476b5c6f4d.tar.gz
MWL#182: Explain running statements
First code - "Asynchronous procedure call" system - new THD::check_killed() that serves APC request is called from within most important loops - EXPLAIN code is now able to generate EXPLAIN output on-the-fly [incomplete] Parts that are still missing: - put THD::check_killed() call into every loop where we could spend significant amount of time - Make sure EXPLAIN code works for group-by queries that replace JOIN::join_tab with make_simple_join() and other such cases. - User interface: what error code to use, where to get timeout settings from, etc.
Diffstat (limited to 'sql/my_apc.h')
-rw-r--r--sql/my_apc.h98
1 files changed, 98 insertions, 0 deletions
diff --git a/sql/my_apc.h b/sql/my_apc.h
new file mode 100644
index 00000000000..3783bd28f54
--- /dev/null
+++ b/sql/my_apc.h
@@ -0,0 +1,98 @@
+/*
+ TODO: MP AB Copyright
+*/
+
+/*
+ Design
+ - Mutex-guarded request queue (it belongs to the target), which can be enabled/
+ disabled (when empty).
+
+ - After the request has been put into queue, the requestor waits for request
+ to be satisfied. The worker satisifes the request and signals the
+ requestor.
+*/
+
+/*
+ Target for asynchronous calls.
+*/
+class Apc_target
+{
+public:
+ Apc_target() : enabled(0), apc_calls(NULL) /*, call_queue_size(0)*/ {}
+ ~Apc_target() { DBUG_ASSERT(!enabled && !apc_calls);}
+
+ /*
+ Initialize the target. This must be called before anything else. Right
+ after initialization, the target is disabled.
+ */
+ void init();
+
+ /*
+ Destroy the target. The target must be disabled when this call is made.
+ */
+ void destroy();
+
+ /*
+ Enter into state where this target will be serving APC requests
+ */
+ void enable();
+
+ /*
+ Leave the state where we could serve APC requests (will serve all already
+ enqueued requests)
+ */
+ void disable();
+
+ /*
+ This should be called periodically to serve observation requests.
+ */
+ void process_apc_requests();
+
+ typedef void (*apc_func_t)(void *arg);
+
+ /*
+ Make an APC call: schedule it for execution and wait until the target
+ thread has executed it. This function must not be called from a thread
+ that's different from the target thread.
+
+ @retval FALSE - Ok, the call has been made
+ @retval TRUE - Call wasnt made (either the target is in disabled state or
+ timeout occured)
+ */
+ bool make_apc_call(apc_func_t func, void *func_arg,
+ int timeout_sec, bool *timed_out);
+
+private:
+ class Call_request;
+ int enabled;
+
+ Call_request *apc_calls;
+ pthread_mutex_t LOCK_apc_queue;
+ //int call_queue_size;
+
+ class Call_request
+ {
+ public:
+ apc_func_t func;
+ void *func_arg;
+ bool done;
+
+ pthread_mutex_t LOCK_request;
+ pthread_cond_t COND_request;
+
+ Call_request *next;
+ Call_request *prev;
+
+ const char *what;
+ };
+
+ void enqueue_request(Call_request *qe);
+ void dequeue_request(Call_request *qe);
+ Call_request *get_first_in_queue()
+ {
+ return apc_calls;
+ }
+};
+
+///////////////////////////////////////////////////////////////////////
+