示例#1
0
bool HTTPBasicAuth::handleRequest(HTTPRequestPtr& request, TCPConnectionPtr& tcp_conn)
{
	if (!needAuthentication(request)) {
		return true; // this request does not require authentication
	}
	
	PionDateTime time_now(boost::posix_time::second_clock::universal_time());
	if (time_now > m_cache_cleanup_time + boost::posix_time::seconds(CACHE_EXPIRATION)) {
		// expire cache
		boost::mutex::scoped_lock cache_lock(m_cache_mutex);
		PionUserCache::iterator i;
		PionUserCache::iterator next=m_user_cache.begin();
		while (next!=m_user_cache.end()) {
			i=next;
			++next;
			if (time_now > i->second.first + boost::posix_time::seconds(CACHE_EXPIRATION)) {
				// ok - this is an old record.. expire it now
				m_user_cache.erase(i);
			}
		}
		m_cache_cleanup_time = time_now;
	}
	
	// if we are here, we need to check if access authorized...
	std::string authorization = request->getHeader(HTTPTypes::HEADER_AUTHORIZATION);
	if (!authorization.empty()) {
		std::string credentials;
		if (parseAuthorization(authorization, credentials)) {
			// to do - use fast cache to match with active credentials
			boost::mutex::scoped_lock cache_lock(m_cache_mutex);
			PionUserCache::iterator user_cache_ptr=m_user_cache.find(credentials);
			if (user_cache_ptr!=m_user_cache.end()) {
				// we found the credentials in our cache...
				// we can approve authorization now!
				request->setUser(user_cache_ptr->second.second);
				user_cache_ptr->second.first = time_now;
				return true;
			}
	
			std::string username;
			std::string password;
	
			if (parseCredentials(credentials, username, password)) {
				// match username/password
				PionUserPtr user=m_user_manager->getUser(username, password);
				if (user) {
					// add user to the cache
					m_user_cache.insert(std::make_pair(credentials, std::make_pair(time_now, user)));
					// add user credentials to the request object
					request->setUser(user);
					return true;
				}
			}
		}
	}

	// user not found
	handleUnauthorized(request, tcp_conn);
	return false;
}
示例#2
0
void remove_cache_item(const char *entry_path, const char *subdir_path, const char *subdir_name, const char *entry_name)
{
    /* Unlink the expired file, and the artist directory if it is empty */
    cache_lock();
    unlink(entry_path);
    rmdir(subdir_path);

    /* Remove any scaled copies of this file, plus parent directories that are now empty */
    char cache_root_path[PATH_MAX];
    make_cache_root_path(cache_root_path, PATH_MAX);
    struct dirent **scaled_dirs = NULL;
    const int scaled_dirs_count = scandir(cache_root_path, &scaled_dirs, filter_scaled_dirs, NULL);
    for (size_t i = 0; i < scaled_dirs_count; i++) {
        char scaled_entry_path[PATH_MAX];
        if (snprintf(scaled_entry_path, PATH_MAX, "%s%s/%s/%s", cache_root_path, scaled_dirs[i]->d_name, subdir_name, entry_name) < PATH_MAX) {
            unlink(scaled_entry_path);
            char *scaled_entry_dir = dirname(scaled_entry_path);
            rmdir(scaled_entry_dir);
            rmdir(dirname(scaled_entry_dir));
        }
        free(scaled_dirs[i]);
    }
    free(scaled_dirs);
    cache_unlock();
}
示例#3
0
cache_t *lru_cache_load(void *arg, inip_file_t *fd, char *grp, data_attr_t *da, int timeout)
{
    cache_t *c;
    cache_lru_t *cp;
    int dt;

    if (grp == NULL) grp = "cache-lru";

    //** Create the default structure
    c = lru_cache_create(arg, da, timeout);
    cp = (cache_lru_t *)c->fn.priv;

    cache_lock(c);
    cp->max_bytes = inip_get_integer(fd, grp, "max_bytes", cp->max_bytes);
    cp->dirty_fraction = inip_get_double(fd, grp, "dirty_fraction", cp->dirty_fraction);
    cp->dirty_bytes_trigger = cp->dirty_fraction * cp->max_bytes;
    c->default_page_size = inip_get_integer(fd, grp, "default_page_size", c->default_page_size);
    dt = inip_get_integer(fd, grp, "dirty_max_wait", apr_time_sec(cp->dirty_max_wait));
    cp->dirty_max_wait = apr_time_make(dt, 0);
    c->max_fetch_fraction = inip_get_double(fd, grp, "max_fetch_fraction", c->max_fetch_fraction);
    c->max_fetch_size = c->max_fetch_fraction * cp->max_bytes;
    c->write_temp_overflow_fraction = inip_get_double(fd, grp, "write_temp_overflow_fraction", c->write_temp_overflow_fraction);
    c->write_temp_overflow_size = c->write_temp_overflow_fraction * cp->max_bytes;
    c->n_ppages = inip_get_integer(fd, grp, "ppages", c->n_ppages);

    log_printf(0, "COP size=" XOT "\n", c->write_temp_overflow_size);

    cache_unlock(c);

    return(c);
}
示例#4
0
int lru_cache_destroy(cache_t *c)
{
    apr_status_t value;

    cache_lru_t *cp = (cache_lru_t *)c->fn.priv;

    //** Shutdown the dirty thread
    cache_lock(c);
    c->shutdown_request = 1;
    apr_thread_cond_signal(cp->dirty_trigger);
    cache_unlock(c);

    apr_thread_join(&value, cp->dirty_thread);  //** Wait for it to complete

    cache_base_destroy(c);

    free_stack(cp->stack, 0);
    free_stack(cp->waiting_stack, 0);
    free_stack(cp->pending_free_tasks, 0);

    destroy_pigeon_coop(cp->free_pending_tables);
    destroy_pigeon_coop(cp->free_page_tables);

    free(cp);
    free(c);

    return(0);
}
示例#5
0
cache_page_t *lru_create_empty_page(cache_t *c, segment_t *seg, int doblock)
{
    cache_lru_t *cp = (cache_lru_t *)c->fn.priv;
    cache_segment_t *s = (cache_segment_t *)seg->priv;
    ex_off_t max_bytes, bytes_to_free;
    cache_page_t *p = NULL;
    int qend;

    cache_lock(c);

    qend = 0;
    do {
        max_bytes = _lru_max_bytes(c);
        bytes_to_free = s->page_size + cp->bytes_used - max_bytes;
        log_printf(15, "lru_create_empty_page: max_bytes=" XOT " used=" XOT " bytes_to_free=" XOT " doblock=%d\n", max_bytes, cp->bytes_used, bytes_to_free, doblock);
        if (bytes_to_free > 0) {
            bytes_to_free = _lru_free_mem(c, seg, bytes_to_free);
            if ((doblock==1) && (bytes_to_free>0)) _lru_wait_for_page(c, seg, qend);
            qend = 1;
        }
    } while ((doblock==1) && (bytes_to_free>0));

    if (bytes_to_free <= 0) p = _lru_new_page(c, seg);

    cache_unlock(c);

    return(p);
}
示例#6
0
	static T get_something(cl_platform_id platform, cl_device_id device,
		T Slot::*member, thread_scoped_lock &slot_locker)
	{
		assert(platform != NULL);

		OpenCLCache &self = global_instance();

		thread_scoped_lock cache_lock(self.cache_lock);

		pair<CacheMap::iterator,bool> ins = self.cache.insert(
			CacheMap::value_type(PlatformDevicePair(platform, device), Slot()));

		Slot &slot = ins.first->second;

		/* create slot lock only while holding cache lock */
		if(!slot.mutex)
			slot.mutex = new thread_mutex;

		/* need to unlock cache before locking slot, to allow store to complete */
		cache_lock.unlock();

		/* lock the slot */
		slot_locker = thread_scoped_lock(*slot.mutex);

		/* If the thing isn't cached */
		if(slot.*member == NULL) {
			/* return with the caller's lock holder holding the slot lock */
			return NULL;
		}

		/* the item was already cached, release the slot lock */
		slot_locker.unlock();

		return slot.*member;
	}
示例#7
0
/**
 * 删除缓存, 并释放资源
 */
static int cache_delete(size_t pos)
{
	cache_image_t *p;

	cache_lock();
	p = &ccacher.caches[pos];

	if (p->data != NULL) {
		dbg_printf(d, "%s: data 0x%08x", __func__, (unsigned) p->data);
		free(p->data);
		p->data = NULL;
	}

	if (p->exif_array) {
		buffer_array_free(p->exif_array);
		p->exif_array = NULL;
	}

	if (p->status == CACHE_OK) {
		ccacher.memory_usage -= p->width * p->height * sizeof(pixel);
	}

	memmove(&ccacher.caches[pos], &ccacher.caches[pos + 1],
			(ccacher.caches_size - pos - 1) * sizeof(ccacher.caches[0]));
	ccacher.caches_size--;
	cache_unlock();

	return 0;
}
示例#8
0
void dbg_dump_cache(void)
{
	cache_image_t *p;
	dword c;

	cache_lock();
	p = ccacher.caches;

	for (c = 0; p != ccacher.caches + ccacher.caches_size; ++p) {
		if (p->status == CACHE_OK || p->status == CACHE_FAILED)
			c++;
	}

	dbg_printf(d, "CLIENT: Dumping cache[%u] %u/%ukb, %u finished",
			   ccacher.caches_size, (unsigned) ccacher.memory_usage / 1024,
			   (unsigned) get_free_mem() / 1024, (unsigned) c);

	for (p = ccacher.caches; p != ccacher.caches + ccacher.caches_size; ++p) {
		dbg_printf(d, "%d: %u st %u res %d mem %lukb", p - ccacher.caches,
				   (unsigned) p->selidx, p->status, p->result,
				   p->width * p->height * sizeof(pixel) / 1024L);
	}

	cache_unlock();
}
Account AccountManager::getAccountByRepo(const QString& repo_id, SeafileRpcClient *rpc)
{
    std::vector<Account> accounts;
    {
        QMutexLocker lock(&accounts_mutex_);
        accounts = accounts_;
    }

    QMutexLocker cache_lock(&accounts_cache_mutex_);

    if (!accounts_cache_.contains(repo_id)) {
        QString relay_addr;
        if (rpc->getRepoProperty(repo_id, kRepoRelayAddrProperty, &relay_addr) < 0) {
            return Account();
        }

        for (size_t i = 0; i < accounts.size(); i++) {
            const Account& account = accounts[i];
            if (account.serverUrl.host() == relay_addr) {
                accounts_cache_[repo_id] = account;
                break;
            }
        }
    }
    return accounts_cache_.value(repo_id, Account());
}
示例#10
0
void cache_hacks(void) {
	flush_caches();

	// lock the caches so nobody replaces our hacks
	cache_lock();

	// prevent the OFW from clearing the caches
	disable_cache_clearing();

	// OFW allocates main heap from addr:0x200000 to addr:0x800000
	// we place our hack at the last 128kb (0x20000) of this space, at addr: 0x7E0000 (see hack_relocate())
	// the original instruction was: MOV R1, #0x800000
	// we change it to: MOV R1, #0x7E0000 (in binary the instruction looks like: 0xE3A0187E)
	cache_fake(0xFF811318, 0xE3A0187E, TYPE_ICACHE);

	// hookup to dmProcInit(), so we can enable massive debug and run our hack_pre_init_hook
	cache_fake(0xFF8111AC, ASM_BL(0xFF8111AC, &hack_dmProcInit), TYPE_ICACHE);

	// hookup our MainCtrlInit
	//cache_fake(0xFF8110E4, ASM_BL(0xFF8110E4, &hack_MainCtrlInit), TYPE_ICACHE);

#ifdef ENABLE_DEBUG
	// hookup our GUI_IdleHandler
	cache_fake(0xFF82A4F0, ASM_BL(0xFF82A4F0, &hack_register_gui_idle_handler), TYPE_ICACHE);
#endif

	// hookup our Intercom
	cache_fake(0xFFA5D590, ASM_BL(0xFFA5D590, &hack_init_intercom_data), TYPE_ICACHE);

	// hookup StartConsole, so we can run our hack_post_init_hook
	cache_fake(0xFF8112E8, ASM_BL(0xFF8112E8, &hack_StartConsole), TYPE_ICACHE);
}
示例#11
0
unsigned long output_alsa_abort_stream(struct output *h,
				       struct output_stream *s)
{
	unsigned long played;

	/* Lock stream access */
	pthread_mutex_lock(&h->mutex);

	/* Pause stream */
	s->is_playing = 0;
	s->abort = 1;

	/* Lock cache */
	cache_lock(s->cache);

	/* Calculate played status */
	played = s->played * 1000 / h->samplerate / h->channels;

	/* Add not played samples */
	played += cache_delay(s->cache);
	played += resample_delay(s->res);

	/* Unlock stream access */
	pthread_mutex_unlock(&h->mutex);

	return played;
}
示例#12
0
static void cache_clear(void)
{
	int i;

	cache_lock();

	for (i = 0; i < ccacher.caches_size; ++i) {
		if (ccacher.caches[i].data != NULL) {
			dbg_printf(d, "%s: %d data 0x%08x", __func__, i,
					   (unsigned) ccacher.caches[i].data);
			free(ccacher.caches[i].data);
			ccacher.caches[i].data = NULL;
		}

		if (ccacher.caches[i].exif_array) {
			buffer_array_free(ccacher.caches[i].exif_array);
			ccacher.caches[i].exif_array = NULL;
		}

		if (ccacher.caches[i].status == CACHE_OK) {
			ccacher.memory_usage -=
				ccacher.caches[i].width * ccacher.caches[i].height *
				sizeof(pixel);
		}
	}

	ccacher.caches_size = 0;
	cacher_cleared = true;
	cache_unlock();
}
示例#13
0
文件: asmcache.c 项目: GYGit/reactos
static HRESULT WINAPI IAssemblyCacheImpl_QueryAssemblyInfo(IAssemblyCache *iface,
                                                           DWORD dwFlags,
                                                           LPCWSTR pszAssemblyName,
                                                           ASSEMBLY_INFO *pAsmInfo)
{
    IAssemblyCacheImpl *cache = impl_from_IAssemblyCache(iface);
    IAssemblyName *asmname, *next = NULL;
    IAssemblyEnum *asmenum = NULL;
    HRESULT hr;

    TRACE("(%p, %d, %s, %p)\n", iface, dwFlags,
          debugstr_w(pszAssemblyName), pAsmInfo);

    if (pAsmInfo)
    {
        if (pAsmInfo->cbAssemblyInfo == 0)
            pAsmInfo->cbAssemblyInfo = sizeof(ASSEMBLY_INFO);
        else if (pAsmInfo->cbAssemblyInfo != sizeof(ASSEMBLY_INFO))
            return E_INVALIDARG;
    }

    hr = CreateAssemblyNameObject(&asmname, pszAssemblyName,
                                  CANOF_PARSE_DISPLAY_NAME, NULL);
    if (FAILED(hr))
        return hr;

    cache_lock( cache );

    hr = CreateAssemblyEnum(&asmenum, NULL, asmname, ASM_CACHE_GAC, NULL);
    if (FAILED(hr))
        goto done;

    for (;;)
    {
        hr = IAssemblyEnum_GetNextAssembly(asmenum, NULL, &next, 0);
        if (hr != S_OK)
        {
            hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
            goto done;
        }
        hr = IAssemblyName_IsEqual(asmname, next, ASM_CMPF_IL_ALL);
        if (hr == S_OK) break;
    }

    if (!pAsmInfo)
        goto done;

    hr = IAssemblyName_GetPath(next, pAsmInfo->pszCurrentAssemblyPathBuf, &pAsmInfo->cchBuf);

    pAsmInfo->dwAssemblyFlags = ASSEMBLYINFO_FLAG_INSTALLED;

done:
    IAssemblyName_Release(asmname);
    if (next) IAssemblyName_Release(next);
    if (asmenum) IAssemblyEnum_Release(asmenum);
    cache_unlock( cache );
    return hr;
}
示例#14
0
/**
 * @param selidx filelist中的文件位置
 * @param where 文件位置类型
 *
 */
static int cache_add_by_selidx(dword selidx, int where)
{
	t_fs_filetype type;
	cache_image_t img;
	const char *archname;
	const char *filename;
	dword filesize;

	archname = config.shortpath;

	if (where == scene_in_dir) {
		filename = filelist[selidx].shortname->ptr;
	} else {
		filename = filelist[selidx].compname->ptr;
	}

	filesize = filelist[selidx].data3;

	type = fs_file_get_type(filename);

	if (!fs_is_image(type)) {
		return -1;
	}

	if (cache_get(archname, filename) != NULL) {
		dbg_printf(d, "SERVER: %s: Image %s duplicate load, FIXME", __func__,
				   filename);

		return -1;
	}

	cache_lock();

	memset(&img, 0, sizeof(img));
	img.archname = archname;
	img.filename = filename;
	img.where = where;
	img.status = CACHE_INIT;
	img.selidx = selidx;
	img.filesize = filesize;

	if (ccacher.caches_size < ccacher.caches_cap) {
		ccacher.caches[ccacher.caches_size] = img;
		ccacher.caches_size++;
		cacher_cleared = false;
	} else {
		dbg_printf(d, "SERVER: cannot add cache any more: size %u cap %u",
				   ccacher.caches_size, ccacher.caches_cap);
		cache_unlock();

		return -1;
	}
	cache_unlock();

	return 0;
}
示例#15
0
void lru_pages_destroy(cache_t *c, cache_page_t **page, int n_pages, int remove_from_segment)
{
    cache_lru_t *cp = (cache_lru_t *)c->fn.priv;
    cache_segment_t *s;
    page_lru_t *lp;
    cache_page_t *p;
//  cache_cond_t *cache_cond;
    int i;
    int cr, cw, cf, count;
    cache_lock(c);

    log_printf(15, " START cp->bytes_used=" XOT "\n", cp->bytes_used);

    for (i=0; i<n_pages; i++) {
        p = page[i];
        s = (cache_segment_t *)p->seg->priv;

        cr = atomic_get(p->access_pending[CACHE_READ]);
        cw = atomic_get(p->access_pending[CACHE_WRITE]);
        cf = atomic_get(p->access_pending[CACHE_FLUSH]);
        count = cr +cw + cf;

//     cache_cond = (cache_cond_t *)pigeon_coop_hole_data(&(p->cond_pch));
//     if (cache_cond == NULL) {  //** No one listening so free normally
        if (count == 0) {  //** No one is listening
            log_printf(15, "lru_pages_destroy i=%d p->offset=" XOT " seg=" XIDT " remove_from_segment=%d limbo=%d\n", i, p->offset, segment_id(p->seg), remove_from_segment, cp->limbo_pages);
            cp->bytes_used -= s->page_size;
            lp = (page_lru_t *)p->priv;

            if (lp->ele != NULL) {
                move_to_ptr(cp->stack, lp->ele);
                delete_current(cp->stack, 0, 0);
            }

            if (remove_from_segment == 1) {
                s = (cache_segment_t *)p->seg->priv;
                list_remove(s->pages, &(p->offset), p);  //** Have to do this here cause p->offset is the key var
            }

            if (p->data[0].ptr) free(p->data[0].ptr);
            if (p->data[1].ptr) free(p->data[1].ptr);
            free(lp);
        } else {  //** Someone is listening so trigger them and also clear the bits so it will be released
            atomic_set(p->bit_fields, C_TORELEASE);
            log_printf(15, "lru_pages_destroy i=%d p->offset=" XOT " seg=" XIDT " remove_from_segment=%d cr=%d cw=%d cf=%d limbo=%d\n", i, p->offset, segment_id(p->seg), remove_from_segment, cr, cw, cf, cp->limbo_pages);
        }
    }

    log_printf(15, " AFTER LOOP cp->bytes_used=" XOT "\n", cp->bytes_used);

    log_printf(15, " END cp->bytes_used=" XOT "\n", cp->bytes_used);

    cache_unlock(c);
}
示例#16
0
static int start_cache(dword selidx)
{
	int re;
	dword pos;
	dword size;

	if (ccacher.first_run) {
		ccacher.first_run = false;
	} else {
		SceUInt timeout = 10000;

		// wait until user notify cache delete
		re = xrKernelWaitEventFlag(cache_del_event, CACHE_EVENT_DELETED,
								   PSP_EVENT_WAITAND, NULL, &timeout);

		if (re == SCE_KERNEL_ERROR_WAIT_TIMEOUT) {
			return 0;
		}

		xrKernelSetEventFlag(cache_del_event, CACHE_EVENT_UNDELETED);
	}

	cache_lock();

	pos = selidx;
	size = ccacher.caches_size;

	while (size-- > 0) {
		pos = cache_get_next_image(pos, ccacher.isforward);
	}

	re = min(ccacher.caches_cap, count_img()) - ccacher.caches_size;
	dbg_printf(d, "SERVER: start pos %u selidx %u caches_size %u re %u",
			   (unsigned) pos, (unsigned) selidx,
			   (unsigned) ccacher.caches_size, (unsigned) re);

	if (re == 0) {
		cache_unlock();
		return 0;
	}
	// dbg_printf(d, "SERVER: Wait for new selidx: memory usage %uKB", (unsigned) ccacher.memory_usage / 1024);
	// dbg_printf(d, "SERVER: %d images to cache, selidx %u, caches_size %u", re, (unsigned)selidx, (unsigned)ccacher.caches_size);

	while (re-- > 0) {
		dbg_printf(d, "SERVER: add cache image %u", (unsigned) pos);
		cache_add_by_selidx(pos, where);
		pos = cache_get_next_image(pos, ccacher.isforward);
	}

	cache_unlock();

	return re;
}
示例#17
0
ex_off_t _lru_force_free_mem(cache_t *c, segment_t *page_seg, ex_off_t bytes_to_free, int check_waiters)
{
    cache_segment_t *s = (cache_segment_t *)page_seg->priv;
    cache_lru_t *cp = (cache_lru_t *)c->fn.priv;
    ex_off_t freed_bytes, bytes_left;
    int top, finished;
    pigeon_coop_hole_t pch;
    cache_cond_t *cache_cond;

    //** I'm holding this coming in but don't need it cause I can touch all segs
    segment_unlock(page_seg);

    top = 0;
    bytes_left = bytes_to_free;
    freed_bytes = _lru_attempt_free_mem(c, page_seg, bytes_left);
    finished = 0;

    while ((freed_bytes < bytes_to_free) && (finished == 0)) {  //** Keep trying to mark space as free until I get enough
        if (top == 0) {
            top = 1;
            pch = reserve_pigeon_coop_hole(s->c->cond_coop);
            cache_cond = (cache_cond_t *)pigeon_coop_hole_data(&pch);
            cache_cond->count = 0;

            move_to_bottom(cp->pending_free_tasks);
            insert_below(cp->pending_free_tasks, cache_cond);  //** Add myself to the bottom
        } else {
            push(cp->pending_free_tasks, cache_cond);  //** I go on the top
        }

        log_printf(15, "not enough space so waiting cache_cond=%p freed_bytes=" XOT " bytes_to_free=" XOT "\n", cache_cond, freed_bytes, bytes_to_free);
        //** Now wait until it's my turn
        apr_thread_cond_wait(cache_cond->cond, c->lock);

        bytes_left -= freed_bytes;
        freed_bytes = _lru_attempt_free_mem(c, page_seg, bytes_left);
        finished = 1;
    }

    //** Now check if we can handle some waiters
    if (check_waiters == 1) _lru_process_waiters(c);

    cache_unlock(c);  //** Reacquire the lock in the proper order
    segment_lock(page_seg);  //** Reacquire the lock cause I had it coming in
    cache_lock(c);

    if (top == 1) release_pigeon_coop_hole(s->c->cond_coop, &pch);

    freed_bytes = bytes_to_free - bytes_left;
//NEW  freed_bytes = bytes_left - freed_bytes;

    return(freed_bytes);
}
示例#18
0
void cache_set_forward(bool forward)
{
	cache_lock();

	if (ccacher.isforward != forward) {
		cache_clear();
		ccacher.first_run = true;
	}

	ccacher.isforward = forward;
	cache_unlock();
}
示例#19
0
void lru_adjust_dirty(cache_t *c, ex_off_t tweak)
{
    cache_lru_t *cp = (cache_lru_t *)c->fn.priv;

    cache_lock(c);
    c->stats.dirty_bytes += tweak;
    if (c->stats.dirty_bytes > cp->dirty_bytes_trigger) {
        if (cp->flush_in_progress == 0) {
            cp->flush_in_progress = 1;
            apr_thread_cond_signal(cp->dirty_trigger);
        }
    }
    cache_unlock(c);
}
示例#20
0
文件: cmus.c 项目: Aseeker/cmus
void cmus_play_file(const char *filename)
{
	struct track_info *ti;

	cache_lock();
	ti = cache_get_ti(filename, 0);
	cache_unlock();
	if (!ti) {
		error_msg("Couldn't get file information for %s\n", filename);
		return;
	}

	player_play_file(ti);
}
示例#21
0
void _lru_wait_for_page(cache_t *c, segment_t *seg, int ontop)
{
    cache_lru_t *cp = (cache_lru_t *)c->fn.priv;
    cache_segment_t *s = (cache_segment_t *)seg->priv;
    lru_page_wait_t pw;
    pigeon_coop_hole_t pch;
    cache_cond_t *cc;
    ex_off_t bytes_free, bytes_needed, n;
    int check_waiters_first;

    check_waiters_first = (ontop == 0) ? 1 : 0;
    pch = reserve_pigeon_coop_hole(c->cond_coop);
    cc = (cache_cond_t *)pigeon_coop_hole_data(&pch);
    pw.cond = cc->cond;
    pw.bytes_needed = s->page_size;

    bytes_free = _lru_max_bytes(c) - cp->bytes_used;
    while (s->page_size > bytes_free) {
        //** Attempt to free pages
        bytes_needed = s->page_size - bytes_free;
        n = _lru_force_free_mem(c, seg, bytes_needed, check_waiters_first);

        if (n > 0) { //** Didn't make it so wait
            if (ontop == 0) {
                move_to_bottom(cp->waiting_stack);
                insert_below(cp->waiting_stack, &pw);
            } else {
                push(cp->waiting_stack, &pw);
            }

            segment_unlock(seg);  //** Unlock the segment to prevent deadlocks

            apr_thread_cond_wait(pw.cond, c->lock);  //** Wait for the space to become available

            //** Have to reaquire both locks in the correct order
            cache_unlock(c);
            segment_lock(seg);
            cache_lock(c);

            ontop = 1;  //** 2nd time we are always placed on the top of the stack
            check_waiters_first = 0;  //** And don't check on waiters
        }

        bytes_free = _lru_max_bytes(c) - cp->bytes_used;
    }

    release_pigeon_coop_hole(c->cond_coop, &pch);

    return;
}
示例#22
0
int cache_delete_first(void)
{
	cache_lock();

	if (ccacher.caches_size != 0 && ccacher.caches != NULL) {
		int ret;

		ret = cache_delete(0);
		xrKernelSetEventFlag(cache_del_event, CACHE_EVENT_DELETED);
		cache_unlock();

		return ret;
	}

	cache_unlock();
	return -1;
}
示例#23
0
void cookie_auth::expire_cache(const boost::posix_time::ptime &time_now)
{
    if (time_now > m_cache_cleanup_time + boost::posix_time::seconds(CACHE_EXPIRATION)) {
        // expire cache
        boost::mutex::scoped_lock cache_lock(m_cache_mutex);
        user_cache_type::iterator i;
        user_cache_type::iterator next=m_user_cache.begin();
        while (next!=m_user_cache.end()) {
            i=next;
            ++next;
            if (time_now > i->second.first + boost::posix_time::seconds(CACHE_EXPIRATION)) {
                // ok - this is an old record.. expire it now
                m_user_cache.erase(i);
            }
        }
        m_cache_cleanup_time = time_now;
    }
}
示例#24
0
int lru_pages_release(cache_t *c, cache_page_t **page, int n_pages)
{
    cache_lru_t *cp = (cache_lru_t *)c->fn.priv;
    cache_segment_t *s;
    page_lru_t *lp;
    cache_page_t *p;
    int bits, i;

    cache_lock(c);

    for (i=0; i<n_pages; i++) {
        p = page[i];
        bits = atomic_get(p->bit_fields);
        log_printf(15, "seg=" XIDT " p->offset=" XOT " bits=%d bytes_used=" XOT "\n", segment_id(p->seg), p->offset, bits, cp->bytes_used);
        if ((bits & C_TORELEASE) > 0) {
            log_printf(15, "DESTROYING seg=" XIDT " p->offset=" XOT " bits=%d bytes_used=" XOT "cache_pages=%d\n", segment_id(p->seg), p->offset, bits, cp->bytes_used, stack_size(cp->stack));
            s = (cache_segment_t *)p->seg->priv;
            lp = (page_lru_t *)p->priv;

            cp->bytes_used -= s->page_size;
            if (lp->ele != NULL) {
                move_to_ptr(cp->stack, lp->ele);
                delete_current(cp->stack, 0, 0);
            } else {
                cp->limbo_pages--;
                log_printf(15, "seg=" XIDT " limbo page p->offset=" XOT " limbo=%d\n", segment_id(p->seg), p->offset, cp->limbo_pages);
            }

            if (p->offset > -1) {
                list_remove(s->pages, &(p->offset), p);  //** Have to do this here cause p->offset is the key var
            }
            if (p->data[0].ptr) free(p->data[0].ptr);
            if (p->data[1].ptr) free(p->data[1].ptr);
            free(lp);
        }
    }

    //** Now check if we can handle some waiters
    _lru_process_waiters(c);

    cache_unlock(c);

    return(0);
}
示例#25
0
void cache_reload_all(void)
{
	cache_image_t *p;
	int i;

	cache_lock();

	for (i = 0; i < ccacher.caches_size; ++i) {
		p = &ccacher.caches[i];

		if (p->status == CACHE_OK) {
			free_cache_image(p);
			ccacher.memory_usage -= p->width * p->height * sizeof(pixel);
		}

		p->status = CACHE_INIT;
	}

	cache_unlock();
}
示例#26
0
文件: topo.c 项目: justinbrewer/SAHN
int topo__update_nodes(){
  char links_buf[64], *link;
  FILE* fp;
  struct topo_node_t* node;

  cache_lock(node_cache);
  cache_flush__crit(node_cache);
  cache_disable_sort__crit(node_cache);
  
  fp = fopen(topo_file,"r");
  
  while(!feof(fp)){
    node = (struct topo_node_t*)malloc(sizeof(struct topo_node_t));
    
    fscanf(fp,"Node %hu %64[^,], %8s %hd %hd links %64[^\n]\n",
	   &node->address,
	   &node->real_address,
	   &node->real_port,
	   &node->loc.x,
	   &node->loc.y,
	   links_buf);
    
    node->links = (uint16_t*)malloc(MAX_LINKS*sizeof(uint16_t));
    link = strtok(links_buf," ");
    while(link != NULL){
      node->links[node->num_links++] = atoi(link);
      link = strtok(NULL," ");
    }
    node->links = (uint16_t*)realloc(node->links,node->num_links*sizeof(uint16_t));

    cache_set__crit(node_cache,node->address,node);
  }
  fclose(fp);

  cache_enable_sort__crit(node_cache);
  cache_unlock(node_cache);

  topo_local_node = cache_get(node_cache,topo_local_address);

  return 0;
}
示例#27
0
bool cookie_auth::handle_request(http::request_ptr& http_request_ptr, tcp::connection_ptr& tcp_conn)
{
    if (process_login(http_request_ptr,tcp_conn)) {
        return false; // we processed login/logout request, no future processing for this request permitted
    }

    if (!need_authentication(http_request_ptr)) {
        return true; // this request does not require authentication
    }

    // check if it is redirection page.. If yes, then do not test its credentials ( as used for login)
    if (!m_redirect.empty() && m_redirect==http_request_ptr->get_resource()) {
        return true; // this request does not require authentication
    }
    
    // check cache for expiration
    boost::posix_time::ptime time_now(boost::posix_time::second_clock::universal_time());
    expire_cache(time_now);

    // if we are here, we need to check if access authorized...
    const std::string auth_cookie(http_request_ptr->get_cookie(AUTH_COOKIE_NAME));
    if (! auth_cookie.empty()) {
        // check if this cookie is in user cache
        boost::mutex::scoped_lock cache_lock(m_cache_mutex);
        user_cache_type::iterator user_cache_itr=m_user_cache.find(auth_cookie);
        if (user_cache_itr != m_user_cache.end()) {
            // we find those credential in our cache...
            // we can approve authorization now!
            http_request_ptr->set_user(user_cache_itr->second.second);
            // and update cache timeout
            user_cache_itr->second.first = time_now;
            return true;
        }
    }

    // user not found
    handle_unauthorized(http_request_ptr,tcp_conn);
    return false;
}
示例#28
0
int lru_page_access(cache_t *c, cache_page_t *p, int rw_mode, ex_off_t request_len)
{
    cache_lru_t *cp = (cache_lru_t *)c->fn.priv;
    page_lru_t *lp = (page_lru_t *)p->priv;

    if (rw_mode == CACHE_FLUSH) return(0);  //** Nothing to do for a flush

    //** Only update the position if the page is linked.
    //** Otherwise the page is destined to be dropped
    if (lp->ele != NULL) {
        cache_lock(c);
        if (lp->ele != NULL) {  //** Recehck with the lock on
            move_to_ptr(cp->stack, lp->ele);
            stack_unlink_current(cp->stack, 1);
            move_to_top(cp->stack);
            insert_link_above(cp->stack, lp->ele);
        }
        cache_unlock(c);
    }

    return(0);
}
示例#29
0
bool HTTPCookieAuth::handleRequest(HTTPRequestPtr& request, TCPConnectionPtr& tcp_conn)
{
	if (processLogin(request,tcp_conn)) {
		return false; // we processed login/logout request, no future processing for this request permitted
	}

	if (!needAuthentication(request)) {
		return true; // this request does not require authentication
	}

	// check if it is redirection page.. If yes, then do not test its credentials ( as used for login)
	if (!m_redirect.empty() && m_redirect==request->getResource()) {
		return true; // this request does not require authentication
	}
	
	// check cache for expiration
	PionDateTime time_now(boost::posix_time::second_clock::universal_time());
	expireCache(time_now);

	// if we are here, we need to check if access authorized...
	const std::string auth_cookie(request->getCookie(AUTH_COOKIE_NAME));
	if (! auth_cookie.empty()) {
		// check if this cookie is in user cache
		boost::mutex::scoped_lock cache_lock(m_cache_mutex);
		PionUserCache::iterator user_cache_itr=m_user_cache.find(auth_cookie);
		if (user_cache_itr != m_user_cache.end()) {
			// we find those credential in our cache...
			// we can approve authorization now!
			request->setUser(user_cache_itr->second.second);
			// and update cache timeout
			user_cache_itr->second.first = time_now;
			return true;
		}
	}

	// user not found
	handleUnauthorized(request,tcp_conn);
	return false;
}
示例#30
0
	static void store_something(cl_platform_id platform, cl_device_id device, T thing,
		T Slot::*member, thread_scoped_lock &slot_locker)
	{
		assert(platform != NULL);
		assert(device != NULL);
		assert(thing != NULL);

		OpenCLCache &self = global_instance();

		thread_scoped_lock cache_lock(self.cache_lock);
		CacheMap::iterator i = self.cache.find(PlatformDevicePair(platform, device));
		cache_lock.unlock();

		Slot &slot = i->second;

		/* sanity check */
		assert(i != self.cache.end());
		assert(slot.*member == NULL);

		slot.*member = thing;

		/* unlock the slot */
		slot_locker.unlock();
	}