Commit f58d41a310cb02f6db7bd9d401c65d8bdf17193d

Authored by boolli
1 parent 728e43f5

Make _matTaken and _matsDimension double pointers to just pointers

openbr/plugins/cuda/MatManager.cu
... ... @@ -14,20 +14,26 @@ namespace br { namespace cuda {
14 14  
15 15 // initialize the an array of Mats
16 16 _mats = (uint8_t**)malloc(num * sizeof(uint8_t*));
17   - _matTaken = (bool**)malloc(num * sizeof(bool*));
18   - _matsDimension = (int**)malloc(num * sizeof(int*));
  17 + _matTaken = (bool*)malloc(num * sizeof(bool));
  18 + _matsDimension = (int*)malloc(num * sizeof(int));
19 19  
20 20 for (int i=0; i < num; i++) {
21 21 cudaMalloc(&_mats[i], 1 * sizeof(uint8_t));
22 22 //_mats[i] = new GpuMat();
23 23  
24 24 // initialize matTaken
  25 + /*
25 26 _matTaken[i] = new bool;
26 27 (*_matTaken[i]) = false;
  28 + */
  29 + _matTaken[i] = false;
27 30  
28 31 // initialize all mat dimensions to be 1
  32 + /*
29 33 _matsDimension[i] = new int;
30 34 (*_matsDimension[i]) = 1;
  35 + */
  36 + _matsDimension[i] = 1;
31 37 }
32 38  
33 39 // initialize the locks
... ... @@ -49,8 +55,8 @@ namespace br { namespace cuda {
49 55 pthread_mutex_lock(_matTakenLock);
50 56 int i;
51 57 for (i=0; i < _numMats; i++) {
52   - if ( !(*_matTaken[i]) ) {
53   - *_matTaken[i] = true;
  58 + if ( !_matTaken[i] ) {
  59 + _matTaken[i] = true;
54 60 reservedMatIndex = i;
55 61 //std::cout << "Taking " << i << std::endl << std::flush;
56 62 break;
... ... @@ -66,11 +72,11 @@ namespace br { namespace cuda {
66 72  
67 73 // reallocate if size does not match
68 74 pthread_mutex_lock(_matsDimensionLock);
69   - if (*_matsDimension[reservedMatIndex] != mat.rows * mat.cols) {
  75 + if (_matsDimension[reservedMatIndex] != mat.rows * mat.cols) {
70 76 cudaFree(_mats[reservedMatIndex]); // free the previous memory first
71 77 cudaMalloc(&_mats[reservedMatIndex], mat.rows * mat.cols * sizeof(uint8_t));
72 78 // change the dimension of that matrix
73   - *_matsDimension[reservedMatIndex] = mat.rows * mat.cols;
  79 + _matsDimension[reservedMatIndex] = mat.rows * mat.cols;
74 80  
75 81 }
76 82 pthread_mutex_unlock(_matsDimensionLock);
... ... @@ -109,7 +115,7 @@ namespace br { namespace cuda {
109 115 bool foundMatch = false;
110 116 for (int i=0; i < _numMats; i++) {
111 117 if (reservedMat == _mats[i]) {
112   - *_matTaken[i] = false;
  118 + _matTaken[i] = false;
113 119 foundMatch = true;
114 120 }
115 121 }
... ...
openbr/plugins/cuda/MatManager.hpp
... ... @@ -17,8 +17,8 @@ namespace br { namespace cuda {
17 17 private:
18 18 int _numMats;
19 19 uint8_t** _mats; // holds all the mats
20   - bool** _matTaken; // holds whether or not they are taken
21   - int** _matsDimension; // holds the dimension of the Mats
  20 + bool* _matTaken; // holds whether or not they are taken
  21 + int* _matsDimension; // holds the dimension of the Mats
22 22  
23 23 pthread_mutex_t* _matTakenLock; // lock for matTaken table
24 24 pthread_mutex_t* _matsDimensionLock; // lock for OpenCV upload/download/realloc operations
... ...