本文整理汇总了C++中Tcl_MutexLock函数的典型用法代码示例。如果您正苦于以下问题:C++ Tcl_MutexLock函数的具体用法?C++ Tcl_MutexLock怎么用?C++ Tcl_MutexLock使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Tcl_MutexLock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ExitHandler
/*
* ExitHandler
*
* Cleans up library on exit, frees all state structures.
*
* Arguments:
* dummy - Not used.
*
* Returns:
* None.
*/
static void
ExitHandler(
ClientData dummy
)
{
/* Init clean-up. */
Tcl_MutexLock(&initMutex);
if (kernelModule != NULL) {
FreeLibrary(kernelModule);
kernelModule = NULL;
}
getDiskFreeSpaceExPtr = NULL;
initialised = FALSE;
Tcl_MutexUnlock(&initMutex);
Tcl_MutexFinalize(&initMutex);
/* Key clean-up. */
Tcl_MutexLock(&keyMutex);
if (keyTable != NULL) {
KeyClearTable();
Tcl_DeleteHashTable(keyTable);
ckfree((char *)keyTable);
keyTable = NULL;
}
Tcl_MutexUnlock(&keyMutex);
Tcl_MutexFinalize(&keyMutex);
#ifdef TCL_MEM_DEBUG
Tcl_DumpActiveMemory("MemDump.txt");
#endif
}
示例2: Tcl_AsyncInvoke
int
Tcl_AsyncInvoke(
Tcl_Interp *interp, /* If invoked from Tcl_Eval just after
* completing a command, points to
* interpreter. Otherwise it is NULL. */
int code) /* If interp is non-NULL, this gives
* completion code from command that just
* completed. */
{
AsyncHandler *asyncPtr;
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
Tcl_MutexLock(&tsdPtr->asyncMutex);
if (tsdPtr->asyncReady == 0) {
Tcl_MutexUnlock(&tsdPtr->asyncMutex);
return code;
}
tsdPtr->asyncReady = 0;
tsdPtr->asyncActive = 1;
if (interp == NULL) {
code = 0;
}
/*
* Make one or more passes over the list of handlers, invoking at most one
* handler in each pass. After invoking a handler, go back to the start of
* the list again so that (a) if a new higher-priority handler gets marked
* while executing a lower priority handler, we execute the higher-
* priority handler next, and (b) if a handler gets deleted during the
* execution of a handler, then the list structure may change so it isn't
* safe to continue down the list anyway.
*/
while (1) {
for (asyncPtr = tsdPtr->firstHandler; asyncPtr != NULL;
asyncPtr = asyncPtr->nextPtr) {
if (asyncPtr->ready) {
break;
}
}
if (asyncPtr == NULL) {
break;
}
asyncPtr->ready = 0;
Tcl_MutexUnlock(&tsdPtr->asyncMutex);
code = (*asyncPtr->proc)(asyncPtr->clientData, interp, code);
Tcl_MutexLock(&tsdPtr->asyncMutex);
}
tsdPtr->asyncActive = 0;
Tcl_MutexUnlock(&tsdPtr->asyncMutex);
return code;
}
示例3: GetCache
static Cache *
GetCache(void)
{
Cache *cachePtr;
/*
* Check for first-time initialization.
*/
if (listLockPtr == NULL) {
Tcl_Mutex *initLockPtr;
unsigned int i;
initLockPtr = Tcl_GetAllocMutex();
Tcl_MutexLock(initLockPtr);
if (listLockPtr == NULL) {
listLockPtr = TclpNewAllocMutex();
objLockPtr = TclpNewAllocMutex();
for (i = 0; i < NBUCKETS; ++i) {
bucketInfo[i].blockSize = MINALLOC << i;
bucketInfo[i].maxBlocks = 1 << (NBUCKETS - 1 - i);
bucketInfo[i].numMove = i < NBUCKETS - 1 ?
1 << (NBUCKETS - 2 - i) : 1;
bucketInfo[i].lockPtr = TclpNewAllocMutex();
}
}
Tcl_MutexUnlock(initLockPtr);
}
/*
* Get this thread's cache, allocating if necessary.
*/
cachePtr = TclpGetAllocCache();
if (cachePtr == NULL) {
cachePtr = calloc(1, sizeof(Cache));
if (cachePtr == NULL) {
Tcl_Panic("alloc: could not allocate new cache");
}
Tcl_MutexLock(listLockPtr);
cachePtr->nextPtr = firstCachePtr;
firstCachePtr = cachePtr;
Tcl_MutexUnlock(listLockPtr);
cachePtr->owner = Tcl_GetCurrentThread();
TclpSetAllocCache(cachePtr);
}
return cachePtr;
}
示例4: TclGetEnv
const char *
TclGetEnv(
const char *name, /* Name of environment variable to find
* (UTF-8). */
Tcl_DString *valuePtr) /* Uninitialized or free DString in which the
* value of the environment variable is
* stored. */
{
int length, index;
const char *result;
Tcl_MutexLock(&envMutex);
index = TclpFindVariable(name, &length);
result = NULL;
if (index != -1) {
Tcl_DString envStr;
result = Tcl_ExternalToUtfDString(NULL, environ[index], -1, &envStr);
result += length;
if (*result == '=') {
result++;
Tcl_DStringInit(valuePtr);
Tcl_DStringAppend(valuePtr, result, -1);
result = Tcl_DStringValue(valuePtr);
} else {
result = NULL;
}
Tcl_DStringFree(&envStr);
}
Tcl_MutexUnlock(&envMutex);
return result;
}
示例5: Tcl_DumpActiveMemory
int
Tcl_DumpActiveMemory(
const char *fileName) /* Name of the file to write info to */
{
FILE *fileP;
struct mem_header *memScanP;
char *address;
if (fileName == NULL) {
fileP = stderr;
} else {
fileP = fopen(fileName, "w");
if (fileP == NULL) {
return TCL_ERROR;
}
}
Tcl_MutexLock(ckallocMutexPtr);
for (memScanP = allocHead; memScanP != NULL; memScanP = memScanP->flink) {
address = &memScanP->body[0];
fprintf(fileP, "%8lx - %8lx %7ld @ %s %d %s",
(long unsigned) address,
(long unsigned) address + memScanP->length - 1,
memScanP->length, memScanP->file, memScanP->line,
(memScanP->tagPtr == NULL) ? "" : memScanP->tagPtr->string);
(void) fputc('\n', fileP);
}
Tcl_MutexUnlock(ckallocMutexPtr);
if (fileP != stderr) {
fclose(fileP);
}
return TCL_OK;
}
示例6: TclFinalizeMemorySubsystem
void
TclFinalizeMemorySubsystem(void)
{
#ifdef TCL_MEM_DEBUG
if (tclMemDumpFileName != NULL) {
Tcl_DumpActiveMemory(tclMemDumpFileName);
} else if (onExitMemDumpFileName != NULL) {
Tcl_DumpActiveMemory(onExitMemDumpFileName);
}
Tcl_MutexLock(ckallocMutexPtr);
if (curTagPtr != NULL) {
TclpFree((char *) curTagPtr);
curTagPtr = NULL;
}
allocHead = NULL;
Tcl_MutexUnlock(ckallocMutexPtr);
#endif
#if USE_TCLALLOC
TclFinalizeAllocSubsystem();
#endif
}
示例7: Tcl_GetMemoryInfo
void
Tcl_GetMemoryInfo(
Tcl_DString *dsPtr)
{
Cache *cachePtr;
char buf[200];
unsigned int n;
Tcl_MutexLock(listLockPtr);
cachePtr = firstCachePtr;
while (cachePtr != NULL) {
Tcl_DStringStartSublist(dsPtr);
if (cachePtr == sharedPtr) {
Tcl_DStringAppendElement(dsPtr, "shared");
} else {
sprintf(buf, "thread%p", cachePtr->owner);
Tcl_DStringAppendElement(dsPtr, buf);
}
for (n = 0; n < NBUCKETS; ++n) {
sprintf(buf, "%lu %ld %ld %ld %ld %ld %ld",
(unsigned long) bucketInfo[n].blockSize,
cachePtr->buckets[n].numFree,
cachePtr->buckets[n].numRemoves,
cachePtr->buckets[n].numInserts,
cachePtr->buckets[n].totalAssigned,
cachePtr->buckets[n].numLocks,
cachePtr->buckets[n].numWaits);
Tcl_DStringAppendElement(dsPtr, buf);
}
Tcl_DStringEndSublist(dsPtr);
cachePtr = cachePtr->nextPtr;
}
Tcl_MutexUnlock(listLockPtr);
}
示例8: TclCreateThread
/* ARGSUSED */
int
TclCreateThread(
Tcl_Interp *interp, /* Current interpreter. */
char *script, /* Script to execute */
int joinable) /* Flag, joinable thread or not */
{
ThreadCtrl ctrl;
Tcl_ThreadId id;
ctrl.script = script;
ctrl.condWait = NULL;
ctrl.flags = 0;
joinable = joinable ? TCL_THREAD_JOINABLE : TCL_THREAD_NOFLAGS;
Tcl_MutexLock(&threadMutex);
if (Tcl_CreateThread(&id, NewTestThread, (ClientData) &ctrl,
TCL_THREAD_STACK_DEFAULT, joinable) != TCL_OK) {
Tcl_MutexUnlock(&threadMutex);
Tcl_AppendResult(interp, "can't create a new thread", NULL);
ckfree((char *) ctrl.script);
return TCL_ERROR;
}
/*
* Wait for the thread to start because it is using something on our stack!
*/
Tcl_ConditionWait(&ctrl.condWait, &threadMutex, NULL);
Tcl_MutexUnlock(&threadMutex);
Tcl_ConditionFinalize(&ctrl.condWait);
Tcl_SetObjResult(interp, Tcl_NewLongObj((long)id));
return TCL_OK;
}
示例9: cmd_rechan
static int
cmd_rechan(ClientData cd_, Tcl_Interp* ip_, int objc_, Tcl_Obj*const* objv_)
{
ReflectingChannel *rc;
int mode;
char buffer [20];
if (objc_ != 3) {
Tcl_WrongNumArgs(ip_, 1, objv_, "command mode");
return TCL_ERROR;
}
if (Tcl_ListObjLength(ip_, objv_[1], &mode) == TCL_ERROR ||
Tcl_GetIntFromObj(ip_, objv_[2], &mode) == TCL_ERROR)
return TCL_ERROR;
Tcl_MutexLock(&rechanMutex);
sprintf(buffer, "rechan%d", ++mkChanSeq);
Tcl_MutexUnlock(&rechanMutex);
rc = rcCreate (ip_, objv_[1], mode, buffer);
rc->_chan = Tcl_CreateChannel(&reChannelType, buffer, (ClientData) rc, mode);
Tcl_RegisterChannel(ip_, rc->_chan);
Tcl_SetChannelOption(ip_, rc->_chan, "-buffering", "none");
Tcl_SetChannelOption(ip_, rc->_chan, "-blocking", "0");
Tcl_SetResult(ip_, buffer, TCL_VOLATILE);
return TCL_OK;
}
示例10: ConsoleThreadActionProc
static void
ConsoleThreadActionProc(
ClientData instanceData,
int action)
{
ConsoleInfo *infoPtr = (ConsoleInfo *) instanceData;
/* We do not access firstConsolePtr in the thread structures. This is not
* for all serials managed by the thread, but only those we are watching.
* Removal of the filevent handlers before transfer thus takes care of
* this structure.
*/
Tcl_MutexLock(&consoleMutex);
if (action == TCL_CHANNEL_THREAD_INSERT) {
/*
* We can't copy the thread information from the channel when the
* channel is created. At this time the channel back pointer has not
* been set yet. However in that case the threadId has already been
* set by TclpCreateCommandChannel itself, so the structure is still
* good.
*/
ConsoleInit();
if (infoPtr->channel != NULL) {
infoPtr->threadId = Tcl_GetChannelThread(infoPtr->channel);
}
} else {
infoPtr->threadId = NULL;
}
Tcl_MutexUnlock(&consoleMutex);
}
示例11: Sv_RegisterListCommands
void
Sv_RegisterListCommands(void)
{
static int initialized = 0;
if (initialized == 0) {
Tcl_MutexLock(&initMutex);
if (initialized == 0) {
/* Create list with 1 empty element. */
Tcl_Obj *listobj = Tcl_NewObj();
listobj = Tcl_NewListObj(1, &listobj);
Sv_RegisterObjType(listobj->typePtr, DupListObjShared);
Tcl_DecrRefCount(listobj);
Sv_RegisterCommand("lpop", SvLpopObjCmd, NULL, 0);
Sv_RegisterCommand("lpush", SvLpushObjCmd, NULL, 0);
Sv_RegisterCommand("lappend", SvLappendObjCmd, NULL, 0);
Sv_RegisterCommand("lreplace", SvLreplaceObjCmd, NULL, 0);
Sv_RegisterCommand("linsert", SvLinsertObjCmd, NULL, 0);
Sv_RegisterCommand("llength", SvLlengthObjCmd, NULL, 0);
Sv_RegisterCommand("lindex", SvLindexObjCmd, NULL, 0);
Sv_RegisterCommand("lrange", SvLrangeObjCmd, NULL, 0);
Sv_RegisterCommand("lsearch", SvLsearchObjCmd, NULL, 0);
Sv_RegisterCommand("lset", SvLsetObjCmd, NULL, 0);
initialized = 1;
}
Tcl_MutexUnlock(&initMutex);
}
}
示例12: tclSendThread
void tclSendThread(Tcl_ThreadId thread, Tcl_Interp *interpreter, CONST char *script)
{
ThreadEvent *event;
Tcl_Channel errorChannel;
Tcl_Obj *object;
int boolean;
object = Tcl_GetVar2Ex(interpreter, "::tcl_platform", "threaded", 0);
if ((object == 0) || (Tcl_GetBooleanFromObj(interpreter, object, &boolean) != TCL_OK) || !boolean) {
errorChannel = Tcl_GetStdChannel(TCL_STDERR);
if (errorChannel == NULL) return;
Tcl_WriteChars(
errorChannel, "error: Python thread requested script evaluation on Tcl core not compiled for multithreading.\n", -1
);
return;
}
event = (ThreadEvent *)Tcl_Alloc(sizeof(ThreadEvent));
event->event.proc = ThreadEventProc;
event->interpreter = interpreter;
event->script = strcpy(Tcl_Alloc(strlen(script) + 1), script);
Tcl_MutexLock(&threadMutex);
Tcl_ThreadQueueEvent(thread, (Tcl_Event *)event, TCL_QUEUE_TAIL);
Tcl_ThreadAlert(thread);
Tcl_MutexUnlock(&threadMutex);
}
示例13: TreeHeadingBorderElementDraw
static void TreeHeadingBorderElementDraw(
void *clientData, void *elementRecord, Tk_Window tkwin,
Drawable d, Ttk_Box b, unsigned state)
{
if (!TileGtk_GtkInitialised()) NO_GTK_STYLE_ENGINE;
NULL_PROXY_WIDGET(TileGtk_QWidget_Widget);
Tcl_MutexLock(&tilegtkMutex);
QPixmap pixmap(b.width, b.height);
QPainter painter(&pixmap);
TILEGTK_PAINT_BACKGROUND(b.width, b.height);
#ifdef TILEGTK_GTK_VERSION_3
QStyle::SFlags sflags = TileGtk_StateTableLookup(treeheading_border_statemap,
state);
sflags |= QStyle::Style_Horizontal;
wc->TileGtk_Style->drawPrimitive(QStyle::PE_HeaderSection, &painter,
QRect(0, 0, b.width, b.height), qApp->palette().active(), sflags);
#endif /* TILEGTK_GTK_VERSION_3 */
#ifdef TILEGTK_GTK_VERSION_4
QStyleOptionHeader option;
option.rect = QRect(0, 0, b.width, b.height);
option.state |=
(QStyle::StateFlag) TileGtk_StateTableLookup(treeview_client_statemap, state);
wc->TileGtk_Style->drawControl(QStyle::CE_HeaderSection, &option,
&painter);
#endif /* TILEGTK_GTK_VERSION_4 */
// printf("x=%d, y=%d, w=%d, h=%d\n", b.x, b.y, b.width, b.height);
TileGtk_CopyGtkPixmapOnToDrawable(gdkDrawable, d, tkwin,
0, 0, b.width, b.height, b.x, b.y);
Tcl_MutexUnlock(&tilegtkMutex);
}
示例14: Tcl_AsyncCreate
Tcl_AsyncHandler
Tcl_AsyncCreate(
Tcl_AsyncProc *proc, /* Procedure to call when handler is
* invoked. */
ClientData clientData) /* Argument to pass to handler. */
{
AsyncHandler *asyncPtr;
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
asyncPtr = (AsyncHandler *) ckalloc(sizeof(AsyncHandler));
asyncPtr->ready = 0;
asyncPtr->nextPtr = NULL;
asyncPtr->proc = proc;
asyncPtr->clientData = clientData;
asyncPtr->originTsd = tsdPtr;
asyncPtr->originThrdId = Tcl_GetCurrentThread();
Tcl_MutexLock(&tsdPtr->asyncMutex);
if (tsdPtr->firstHandler == NULL) {
tsdPtr->firstHandler = asyncPtr;
} else {
tsdPtr->lastHandler->nextPtr = asyncPtr;
}
tsdPtr->lastHandler = asyncPtr;
Tcl_MutexUnlock(&tsdPtr->asyncMutex);
return (Tcl_AsyncHandler) asyncPtr;
}
示例15: Tcl_Release
void
Tcl_Release(
ClientData clientData) /* Pointer to malloc'ed block of memory. */
{
Reference *refPtr;
int i;
Tcl_MutexLock(&preserveMutex);
for (i=0, refPtr=refArray ; i<inUse ; i++, refPtr++) {
int mustFree;
Tcl_FreeProc *freeProc;
if (refPtr->clientData != clientData) {
continue;
}
if (--refPtr->refCount != 0) {
Tcl_MutexUnlock(&preserveMutex);
return;
}
/*
* Must remove information from the slot before calling freeProc to
* avoid reentrancy problems if the freeProc calls Tcl_Preserve on the
* same clientData. Copy down the last reference in the array to
* overwrite the current slot.
*/
freeProc = refPtr->freeProc;
mustFree = refPtr->mustFree;
inUse--;
if (i < inUse) {
refArray[i] = refArray[inUse];
}
/*
* Now committed to disposing the data. But first, we've patched up
* all the global data structures so we should release the mutex now.
* Only then should we dabble around with potentially-slow memory
* managers...
*/
Tcl_MutexUnlock(&preserveMutex);
if (mustFree) {
if (freeProc == TCL_DYNAMIC) {
ckfree((char *) clientData);
} else {
freeProc((char *) clientData);
}
}
return;
}
Tcl_MutexUnlock(&preserveMutex);
/*
* Reference not found. This is a bug in the caller.
*/
Tcl_Panic("Tcl_Release couldn't find reference for 0x%x", clientData);
}