int DBManager::insert(const QString &statement) { if (!isLoaded_) // There is no DB connection return 0; QStringList values; int error, rc = 0; const char *tail; sqlite3_stmt *stmt; int busyCnt = 0; int retryCnt = 0; do { do { if (busyCnt) { _SLEEP(100000); // BUSY COUNTER } error = sqlite3_prepare(db_, statement.toUtf8(), -1, &stmt, &tail); } while (error == SQLITE_BUSY && busyCnt++ < 120); if (error != SQLITE_OK) { if (error == SQLITE_BUSY) KMessageBox::sorry(0L, i18n("Sorry, Database is locked right now. Please try again later.")); values = QStringList(); } else { busyCnt = 0; while (1) { error = sqlite3_step(stmt); if (error == SQLITE_BUSY) { if (busyCnt++ > 120) { KMessageBox::sorry(0L, i18n("Sorry, Database is locked right now. Please try again later.")); break; } _SLEEP(100000); continue; } if (error == SQLITE_DONE || error == SQLITE_ERROR) break; } rc = sqlite3_finalize(stmt); if (error != SQLITE_DONE && rc != SQLITE_SCHEMA) { values = QStringList(); } if (rc == SQLITE_SCHEMA) { retryCnt++; if (retryCnt >= 10) { KMessageBox::error(0L, i18n("Retry count has reached maximum")); values = QStringList(); } } } } while (rc == SQLITE_SCHEMA && retryCnt < 10); return sqlite3_last_insert_rowid(db_); }
int pause(void) { for(;;) if(_SLEEP(1000*1000) < 0) return -1; }
int main(void){ config(); // Lamamos a la rutina de configuración/inicialización while(1) { SMCR|=(1<<SE); // Nos vamos a dormir _SLEEP(); SMCR&=~(1<<SE); } }
int main(void){ config(); while(1) { SMCR|=(1<<SE); _SLEEP(); SMCR&=~(1<<SE); } }
unsigned int sleep(unsigned int secs) { time_t t0, t1; t0 = time(0); if(_SLEEP(secs*1000) < 0){ t1 = time(0); return t1-t0; } return 0; }
/* * This is an extension to POSIX */ unsigned int _nap(unsigned int millisecs) { time_t t0, t1; t0 = time(0); if(_SLEEP(millisecs) < 0){ t1 = time(0); return t1-t0; } return 0; }
void lock(Lock *lk) { int *hwsem; int hash; retry: switch(arch) { case 0: lockinit(); goto retry; case MAGNUM: case MAGNUMII: while(C_3ktas(&lk->val)) _SLEEP(0); return; case R4K: for(;;){ while(lk->val) ; if(C_4ktas(&lk->val) == 0) return; } break; case POWER: /* Use low order lock bits to generate hash */ hash = ((int)lk/sizeof(int)) & (Semperpg-1); hwsem = (int*)Lockaddr+hash; for(;;) { if((*hwsem & 1) == 0) { if(lk->val) *hwsem = 0; else { lk->val = 1; *hwsem = 0; return; } } while(lk->val) ; } } }
void lock(Lock *lk) { while(tas(&lk->val)) _SLEEP(0); }