IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 13, 2008, 5:25:55 PM (18 years ago)
Author:
Paul Price
Message:

Adding threading for pmSubtractionConvolve. This was more difficult than for the others because the threads are working on a common image. Turns out that making child images using psImageSubset is not thread-safe: the image (which all threads are using) is modified. Wrapped those calls up in mutexes, and now threading seems to work fine.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/imcombine/pmSubtractionThreads.c

    r18962 r19059  
    88#include "pmSubtractionMatch.h"
    99#include "pmSubtractionEquation.h"
     10#include "pmSubtraction.h"
    1011
    1112bool threaded = false;                  // Run with threads?
     
    1617}
    1718
    18 void pmSubtractionThreadSetup(void)
     19// Initialise a mutex in each of the input
     20static void subtractionMutexInit(pmReadout *ro)
     21{
     22    if (!ro) {
     23        return;
     24    }
     25
     26    if (ro->image) {
     27        psMutexInit(ro->image);
     28    }
     29    if (ro->weight) {
     30        psMutexInit(ro->weight);
     31    }
     32
     33    return;
     34}
     35
     36static void subtractionMutexDestroy(pmReadout *ro)
     37{
     38    if (!ro) {
     39        return;
     40    }
     41
     42    if (ro->image) {
     43        psMutexDestroy(ro->image);
     44    }
     45    if (ro->weight) {
     46        psMutexDestroy(ro->weight);
     47    }
     48
     49    return;
     50}
     51
     52void pmSubtractionThreadsInit(pmReadout *out1, pmReadout *out2, pmReadout *in1, pmReadout *in2)
    1953{
    2054    if (threaded) {
    21         psAbort("%s called multiple times.", __func__);
     55        psAbort("Already running threaded.");
    2256    }
    2357
    2458    threaded = true;
     59
     60    subtractionMutexInit(out1);
     61    subtractionMutexInit(out2);
     62    subtractionMutexInit(in1);
     63    subtractionMutexInit(in2);
    2564
    2665    {
     
    3877    }
    3978
     79    {
     80        psThreadTask *task = psThreadTaskAlloc("PSMODULES_SUBTRACTION_CONVOLVE", 17);
     81        task->function = &pmSubtractionConvolveThread;
     82        psThreadTaskAdd(task);
     83        psFree(task);
     84    }
     85
    4086    return;
    4187}
    4288
     89
     90void pmSubtractionThreadsFinalize(pmReadout *out1, pmReadout *out2, pmReadout *in1, pmReadout *in2)
     91{
     92    if (!threaded) {
     93        return;
     94    }
     95
     96    threaded = false;
     97    psThreadTaskRemove("PSMODULES_SUBTRACTION_ORDER");
     98    psThreadTaskRemove("PSMODULES_SUBTRACTION_CALCULATE_EQUATION");
     99    psThreadTaskRemove("PSMODULES_SUBTRACTION_CONVOLVE");
     100
     101    subtractionMutexDestroy(out1);
     102    subtractionMutexDestroy(out2);
     103    subtractionMutexDestroy(in1);
     104    subtractionMutexDestroy(in1);
     105    return;
     106}
Note: See TracChangeset for help on using the changeset viewer.