* fixes for windows

* corrected allocation in ftfilecreator



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@707 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2008-08-25 20:03:39 +00:00
parent f243e5f6d3
commit d62876ae37
5 changed files with 101 additions and 18 deletions

View File

@ -86,7 +86,11 @@ void ftController::run()
while(1) while(1)
{ {
#ifdef WIN32
Sleep(1000);
#else
sleep(1); sleep(1);
#endif
std::cerr << "ftController::run()"; std::cerr << "ftController::run()";
std::cerr << std::endl; std::cerr << std::endl;

View File

@ -61,8 +61,12 @@ void ftExtraList::run()
/* Hash a file */ /* Hash a file */
hashAFile(); hashAFile();
#ifdef WIN32
Sleep(1);
#else
/* microsleep */ /* microsleep */
usleep(10); usleep(10);
#endif
} }
else else
{ {
@ -74,7 +78,11 @@ void ftExtraList::run()
} }
/* sleep */ /* sleep */
#ifdef WIN32
Sleep(1000);
#else
sleep(1); sleep(1);
#endif
} }
} }
} }

View File

@ -312,38 +312,62 @@ bool ftFileChunker::getMissingChunk(uint64_t &offset, uint32_t &chunk)
i++; i++;
} }
/* if we get here, there is no available chunk bigger
* than requested ...
* NB: Request size should be a larger than std_chunk_size.
* So Edge (sub chunk allocation) condition is handled here.
*
* Find largest remaining chunk.
*/
if (!found) if (!found)
{ {
i=0; i=0;
uint64_t min = allocationTable.at(i)->max_chunk_size - chunk; uint64_t max = allocationTable.at(i)->max_chunk_size;
uint64_t diff = min; uint64_t size = max;
int mini = -1; int maxi = -1;
while(i<allocationTable.size()) while(i<allocationTable.size())
{ {
diff = allocationTable.at(i)->max_chunk_size-chunk; size = allocationTable.at(i)->max_chunk_size;
if(diff <= min && diff >0) if(size > max)
{ {
min = allocationTable.at(i)->max_chunk_size - chunk; max = allocationTable.at(i)->max_chunk_size;
mini = i; maxi = i;
} }
i++; i++;
} }
if (mini > -1) //mini or min if (maxi > -1) //maxi or max
{ {
offset = allocationTable.at(mini)->offset; offset = allocationTable.at(maxi)->offset;
chunk = allocationTable.at(mini)->max_chunk_size; chunk = allocationTable.at(maxi)->max_chunk_size;
chunks_after = chunk/std_chunk_size; //10KB chunks_after = chunk/std_chunk_size; //10KB
/* Handle end condition ...
* max_chunk_size < std_chunk_size
* Trim if not end condition.
*/
if (chunks_after > 0)
{
chunks_rem = chunk % std_chunk_size; chunks_rem = chunk % std_chunk_size;
chunk -= chunks_rem; chunk -= chunks_rem;
allocationTable.at(mini)->max_chunk_size=0; }
allocationTable.at(mini)->timestamp = time(NULL); else
allocationTable.at(mini)->chunk_status = ftChunk::ALLOCATED; {
/* end condition */
chunks_after = 1;
}
allocationTable.at(maxi)->max_chunk_size=0;
allocationTable.at(maxi)->timestamp = time(NULL);
allocationTable.at(maxi)->chunk_status = ftChunk::ALLOCATED;
found = true; found = true;
} }
} //if not found } //if not found
if (found) {
if (found)
{
std::cout << "Chunks remaining " << chunks_rem << std::endl; std::cout << "Chunks remaining " << chunks_rem << std::endl;
/* /*
* update all previous chunks max available size * update all previous chunks max available size
@ -386,13 +410,52 @@ bool ftFileChunker::getMissingChunk(uint64_t &offset, uint32_t &chunk)
int ftFileChunker::monitor() int ftFileChunker::monitor()
{ {
int reset = 0; int reset = 0;
uint32_t prev_size = 0;
uint32_t size = 0;
std::cout<<"Running monitor.."<<std::endl; std::cout<<"Running monitor.."<<std::endl;
for(unsigned int j=0;j<allocationTable.size();j++){
if(allocationTable.at(j)->chunk_status == ftChunk::ALLOCATED && allocationTable.at(j)->timestamp - time(NULL) > 30){ RsStackMutex stack(chunkerMutex); /********** STACK LOCKED MTX ******/
for(unsigned int j=allocationTable.size()-1 ;j>= 0;)
{
if((allocationTable.at(j)->chunk_status == ftChunk::ALLOCATED) &&
(allocationTable.at(j)->timestamp - time(NULL) > 30))
{
allocationTable.at(j)->chunk_status = ftChunk::AVAIL; allocationTable.at(j)->chunk_status = ftChunk::AVAIL;
if (j == allocationTable.size()-1)
{
/* at end */
prev_size = 0;
size = file_size % std_chunk_size;
if (size == 0)
{
size = std_chunk_size;
}
}
else
{
prev_size = allocationTable.at(j+1)->max_chunk_size;
size = std_chunk_size;
}
allocationTable.at(j)->max_chunk_size = size + prev_size;
prev_size = allocationTable.at(j)->max_chunk_size;
for(j--; j >= 0; j--)
{
if (allocationTable.at(j)->chunk_status != ftChunk::AVAIL)
break;
allocationTable.at(j)->max_chunk_size += prev_size;
prev_size = allocationTable.at(j)->max_chunk_size;
reset++; reset++;
} }
} }
else
{
j--;
}
}
return reset; return reset;
} }

View File

@ -168,7 +168,11 @@ void ftServer::run()
{ {
while(1) while(1)
{ {
#ifdef WIN32
Sleep(1000);
#else
sleep(1); sleep(1);
#endif
} }
} }

View File

@ -115,7 +115,11 @@ void P3Hub::run()
*/ */
/* sleep a bit */ /* sleep a bit */
#ifdef WIN32
Sleep(1000);
#else
sleep(1); sleep(1);
#endif
} }
} }