sqInt clipboardSize(void) {
extern int	forceInterruptCheck(void);

/* return the number of characters in the clipboard entry */
	if (!sqHasClipboard) {
		/* if squeak doesn't have the clipboard, we need to
		 * fetch the clipboard contents from the current holder
		 */
		fetchClipboard();
		forceInterruptCheck();
	}
	return strlen(clipboardBuffer);
}
Ejemplo n.º 2
0
/* Signal the external semaphore with the given index.  Answer non-zero on
 * success, zero otherwise.  This function is (should be) thread-safe;
 * multiple threads may attempt to signal the same semaphore without error.
 * An index of zero should be and is silently ignored.
 *
 *  (sig) As well as negative index.
 */
sqInt
signalSemaphoreWithIndex(sqInt index)
{
    int next;

    /* An index of zero should be and is silently ignored. */
    if (index <=0)
        return 0;

    /* we must use the locking semantics to avoid ABA problem on writing a semaphore index to queue,
     so there is no chance for fetching thread to observe queue in inconsistent state.
     */
    lockSignalQueue();

    /* check for queue overflow */
    next = succIndex(sigIndexHigh);
    if (next == sigIndexLow ) {

#if SQ_DYNAMIC_QUEUE_SIZE
        // grow and retry
        unlockSignalQueue();
        ioGrowSignalQueue( maxPendingSignals + 100);
        return signalSemaphoreWithIndex(index);

#else
        unlockSignalQueue();
        // error if queue size is static  (perhaps better would be to sleep for a while and retry?)
        error("External semaphore signal queue overflow");
#endif
    }

    signalQueue[sigIndexHigh] = index;
    /* make sure semaphore index is written before we advance sigIndexHigh */
    sqLowLevelMFence();

    sigIndexHigh = next;
    /* reset lock */

    unlockSignalQueue();
    forceInterruptCheck();
    return 1;
}