Skip to content

Instantly share code, notes, and snippets.

@MicBrain
Created August 20, 2015 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MicBrain/058b0a533297a3267c91 to your computer and use it in GitHub Desktop.
Save MicBrain/058b0a533297a3267c91 to your computer and use it in GitHub Desktop.
Add() function
void MultiFetcher::Add(JobInfo *info) {
assert(info != NULL);
assert(info->url != NULL);
Failures result;
result = PrepareDownloadDestination(info);
if (result != kFailOk)
return result;
if (info->expected_hash) {
const shash::Algorithms algorithm = info->expected_hash->algorithm;
info->hash_context.algorithm = algorithm;
info->hash_context.size = shash::GetContextSize(algorithm);
info->hash_context.buffer = alloca(info->hash_context.size);
}
// Prepare cvmfs-info: header, allocate string on the stack
info->info_header = NULL;
if (enable_info_header_ && info->extra_info) {
const char *header_name = "cvmfs-info: ";
const size_t header_name_len = strlen(header_name);
const unsigned header_size = 1 + header_name_len +
EscapeHeader(*(info->extra_info), NULL, 0);
info->info_header = static_cast<char *>(alloca(header_size));
memcpy(info->info_header, header_name, header_name_len);
EscapeHeader(*(info->extra_info), info->info_header + header_name_len,
header_size - header_name_len);
info->info_header[header_size-1] = '\0';
}
if (OVERALL NUMBER OF JOBINFO OBJECTS <= THRESHOLD) {
ADD TO THE MAIN QUEUE;
} else {
ADD TO THE SECONDARY QUEUE;
}
if (atomic_xadd32(&multi_threaded_, 0) == 1) {
if (info->wait_at[0] == -1) {
MakePipe(info->wait_at);
}
WritePipe(pipe_jobs_[1], &info, sizeof(info));
} else {
assert(false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment