23
23
there was an de/compress object-specific lock. However, for the
24
24
moment the ENTER_ZLIB and LEAVE_ZLIB calls are global for ALL
25
25
de/compress objects.
26
+
27
+ S.T.
28
+ And this is exactly what we do, have one lock per object. This should allow
29
+ multi-threaded compression and decompression
26
30
*/
27
31
28
- static PyThread_type_lock zlib_lock = NULL ; /* initialized on module load */
29
-
30
32
#define ENTER_ZLIB \
31
33
Py_BEGIN_ALLOW_THREADS \
32
- PyThread_acquire_lock(zlib_lock, 1); \
34
+ PyThread_acquire_lock(self-> zlib_lock, 1); \
33
35
Py_END_ALLOW_THREADS
34
36
35
37
#define LEAVE_ZLIB \
36
- PyThread_release_lock(zlib_lock);
38
+ PyThread_release_lock(self-> zlib_lock);
37
39
38
40
#else
39
41
40
42
#define ENTER_ZLIB
41
43
#define LEAVE_ZLIB
42
44
43
- #endif
45
+ #endif /* WITH THREAD */
44
46
45
47
/* The following parameters are copied from zutil.h, version 0.95 */
46
48
#define DEFLATED 8
@@ -67,6 +69,10 @@ typedef struct
67
69
PyObject * unused_data ;
68
70
PyObject * unconsumed_tail ;
69
71
int is_initialised ;
72
+
73
+ #ifdef WITH_THREAD
74
+ PyThread_type_lock zlib_lock ;
75
+ #endif
70
76
} compobject ;
71
77
72
78
static void
@@ -106,6 +112,10 @@ newcompobject(PyTypeObject *type)
106
112
Py_DECREF (self );
107
113
return NULL ;
108
114
}
115
+
116
+ #ifdef WITH_THREAD
117
+ self -> zlib_lock = PyThread_allocate_lock ();
118
+ #endif /* WITH_THREAD */
109
119
return self ;
110
120
}
111
121
@@ -368,6 +378,11 @@ Comp_dealloc(compobject *self)
368
378
deflateEnd (& self -> zst );
369
379
Py_XDECREF (self -> unused_data );
370
380
Py_XDECREF (self -> unconsumed_tail );
381
+
382
+ #ifdef WITH_THREAD
383
+ PyThread_free_lock (self -> zlib_lock );
384
+ #endif /* WITH_THREAD */
385
+
371
386
PyObject_Del (self );
372
387
}
373
388
@@ -378,6 +393,11 @@ Decomp_dealloc(compobject *self)
378
393
inflateEnd (& self -> zst );
379
394
Py_XDECREF (self -> unused_data );
380
395
Py_XDECREF (self -> unconsumed_tail );
396
+
397
+ #ifdef WITH_THREAD
398
+ PyThread_free_lock (self -> zlib_lock );
399
+ #endif /* WITH_THREAD */
400
+
381
401
PyObject_Del (self );
382
402
}
383
403
@@ -1032,8 +1052,4 @@ PyInit_zlib(void)
1032
1052
PyModule_AddObject (m , "ZLIB_VERSION" , ver );
1033
1053
1034
1054
PyModule_AddStringConstant (m , "__version__" , "1.0" );
1035
-
1036
- #ifdef WITH_THREAD
1037
- zlib_lock = PyThread_allocate_lock ();
1038
- #endif /* WITH_THREAD */
1039
1055
}
0 commit comments