summaryrefslogtreecommitdiffstats
path: root/ppapi/c/pp_completion_callback.h
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-27 16:15:38 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-27 16:15:38 +0000
commitf03c9cd35d919838e54df2a698c6a7c53c21b665 (patch)
treeebc8a4dd0c6e11344a6b2bf73178f06caa74e620 /ppapi/c/pp_completion_callback.h
parent3628ecafa37224bc55fa33911084995a584445d9 (diff)
downloadchromium_src-f03c9cd35d919838e54df2a698c6a7c53c21b665.zip
chromium_src-f03c9cd35d919838e54df2a698c6a7c53c21b665.tar.gz
chromium_src-f03c9cd35d919838e54df2a698c6a7c53c21b665.tar.bz2
Add a new function to run and claer a completion callback. This is a common
pattern and is a bit tricky since we need to clear it before actually executing the callback. TEST=ppapi ui_tests BUG=none Review URL: http://codereview.chromium.org/6962021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87028 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/c/pp_completion_callback.h')
-rw-r--r--ppapi/c/pp_completion_callback.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/ppapi/c/pp_completion_callback.h b/ppapi/c/pp_completion_callback.h
index 5778beb1..248dedc 100644
--- a/ppapi/c/pp_completion_callback.h
+++ b/ppapi/c/pp_completion_callback.h
@@ -101,6 +101,7 @@ PP_INLINE void PP_RunCompletionCallback(struct PP_CompletionCallback* cc,
int32_t res) {
cc->func(cc->user_data, res);
}
+
/**
* @}
*/
@@ -121,6 +122,27 @@ PP_INLINE void PP_RunCompletionCallback(struct PP_CompletionCallback* cc,
PP_INLINE struct PP_CompletionCallback PP_BlockUntilComplete() {
return PP_MakeCompletionCallback(NULL, NULL);
}
+
+/**
+ * Runs a callback and clears the reference to it.
+ *
+ * This is used when the null-ness of a completion callback is used as a signal
+ * for whether a completion callback has been registered. In this case, after
+ * the execution of the callback, it should be cleared.
+ *
+ * However, this introduces a conflict if the completion callback wants to
+ * schedule more work that involves the same completion callback again (for
+ * example, when reading data from an URLLoader, one would typically queue up
+ * another read callback). As a result, this function clears the pointer
+ * *before* the given callback is executed.
+ */
+PP_INLINE void PP_RunAndClearCompletionCallback(
+ struct PP_CompletionCallback* cc,
+ int32_t res) {
+ struct PP_CompletionCallback temp = *cc;
+ *cc = PP_BlockUntilComplete();
+ PP_RunCompletionCallback(&temp, res);
+}
/**
* @}
*/