Exemple #1
0
FreeTypeFontInfo* FreeTypeFontEngine::AddFont(LPCTSTR lpFaceName, int weight, bool italic, BOOL* bIsFontLoaded)
{
	CCriticalSectionLock __lock(CCriticalSectionLock::CS_FONTENG);
	if(lpFaceName == NULL || _tcslen(lpFaceName) == 0/* || FontExists(lpFaceName, weight, italic)*/)
		return NULL;

	//FontListArray& arr = m_arrFontList;

	const CGdippSettings* pSettings = CGdippSettings::GetInstance();
	//const CFontSettings& fs = pSettings->FindIndividual(lpFaceName);
	wstring dumy;
	//dumy.clear();
	FreeTypeFontInfo* pfi = new FreeTypeFontInfo(/*m_mfullMap.size() + 1*/GetFaceID(), lpFaceName, weight, italic, MruIncrement(), dumy, dumy);
	if (!pfi)
		return NULL;
	if (pfi->GetFullName().size()==0)	//点阵字
	{
		delete pfi;
		ReleaseFaceID();
		return NULL;
	}

	FullNameMap::const_iterator it = m_mfullMap.find(pfi->GetFullName()); //是否在主map表中存在了
	if (it!=m_mfullMap.end())	//已经存在
	{
		delete pfi;	//删除创建出来的字体
		ReleaseFaceID();
		pfi = it->second;	//指向已经存在的字体
		if (bIsFontLoaded)
			*bIsFontLoaded = true;
		//pfi->AddRef();
	}
	else
	{
		m_mfullMap[pfi->GetFullName()]=pfi;	//不存在,添加到map表
		m_mfontList.push_back(pfi);
		if (bIsFontLoaded)
			*bIsFontLoaded = false;
	}

	//bool ret = !!arr.Add(pfi);
	//weight = weight < FW_BOLD ? 0: FW_BOLD;
	myfont font(lpFaceName, weight, italic);
	m_mfontMap[font]=pfi;		//添加在次要map表
/*
	if (!ret) {
		delete pfi;
		return NULL;
	}*/

	
#ifdef _DEBUG
	{
		const CFontSettings& fs = pfi->GetFontSettings();
		TRACE(_T("AddFont: %s, %d, %d, %d, %d, %d, %d\n"), pfi->GetName(),
				fs.GetParam(0), fs.GetParam(1), fs.GetParam(2), fs.GetParam(3), fs.GetParam(4), fs.GetParam(5));
	}
#endif
	return pfi;
}
Exemple #2
0
FreeTypeFontInfo* FreeTypeFontEngine::FindFont(LPCTSTR lpFaceName, int weight, bool italic, bool AddOnFind, BOOL* bIsFontLoaded)
{
/*
	if (m_bAddOnFind) 
	{
		m_bAddOnFind = false;
		return NULL;
	}*/

	CCriticalSectionLock __lock(CCriticalSectionLock::CS_FONTMAP);
	weight = CalcBoldWeight(weight);
	myfont font(lpFaceName, weight, italic);
	FontMap::const_iterator iter=m_mfontMap.find(font);
	if (iter!=m_mfontMap.end())
	{
		FreeTypeFontInfo* p = iter->second;
		p->SetMruCounter(this);
/*
		TCHAR buff[255]={0};
		if (wcslen(lpFaceName)==8)
		{
			wsprintf(buff, L"Finding familiyname \"%s\" weight %d\n\tFound: \"%s\"\n", lpFaceName,
				weight, p->GetFullName().c_str());
			Log(buff);
		}*/
		if (bIsFontLoaded)
			*bIsFontLoaded = true;
		return p;
	}
	//m_bAddOnFind = true;
	return AddFont(lpFaceName, weight, italic, bIsFontLoaded);
}
Exemple #3
0
BOOL FreeTypeFontEngine::RemoveFont(FreeTypeFontInfo* fontinfo)
{
	CCriticalSectionLock __lock(CCriticalSectionLock::CS_FONTMAP);
	{
		FontMap::const_iterator iter=m_mfontMap.begin();	//遍历fontmap
		while (iter!=m_mfontMap.end())
		{
			FreeTypeFontInfo* p = iter->second;
			if (p==fontinfo)
				m_mfontMap.erase(iter++);	//删除引用
			else
				++iter;
		}
	}
	{
		FullNameMap::const_iterator iter=m_mfullMap.begin();	//遍历fullmap
		while (iter!=m_mfullMap.end())
		{
			FreeTypeFontInfo* p = iter->second;
			if (p==fontinfo)
				m_mfullMap.erase(iter++);	//删除引用
			else
			{
				iter->second->UpdateFontSetting();
				++iter;
			}
		}
	}
	delete fontinfo;
	return true;
}
Exemple #4
0
bool FreeTypeFontInfo::EmbeddedBmpExist(int px)
{
	if (px>=256 || px<0)
		return false;
	if (m_ebmps[px]!=-1)
		return !!m_ebmps[px];
	CCriticalSectionLock __lock(CCriticalSectionLock::CS_MANAGER);
	FTC_ImageTypeRec imgtype={(FTC_FaceID)m_id, px, px, FT_LOAD_DEFAULT};	//构造一个当前大小的imagetype
	FT_Glyph temp_glyph=NULL;
	FT_UInt gindex = FTC_CMapCache_Lookup(cmap_cache, (FTC_FaceID)m_id, -1, FT_UInt32(L'0'));	//获得0的索引值
	FTC_ImageCache_Lookup(image_cache, &imgtype, gindex, &temp_glyph, NULL);
	if (temp_glyph && temp_glyph->format==FT_GLYPH_FORMAT_BITMAP)	//如果可以读到0的点阵
		m_ebmps[px]=1;	//则该字号存在点阵
	else
	{
		gindex = FTC_CMapCache_Lookup(cmap_cache, (FTC_FaceID)m_id, -1, FT_UInt32(L'的'));	//获得"的"的索引值
		if (gindex)
			FTC_ImageCache_Lookup(image_cache, &imgtype, gindex, &temp_glyph, NULL);	//读取“的”的点阵
		if (temp_glyph && temp_glyph->format==FT_GLYPH_FORMAT_BITMAP)	//如果可以读到0的点阵
			m_ebmps[px]=1;	//则该字号存在点阵
		else
			m_ebmps[px]=0;
	}
	return !!m_ebmps[px];
}
Exemple #5
0
static ssize_t
kfs_default_read(struct file * dir,
		 char *        buf,
		 size_t        len,
		 loff_t *      off
)
{
	size_t offset = 0;
	struct inode * inode;
__lock(&_lock);
	struct htable_iter iter = htable_iter( dir->inode->files );
	while( (inode = htable_next( &iter )) )
	{
		int rc = snprintf(
			(char*)buf + offset,
			len - offset,
			"%s\n",
			inode->name
		);

		if( rc > len - offset )
		{
			offset = len-1;
			goto done;
		}

		offset += rc;
	}

done:
__unlock(&_lock);
	return offset;
}
Exemple #6
0
int  app::push(const app_hd & temp){
	
	if(!m_mutil_thread){
		return dispatch(&temp);
	}
	
	app_hd * msg = (app_hd*)malloc(sizeof(app_hd) + temp.length + 1);
	if(!msg){
		error_log("malloc %d bytes fail, error(%d)\n", sizeof(app_hd) + temp.length + 1, errno);
		return -1;
	}
	memcpy(msg, &temp, sizeof(app_hd));
	
	if(temp.length){
		msg->content = (char*)msg + sizeof(app_hd) ;
		memcpy(msg->content, temp.content, temp.length);
		msg->content[temp.length] = 0;	
	}
	
	auto_lock __lock(m_push_mutex);
	int ret = m_ring_buf.push(msg);
	if(ret < 0){
		error_log("drop msg total(%d)\n", ++m_drop_msg);
		free(msg);
	}
	return ret;
}
Exemple #7
0
/** Openat system call
 *
 * \todo Implement flags and mode tests.
 */
int
sys_openat(int     dirfd,
	   uaddr_t u_pathname,
	   int     flags,
	   mode_t  mode)
{
	int fd;
	char pathname[ MAX_PATHLEN ];
	struct file *file;
	struct inode * root_inode = NULL;

	if( strncpy_from_user( pathname, (void*) u_pathname,
			       sizeof(pathname) ) < 0 )
		return -EFAULT;

	//printk("sys_openat(%s): %d %08x %03x\n", pathname, dirfd, flags, mode);

	dbg( "name='%s' dirfd=%d flags %x mode %x\n", pathname, dirfd, flags, mode);
	//_KDBG( "name='%s' flags %x mode %x\n", pathname, flags, mode);

	if ((pathname[0] == '/') ||
	    (dirfd       == AT_FDCWD)) {
	    root_inode = kfs_root;
	} else {
	    struct file * root_file = get_current_file(dirfd);
	    
	    if (!root_file) {
		return -EBADF;
	    }

	    root_inode = root_file->inode;
	}


	// FIX ME
__lock(&_lock);
	if ( ! kfs_lookup( root_inode, pathname, 0 ) && ( flags & O_CREAT ) )  {
		extern struct kfs_fops in_mem_fops;
		extern struct inode_operations in_mem_iops;
		if ( kfs_create_at( root_inode, pathname, &in_mem_iops, &in_mem_fops, 0777, 0, 0 )
		     == NULL ) {
			fd = -EFAULT;
			goto out;
       		}
    	}

	if((fd = kfs_open_path_at(root_inode, pathname, flags, mode, &file)) < 0) {
		//printk("sys_openat failed : %s (%d)\n",pathname,fd);
		goto out;
	}
	fd = fdTableGetUnused( current->fdTable );
	fdTableInstallFd( current->fdTable, fd, file );

	// TODO XXX - check to see if the file's path identifies it as a pipe, and set the pipe stuff

        dbg("name=`%s` fd=%d \n", pathname, fd );
out:
__unlock(&_lock);
	return fd;
}
Exemple #8
0
void lock(lock_t *_lock)
{
	pid_t pid = getpid();

	while (_lock->lock != UNLOCKED) {
		if (_lock->owner == pid) {
			debugf("lol, already have lock!\n");
			show_backtrace();
			panic(EXIT_LOCKING_CATASTROPHE);
			_exit(EXIT_FAILURE);
		}

		/* This is pretty horrible. But if we call lock()
		 * from stuck_syscall_info(), and a child is hogging a lock
		 * (or worse, a dead child), we'll deadlock, because main won't
		 *  ever get back, and subsequently check_lock().
		 * So we add an extra explicit check here.
		 */
		if (pid == mainpid) {
			check_lock(_lock);
		} else {
			/* Ok, we're a child pid.
			 * if something bad happened, like main crashed,
			 * we don't want to spin forever, so just get out.
			 */
			if ((shm->exit_reason != STILL_RUNNING) &&
			    (shm->exit_reason != EXIT_REACHED_COUNT)) {
				_exit(EXIT_FAILURE);
			}
		}

		usleep(1);
	}
	__lock(_lock);
}
    void addReply( std::shared_ptr<QNetworkReply> r ) {
        {
            std::unique_lock<std::recursive_mutex> __lock(reply_mutex);
            if (replys) { replys->insert(r); }
        }

    }
Exemple #10
0
bool trylock(lock_t *_lock)
{
	if (_lock->lock == UNLOCKED) {
		__lock(_lock);
		return TRUE;
	}
	return FALSE;
}
int pthread_setschedparam(pthread_t t, int policy, const struct sched_param *param)
{
	int r;
	__lock(t->killlock);
	r = t->dead ? ESRCH : -__syscall(SYS_sched_setscheduler, t->tid, policy, &param);
	__unlock(t->killlock);
	return r;
}
static void return_to_pool(message_t *msg) {
  /*** NB: there's an implicit s-l-o-w SW multiply in msg-mpool !!! */
  uint16_t mask = _bmaps[msg - mpool];

  __lock();
  bmask |= mask;
  __unlock();
}
Exemple #13
0
int app_timer::latency_time(){
	auto_lock __lock(m_mutex);
	int timeout = m_timer.latency_time();
	if(timeout < 0 || timeout > m_precision){
		return m_precision;
	}
	return timeout;
}
Exemple #14
0
/* Return a random integer between 0 and RAND_MAX inclusive.  */
int rand(void)
{
	int n;
	__lock();
	n = rand_r(&_seed);
	__unlock();
	return n;
}
int pthread_setschedprio(pthread_t t, int prio)
{
	int r;
	__lock(t->killlock);
	r = t->dead ? ESRCH : -__syscall(SYS_sched_setparam, t->tid, &prio);
	__unlock(t->killlock);
	return r;
}
Exemple #16
0
int
kfs_readdir(struct file * filp, uaddr_t buf, unsigned int count,
	    dirent_filler f)
{
	struct inode *child;
__lock(&_lock);
	struct htable_iter iter = htable_iter( filp->inode->files );
	int res = 0, rv = 0, i;

	/* for directories, we just increase pos by 1 for every
	   child we successfully fill into the dirent buffer;
	   linux uses 0 and 1 for . and .., then inodes for the
	   rest */
	if(filp->pos == 0) {
		rv = f(buf, count, filp->inode,
		       ".", 1, filp->pos + 1,
		       4 /* DT_DIR */);
		if(rv < 0)
			goto out;
		res += rv;
		count -= rv;
		filp->pos++;
		buf += rv;
	}
	if(filp->pos == 1) {
		rv = f(buf, count, filp->inode,
		       "..", 2, filp->pos + 1,
		       4 /* DT_DIR */);
		if(rv < 0)
			goto out;
		res += rv;
		count -= rv;
		filp->pos++;
		buf += rv;
	}
	i = 2;
	while( (child = htable_next( &iter )) )
	{
		if(filp->pos > i++)
			continue;
		rv = f(buf, count, child,
		       child->name,
		       strlen(child->name),
		       filp->pos + 1,
		       (child->mode >> 12) & 15);
		if(rv < 0)
			goto out;
		res += rv;
		count -= rv;
		filp->pos++;
		buf += rv;
	}
 out:
__unlock(&_lock);
	if(rv < 0 && (rv != -EINVAL || res == 0))
		return rv;
	return res;
}
Exemple #17
0
void hash_map(struct hash *h, void (*fn)(struct hashelem *obj))
{
	__lock(h);
	for(size_t index = 0;index < h->length;index++) {
		if(h->table[index])
			linkedlist_apply_data(h->table[index], __fnjmp, fn);
	}
	__unlock(h);
}
Exemple #18
0
int array_count(struct array *a)
{
	int retval;
	
	__lock(a);
	retval = a->a_items;
	__unlock(a);
	return retval;
}
static void max14688_det_work (struct work_struct *work)
{
    struct max14688 *me = container_of(work, struct max14688, det_work.work);
    int micZ, leftZ;

    if(earjack_detect == true) {
	    log_dbg("duplication intterupt already connect earjack\n");
	    return;
    } else {
	    earjack_detect = true;
    }

    __lock(me);

    if (unlikely(!me->detect_jack(me->dev))) {
	    log_warn("no jack in detection work\n");
	    earjack_detect = false;
	    goto out;
    }

    max14688_update_status(me);

    /* Read MIC and L-line impedences */
    micZ  = me->read_mic_impedence(me->dev);
    leftZ = me->read_left_impedence(me->dev);

    log_dbg("%s[micZ = %d, leftZ = %d\n", __func__, micZ, leftZ);

    /* Look up jack matching impedence ranges */
    max14688_lookup_jack(me, micZ, leftZ);

    if (unlikely(!__present_valid_jack(me))) {
	    earjack_detect = false;
	    goto no_match_found;
    }

    max14688_write_mode0(me, __current_jack_mode0(me));
    max14688_write_mode1(me, __current_jack_mode1(me));

    if (__current_jack_has_button(me)) {
	    max14688_enable_irq(me, IRQ_SWD);
    } else {
	    max14688_disable_irq(me, IRQ_SWD);
    }

    log_dbg("jack %s inserted\n", __current_jack_name(me));
    me->report_jack(me->dev, __current_jack(me), JACK_IN_VALUE);
    goto out;

no_match_found:
    /* Handle exception */
    log_err("unknown jack - mic %d, left %d\n", micZ, leftZ);

out:
    __unlock(me);
    return;
}
Exemple #20
0
 inline int32_t decrement_suffix()
 {
     int32_t __result;
     {
         mutex::scoped_lock __lock(_mutex);
         __result = _value--;
     }
     return __result;
 }
Exemple #21
0
 inline int32_t decrement_prefix()
 {
     int32_t __result;
     {
         mutex::scoped_lock __lock(_mutex);
         __result = --_value;
     }
     return __result;
 }
Exemple #22
0
 inline int32_t get_value() const
 {
     int32_t __result;
     {
         mutex::scoped_lock __lock(_mutex);
         __result = _value;
     }
     return __result;
 }
/*** return msg to pool (you'd better have gotten it from get_from_pool :-) */
static void return_to_pool(message_t *msg) {
  message_item_t *mi;

  __lock();
  mi         = (message_item_t *) (((char *) msg) - msg_ofs);
  mi->next   = mpool_head;
  mpool_head = mi;
  __unlock();
}
Exemple #24
0
//FreeTypeFontEngine
void FreeTypeFontEngine::Compact()
{
	CCriticalSectionLock __lock(CCriticalSectionLock::CS_FONTENG);

	TRACE(_T("FreeTypeFontEngine::Compact: %d > %d\n"), m_mfontMap.size(), m_nMaxFaces);
	ResetGCCounter();
	//memset(m_arrFace, 0, sizeof(FT_Face)*m_nFaceCount);	//超过最大face数了,老的face会被ft释放掉,所以需要全部重新获取
	//FontListArray& arr = m_arrFontList;
	//::Compact(arr.GetData(), arr.GetSize(), m_nMaxFaces);
}
Exemple #25
0
 void pilo::core::threading::recursive_mutex::lock()
 {
     long const current_thread_id = ::GetCurrentThreadId();
     if (!_try_recursive_lock(current_thread_id))
     {
         __lock();
         PILO_WIN_INTERLOCKED_EXCHANGE(&_m_locking_thread_id, current_thread_id);
         _m_recursion_count = 1;
     }
 }
Exemple #26
0
void array_free(struct array *a)
{
	__lock(a);
	if (a->a_arr)
		free(a->a_arr);
	a->a_arr = NULL;
	a->a_size = 0;
	a->a_items = 0;
	__unlock(a);
}
Exemple #27
0
BOOL FreeTypeFontEngine::RemoveFont(LPCWSTR FontName)
{
	if (!FontName) return false;
	LOGFONTW* fontarray = GetFontNameFromFile(FontName);
	LOGFONTW* c_fontarray = fontarray;	//记录原始指针
	if (!fontarray) return false;
	FTC_FaceID fid = NULL;
	BOOL bIsFontLoaded, bIsFontFileLoaded = false;
	COwnedCriticalSectionLock __lock2(2, COwnedCriticalSectionLock::OCS_DC);	//获取所有权,现在要处理DC,禁止所有绘图函数访问
	CCriticalSectionLock __lock(CCriticalSectionLock::CS_MANAGER);
	while (*(char*)fontarray)
	{
		bIsFontLoaded = false;
		FreeTypeFontInfo* result = FindFont(fontarray->lfFaceName, fontarray->lfWeight, !!fontarray->lfItalic, false, &bIsFontLoaded);
		if (result)
		{
			fid = (FTC_FaceID)result->GetId();
			if (bIsFontLoaded)	//该字体已经被使用过
			{
				RemoveFont(result);	//枚举字体信息全部删除
				bIsFontFileLoaded = true;	//设置字体文件也被使用过
			}
			else
				RemoveThisFont(result, fontarray);
			CCriticalSectionLock __lock(CCriticalSectionLock::CS_FONTENG);
			FTC_Manager_RemoveFaceID(cache_man, fid);
			m_mfontList[(int)fid-1]=NULL;
		}
		fontarray++;
	}
	free(c_fontarray); //利用原始指针释放
	if (bIsFontFileLoaded)	//若字体文件被使用过,则需要清楚所有DC
	{
		CTLSDCArray::iterator iter = TLSDCArray.begin();
		while (iter!=TLSDCArray.end())
		{
			((CBitmapCache*)*iter)->~CBitmapCache();	//清除掉所有使用中的DC
			++iter;
		}
	}
	return true;
}
Exemple #28
0
void print(_Stream& _cout,const CString_& _s)
{
	static CCriticalSection critsect;

	CAutoLock __lock(critsect);

	long i=0;
	for(i=0;i<_s.GetLength();i+=256)
	{
		_cout << (LPCTSTR)_s.Mid(i,256);
	}
}
Exemple #29
0
void* thread_fct(void *arg)
{
  int id = *((int*)arg);
  int j=0;
  for (j=0 ; j<NB_LOOP ; j++) {
    __lock(&global_lock, id);
    /* critical section */
    global_var++;
    __unlock(&global_lock, id);
  }
  pthread_exit(0);
}
Exemple #30
0
void *array_at(struct array *a, int nr)
{
	void *retval;
	
	__lock(a);
	if (nr < 0 || nr >= a->a_size)
		retval = NULL;
	else
		retval = a->a_arr[nr].ai_data;
	__unlock(a);
	return retval;
}