Skip to content

[#557] Workers: Use Deque - #565

Merged
jesperpedersen merged 1 commit into
pgmoneta:mainfrom
dancingactor:test4
Apr 2, 2025
Merged

jesperpedersen merged 1 commit into
pgmoneta:mainfrom
dancingactor:test4

Conversation

@dancingactor

Copy link
Copy Markdown
Contributor

implement #557

This PR replace the custom queue in workers.c with the existing deque in deque.c implementation.

Details

  1. The task is now included into worker_common, instead of being wrapped in a separate struct task. Since the deque is designed to hold generic values (with cleanup via value_config), storing the complete task in a single structure simplifies both insertion and memory management.
  2. Move struct semaphore* has_tasks; from original queue to workers since deque doesn't have semaphore logic.

Comment thread src/libpgmoneta/workers.c Outdated
#include <pgmoneta.h>
#include <logging.h>
#include <workers.h>
#include <deque.h>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorting

Comment thread src/libpgmoneta/workers.c Outdated
w->outcome = true;

if (queue_init(&w->queue))
pgmoneta_deque_create(true, &w->queue);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing goto error

Comment thread src/libpgmoneta/workers.c Outdated

queue_push(&workers->queue, t);
struct value_config config = {0};
config.destroy_data = destroy_data_wrapper; // define the task destroy function of the deque

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment

Comment thread src/libpgmoneta/workers.c Outdated

free(t);
task_wc->function(task_wc);
// Note: No need to free task_wc here since the deque's value_config.destroy will handle it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment

@jesperpedersen

Copy link
Copy Markdown
Member

If you want to add comments to a code segment then do

/* My comment */

or

/*
 * This a long comment over
 * multiple lines
 */

@dancingactor

Copy link
Copy Markdown
Contributor Author

If you want to add comments to a code segment then do

/* My comment */

or

/*
 * This a long comment over
 * multiple lines
 */

got it, so you mean we should avoid inline comment

@jesperpedersen

Copy link
Copy Markdown
Member

squash

Comment thread src/libpgmoneta/workers.c Outdated
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <deque.h>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pgmoneta.h is always first

@jesperpedersen

Copy link
Copy Markdown
Member

Merged.

Thanks for your contribution !

@dancingactor

dancingactor commented Apr 2, 2025 •

Copy link
Copy Markdown
Contributor Author

@jesperpedersen Thanks so much for your valuable feedback and time! Are there any other issues to contribute?

@jesperpedersen

Copy link
Copy Markdown
Member

@dancingactor Take #567

This was referenced Apr 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants