Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7bb1c9a

Browse files
committed
Remove the unused & broken PyThread_*_sema() functions and related constants.
This closes SF patch #504215.
1 parent 72c3bf0 commit 7bb1c9a

11 files changed

Lines changed: 0 additions & 557 deletions

Include/pythread.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ DL_IMPORT(int) PyThread_acquire_lock(PyThread_type_lock, int);
2525
#define NOWAIT_LOCK 0
2626
DL_IMPORT(void) PyThread_release_lock(PyThread_type_lock);
2727

28-
DL_IMPORT(PyThread_type_sema) PyThread_allocate_sema(int);
29-
DL_IMPORT(void) PyThread_free_sema(PyThread_type_sema);
30-
DL_IMPORT(int) PyThread_down_sema(PyThread_type_sema, int);
31-
#define WAIT_SEMA 1
32-
#define NOWAIT_SEMA 0
33-
DL_IMPORT(void) PyThread_up_sema(PyThread_type_sema);
34-
3528
#ifndef NO_EXIT_PROG
3629
DL_IMPORT(void) PyThread_exit_prog(int);
3730
DL_IMPORT(void) PyThread__PyThread_exit_prog(int);

Python/thread_beos.h

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -285,73 +285,3 @@ void PyThread_release_lock( PyThread_type_lock lock )
285285
return;
286286
}
287287
}
288-
289-
/* ----------------------------------------------------------------------
290-
* Semaphore support.
291-
*
292-
* Guido says not to implement this because it's not used anywhere;
293-
* I'll do it anyway, you never know when it might be handy, and it's
294-
* easy...
295-
*/
296-
PyThread_type_sema PyThread_allocate_sema( int value )
297-
{
298-
sem_id sema;
299-
300-
dprintf(("PyThread_allocate_sema called\n"));
301-
302-
sema = create_sem( value, "python semaphore" );
303-
if( sema < B_NO_ERROR ) {
304-
/* TODO: that's bad, raise an exception */
305-
return 0;
306-
}
307-
308-
dprintf(("PyThread_allocate_sema() -> %p\n", sema));
309-
return (PyThread_type_sema) sema;
310-
}
311-
312-
void PyThread_free_sema( PyThread_type_sema sema )
313-
{
314-
status_t retval;
315-
316-
dprintf(("PyThread_free_sema(%p) called\n", sema));
317-
318-
retval = delete_sem( (sem_id)sema );
319-
if( retval != B_NO_ERROR ) {
320-
/* TODO: that's bad, raise an exception */
321-
return;
322-
}
323-
}
324-
325-
int PyThread_down_sema( PyThread_type_sema sema, int waitflag )
326-
{
327-
status_t retval;
328-
329-
dprintf(("PyThread_down_sema(%p, %d) called\n", sema, waitflag));
330-
331-
if( waitflag ) {
332-
retval = acquire_sem( (sem_id)sema );
333-
} else {
334-
retval = acquire_sem_etc( (sem_id)sema, 1, B_TIMEOUT, 0 );
335-
}
336-
337-
if( retval != B_NO_ERROR ) {
338-
/* TODO: that's bad, raise an exception */
339-
return 0;
340-
}
341-
342-
dprintf(("PyThread_down_sema(%p) return\n", sema));
343-
return -1;
344-
}
345-
346-
void PyThread_up_sema( PyThread_type_sema sema )
347-
{
348-
status_t retval;
349-
350-
dprintf(("PyThread_up_sema(%p)\n", sema));
351-
352-
retval = release_sem( (sem_id)sema );
353-
if( retval != B_NO_ERROR ) {
354-
/* TODO: that's bad, raise an exception */
355-
return;
356-
}
357-
}

Python/thread_cthread.h

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -154,49 +154,3 @@ PyThread_release_lock(PyThread_type_lock lock)
154154
dprintf(("PyThread_release_lock(%p) called\n", lock));
155155
mutex_unlock((mutex_t )lock);
156156
}
157-
158-
/*
159-
* Semaphore support.
160-
*
161-
* This implementation is ripped directly from the pthreads implementation.
162-
* Which is to say that it is 100% non-functional at this time.
163-
*
164-
* Assuming the page is still up, documentation can be found at:
165-
*
166-
* http://www.doc.ic.ac.uk/~mac/manuals/solaris-manual-pages/solaris/usr/man/man2/_lwp_sema_wait.2.html
167-
*
168-
* Looking at the man page, it seems that one could easily implement a
169-
* semaphore using a condition.
170-
*
171-
*/
172-
PyThread_type_sema
173-
PyThread_allocate_sema(int value)
174-
{
175-
char *sema = 0;
176-
dprintf(("PyThread_allocate_sema called\n"));
177-
if (!initialized)
178-
PyThread_init_thread();
179-
180-
dprintf(("PyThread_allocate_sema() -> %p\n", sema));
181-
return (PyThread_type_sema) sema;
182-
}
183-
184-
void
185-
PyThread_free_sema(PyThread_type_sema sema)
186-
{
187-
dprintf(("PyThread_free_sema(%p) called\n", sema));
188-
}
189-
190-
int
191-
PyThread_down_sema(PyThread_type_sema sema, int waitflag)
192-
{
193-
dprintf(("PyThread_down_sema(%p, %d) called\n", sema, waitflag));
194-
dprintf(("PyThread_down_sema(%p) return\n", sema));
195-
return -1;
196-
}
197-
198-
void
199-
PyThread_up_sema(PyThread_type_sema sema)
200-
{
201-
dprintf(("PyThread_up_sema(%p)\n", sema));
202-
}

Python/thread_foobar.h

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -113,37 +113,3 @@ PyThread_release_lock(PyThread_type_lock lock)
113113
{
114114
dprintf(("PyThread_release_lock(%p) called\n", lock));
115115
}
116-
117-
/*
118-
* Semaphore support.
119-
*/
120-
PyThread_type_sema
121-
PyThread_allocate_sema(int value)
122-
{
123-
dprintf(("PyThread_allocate_sema called\n"));
124-
if (!initialized)
125-
PyThread_init_thread();
126-
127-
dprintf(("PyThread_allocate_sema() -> %p\n", sema));
128-
return (PyThread_type_sema) sema;
129-
}
130-
131-
void
132-
PyThread_free_sema(PyThread_type_sema sema)
133-
{
134-
dprintf(("PyThread_free_sema(%p) called\n", sema));
135-
}
136-
137-
int
138-
PyThread_down_sema(PyThread_type_sema sema, int waitflag)
139-
{
140-
dprintf(("PyThread_down_sema(%p, %d) called\n", sema, waitflag));
141-
dprintf(("PyThread_down_sema(%p) return\n", sema));
142-
return -1;
143-
}
144-
145-
void
146-
PyThread_up_sema(PyThread_type_sema sema)
147-
{
148-
dprintf(("PyThread_up_sema(%p)\n", sema));
149-
}

Python/thread_lwp.h

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -147,34 +147,3 @@ void PyThread_release_lock(PyThread_type_lock lock)
147147
cv_broadcast(((struct lock *) lock)->lock_condvar);
148148
mon_exit(((struct lock *) lock)->lock_monitor);
149149
}
150-
151-
/*
152-
* Semaphore support.
153-
*/
154-
PyThread_type_sema PyThread_allocate_sema(int value)
155-
{
156-
PyThread_type_sema sema = 0;
157-
dprintf(("PyThread_allocate_sema called\n"));
158-
if (!initialized)
159-
PyThread_init_thread();
160-
161-
dprintf(("PyThread_allocate_sema() -> %p\n", sema));
162-
return (PyThread_type_sema) sema;
163-
}
164-
165-
void PyThread_free_sema(PyThread_type_sema sema)
166-
{
167-
dprintf(("PyThread_free_sema(%p) called\n", sema));
168-
}
169-
170-
int PyThread_down_sema(PyThread_type_sema sema, int waitflag)
171-
{
172-
dprintf(("PyThread_down_sema(%p, %d) called\n", sema, waitflag));
173-
dprintf(("PyThread_down_sema(%p) return\n", sema));
174-
return -1;
175-
}
176-
177-
void PyThread_up_sema(PyThread_type_sema sema)
178-
{
179-
dprintf(("PyThread_up_sema(%p)\n", sema));
180-
}

Python/thread_nt.h

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -319,56 +319,3 @@ void PyThread_release_lock(PyThread_type_lock aLock)
319319
if (!(aLock && LeaveNonRecursiveMutex((PNRMUTEX) aLock)))
320320
dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n", PyThread_get_thread_ident(), aLock, GetLastError()));
321321
}
322-
323-
/*
324-
* Semaphore support.
325-
*/
326-
PyThread_type_sema PyThread_allocate_sema(int value)
327-
{
328-
HANDLE aSemaphore;
329-
330-
dprintf(("%ld: PyThread_allocate_sema called\n", PyThread_get_thread_ident()));
331-
if (!initialized)
332-
PyThread_init_thread();
333-
334-
aSemaphore = CreateSemaphore( NULL, /* Security attributes */
335-
value, /* Initial value */
336-
INT_MAX, /* Maximum value */
337-
NULL); /* Name of semaphore */
338-
339-
dprintf(("%ld: PyThread_allocate_sema() -> %p\n", PyThread_get_thread_ident(), aSemaphore));
340-
341-
return (PyThread_type_sema) aSemaphore;
342-
}
343-
344-
void PyThread_free_sema(PyThread_type_sema aSemaphore)
345-
{
346-
dprintf(("%ld: PyThread_free_sema(%p) called\n", PyThread_get_thread_ident(), aSemaphore));
347-
348-
CloseHandle((HANDLE) aSemaphore);
349-
}
350-
351-
/*
352-
XXX must do something about waitflag
353-
*/
354-
int PyThread_down_sema(PyThread_type_sema aSemaphore, int waitflag)
355-
{
356-
DWORD waitResult;
357-
358-
dprintf(("%ld: PyThread_down_sema(%p) called\n", PyThread_get_thread_ident(), aSemaphore));
359-
360-
waitResult = WaitForSingleObject( (HANDLE) aSemaphore, INFINITE);
361-
362-
dprintf(("%ld: PyThread_down_sema(%p) return: %l\n", PyThread_get_thread_ident(), aSemaphore, waitResult));
363-
return 0;
364-
}
365-
366-
void PyThread_up_sema(PyThread_type_sema aSemaphore)
367-
{
368-
ReleaseSemaphore(
369-
(HANDLE) aSemaphore, /* Handle of semaphore */
370-
1, /* increment count by one */
371-
NULL); /* not interested in previous count */
372-
373-
dprintf(("%ld: PyThread_up_sema(%p)\n", PyThread_get_thread_ident(), aSemaphore));
374-
}

Python/thread_os2.h

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -209,30 +209,3 @@ void PyThread_release_lock(PyThread_type_lock aLock)
209209

210210
DosExitCritSec();
211211
}
212-
213-
/*
214-
* Semaphore support.
215-
*/
216-
PyThread_type_sema
217-
PyThread_allocate_sema(int value)
218-
{
219-
return (PyThread_type_sema) 0;
220-
}
221-
222-
void
223-
PyThread_free_sema(PyThread_type_sema aSemaphore)
224-
{
225-
226-
}
227-
228-
int
229-
PyThread_down_sema(PyThread_type_sema aSemaphore, int waitflag)
230-
{
231-
return -1;
232-
}
233-
234-
void
235-
PyThread_up_sema(PyThread_type_sema aSemaphore)
236-
{
237-
dprintf(("%ld: PyThread_up_sema(%p)\n", PyThread_get_thread_ident(), aSemaphore));
238-
}

Python/thread_pth.h

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -206,90 +206,3 @@ void PyThread_release_lock(PyThread_type_lock lock)
206206
status = pth_cond_notify( &thelock->lock_released, 0 );
207207
CHECK_STATUS("pth_cond_notify");
208208
}
209-
210-
/*
211-
* Semaphore support.
212-
*/
213-
214-
struct semaphore {
215-
pth_mutex_t mutex;
216-
pth_cond_t cond;
217-
int value;
218-
};
219-
220-
PyThread_type_sema PyThread_allocate_sema(int value)
221-
{
222-
struct semaphore *sema;
223-
int status, error = 0;
224-
225-
dprintf(("PyThread_allocate_sema called\n"));
226-
if (!initialized)
227-
PyThread_init_thread();
228-
229-
sema = (struct semaphore *) malloc(sizeof(struct semaphore));
230-
if (sema != NULL) {
231-
sema->value = value;
232-
status = pth_mutex_init(&sema->mutex);
233-
CHECK_STATUS("pth_mutex_init");
234-
status = pth_cond_init(&sema->cond);
235-
CHECK_STATUS("pth_mutex_init");
236-
if (error) {
237-
free((void *) sema);
238-
sema = NULL;
239-
}
240-
}
241-
dprintf(("PyThread_allocate_sema() -> %p\n", sema));
242-
return (PyThread_type_sema) sema;
243-
}
244-
245-
void PyThread_free_sema(PyThread_type_sema sema)
246-
{
247-
struct semaphore *thesema = (struct semaphore *) sema;
248-
249-
dprintf(("PyThread_free_sema(%p) called\n", sema));
250-
free((void *) thesema);
251-
}
252-
253-
int PyThread_down_sema(PyThread_type_sema sema, int waitflag)
254-
{
255-
int status, error = 0, success;
256-
struct semaphore *thesema = (struct semaphore *) sema;
257-
258-
dprintf(("PyThread_down_sema(%p, %d) called\n", sema, waitflag));
259-
status = pth_mutex_acquire(&thesema->mutex, !waitflag, NULL);
260-
CHECK_STATUS("pth_mutex_acquire");
261-
if (waitflag) {
262-
while (!error && thesema->value <= 0) {
263-
status = pth_cond_await(&thesema->cond,
264-
&thesema->mutex, NULL);
265-
CHECK_STATUS("pth_cond_await");
266-
}
267-
}
268-
if (error)
269-
success = 0;
270-
else if (thesema->value > 0) {
271-
thesema->value--;
272-
success = 1;
273-
}
274-
else
275-
success = 0;
276-
status = pth_mutex_release(&thesema->mutex);
277-
CHECK_STATUS("pth_mutex_release");
278-
dprintf(("PyThread_down_sema(%p) return\n", sema));
279-
return success;
280-
}
281-
282-
void PyThread_up_sema(PyThread_type_sema sema)
283-
{
284-
int status, error = 0;
285-
struct semaphore *thesema = (struct semaphore *) sema;
286-
287-
dprintf(("PyThread_up_sema(%p)\n", sema));
288-
status = pth_mutex_acquire(&thesema->mutex, 0, NULL);
289-
CHECK_STATUS("pth_mutex_acquire");
290-
thesema->value++;
291-
status = pth_cond_notify(&thesema->cond, 1);
292-
CHECK_STATUS("pth_cond_notify");
293-
status = pth_mutex_release(&thesema->mutex);
294-
CHECK_STATUS("pth_mutex_release");
295-
}

0 commit comments

Comments
 (0)