AsyncThreadSpecificData * asyncGetThreadSpecificData (void) { int error; if (!(error = pthread_once(&tsdOnce, tsdCreateKey))) { if (tsdKeyCreated) { AsyncThreadSpecificData *tsd = pthread_getspecific(tsdKey); if (tsd) return tsd; if ((tsd = newThreadSpecificData())) { if (!(error = pthread_setspecific(tsdKey, tsd))) { return tsd; } else { logActionError(error, "pthread_setspecific"); } destroyThreadSpecificData(tsd); } } } else { logActionError(error, "pthread_once"); } return NULL; }
static int constructLockDescriptor (LockDescriptor *lock) { int error; if (!(error = pthread_cond_init(&lock->read, NULL))) { if (!(error = pthread_cond_init(&lock->write, NULL))) { if (!(error = pthread_mutex_init(&lock->mutex, NULL))) { lock->count = 0; lock->writers = 0; return 1; } else { logActionError(error, "pthread_mutex_init"); } pthread_cond_destroy(&lock->write); } else { logActionError(error, "pthread_cond_init"); } pthread_cond_destroy(&lock->read); } else { logActionError(error, "pthread_cond_init"); } return 0; }
static void tsdCreateKey (void) { int error = pthread_key_create(&tsdKey, tsdDestroyData); if (!error) { tsdKeyCreated = 1; } else { logActionError(error, "pthread_key_create"); } }
static int constructLockDescriptor (LockDescriptor *lock) { int error; if (!(error = pthread_rwlock_init(&lock->lock, NULL))) { return 1; } else { logActionError(error, "pthread_rwlock_init"); } return 0; }
static GIO_INPUT_HANDLER(handleBrailleInput) { int processed = 0; { int error = parameters->error; if (error) { logActionError(error, "braille input monitor"); brl.hasFailed = 1; return 0; } } suspendCommandQueue(); if (!brl.isSuspended) { if (brl.api) brl.api->claimDriver(); if (processInput()) processed = 1; if (brl.api) brl.api->releaseDriver(); } #ifdef ENABLE_API else if (brl.api && brl.api->isStarted()) { switch (readBrailleCommand(&brl, KTB_CTX_DEFAULT)) { case BRL_CMD_RESTARTBRL: brl.hasFailed = 1; break; default: processed = 1; case EOF: break; } } #endif /* ENABLE_API */ resumeCommandQueue(); return processed; }
static int startTuneThread (void) { if (tuneThreadState == TUNE_THREAD_NONE) { setTuneThreadState(TUNE_THREAD_STARTING); if ((tuneMessageEvent = asyncNewEvent(handleTuneMessageEvent, NULL))) { int creationError = createThread("tune-thread", &tuneThreadIdentifier, NULL, runTuneThread, NULL); if (!creationError) { asyncWaitFor(testTuneThreadStarted, NULL); if (tuneThreadState == TUNE_THREAD_RUNNING) return 1; } else { logActionError(creationError, "tune thread creation"); setTuneThreadState(TUNE_THREAD_FAILED); } asyncDiscardEvent(tuneMessageEvent); tuneMessageEvent = NULL; } } return tuneThreadState == TUNE_THREAD_RUNNING; }