Commits

marcus  committed 7355da1

Release GIL where possible in PixelArray.

  • Participants
  • Parent commits 509ba60

Comments (0)

Files changed (2)

File src/pixelarray.c

     y = ystart;
     vy = val->ystart;
 
+    Py_BEGIN_ALLOW_THREADS;
     /* Single value assignment. */
     switch (bpp)
     {
         }
         break;
     }
+    Py_END_ALLOW_THREADS;
     
     if (copied)
     {
     absystep = ABS (ystep);
     y = ystart;
 
+    Py_BEGIN_ALLOW_THREADS;
     switch (bpp)
     {
     case 1:
         }
         break;
     }
+    Py_END_ALLOW_THREADS;
     return 0;
 }
 
     absystep = ABS (ystep);
     y = ystart;
 
+    Py_BEGIN_ALLOW_THREADS;
     /* Single value assignment. */
     switch (bpp)
     {
         }
         break;
     }
+    Py_END_ALLOW_THREADS;
     return 0;
 }
 
     absystep = ABS (ystep);
     y = ystart;
 
+    Py_BEGIN_ALLOW_THREADS;
     /* Single value assignment. */
     switch (bpp)
     {
         }
         break;
     }
+    Py_END_ALLOW_THREADS;
     return 0;
 }
 
     Uint32 posy = 0;
     Sint32 absxstep;
     Sint32 absystep;
+    int found = 0;
 
     surface = PySurface_AsSurface (array->surface);
     bpp = surface->format->BytesPerPixel;
     absystep = ABS (array->ystep);
     y = array->ystart;
 
+    Py_BEGIN_ALLOW_THREADS;
     switch (bpp)
     {
     case 1:
-        while (posy < array->ylen)
+        while (posy < array->ylen && !found)
         {
             posx = 0;
             x = array->xstart;
             {
                 if (*((Uint8 *) pixels + y * array->padding + x)
                     == (Uint8) color)
-                    return 1;
+                {
+                    found = 1;
+                    break;
+                }
                 x += array->xstep;
                 posx += absxstep;
             }
         }
         break;
     case 2:
-        while (posy < array->ylen)
+        while (posy < array->ylen && !found)
         {
             posx = 0;
             x = array->xstart;
             {
                 if (*((Uint16 *) (pixels + y * array->padding) + x)
                     == (Uint16) color)
-                    return 1;
+                {
+                    found = 1;
+                    break;
+                }
                 x += array->xstep;
                 posx += absxstep;
             }
         Uint32 pxcolor;
         Uint8 *pix;
 
-        while (posy < array->ylen)
+        while (posy < array->ylen && !found)
         {
             posx = 0;
             x = array->xstart;
                 pxcolor = (pix[2]) + (pix[1] << 8) + (pix[0] << 16);
 #endif
                 if (pxcolor == color)
-                    return 1;
+                {
+                    found = 1;
+                    break;
+                }
                 x += array->xstep;
                 posx += absxstep;
             }
         break;
     }
     default: /* 4 bpp */
-        while (posy < array->ylen)
+        while (posy < array->ylen && !found)
         {
             posx = 0;
             x = array->xstart;
             {
                 if (*((Uint32 *) (pixels + y * array->padding) + x)
                     == color)
-                    return 1;
+                {
+                    found = 1;
+                    break;
+                }
                 x += array->xstep;
                 posx += absxstep;
             }
         }
         break;
     }
-    return 0;
+
+    Py_END_ALLOW_THREADS;
+    return found;
 }
 
 /**

File src/pixelarray_methods.c

     absystep = ABS (array->ystep);
     y = array->ystart;
 
+    Py_BEGIN_ALLOW_THREADS;
     /* Single value assignment. */
     switch (bpp)
     {
         }
         break;
     }
+    Py_END_ALLOW_THREADS;
+
     if (SDL_MUSTLOCK (newsurf) == 0)
         SDL_UnlockSurface (newsurf);
     newsf = PySurface_New (newsurf);
     if (distance)
         SDL_GetRGB (dcolor, surface->format, &r1, &g1, &b1);
 
+    Py_BEGIN_ALLOW_THREADS;
     switch (surface->format->BytesPerPixel)
     {
     case 1:
         break;
     }
     }
+    Py_END_ALLOW_THREADS;
     Py_RETURN_NONE;
 }
 
     absystep = ABS (newarray->ystep);
     y = newarray->ystart;
 
+    Py_BEGIN_ALLOW_THREADS;
     switch (surface->format->BytesPerPixel)
     {
     case 1:
         break;
     }
     }
+    Py_END_ALLOW_THREADS;
     return (PyObject *) newarray;
 }