git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
blob 22411af1b0d2f093258955e86e375198f693f244 1118 bytes (raw)
name: mpmcqueue.c 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 
#include "mpmcqueue.h"

void mpmcq_init(struct mpmcq *queue)
{
	queue->head = NULL;
	queue->cancel = 0;
	pthread_mutex_init(&queue->mutex, NULL);
	pthread_cond_init(&queue->condition, NULL);
}

void mpmcq_destroy(struct mpmcq *queue)
{
	pthread_mutex_destroy(&queue->mutex);
	pthread_cond_destroy(&queue->condition);
}

void mpmcq_push(struct mpmcq *queue, struct mpmcq_entry *entry)
{
	pthread_mutex_lock(&queue->mutex);
	entry->next = queue->head;
	queue->head = entry;
	pthread_cond_signal(&queue->condition);
	pthread_mutex_unlock(&queue->mutex);
}

struct mpmcq_entry *mpmcq_pop(struct mpmcq *queue)
{
	struct mpmcq_entry *entry = NULL;

	pthread_mutex_lock(&queue->mutex);
	while (!queue->head && !queue->cancel)
		pthread_cond_wait(&queue->condition, &queue->mutex);
	if (!queue->cancel) {
		entry = queue->head;
		queue->head = entry->next;
	}
	pthread_mutex_unlock(&queue->mutex);
	return entry;
}

void mpmcq_cancel(struct mpmcq *queue)
{
	struct mpmcq_entry *entry;

	pthread_mutex_lock(&queue->mutex);
	queue->cancel = 1;
	pthread_cond_broadcast(&queue->condition);
	pthread_mutex_unlock(&queue->mutex);
}

debug log:

solving 22411af1b0 ...
found 22411af1b0 in https://public-inbox.org/git/20180718204458.20936-2-benpeart@microsoft.com/

applying [1/1] https://public-inbox.org/git/20180718204458.20936-2-benpeart@microsoft.com/
diff --git a/mpmcqueue.c b/mpmcqueue.c
new file mode 100644
index 0000000000..22411af1b0

Checking patch mpmcqueue.c...
Applied patch mpmcqueue.c cleanly.

index at:
100644 22411af1b0d2f093258955e86e375198f693f244	mpmcqueue.c

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).