Changeset 27903 for trunk/psModules
- Timestamp:
- May 10, 2010, 12:47:31 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/objects/pmSourceFitSet.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/objects/pmSourceFitSet.c
r25754 r27903 62 62 // before pmSourceFitSetInit is called 63 63 for (int i = 0; i < fitSets->n; i++) { 64 psAssert (fitSets->data[i] == NULL, "failure to init or clear fitSets?");64 psAssert(fitSets->data[i] == NULL, "failure to init or clear fitSets?"); 65 65 } 66 66 return true; … … 68 68 69 69 void pmSourceFitSetDone (void) { 70 psFree (fitSets); 70 psFree(fitSets); 71 fitSets = NULL; 71 72 } 72 73 … … 113 114 } 114 115 115 pmSourceFitSetData *pmSourceFitSetDataSet (psArray *modelSet) { 116 117 pmSourceFitSetData *thisSet = NULL; 118 119 psAssert (fitSets, "pmSourceFitSetInit not called"); 116 pmSourceFitSetData *pmSourceFitSetDataSet (psArray *modelSet) 117 { 118 psAssert(fitSets, "pmSourceFitSetInit not called"); 120 119 121 120 // find the fitSet used by this thread 122 121 pthread_t id = pthread_self(); 123 122 124 // is our ID is already on the stack, abort. 125 // we do not need to lock to do this.... 123 // If our ID is already on the stack, abort. 124 // We do need to lock on this because someone might pull one of the fitSets out from under us 125 pthread_mutex_lock(&fitSetInitMutex); 126 126 for (int i = 0; i < fitSets->n; i++) { 127 thisSet = fitSets->data[i];127 pmSourceFitSetData *thisSet = fitSets->data[i]; 128 128 if (!thisSet) continue; 129 129 if (thisSet->thread == id) { 130 break; 131 } 132 thisSet = NULL; 133 } 134 psAssert (thisSet == NULL, "pmSourceFitSetDataSet() called but previous entry not cleared"); 135 136 thisSet = pmSourceFitSetDataAlloc(modelSet); 137 138 pthread_mutex_lock (&fitSetInitMutex); 139 140 // find an entry that is NULL and place it there 130 psAbort("pmSourceFitSetDataSet() called but previous entry not cleared"); 131 } 132 } 133 134 // Find an open slot 141 135 for (int i = 0; i < fitSets->n; i++) { 142 136 if (fitSets->data[i]) continue; 143 fitSets->data[i] = thisSet;144 pthread_mutex_unlock (&fitSetInitMutex);137 pmSourceFitSetData *thisSet = fitSets->data[i] = pmSourceFitSetDataAlloc(modelSet); 138 pthread_mutex_unlock(&fitSetInitMutex); 145 139 return thisSet; 146 140 } 147 pthread_mutex_unlock (&fitSetInitMutex);148 psAbort ("no empty slot for new pmSourceFitSetData");141 pthread_mutex_unlock(&fitSetInitMutex); 142 psAbort("no empty slot for new pmSourceFitSetData"); 149 143 return NULL; 150 144 } … … 152 146 pmSourceFitSetData *pmSourceFitSetDataGet (void) { 153 147 154 psAssert (fitSets, "pmSourceFitSetInit not called"); 155 156 // find the fitSet used by this thread 148 psAssert(fitSets, "pmSourceFitSetInit not called"); 149 150 // Find the fitSet used by this thread 151 // We do need to lock on this because someone might pull one of the fitSets out from under us 157 152 pthread_t id = pthread_self(); 158 159 // can we find our fitSet? we do not need to lock to do this.... 160 pmSourceFitSetData *thisSet = NULL; 153 pthread_mutex_lock(&fitSetInitMutex); 161 154 for (int i = 0; i < fitSets->n; i++) { 162 thisSet = fitSets->data[i];155 pmSourceFitSetData *thisSet = fitSets->data[i]; 163 156 if (!thisSet) continue; 164 157 if (thisSet->thread == id) { 165 break; 166 } 167 thisSet = NULL; 168 } 169 psAssert (thisSet != NULL, "pmSourceFitSetDataGet() called, but no entry found"); 170 171 return thisSet; 172 } 173 174 void pmSourceFitSetDataClear (void) { 175 176 int i; 177 158 pthread_mutex_unlock(&fitSetInitMutex); 159 return thisSet; 160 } 161 } 162 psAbort("pmSourceFitSetDataGet() called, but no entry found"); 163 } 164 165 void pmSourceFitSetDataClear (void) 166 { 178 167 psAssert (fitSets, "pmSourceFitSetInit not called"); 179 168 180 // find the fitSet used by this thread 169 // Find the fitSet used by this thread 170 // We do need to lock on this because someone might pull one of the fitSets out from under us 181 171 pthread_t id = pthread_self(); 182 183 // can we find our fitSet? we do not need to lock to do this.... 184 pmSourceFitSetData *thisSet = NULL; 185 for (i = 0; i < fitSets->n; i++) { 186 thisSet = fitSets->data[i]; 172 pthread_mutex_lock(&fitSetInitMutex); 173 for (int i = 0; i < fitSets->n; i++) { 174 pmSourceFitSetData *thisSet = fitSets->data[i]; 187 175 if (!thisSet) continue; 188 176 if (thisSet->thread == id) { 189 break;190 }191 thisSet = NULL;192 }193 psAssert (thisSet != NULL, "pmSourceFitSetDataClear() called, but no entry found");194 195 ps Free (thisSet);196 fitSets->data[i] = NULL; 177 psFree(thisSet); 178 fitSets->data[i] = NULL; 179 pthread_mutex_unlock(&fitSetInitMutex); 180 return; 181 } 182 } 183 psAbort("pmSourceFitSetDataClear() called, but no entry found"); 184 197 185 return; 198 186 } … … 481 469 482 470 // Convert i/j to image space: 483 // 0.5 PIX: the coordinate values must be in pixel coords, not index 471 // 0.5 PIX: the coordinate values must be in pixel coords, not index 484 472 coord->data.F32[0] = (psF32) (j + 0.5 + source->pixels->col0); 485 473 coord->data.F32[1] = (psF32) (i + 0.5 + source->pixels->row0);
Note:
See TracChangeset
for help on using the changeset viewer.
