本文整理汇总了C++中ThreadUnlock函数的典型用法代码示例。如果您正苦于以下问题:C++ ThreadUnlock函数的具体用法?C++ ThreadUnlock怎么用?C++ ThreadUnlock使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ThreadUnlock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddThread
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AddThread(void (*func)(int))
{
thread_t *thread;
if (numthreads == 1)
{
if (currentnumthreads >= numthreads)
{
return;
}
currentnumthreads++;
func(-1);
currentnumthreads--;
} //end if
else
{
ThreadLock();
if (currentnumthreads >= numthreads)
{
ThreadUnlock();
return;
} //end if
//allocate new thread
thread = GetMemory(sizeof(thread_t));
if (!thread)
{
Error("can't allocate memory for thread\n");
}
//
thread->threadid = currentthreadid;
thread->id = sprocsp((void (*)(void *, size_t))func, PR_SALL, (void *)thread->threadid, NULL, 0x100000);
if (thread->id == -1)
{
perror("sproc");
Error("sproc failed");
}
//add the thread to the end of the list
thread->next = NULL;
if (lastthread)
{
lastthread->next = thread;
}
else
{
firstthread = thread;
}
lastthread = thread;
//
#ifdef THREAD_DEBUG
qprintf("added thread with id %d\n", thread->threadid);
#endif //THREAD_DEBUG
//
currentnumthreads++;
currentthreadid++;
//
ThreadUnlock();
} //end else
} //end of the function AddThread
示例2: xxxHotTrackMenu
/***************************************************************************\
* xxxHotTrackMenu
*
* Hot-track a menu item in the menu bar.
\***************************************************************************/
BOOL xxxHotTrackMenu(PWND pwnd, UINT nItem, BOOL fDraw)
{
PMENU pmenu = pwnd->spmenu;
PITEM pItem;
HDC hdc;
UINT oldAlign;
TL tlpmenu;
CheckLock(pwnd);
/*
* The window may have lied about the hit-test code on
* WM_NCHITTEST. Make sure it does indeed have a menu.
*/
if (!TestWF(pwnd, WFMPRESENT) || pmenu == NULL)
return FALSE;
if (nItem >= pmenu->cItems) {
RIPMSG0(RIP_WARNING, "xxxHotTrackMenu: menu too large");
return FALSE;
}
pItem = &pmenu->rgItems[nItem];
/*
* Make sure we draw on the right spot
*/
ThreadLock(pmenu, &tlpmenu);
xxxMNRecomputeBarIfNeeded(pwnd, pmenu);
ValidateThreadLocks(NULL, PtiCurrent()->ptl, (ULONG_PTR)&tlpmenu, TRUE);
if (fDraw) {
if (TestMFS(pItem, MF_GRAYED)) {
ThreadUnlock(&tlpmenu);
return FALSE;
}
SetMFS(pItem, MFS_HOTTRACK);
} else {
ClearMFS(pItem, MFS_HOTTRACK);
}
hdc = _GetDCEx(pwnd, NULL, DCX_WINDOW | DCX_USESTYLE | DCX_CACHE);
GreSelectBrush(hdc, SYSHBR(MENUTEXT));
GreSelectFont(hdc, ghMenuFont);
oldAlign = GreGetTextAlign(hdc);
if (pmenu->rgItems && TestMFT(pmenu->rgItems, MFT_RIGHTORDER))
GreSetTextAlign(hdc, oldAlign | TA_RTLREADING);
/*
* When the item is not owner draw, xxxDrawMenuItem does not
* call back and does not leave the critical section.
*/
xxxDrawMenuItem(hdc, pmenu, pItem, 0);
GreSetTextAlign(hdc, oldAlign);
ThreadUnlock(&tlpmenu);
_ReleaseDC(hdc);
return TRUE;
}
示例3: GetThreadWork
// get a new work for thread
int GetThreadWork ( void )
{
int r;
int f;
ThreadLock();
if (dispatch >= workcount)
{
ThreadUnlock();
return -1;
}
if (pacifier == qtrue)
{
f = 10 * dispatch / workcount;
while ( oldf < f)
{
oldf++;
Sys_Printf ("%i...", oldf);
}
}
r = dispatch;
dispatch++;
ThreadUnlock ();
return r;
}
示例4: GetThreadWork
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int GetThreadWork(void)
{
int r;
int f;
ThreadLock();
if (dispatch == workcount)
{
ThreadUnlock ();
return -1;
}
f = 10*dispatch / workcount;
if (f != oldf)
{
oldf = f;
if (pacifier)
printf ("%i...", f);
} //end if
r = dispatch;
dispatch++;
ThreadUnlock ();
return r;
} //end of the function GetThreadWork
示例5: GetThreadWork
/**
* @brief Return an iteration of work, updating progress when appropriate.
*/
static int GetThreadWork (void)
{
int r;
int f;
ThreadLock();
if (threadstate.workindex == threadstate.workcount) { /* done */
ThreadUnlock();
return -1;
}
/* update work fraction and output progress if desired */
f = 10 * threadstate.workindex / threadstate.workcount;
if (f != threadstate.workfrac) {
threadstate.workfrac = f;
if (threadstate.progress) {
fprintf(stdout, "%i...", f);
fflush(stdout);
}
} else if (threadstate.progress && threadstate.workindex % threadstate.worktick == 0) {
fprintf(stdout, "%c\b", "-\\|/"[(threadstate.workindex / threadstate.worktick) & 3]);
fflush(stdout);
}
/* assign the next work iteration */
r = threadstate.workindex;
threadstate.workindex++;
ThreadUnlock();
return r;
}
示例6: GetThreadWork
/*
=============
GetThreadWork
=============
*/
int GetThreadWork (void)
{
int r;
int f;
ThreadLock ();
if (dispatch == workcount)
{
ThreadUnlock ();
return -1;
}
f = 10*dispatch / workcount;
if (f != oldf)
{
oldf = f;
if (pacifier)
{
Sys_Printf ("%i...", f);
fflush( stdout ); /* ydnar */
}
}
r = dispatch;
dispatch++;
ThreadUnlock ();
return r;
}
示例7: RemoveDBHandle
static int RemoveDBHandle(CF_DB *dbp)
/* Remove a specific DB handle */
{ int i;
if (!ThreadLock(cft_dbhandle))
{
return false;
}
i = 0;
while(OPENDB[i] != dbp)
{
i++;
if(i == MAX_OPENDB)
{
ThreadUnlock(cft_dbhandle);
CfOut(cf_error,"","!! Database handle was not found");
return false;
}
}
// free slot
OPENDB[i] = NULL;
ThreadUnlock(cft_dbhandle);
return true;
}
示例8: GetDBHandle
static int GetDBHandle(CF_DB **dbp)
/* Return the first unused DB handle in the parameter - NULL if empty */
{ int i;
if (!ThreadLock(cft_dbhandle))
{
return false;
}
i = 0;
while (OPENDB[i] == NULL)
{
i++;
if(i == MAX_OPENDB)
{
ThreadUnlock(cft_dbhandle);
*dbp = NULL;
return true;
}
}
*dbp = OPENDB[i];
ThreadUnlock(cft_dbhandle);
return true;
}
示例9: ScopeClear
void ScopeClear(const char *ns, const char *name)
{
assert(name);
assert(!ScopeIsReserved(name));
if (!ns)
{
ns = "default";
}
if (!ThreadLock(cft_vscope))
{
Log(LOG_LEVEL_ERR, "Could not lock VSCOPE");
return;
}
Scope *scope = ScopeGet(ns, name);
if (!scope)
{
Log(LOG_LEVEL_DEBUG, "No scope '%s' to clear", name);
ThreadUnlock(cft_vscope);
return;
}
HashFree(scope->hashtable);
scope->hashtable = HashInit();
Log(LOG_LEVEL_DEBUG, "Scope '%s' cleared", name);
ThreadUnlock(cft_vscope);
}
示例10: SaveDBHandle
static int SaveDBHandle(CF_DB *dbp)
{ int i;
if (!ThreadLock(cft_dbhandle))
{
return false;
}
// find first free slot
i = 0;
while(OPENDB[i] != NULL)
{
i++;
if(i == MAX_OPENDB)
{
ThreadUnlock(cft_dbhandle);
CfOut(cf_error,"","!! Too many open databases");
return false;
}
}
OPENDB[i] = dbp;
ThreadUnlock(cft_dbhandle);
return true;
}
示例11: CfDebug
Scope *ScopeNew(const char *name)
{
Scope *ptr;
CfDebug("Adding scope data %s\n", name);
if (!ThreadLock(cft_vscope))
{
CfOut(OUTPUT_LEVEL_ERROR, "", "!! Could not lock VSCOPE");
return NULL;
}
for (ptr = VSCOPE; ptr != NULL; ptr = ptr->next)
{
if (strcmp(ptr->scope, name) == 0)
{
ThreadUnlock(cft_vscope);
CfDebug("SCOPE Object %s already exists\n", name);
return NULL;
}
}
ptr = xcalloc(1, sizeof(Scope));
ptr->next = VSCOPE;
ptr->scope = xstrdup(name);
ptr->hashtable = HashInit();
VSCOPE = ptr;
ThreadUnlock(cft_vscope);
return ptr;
}
示例12: GetThreadWork
/*
* GetThreadWork
*
* Return an iteration of work, updating progress when appropriate.
*/
static int GetThreadWork(void){
int r;
int f;
ThreadLock();
if(thread_work.index == thread_work.count){ // done
ThreadUnlock();
return -1;
}
// update work fraction and output progress if desired
f = 10 * thread_work.index / thread_work.count;
if(f != thread_work.fraction){
thread_work.fraction = f;
if(thread_work.progress && !(verbose || debug)){
Com_Print("%i...", f);
fflush(stdout);
}
}
// assign the next work iteration
r = thread_work.index;
thread_work.index++;
ThreadUnlock();
return r;
}
示例13: NewScope
void NewScope(const char *name)
/*
* Thread safe
*/
{
Scope *ptr;
CfDebug("Adding scope data %s\n", name);
if (!ThreadLock(cft_vscope))
{
CfOut(cf_error, "", "!! Could not lock VSCOPE");
return;
}
for (ptr = VSCOPE; ptr != NULL; ptr = ptr->next)
{
if (strcmp(ptr->scope, name) == 0)
{
ThreadUnlock(cft_vscope);
CfDebug("SCOPE Object %s already exists\n", name);
return;
}
}
ptr = xcalloc(1, sizeof(Scope));
ptr->next = VSCOPE;
ptr->scope = xstrdup(name);
ptr->hashtable = HashInit();
VSCOPE = ptr;
ThreadUnlock(cft_vscope);
}
示例14: Log
Scope *ScopeNew(const char *name)
{
Scope *ptr;
if (!ThreadLock(cft_vscope))
{
Log(LOG_LEVEL_ERR, "Could not lock VSCOPE");
return NULL;
}
for (ptr = VSCOPE; ptr != NULL; ptr = ptr->next)
{
if (strcmp(ptr->scope, name) == 0)
{
ThreadUnlock(cft_vscope);
return NULL;
}
}
ptr = xcalloc(1, sizeof(Scope));
ptr->next = VSCOPE;
ptr->scope = xstrdup(name);
ptr->hashtable = HashInit();
VSCOPE = ptr;
ThreadUnlock(cft_vscope);
return ptr;
}
示例15: ThreadLock
//get the first node from the front of the node list
node_t *NextNodeFromList( void ) {
node_t *node;
ThreadLock();
numwaiting++;
if ( !firstnode ) {
if ( numwaiting >= GetNumThreads() ) {
ThreadSemaphoreIncrease( GetNumThreads() );
}
} //end if
ThreadUnlock();
ThreadSemaphoreWait();
ThreadLock();
numwaiting--;
node = firstnode;
if ( firstnode ) {
firstnode = firstnode->next;
nodelistsize--;
} //end if
if ( !firstnode ) {
lastnode = NULL;
}
ThreadUnlock();
return node;
} //end of the function NextNodeFromList