-
Notifications
You must be signed in to change notification settings - Fork 34
Pseudo batch-less operations #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
b49728e
95c8802
0bd312c
ae5eb1c
eaefc2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,16 @@ G_BEGIN_DECLS | |
|
|
||
| struct JBatch; | ||
|
|
||
| /** | ||
| * Simulate batch-less operations. | ||
| * | ||
| * J_SINGLE_OP can be passed to operations instead of an actual batch. | ||
| * The operation will then be executed immediately and is finished after the call returns. | ||
| * Default semantic settings will be used for execution. | ||
| * | ||
| */ | ||
| #define J_SINGLE_OP NULL | ||
|
|
||
| typedef struct JBatch JBatch; | ||
|
|
||
| typedef void (*JBatchAsyncCallback)(JBatch*, gboolean, gpointer); | ||
|
|
@@ -102,6 +112,8 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(JBatch, j_batch_unref) | |
| /** | ||
| * Returns a batch's semantics. | ||
| * | ||
| * The returned object must be freed using j_semantic_unref. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this affect any existing code? It could lead to memory leaks. |
||
| * | ||
| * \code | ||
| * \endcode | ||
| * | ||
|
|
@@ -114,6 +126,8 @@ JSemantics* j_batch_get_semantics(JBatch* batch); | |
| /** | ||
| * Adds a new operation to the batch. | ||
| * | ||
| * Passing J_SINGLE_OP creates a temporary batch and calls j_batch_execute. | ||
| * | ||
| * \private | ||
| * | ||
| * \code | ||
|
|
@@ -122,7 +136,7 @@ JSemantics* j_batch_get_semantics(JBatch* batch); | |
| * \param batch A batch. | ||
| * \param operation An operation. | ||
| **/ | ||
| void j_batch_add(JBatch* batch, JOperation* operation); | ||
| gboolean j_batch_add(JBatch* batch, JOperation* operation); | ||
|
|
||
| /** | ||
| * Executes the batch. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -273,20 +273,32 @@ j_batch_get_semantics(JBatch* batch) | |
| { | ||
| J_TRACE_FUNCTION(NULL); | ||
|
|
||
| g_return_val_if_fail(batch != NULL, NULL); | ||
| if (batch == J_SINGLE_OP) | ||
| { | ||
| return j_semantics_new(J_SEMANTICS_TEMPLATE_DEFAULT); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could also allocate a semantics singleton so callers do not have to free the semantics. I'm not sure whether it's worth the effort, though. |
||
|
|
||
| return batch->semantics; | ||
| return j_semantics_ref(batch->semantics); | ||
| } | ||
|
|
||
| void | ||
| gboolean | ||
| j_batch_add(JBatch* batch, JOperation* operation) | ||
| { | ||
| J_TRACE_FUNCTION(NULL); | ||
|
|
||
| g_return_if_fail(batch != NULL); | ||
| g_return_if_fail(operation != NULL); | ||
| g_return_val_if_fail(operation != NULL, FALSE); | ||
|
|
||
| // pseudo batch-less ops by passing J_SINGLE_OP | ||
| if (batch == J_SINGLE_OP) | ||
| { | ||
| g_autoptr(JBatch) tmp_batch = NULL; | ||
| tmp_batch = j_batch_new_for_template(J_SEMANTICS_TEMPLATE_DEFAULT); | ||
| j_list_append(tmp_batch->list, operation); | ||
| return j_batch_execute(tmp_batch); | ||
| } | ||
|
|
||
| j_list_append(batch->list, operation); | ||
| return TRUE; | ||
| } | ||
|
|
||
| /* Internal */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the name should include batch, maybe
J_BATCH_SINGLE?