mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
Issue #18203: Replace malloc() with PyMem_RawMalloc() to allocate thread locks
This commit is contained in:
parent
b7f1f65f1c
commit
80aa565fb4
2 changed files with 10 additions and 10 deletions
|
@ -34,7 +34,7 @@ typedef NRMUTEX *PNRMUTEX;
|
||||||
PNRMUTEX
|
PNRMUTEX
|
||||||
AllocNonRecursiveMutex()
|
AllocNonRecursiveMutex()
|
||||||
{
|
{
|
||||||
PNRMUTEX m = (PNRMUTEX)malloc(sizeof(NRMUTEX));
|
PNRMUTEX m = (PNRMUTEX)PyMem_RawMalloc(sizeof(NRMUTEX));
|
||||||
if (!m)
|
if (!m)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (PyCOND_INIT(&m->cv))
|
if (PyCOND_INIT(&m->cv))
|
||||||
|
@ -46,7 +46,7 @@ AllocNonRecursiveMutex()
|
||||||
m->locked = 0;
|
m->locked = 0;
|
||||||
return m;
|
return m;
|
||||||
fail:
|
fail:
|
||||||
free(m);
|
PyMem_RawFree(m);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ FreeNonRecursiveMutex(PNRMUTEX mutex)
|
||||||
if (mutex) {
|
if (mutex) {
|
||||||
PyCOND_FINI(&mutex->cv);
|
PyCOND_FINI(&mutex->cv);
|
||||||
PyMUTEX_FINI(&mutex->cs);
|
PyMUTEX_FINI(&mutex->cs);
|
||||||
free(mutex);
|
PyMem_RawFree(mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ LeaveNonRecursiveMutex(PNRMUTEX mutex)
|
||||||
result = PyCOND_SIGNAL(&mutex->cv);
|
result = PyCOND_SIGNAL(&mutex->cv);
|
||||||
result &= PyMUTEX_UNLOCK(&mutex->cs);
|
result &= PyMUTEX_UNLOCK(&mutex->cs);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* if ! _PY_USE_CV_LOCKS */
|
#else /* if ! _PY_USE_CV_LOCKS */
|
||||||
|
|
||||||
|
|
|
@ -282,14 +282,14 @@ PyThread_allocate_lock(void)
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
PyThread_init_thread();
|
PyThread_init_thread();
|
||||||
|
|
||||||
lock = (sem_t *)malloc(sizeof(sem_t));
|
lock = (sem_t *)PyMem_RawMalloc(sizeof(sem_t));
|
||||||
|
|
||||||
if (lock) {
|
if (lock) {
|
||||||
status = sem_init(lock,0,1);
|
status = sem_init(lock,0,1);
|
||||||
CHECK_STATUS("sem_init");
|
CHECK_STATUS("sem_init");
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
free((void *)lock);
|
PyMem_RawFree((void *)lock);
|
||||||
lock = NULL;
|
lock = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -313,7 +313,7 @@ PyThread_free_lock(PyThread_type_lock lock)
|
||||||
status = sem_destroy(thelock);
|
status = sem_destroy(thelock);
|
||||||
CHECK_STATUS("sem_destroy");
|
CHECK_STATUS("sem_destroy");
|
||||||
|
|
||||||
free((void *)thelock);
|
PyMem_RawFree((void *)thelock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -410,7 +410,7 @@ PyThread_allocate_lock(void)
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
PyThread_init_thread();
|
PyThread_init_thread();
|
||||||
|
|
||||||
lock = (pthread_lock *) malloc(sizeof(pthread_lock));
|
lock = (pthread_lock *) PyMem_RawMalloc(sizeof(pthread_lock));
|
||||||
if (lock) {
|
if (lock) {
|
||||||
memset((void *)lock, '\0', sizeof(pthread_lock));
|
memset((void *)lock, '\0', sizeof(pthread_lock));
|
||||||
lock->locked = 0;
|
lock->locked = 0;
|
||||||
|
@ -430,7 +430,7 @@ PyThread_allocate_lock(void)
|
||||||
CHECK_STATUS("pthread_cond_init");
|
CHECK_STATUS("pthread_cond_init");
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
free((void *)lock);
|
PyMem_RawFree((void *)lock);
|
||||||
lock = 0;
|
lock = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -457,7 +457,7 @@ PyThread_free_lock(PyThread_type_lock lock)
|
||||||
status = pthread_mutex_destroy( &thelock->mut );
|
status = pthread_mutex_destroy( &thelock->mut );
|
||||||
CHECK_STATUS("pthread_mutex_destroy");
|
CHECK_STATUS("pthread_mutex_destroy");
|
||||||
|
|
||||||
free((void *)thelock);
|
PyMem_RawFree((void *)thelock);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyLockStatus
|
PyLockStatus
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue