Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/lcms2/plugins/threaded/src/threaded_scheduler.c @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 //--------------------------------------------------------------------------------- | |
| 2 // | |
| 3 // Little Color Management System, multithreaded extensions | |
| 4 // Copyright (c) 1998-2023 Marti Maria Saguer, all rights reserved | |
| 5 // | |
| 6 // | |
| 7 // This program is free software: you can redistribute it and/or modify | |
| 8 // it under the terms of the GNU General Public License as published by | |
| 9 // the Free Software Foundation, either version 3 of the License, or | |
| 10 // (at your option) any later version. | |
| 11 // | |
| 12 // This program is distributed in the hope that it will be useful, | |
| 13 // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 // GNU General Public License for more details. | |
| 16 // | |
| 17 // You should have received a copy of the GNU General Public License | |
| 18 // along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 19 // | |
| 20 //--------------------------------------------------------------------------------- | |
| 21 | |
| 22 #include "threaded_internal.h" | |
| 23 | |
| 24 // The scheduler is responsible to split the work in several portions in a way that each | |
| 25 // portion can be calculated by a different thread. All locking is already done by lcms | |
| 26 // mutexes, memory should not overlap. | |
| 27 void _cmsThrScheduler(struct _cmstransform_struct* CMMcargo, | |
| 28 const void* InputBuffer, | |
| 29 void* OutputBuffer, | |
| 30 cmsUInt32Number PixelsPerLine, | |
| 31 cmsUInt32Number LineCount, | |
| 32 const cmsStride* Stride) | |
| 33 { | |
| 34 cmsContext ContextID = cmsGetTransformContextID(CMMcargo); | |
| 35 _cmsTransform2Fn worker = _cmsGetTransformWorker(CMMcargo); | |
| 36 cmsInt32Number MaxWorkers = _cmsGetTransformMaxWorkers(CMMcargo); | |
| 37 | |
| 38 // flags are not actually being used | |
| 39 // cmsUInt32Number flags = _cmsGetTransformWorkerFlags(CMMcargo); | |
| 40 | |
| 41 _cmsWorkSlice master; | |
| 42 _cmsWorkSlice* slices; | |
| 43 cmsStride FixedStride = *Stride; | |
| 44 cmsHANDLE* handles; | |
| 45 | |
| 46 // Count the number of threads needed for this job. MaxWorkers is the upper limit or -1 to auto | |
| 47 cmsUInt32Number nSlices = _cmsThrCountSlices(CMMcargo, MaxWorkers, PixelsPerLine, LineCount, &FixedStride); | |
| 48 | |
| 49 // Abort early if no threaded code | |
| 50 if (nSlices <= 1) { | |
| 51 | |
| 52 worker(CMMcargo, InputBuffer, OutputBuffer, PixelsPerLine, LineCount, Stride); | |
| 53 return; | |
| 54 } | |
| 55 | |
| 56 // Setup master thread | |
| 57 master.CMMcargo = CMMcargo; | |
| 58 master.InputBuffer = InputBuffer; | |
| 59 master.OutputBuffer = OutputBuffer; | |
| 60 master.PixelsPerLine = PixelsPerLine; | |
| 61 master.LineCount = LineCount; | |
| 62 master.Stride = &FixedStride; | |
| 63 | |
| 64 // Create memory for the slices | |
| 65 slices = (_cmsWorkSlice*)_cmsCalloc(ContextID, nSlices, sizeof(_cmsWorkSlice)); | |
| 66 handles = (cmsHANDLE*) _cmsCalloc(ContextID, nSlices, sizeof(cmsHANDLE)); | |
| 67 | |
| 68 if (slices == NULL || handles == NULL) | |
| 69 { | |
| 70 if (slices) _cmsFree(ContextID, slices); | |
| 71 if (handles) _cmsFree(ContextID, handles); | |
| 72 | |
| 73 // Out of memory in this case only can come from a corruption, but we do the work anyway | |
| 74 worker(CMMcargo, InputBuffer, OutputBuffer, PixelsPerLine, LineCount, Stride); | |
| 75 return; | |
| 76 } | |
| 77 | |
| 78 // All seems ok so far | |
| 79 if (_cmsThrSplitWork(&master, nSlices, slices)) | |
| 80 { | |
| 81 // Work is splitted. Create threads | |
| 82 cmsUInt32Number i; | |
| 83 | |
| 84 for (i = 1; i < nSlices; i++) | |
| 85 { | |
| 86 handles[i] = _cmsThrCreateWorker(ContextID, worker, &slices[i]); | |
| 87 } | |
| 88 | |
| 89 // Do our portion of work | |
| 90 worker(CMMcargo, slices[0].InputBuffer, slices[0].OutputBuffer, | |
| 91 slices[0].PixelsPerLine, slices[0].LineCount, slices[0].Stride); | |
| 92 | |
| 93 // Wait until all threads are finished | |
| 94 for (i = 1; i < nSlices; i++) | |
| 95 { | |
| 96 _cmsThrJoinWorker(ContextID, handles[i]); | |
| 97 } | |
| 98 } | |
| 99 else | |
| 100 { | |
| 101 // Not able to split the work, so don't thread | |
| 102 worker(CMMcargo, InputBuffer, OutputBuffer, PixelsPerLine, LineCount, Stride); | |
| 103 } | |
| 104 | |
| 105 _cmsFree(ContextID, slices); | |
| 106 _cmsFree(ContextID, handles); | |
| 107 } | |
| 108 |
