diff -r 7f798c38beea django/contrib/gis/geos/prototypes/threadsafe.py
|
a
|
b
|
|
| 20 | 20 | |
| 21 | 21 | thread_context = GEOSContext() |
| 22 | 22 | |
| 23 | | def call_geos_threaded(cfunc, args): |
| 24 | | """ |
| 25 | | This module-level routine calls the specified GEOS C thread-safe |
| 26 | | function with the context for this current thread. |
| 27 | | """ |
| 28 | | # If a context handle does not exist for this thread, initialize one. |
| 29 | | if not thread_context.handle: |
| 30 | | thread_context.handle = GEOSContextHandle() |
| 31 | | # Call the threaded GEOS routine with pointer of the context handle |
| 32 | | # as the first argument. |
| 33 | | return cfunc(thread_context.handle.ptr, *args) |
| 34 | | |
| 35 | 23 | class GEOSFunc(object): |
| 36 | 24 | """ |
| 37 | 25 | Class that serves as a wrapper for GEOS C Functions, and will |
| … |
… |
|
| 43 | 31 | # take an additional context handle parameter. |
| 44 | 32 | self.cfunc = getattr(lgeos, func_name + '_r') |
| 45 | 33 | self.threaded = True |
| | 34 | # Create a reference here to thread_context so it's not |
| | 35 | # garbage-collected before an attempt to call this object. |
| | 36 | self.thread_context = thread_context |
| 46 | 37 | except AttributeError: |
| 47 | 38 | # Otherwise, use usual function. |
| 48 | 39 | self.cfunc = getattr(lgeos, func_name) |
| … |
… |
|
| 50 | 41 | |
| 51 | 42 | def __call__(self, *args): |
| 52 | 43 | if self.threaded: |
| 53 | | return call_geos_threaded(self.cfunc, args) |
| | 44 | # If a context handle does not exist for this thread, initialize one. |
| | 45 | if not self.thread_context.handle: |
| | 46 | self.thread_context.handle = GEOSContextHandle() |
| | 47 | # Call the threaded GEOS routine with pointer of the context handle |
| | 48 | # as the first argument. |
| | 49 | return self.cfunc(self.thread_context.handle.ptr, *args) |
| 54 | 50 | else: |
| 55 | 51 | return self.cfunc(*args) |
| 56 | 52 | |