Skip to content

Commit c0a087a

Browse files
committed
Simplify some code away.
1 parent d3e890c commit c0a087a

File tree

2 files changed

+7
-28
lines changed

2 files changed

+7
-28
lines changed

Modules/_queuemodule.c

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
2-
/* Thread module */
3-
/* Interface to Sjoerd's portable C thread library */
4-
51
#include "Python.h"
62
#include "structmember.h" /* offsetof */
73

@@ -23,8 +19,6 @@ extern PyTypeObject PySimpleQueueType; /* forward decl */
2319

2420
static PyObject *EmptyError;
2521

26-
static _PyTime_t infinite_timeout_val;
27-
2822

2923
typedef struct {
3024
PyObject_HEAD
@@ -103,7 +97,7 @@ _queue_SimpleQueue___init___impl(simplequeueobject *self)
10397
_queue.SimpleQueue.put
10498
item: object
10599
106-
Put the item on the queue, without blocking.
100+
Put the item on the queue. This method never blocks.
107101
108102
[clinic start generated code]*/
109103

@@ -147,8 +141,9 @@ simplequeue_pop_item(simplequeueobject *self)
147141
self->lst_pos += 1;
148142
count = n - self->lst_pos;
149143
if (self->lst_pos > count) {
150-
/* reclaim space at beginning of list */
144+
/* The list is more than 50% empty, reclaim space at the beginning */
151145
if (PyList_SetSlice(self->lst, 0, self->lst_pos, NULL)) {
146+
/* Undo pop */
152147
self->lst_pos -= 1;
153148
PyList_SET_ITEM(self->lst, self->lst_pos, item);
154149
return NULL;
@@ -214,25 +209,6 @@ _queue_SimpleQueue_get_impl(simplequeueobject *self, int block,
214209
microseconds = -1;
215210
}
216211

217-
// fprintf(stderr,
218-
// "GET [%lu] (lst_pos = %zd, count = %zd, locked = %d)\n",
219-
// PyThread_get_thread_ident(), self->lst_pos, PyList_GET_SIZE(self->lst) - self->lst_pos, self->locked);
220-
if (self->lst_pos < PyList_GET_SIZE(self->lst)) {
221-
/* Fast path */
222-
assert(!self->locked);
223-
/* BEGIN GIL-protected critical section */
224-
item = simplequeue_pop_item(self);
225-
if (item == NULL) {
226-
return NULL;
227-
}
228-
/* END GIL-protected critical section */
229-
assert(!self->locked);
230-
// fprintf(stderr,
231-
// "/GET [%lu] fast (lst_pos = %zd, count = %zd, locked = %d)\n",
232-
// PyThread_get_thread_ident(), self->lst_pos, PyList_GET_SIZE(self->lst) - self->lst_pos, self->locked);
233-
return item;
234-
}
235-
236212
/* put() signals the queue to be non-empty by releasing the lock.
237213
* So we simply try to acquire the lock in a loop, until the condition
238214
* (queue non-empty) becomes true.
@@ -383,6 +359,5 @@ PyInit__queue(void)
383359
if (PyModule_AddObject(m, "SimpleQueue", (PyObject *)&PySimpleQueueType) < 0)
384360
return NULL;
385361

386-
infinite_timeout_val = _PyTime_FromSeconds(-1);
387362
return m;
388363
}

Modules/_threadmodule.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2+
/* Thread module */
3+
/* Interface to Sjoerd's portable C thread library */
4+
15
#include "Python.h"
26
#include "structmember.h" /* offsetof */
37

0 commit comments

Comments
 (0)