os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/mac/tclMacNotify.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/* 
sl@0
     2
 * tclMacNotify.c --
sl@0
     3
 *
sl@0
     4
 *	This file contains Macintosh-specific procedures for the notifier,
sl@0
     5
 *	which is the lowest-level part of the Tcl event loop.  This file
sl@0
     6
 *	works together with ../generic/tclNotify.c.
sl@0
     7
 *
sl@0
     8
 *	The Mac notifier only polls for system and OS events, so it is process
sl@0
     9
 *	wide, rather than thread specific.  However, this means that the convert
sl@0
    10
 *	event proc will have to arbitrate which events go to which threads.
sl@0
    11
 *
sl@0
    12
 * Copyright (c) 1995-1996 Sun Microsystems, Inc.
sl@0
    13
 *
sl@0
    14
 * See the file "license.terms" for information on usage and redistribution
sl@0
    15
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
sl@0
    16
 *
sl@0
    17
 * RCS: @(#) $Id: tclMacNotify.c,v 1.8.4.1 2003/03/21 03:24:08 dgp Exp $
sl@0
    18
 */
sl@0
    19
sl@0
    20
#include "tclInt.h"
sl@0
    21
#include "tclPort.h"
sl@0
    22
#include "tclMac.h"
sl@0
    23
#include "tclMacInt.h"
sl@0
    24
#include <signal.h>
sl@0
    25
#include <Events.h>
sl@0
    26
#include <LowMem.h>
sl@0
    27
#include <Processes.h>
sl@0
    28
#include <Timer.h>
sl@0
    29
#include <Threads.h>
sl@0
    30
sl@0
    31
sl@0
    32
/* 
sl@0
    33
 * This is necessary to work around a bug in Apple's Universal header files
sl@0
    34
 * for the CFM68K libraries.
sl@0
    35
 */
sl@0
    36
sl@0
    37
#ifdef __CFM68K__
sl@0
    38
#undef GetEventQueue
sl@0
    39
extern pascal QHdrPtr GetEventQueue(void)
sl@0
    40
 THREEWORDINLINE(0x2EBC, 0x0000, 0x014A);
sl@0
    41
#pragma import list GetEventQueue
sl@0
    42
#define GetEvQHdr() GetEventQueue()
sl@0
    43
#endif
sl@0
    44
sl@0
    45
/*
sl@0
    46
 * Need this for replacing Tcl_SetTimer and Tcl_WaitForEvent defined 
sl@0
    47
 * in THIS file with ones defined in the stub table.
sl@0
    48
 */
sl@0
    49
 
sl@0
    50
extern TclStubs tclStubs;
sl@0
    51
extern Tcl_NotifierProcs tclOriginalNotifier;
sl@0
    52
sl@0
    53
/*
sl@0
    54
 * The follwing static indicates whether this module has been initialized.
sl@0
    55
 */
sl@0
    56
sl@0
    57
static int initialized = 0;
sl@0
    58
sl@0
    59
/*
sl@0
    60
 * The following structure contains the state information for the
sl@0
    61
 * notifier module.
sl@0
    62
 */
sl@0
    63
sl@0
    64
static struct {
sl@0
    65
    int timerActive;		/* 1 if timer is running. */
sl@0
    66
    Tcl_Time timer;		/* Time when next timer event is expected. */
sl@0
    67
    int flags;			/* OR'ed set of flags defined below. */
sl@0
    68
    Point lastMousePosition;	/* Last known mouse location. */
sl@0
    69
    RgnHandle utilityRgn;	/* Region used as the mouse region for
sl@0
    70
				 * WaitNextEvent and the update region when
sl@0
    71
				 * checking for events. */   
sl@0
    72
    Tcl_MacConvertEventPtr eventProcPtr;
sl@0
    73
				/* This pointer holds the address of the
sl@0
    74
				 * function that will handle all incoming
sl@0
    75
				 * Macintosh events. */
sl@0
    76
} notifier;
sl@0
    77
sl@0
    78
/*
sl@0
    79
 * The following defines are used in the flags field of the notifier struct.
sl@0
    80
 */
sl@0
    81
sl@0
    82
#define NOTIFY_IDLE	(1<<1)	/* Tcl_ServiceIdle should be called. */
sl@0
    83
#define NOTIFY_TIMER	(1<<2)	/* Tcl_ServiceTimer should be called. */
sl@0
    84
sl@0
    85
/*
sl@0
    86
 * Prototypes for procedures that are referenced only in this file:
sl@0
    87
 */
sl@0
    88
sl@0
    89
static int		HandleMacEvents _ANSI_ARGS_((void));
sl@0
    90
static void		InitNotifier _ANSI_ARGS_((void));
sl@0
    91
static void		NotifierExitHandler _ANSI_ARGS_((
sl@0
    92
			    ClientData clientData));
sl@0
    93

sl@0
    94
/*
sl@0
    95
 *----------------------------------------------------------------------
sl@0
    96
 *
sl@0
    97
 * Tcl_InitNotifier --
sl@0
    98
 *
sl@0
    99
 *	Initializes the platform specific notifier state.  There is no thread
sl@0
   100
 *	specific platform notifier on the Mac, so this really doesn't do 
sl@0
   101
 *	anything.  However, we need to return the ThreadID, since the generic
sl@0
   102
 *	notifier hands this back to us in AlertThread.
sl@0
   103
 *
sl@0
   104
 * Results:
sl@0
   105
 *	Returns the threadID for this thread.  
sl@0
   106
 *
sl@0
   107
 * Side effects:
sl@0
   108
 *	None.
sl@0
   109
 *
sl@0
   110
 *----------------------------------------------------------------------
sl@0
   111
 */
sl@0
   112
sl@0
   113
ClientData
sl@0
   114
Tcl_InitNotifier()
sl@0
   115
{
sl@0
   116
    
sl@0
   117
#ifdef TCL_THREADS
sl@0
   118
    ThreadID curThread;
sl@0
   119
    if (TclMacHaveThreads()) {
sl@0
   120
        GetCurrentThread(&curThread);
sl@0
   121
        return (ClientData) curThread;
sl@0
   122
    } else {
sl@0
   123
        return NULL;
sl@0
   124
    }
sl@0
   125
#else
sl@0
   126
    return NULL;
sl@0
   127
#endif
sl@0
   128
sl@0
   129
}
sl@0
   130

sl@0
   131
/*
sl@0
   132
 *----------------------------------------------------------------------
sl@0
   133
 *
sl@0
   134
 * Tcl_FinalizeNotifier --
sl@0
   135
 *
sl@0
   136
 *	This function is called to cleanup the notifier state before
sl@0
   137
 *	a thread is terminated.  There is no platform thread specific
sl@0
   138
 *	notifier, so this does nothing.
sl@0
   139
 *
sl@0
   140
 * Results:
sl@0
   141
 *	None.
sl@0
   142
 *
sl@0
   143
 * Side effects:
sl@0
   144
 *	None.
sl@0
   145
 *
sl@0
   146
 *----------------------------------------------------------------------
sl@0
   147
 */
sl@0
   148
sl@0
   149
void
sl@0
   150
Tcl_FinalizeNotifier(clientData)
sl@0
   151
    ClientData clientData;	/* Pointer to notifier data. */
sl@0
   152
{
sl@0
   153
    /* Nothing to do on the Mac */
sl@0
   154
}
sl@0
   155

sl@0
   156
/*
sl@0
   157
 *----------------------------------------------------------------------
sl@0
   158
 *
sl@0
   159
 * Tcl_AlertNotifier --
sl@0
   160
 *
sl@0
   161
 *	Wake up the specified notifier from any thread. This routine
sl@0
   162
 *	is called by the platform independent notifier code whenever
sl@0
   163
 *	the Tcl_ThreadAlert routine is called.  This routine is
sl@0
   164
 *	guaranteed not to be called on a given notifier after
sl@0
   165
 *	Tcl_FinalizeNotifier is called for that notifier.
sl@0
   166
 *
sl@0
   167
 * Results:
sl@0
   168
 *	None.
sl@0
   169
 *
sl@0
   170
 * Side effects:
sl@0
   171
 *	Calls YieldToThread from this thread.
sl@0
   172
 *
sl@0
   173
 *----------------------------------------------------------------------
sl@0
   174
 */
sl@0
   175
sl@0
   176
void
sl@0
   177
Tcl_AlertNotifier(clientData)
sl@0
   178
    ClientData clientData;	/* Pointer to thread data. */
sl@0
   179
{
sl@0
   180
sl@0
   181
#ifdef TCL_THREADS
sl@0
   182
    if (TclMacHaveThreads()) {
sl@0
   183
        YieldToThread((ThreadID) clientData);
sl@0
   184
    }
sl@0
   185
#endif
sl@0
   186
sl@0
   187
}
sl@0
   188

sl@0
   189
/*
sl@0
   190
 *----------------------------------------------------------------------
sl@0
   191
 *
sl@0
   192
 * InitNotifier --
sl@0
   193
 *
sl@0
   194
 *	Initializes the notifier structure.  Note - this function is never
sl@0
   195
 *	used.
sl@0
   196
 *
sl@0
   197
 * Results:
sl@0
   198
 *	None.
sl@0
   199
 *
sl@0
   200
 * Side effects:
sl@0
   201
 *	Creates a new exit handler.
sl@0
   202
 *
sl@0
   203
 *----------------------------------------------------------------------
sl@0
   204
 */
sl@0
   205
sl@0
   206
static void
sl@0
   207
InitNotifier(void)
sl@0
   208
{
sl@0
   209
    initialized = 1;
sl@0
   210
    memset(&notifier, 0, sizeof(notifier));
sl@0
   211
    Tcl_CreateExitHandler(NotifierExitHandler, NULL);
sl@0
   212
}
sl@0
   213

sl@0
   214
/*
sl@0
   215
 *----------------------------------------------------------------------
sl@0
   216
 *
sl@0
   217
 * NotifierExitHandler --
sl@0
   218
 *
sl@0
   219
 *	This function is called to cleanup the notifier state before
sl@0
   220
 *	Tcl is unloaded.  This function is never used, since InitNotifier
sl@0
   221
 *	isn't either.
sl@0
   222
 *
sl@0
   223
 * Results:
sl@0
   224
 *	None.
sl@0
   225
 *
sl@0
   226
 * Side effects:
sl@0
   227
 *	None.
sl@0
   228
 *
sl@0
   229
 *----------------------------------------------------------------------
sl@0
   230
 */
sl@0
   231
sl@0
   232
static void
sl@0
   233
NotifierExitHandler(
sl@0
   234
    ClientData clientData)	/* Not used. */
sl@0
   235
{
sl@0
   236
    initialized = 0;
sl@0
   237
}
sl@0
   238

sl@0
   239
/*
sl@0
   240
 *----------------------------------------------------------------------
sl@0
   241
 *
sl@0
   242
 * HandleMacEvents --
sl@0
   243
 *
sl@0
   244
 *	This function checks for events from the Macintosh event queue.
sl@0
   245
 *
sl@0
   246
 * Results:
sl@0
   247
 *	Returns 1 if event found, 0 otherwise.
sl@0
   248
 *
sl@0
   249
 * Side effects:
sl@0
   250
 *	Pulls events off of the Mac event queue and then calls
sl@0
   251
 *	convertEventProc.
sl@0
   252
 *
sl@0
   253
 *----------------------------------------------------------------------
sl@0
   254
 */
sl@0
   255
sl@0
   256
static int
sl@0
   257
HandleMacEvents(void)
sl@0
   258
{
sl@0
   259
    EventRecord theEvent;
sl@0
   260
    int eventFound = 0, needsUpdate = 0;
sl@0
   261
    Point currentMouse;
sl@0
   262
    WindowRef windowRef;
sl@0
   263
    Rect mouseRect;
sl@0
   264
sl@0
   265
    /*
sl@0
   266
     * Check for mouse moved events.  These events aren't placed on the
sl@0
   267
     * system event queue unless we call WaitNextEvent.
sl@0
   268
     */
sl@0
   269
sl@0
   270
    GetGlobalMouseTcl(&currentMouse);
sl@0
   271
    if ((notifier.eventProcPtr != NULL) &&
sl@0
   272
	    !EqualPt(currentMouse, notifier.lastMousePosition)) {
sl@0
   273
	notifier.lastMousePosition = currentMouse;
sl@0
   274
	theEvent.what = nullEvent;
sl@0
   275
	if ((*notifier.eventProcPtr)(&theEvent) == true) {
sl@0
   276
	    eventFound = 1;
sl@0
   277
	}
sl@0
   278
    }
sl@0
   279
sl@0
   280
    /*
sl@0
   281
     * Check for update events.  Since update events aren't generated
sl@0
   282
     * until we call GetNextEvent, we may need to force a call to
sl@0
   283
     * GetNextEvent, even if the queue is empty.
sl@0
   284
     */
sl@0
   285
sl@0
   286
    for (windowRef = FrontWindow(); windowRef != NULL;
sl@0
   287
	    windowRef = GetNextWindow(windowRef)) {
sl@0
   288
	GetWindowUpdateRgn(windowRef, notifier.utilityRgn);
sl@0
   289
	if (!EmptyRgn(notifier.utilityRgn)) {
sl@0
   290
	    needsUpdate = 1;
sl@0
   291
	    break;
sl@0
   292
	}
sl@0
   293
    }
sl@0
   294
    
sl@0
   295
    /*
sl@0
   296
     * Process events from the OS event queue.
sl@0
   297
     */
sl@0
   298
sl@0
   299
    while (needsUpdate || (GetEvQHdr()->qHead != NULL)) {
sl@0
   300
	GetGlobalMouseTcl(&currentMouse);
sl@0
   301
	SetRect(&mouseRect, currentMouse.h, currentMouse.v,
sl@0
   302
		currentMouse.h + 1, currentMouse.v + 1);
sl@0
   303
	RectRgn(notifier.utilityRgn, &mouseRect);
sl@0
   304
	
sl@0
   305
	WaitNextEvent(everyEvent, &theEvent, 5, notifier.utilityRgn);
sl@0
   306
	needsUpdate = 0;
sl@0
   307
	if ((notifier.eventProcPtr != NULL)
sl@0
   308
		&& ((*notifier.eventProcPtr)(&theEvent) == true)) {
sl@0
   309
	    eventFound = 1;
sl@0
   310
	}
sl@0
   311
    }
sl@0
   312
    
sl@0
   313
    return eventFound;
sl@0
   314
}
sl@0
   315

sl@0
   316
/*
sl@0
   317
 *----------------------------------------------------------------------
sl@0
   318
 *
sl@0
   319
 * Tcl_SetTimer --
sl@0
   320
 *
sl@0
   321
 *	This procedure sets the current notifier timer value.  The
sl@0
   322
 *	notifier will ensure that Tcl_ServiceAll() is called after
sl@0
   323
 *	the specified interval, even if no events have occurred.
sl@0
   324
 *
sl@0
   325
 * Results:
sl@0
   326
 *	None.
sl@0
   327
 *
sl@0
   328
 * Side effects:
sl@0
   329
 *	Replaces any previous timer.
sl@0
   330
 *
sl@0
   331
 *----------------------------------------------------------------------
sl@0
   332
 */
sl@0
   333
sl@0
   334
void
sl@0
   335
Tcl_SetTimer(
sl@0
   336
    Tcl_Time *timePtr)		/* New value for interval timer. */
sl@0
   337
{
sl@0
   338
    /*
sl@0
   339
     * Allow the notifier to be hooked.  This may not make sense
sl@0
   340
     * on the Mac, but mirrors the UNIX hook.
sl@0
   341
     */
sl@0
   342
sl@0
   343
    if (tclStubs.tcl_SetTimer != tclOriginalNotifier.setTimerProc) {
sl@0
   344
	tclStubs.tcl_SetTimer(timePtr);
sl@0
   345
	return;
sl@0
   346
    }
sl@0
   347
sl@0
   348
    if (!timePtr) {
sl@0
   349
	notifier.timerActive = 0;
sl@0
   350
    } else {
sl@0
   351
	/*
sl@0
   352
	 * Compute when the timer should fire.
sl@0
   353
	 */
sl@0
   354
	
sl@0
   355
	Tcl_GetTime(&notifier.timer);
sl@0
   356
	notifier.timer.sec += timePtr->sec;
sl@0
   357
	notifier.timer.usec += timePtr->usec;
sl@0
   358
	if (notifier.timer.usec >= 1000000) {
sl@0
   359
	    notifier.timer.usec -= 1000000;
sl@0
   360
	    notifier.timer.sec += 1;
sl@0
   361
	}
sl@0
   362
	notifier.timerActive = 1;
sl@0
   363
    }
sl@0
   364
}
sl@0
   365

sl@0
   366
/*
sl@0
   367
 *----------------------------------------------------------------------
sl@0
   368
 *
sl@0
   369
 * Tcl_ServiceModeHook --
sl@0
   370
 *
sl@0
   371
 *	This function is invoked whenever the service mode changes.
sl@0
   372
 *
sl@0
   373
 * Results:
sl@0
   374
 *	None.
sl@0
   375
 *
sl@0
   376
 * Side effects:
sl@0
   377
 *	None.
sl@0
   378
 *
sl@0
   379
 *----------------------------------------------------------------------
sl@0
   380
 */
sl@0
   381
sl@0
   382
void
sl@0
   383
Tcl_ServiceModeHook(mode)
sl@0
   384
    int mode;			/* Either TCL_SERVICE_ALL, or
sl@0
   385
				 * TCL_SERVICE_NONE. */
sl@0
   386
{
sl@0
   387
}
sl@0
   388

sl@0
   389
/*
sl@0
   390
 *----------------------------------------------------------------------
sl@0
   391
 *
sl@0
   392
 * Tcl_WaitForEvent --
sl@0
   393
 *
sl@0
   394
 *	This function is called by Tcl_DoOneEvent to wait for new
sl@0
   395
 *	events on the message queue.  If the block time is 0, then
sl@0
   396
 *	Tcl_WaitForEvent just polls the event queue without blocking.
sl@0
   397
 *
sl@0
   398
 * Results:
sl@0
   399
 *	Always returns 0.
sl@0
   400
 *
sl@0
   401
 * Side effects:
sl@0
   402
 *	None.
sl@0
   403
 *
sl@0
   404
 *----------------------------------------------------------------------
sl@0
   405
 */
sl@0
   406
sl@0
   407
int
sl@0
   408
Tcl_WaitForEvent(
sl@0
   409
    Tcl_Time *timePtr)		/* Maximum block time. */
sl@0
   410
{
sl@0
   411
    int found;
sl@0
   412
    EventRecord macEvent;
sl@0
   413
    long sleepTime = 5;
sl@0
   414
    long ms;
sl@0
   415
    Point currentMouse;
sl@0
   416
    void * timerToken;
sl@0
   417
    Rect mouseRect;
sl@0
   418
sl@0
   419
    /*
sl@0
   420
     * Allow the notifier to be hooked.  This may not make
sl@0
   421
     * sense on the Mac, but mirrors the UNIX hook.
sl@0
   422
     */
sl@0
   423
sl@0
   424
    if (tclStubs.tcl_WaitForEvent != tclOriginalNotifier.waitForEventProc) {
sl@0
   425
	return tclStubs.tcl_WaitForEvent(timePtr);
sl@0
   426
    }
sl@0
   427
sl@0
   428
    /*
sl@0
   429
     * Compute the next timeout value.
sl@0
   430
     */
sl@0
   431
sl@0
   432
    if (!timePtr) {
sl@0
   433
	ms = INT_MAX;
sl@0
   434
    } else {
sl@0
   435
	ms = (timePtr->sec * 1000) + (timePtr->usec / 1000);
sl@0
   436
    }
sl@0
   437
    timerToken = TclMacStartTimer((long) ms);
sl@0
   438
   
sl@0
   439
    /*
sl@0
   440
     * Poll the Mac event sources.  This loop repeats until something
sl@0
   441
     * happens: a timeout, a socket event, mouse motion, or some other
sl@0
   442
     * window event.  Note that we don't call WaitNextEvent if another
sl@0
   443
     * event is found to avoid context switches.  This effectively gives
sl@0
   444
     * events coming in via WaitNextEvent a slightly lower priority.
sl@0
   445
     */
sl@0
   446
sl@0
   447
    found = 0;
sl@0
   448
    if (notifier.utilityRgn == NULL) {
sl@0
   449
	notifier.utilityRgn = NewRgn();
sl@0
   450
    }
sl@0
   451
sl@0
   452
    while (!found) {
sl@0
   453
	/*
sl@0
   454
	 * Check for generated and queued events.
sl@0
   455
	 */
sl@0
   456
sl@0
   457
	if (HandleMacEvents()) {
sl@0
   458
	    found = 1;
sl@0
   459
	}
sl@0
   460
sl@0
   461
	/*
sl@0
   462
	 * Check for time out.
sl@0
   463
	 */
sl@0
   464
sl@0
   465
	if (!found && TclMacTimerExpired(timerToken)) {
sl@0
   466
	    found = 1;
sl@0
   467
	}
sl@0
   468
sl@0
   469
	/*
sl@0
   470
	 * Check for window events.  We may receive a NULL event for
sl@0
   471
	 * various reasons. 1) the timer has expired, 2) a mouse moved
sl@0
   472
	 * event is occuring or 3) the os is giving us time for idle
sl@0
   473
	 * events.  Note that we aren't sharing the processor very
sl@0
   474
	 * well here.  We really ought to do a better job of calling
sl@0
   475
	 * WaitNextEvent for time slicing purposes.
sl@0
   476
	 */
sl@0
   477
sl@0
   478
	if (!found) {
sl@0
   479
	    /*
sl@0
   480
	     * Set up mouse region so we will wake if the mouse is moved.
sl@0
   481
	     * We do this by defining the smallest possible region around
sl@0
   482
	     * the current mouse position.
sl@0
   483
	     */
sl@0
   484
sl@0
   485
	    GetGlobalMouseTcl(&currentMouse);
sl@0
   486
	    SetRect(&mouseRect, currentMouse.h, currentMouse.v,
sl@0
   487
		    currentMouse.h + 1, currentMouse.v + 1);
sl@0
   488
	    RectRgn(notifier.utilityRgn, &mouseRect);
sl@0
   489
	
sl@0
   490
	    WaitNextEvent(everyEvent, &macEvent, sleepTime,
sl@0
   491
		    notifier.utilityRgn);
sl@0
   492
sl@0
   493
	    if (notifier.eventProcPtr != NULL) {
sl@0
   494
		if ((*notifier.eventProcPtr)(&macEvent) == true) {
sl@0
   495
		    found = 1;
sl@0
   496
		}
sl@0
   497
	    }
sl@0
   498
	}
sl@0
   499
    }
sl@0
   500
    TclMacRemoveTimer(timerToken);
sl@0
   501
    
sl@0
   502
    /*
sl@0
   503
     * Yield time to nay other thread at this point.  If we find that the
sl@0
   504
     * apps thrash too switching between threads, we can put a timer here,
sl@0
   505
     * and only yield when the timer fires.
sl@0
   506
     */
sl@0
   507
     
sl@0
   508
    if (TclMacHaveThreads()) {
sl@0
   509
        YieldToAnyThread();
sl@0
   510
    }
sl@0
   511
    
sl@0
   512
    return 0;
sl@0
   513
}
sl@0
   514

sl@0
   515
/*
sl@0
   516
 *----------------------------------------------------------------------
sl@0
   517
 *
sl@0
   518
 * Tcl_Sleep --
sl@0
   519
 *
sl@0
   520
 *	Delay execution for the specified number of milliseconds.  This
sl@0
   521
 *	is not a very good call to make.  It will block the system -
sl@0
   522
 *	you will not even be able to switch applications.
sl@0
   523
 *
sl@0
   524
 * Results:
sl@0
   525
 *	None.
sl@0
   526
 *
sl@0
   527
 * Side effects:
sl@0
   528
 *	Time passes.
sl@0
   529
 *
sl@0
   530
 *----------------------------------------------------------------------
sl@0
   531
 */
sl@0
   532
sl@0
   533
void
sl@0
   534
Tcl_Sleep(
sl@0
   535
    int ms)			/* Number of milliseconds to sleep. */
sl@0
   536
{
sl@0
   537
    EventRecord dummy;
sl@0
   538
    void *timerToken;
sl@0
   539
    
sl@0
   540
    if (ms <= 0) {
sl@0
   541
	return;
sl@0
   542
    }
sl@0
   543
    
sl@0
   544
    timerToken = TclMacStartTimer((long) ms);
sl@0
   545
    while (1) {
sl@0
   546
	WaitNextEvent(0, &dummy, (ms / 16.66) + 1, NULL);
sl@0
   547
        if (TclMacHaveThreads()) {
sl@0
   548
	    YieldToAnyThread();
sl@0
   549
	}
sl@0
   550
	if (TclMacTimerExpired(timerToken)) {
sl@0
   551
	    break;
sl@0
   552
	}
sl@0
   553
    }
sl@0
   554
    TclMacRemoveTimer(timerToken);
sl@0
   555
}
sl@0
   556

sl@0
   557
/*
sl@0
   558
 *----------------------------------------------------------------------
sl@0
   559
 *
sl@0
   560
 * Tcl_MacSetEventProc --
sl@0
   561
 *
sl@0
   562
 *	This function sets the event handling procedure for the 
sl@0
   563
 *	application.  This function will be passed all incoming Mac
sl@0
   564
 *	events.  This function usually controls the console or some
sl@0
   565
 *	other entity like Tk.
sl@0
   566
 *
sl@0
   567
 * Results:
sl@0
   568
 *	None.
sl@0
   569
 *
sl@0
   570
 * Side effects:
sl@0
   571
 *	Changes the event handling function.
sl@0
   572
 *
sl@0
   573
 *----------------------------------------------------------------------
sl@0
   574
 */
sl@0
   575
sl@0
   576
void
sl@0
   577
Tcl_MacSetEventProc(
sl@0
   578
    Tcl_MacConvertEventPtr procPtr)
sl@0
   579
{
sl@0
   580
    notifier.eventProcPtr = procPtr;
sl@0
   581
}