Skip to content

Commit fb15d2b

Browse files
committed
Remove last DBMUTEX_FORCE
1 parent 1216a58 commit fb15d2b

2 files changed

Lines changed: 5 additions & 32 deletions

File tree

src/connection.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -755,22 +755,17 @@ Connection_init(PyObject *self_, PyObject *args, PyObject *kwargs)
755755
/* clean up db since it is useless - no need for user to call close */
756756
assert(PyErr_Occurred());
757757
res = -1;
758-
DBMUTEX_FORCE(self->dbmutex);
759-
Connection_close_internal(self, 2);
760-
assert(PyErr_Occurred());
761758

762759
finally:
763760
Py_XDECREF(iterator);
764761
Py_XDECREF(hook);
765762
if (res == 0)
766-
{
767763
res = apsw_connection_add(self);
768-
if (res)
769-
{
770-
DBMUTEX_FORCE(self->dbmutex);
771-
Connection_close_internal(self, 2);
772-
}
773-
}
764+
765+
/* proactively cleanup if possible */
766+
if (res != 0 && sqlite3_mutex_try(self->dbmutex) == SQLITE_OK)
767+
Connection_close_internal(self, 2);
768+
774769
assert((PyErr_Occurred() && res != 0) || (res == 0 && !PyErr_Occurred()));
775770
return res;
776771
}

src/util.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,6 @@
4747
} \
4848
} while (0)
4949

50-
/* use this when we have to get the dbmutex - eg in dealloc functions
51-
- where we busy wait releasing gil until dbmutex is acquired.
52-
53-
a different thread could be running a sqlite3_step with the GIL
54-
released and holding the mutex. when it finishes it will want
55-
the GIL so it can copy error messages etc, but we are holding the
56-
GIL. only after it has copied data into python will it then
57-
release the db mutex.
58-
59-
if the fork checker is in use and this object was allocated in one
60-
process and then freed in the next, it will busy loop forever
61-
on SQLITE_MISUSE and spamming the unraisable exception hook with
62-
forking violation */
63-
#define DBMUTEX_FORCE(mutex) \
64-
do \
65-
{ \
66-
while (sqlite3_mutex_try(mutex) != SQLITE_OK) \
67-
{ \
68-
Py_BEGIN_ALLOW_THREADS Py_END_ALLOW_THREADS; \
69-
} \
70-
} while (0)
71-
7250
#define DBMUTEX_RETRY_2(conn1, conn2, func) \
7351
do \
7452
{ \

0 commit comments

Comments
 (0)