static int FifoFlush(Fifo *fifo) { int rv = 0; while (1) { if (FULL(fifo) && fifo->MyGroup) { struct timeval tv; int flushed; tv.tv_sec = 1; tv.tv_usec = 0; flushed = FifoGroupFlushOnce(fifo->MyGroup, &tv, 0); if (flushed == -1) { return -1; } else if (flushed == 0) { puts("Unable to flush any fifos (may be stuck; trying again)"); } } else { int frv = FifoFlushOnce(fifo); if (frv == -1) { return -1; } else { rv += frv; } break; } } return rv; }
int FifoPush(Fifo *fifo, void *data, int size) { struct FifoElem *cur; int rv = FifoFlush(fifo); if (rv == -1) { return -1; } if (EMPTY(fifo)) { int newSize = TryWrite(fifo->fd, data, size); if (newSize == -1) { return -1; } else if (newSize == size) { return 1; } else { data += newSize; size -= newSize; } } else if (FULL(fifo)) { return 0; } void *dataCopy = malloc(size); memcpy(dataCopy, data, size); fifo->Tail = (fifo->Tail+1)%(FIFO_ELEMS*2); cur = &TAIL_ELEM(fifo); cur->DataCur = cur->DataStart = dataCopy; cur->Remaining = size; return 1; }
static void sleep_if_full(struct tty_queue * queue) { if (!FULL(*queue)) return; cli(); while (!current->signal && LEFT(*queue)<128) interruptible_sleep_on(&queue->proc_list); sti(); }
static inline void pty_copy(struct tty_struct * from, struct tty_struct * to) { int c; while (!from->stopped && !EMPTY(&from->write_q)) { if (FULL(&to->read_q)) { if (FULL(&to->secondary)) break; TTY_READ_FLUSH(to); continue; } c = get_tty_queue(&from->write_q); put_tty_queue(c, &to->read_q); if (current->signal & ~current->blocked) break; } TTY_READ_FLUSH(to); wake_up(&from->write_q.proc_list); }
void *mm_realloc(void *currblock, size_t size) { void *new_currblock = currblock; size_t new_size = size; int remainder; int extendsize; int block_buffer; if (size == 0) return NULL; if (new_size <= DSIZE) { new_size = 2 * DSIZE; } else { new_size = DSIZE * ((new_size + (DSIZE) + (DSIZE - 1)) / DSIZE); } new_size += 16; block_buffer = GETSIZE(HEADER(currblock)) - new_size; if (block_buffer < 0) { if (!FULL(HEADER(NEXT(currblock))) || !GETSIZE(HEADER(NEXT(currblock)))) { remainder = GETSIZE(HEADER(currblock)) + GETSIZE(HEADER(NEXT(currblock))) - new_size; if (remainder < 0) { extendsize = ((-remainder)>CHUNKSIZE?(-remainder):CHUNKSIZE); if (extend_heap(extendsize) == NULL) return NULL; remainder += extendsize; } deletefree(NEXT(currblock)); CLEARTAG(HEADER(currblock), PACK(new_size + remainder, 1)); // Block header CLEARTAG(FOOTER(currblock), PACK(new_size + remainder, 1)); // Block footer } else { new_currblock = mm_malloc(new_size - DSIZE); line_count--; memmove(new_currblock, currblock,((size)<new_size?(size):new_size)); mm_free(currblock); line_count--; } block_buffer = GETSIZE(HEADER(new_currblock)) - new_size; } if (block_buffer < 2 * 16) SETRTAG(HEADER(NEXT(new_currblock))); line_count++; if (MMCHECK) { mm_check('r', currblock, size); } return new_currblock; }
static int opost(unsigned char c, struct tty_struct *tty) { if (FULL(&tty->write_q)) return -1; if (O_OPOST(tty)) { switch (c) { case '\n': if (O_ONLRET(tty)) tty->column = 0; if (O_ONLCR(tty)) { if (LEFT(&tty->write_q) < 2) return -1; put_tty_queue('\r', &tty->write_q); tty->column = 0; } tty->canon_column = tty->column; break; case '\r': if (O_ONOCR(tty) && tty->column == 0) return 0; if (O_OCRNL(tty)) { c = '\n'; if (O_ONLRET(tty)) tty->canon_column = tty->column = 0; break; } tty->canon_column = tty->column = 0; break; case '\t': if (O_TABDLY(tty) == XTABS) { if (LEFT(&tty->write_q) < 8) return -1; do put_tty_queue(' ', &tty->write_q); while (++tty->column % 8); return 0; } tty->column = (tty->column | 7) + 1; break; case '\b': if (tty->column > 0) tty->column--; break; default: if (O_OLCUC(tty)) c = toupper(c); if (!iscntrl(c)) tty->column++; break; } } put_tty_queue(c, &tty->write_q); return 0; }
int TTY_WriteByte(int handle, byte data) { ComPort *p; p = handleToPort [handle]; if (FULL(p->outputQueue)) return -1; ENQUEUE (p->outputQueue, data); return 0; }
static void *coalesce(void *currblock) { size_t prev_alloc = FULL(HEADER(PREV(currblock))); size_t next_alloc = FULL(HEADER(NEXT(currblock))); size_t size = GETSIZE(HEADER(currblock)); if (prev_alloc && next_alloc) { return currblock; } if (RTAG(HEADER(PREV(currblock)))) prev_alloc = 1; deletefree(currblock); if (prev_alloc && !next_alloc) { deletefree(NEXT(currblock)); size += GETSIZE(HEADER(NEXT(currblock))); PUT(HEADER(currblock), PACK(size, 0)); PUT(FOOTER(currblock), PACK(size, 0)); } else if (!prev_alloc && next_alloc) { deletefree(PREV(currblock)); size += GETSIZE(HEADER(PREV(currblock))); PUT(FOOTER(currblock), PACK(size, 0)); PUT(HEADER(PREV(currblock)), PACK(size, 0)); currblock = PREV(currblock); } else { deletefree(PREV(currblock)); deletefree(NEXT(currblock)); size += GETSIZE(HEADER(PREV(currblock))) + GETSIZE(HEADER(NEXT(currblock))); PUT(HEADER(PREV(currblock)), PACK(size, 0)); PUT(FOOTER(NEXT(currblock)), PACK(size, 0)); currblock = PREV(currblock); } insertfree(currblock, size); return coalesce(currblock); }
static inline void pty_copy(struct tty_struct * from, struct tty_struct * to) { int c; while (!from->stopped && !EMPTY(&from->write_q)) { if (FULL(&to->read_q)) { if (FULL(&to->secondary)) break; TTY_READ_FLUSH(to); continue; } c = get_tty_queue(&from->write_q); put_tty_queue(c, &to->read_q); if (current->signal & ~current->blocked) break; } TTY_READ_FLUSH(to); wake_up_interruptible(&from->write_q.proc_list); if (from->write_data_cnt) { set_bit(from->line, &tty_check_write); mark_bh(TTY_BH); } }
/* * Enter/exit with stream mutex held. * On error, does not hold the stream mutex. */ static jint waitForSpace(SharedMemoryConnection *connection, Stream *stream) { jint error = SYS_OK; /* Assumes mutex is held on call */ while ((error == SYS_OK) && FULL(stream)) { CHECK_ERROR(leaveMutex(stream)); error = sysEventWait(connection->otherProcess, stream->hasSpace); if (error == SYS_OK) { CHECK_ERROR(enterMutex(stream, connection->shutdown)); } } return error; }
static int check_out(select_table * wait, struct m_inode * inode) { struct tty_struct * tty; if (tty = get_tty(inode)) if (!FULL(tty->write_q)) return 1; else add_wait(&tty->write_q->proc_list, wait); else if (inode->i_pipe) if (!PIPE_FULL(*inode)) return 1; else add_wait(&inode->i_wait, wait); return 0; }
static int check_ex(select_table * wait, struct m_inode * inode) { struct tty_struct * tty; if (tty = get_tty(inode)) if (!FULL(tty->write_q)) return 0; else return 0; else if (inode->i_pipe) if (inode->i_count < 2) return 1; else add_wait(&inode->i_wait,wait); return 0; }
static void ISR_8250 (ComPort *p) { byte source = 0; byte b; disable(); while((source = inportb (p->uart + INTERRUPT_ID_REGISTER) & 0x07) != 1) { switch (source) { case IIR_RX_DATA_READY_INTERRUPT: b = inportb (p->uart + RECEIVE_BUFFER_REGISTER); if (! FULL(p->inputQueue)) { ENQUEUE (p->inputQueue, b); } else { p->lineStatus |= LSR_OVERRUN_ERROR; p->statusUpdated = true; } break; case IIR_TX_HOLDING_REGISTER_INTERRUPT: if (! EMPTY(p->outputQueue)) { DEQUEUE (p->outputQueue, b); outportb (p->uart + TRANSMIT_HOLDING_REGISTER, b); } break; case IIR_MODEM_STATUS_INTERRUPT: p->modemStatus = (inportb (p->uart + MODEM_STATUS_REGISTER) & MODEM_STATUS_MASK) | p->modemStatusIgnore; p->statusUpdated = true; break; case IIR_LINE_STATUS_INTERRUPT: p->lineStatus = inportb (p->uart + LINE_STATUS_REGISTER); p->statusUpdated = true; break; } source = inportb (p->uart + INTERRUPT_ID_REGISTER) & 0x07; } outportb (0x20, 0x20); }
/** * for console, channel = 0. 指定的是使用哪个tty_table来输出,0指定的是控制台 nr=0 number of bytes ,指定buf有多少个字节。 */ int tty_write(unsigned channel, char * buf, int nr) { static int cr_flag=0; struct tty_struct * tty; char c, *b=buf; if (channel>2 || nr<0) return -1; tty = channel + tty_table; /*使用控制台输出*/ /**/ while (nr>0) { sleep_if_full(&tty->write_q); /*if (current->signal) break; */ while (nr>0 && !FULL(tty->write_q)) { c=get_fs_byte(b); if (O_POST(tty)) { if (c=='\r' && O_CRNL(tty)) c='\n'; else if (c=='\n' && O_NLRET(tty)) c='\r'; if (c=='\n' && !cr_flag && O_NLCR(tty)) { cr_flag = 1; PUTCH(13,tty->write_q); continue; } if (O_LCUC(tty)) c=toupper(c); } b++; nr--; cr_flag = 0; PUTCH(c,tty->write_q); } tty->write(tty); if (nr>0) /*schedule()*/; } return (b-buf); }
jint shmemBase_sendByte(SharedMemoryConnection *connection, jbyte data) { Stream *stream = &connection->outgoing; SharedStream *shared = stream->shared; int offset; CHECK_ERROR(enterMutex(stream, connection->shutdown)); CHECK_ERROR(waitForSpace(connection, stream)); SHMEM_ASSERT(!FULL(stream)); offset = shared->writeOffset; shared->buffer[offset] = data; shared->writeOffset = ADD_OFFSET(offset, 1); shared->isFull = (shared->readOffset == shared->writeOffset); STREAM_INVARIANT(stream); CHECK_ERROR(leaveMutex(stream)); CHECK_ERROR(signalData(stream)); return SYS_OK; }
static jint sendBytes(SharedMemoryConnection *connection, const void *bytes, jint length) { Stream *stream = &connection->outgoing; SharedStream *shared = stream->shared; jint fragmentStart; jint fragmentLength; jint index = 0; jint maxLength; clearLastError(); CHECK_ERROR(enterMutex(stream, connection->shutdown)); while (index < length) { CHECK_ERROR(waitForSpace(connection, stream)); SHMEM_ASSERT(!FULL(stream)); fragmentStart = shared->writeOffset; if (fragmentStart < shared->readOffset) { maxLength = shared->readOffset - fragmentStart; } else { maxLength = SHARED_BUFFER_SIZE - fragmentStart; } fragmentLength = MIN(maxLength, length - index); memcpy(shared->buffer + fragmentStart, (jbyte *)bytes + index, fragmentLength); shared->writeOffset = ADD_OFFSET(fragmentStart, fragmentLength); index += fragmentLength; shared->isFull = (shared->readOffset == shared->writeOffset); STREAM_INVARIANT(stream); CHECK_ERROR(signalData(stream)); } CHECK_ERROR(leaveMutex(stream)); return SYS_OK; }
void copy_to_cooked(struct tty_struct * tty) { signed char c; while (!EMPTY(tty->read_q) && !FULL(tty->secondary)) { GETCH(tty->read_q,c); if (c==13) if (I_CRNL(tty)) c=10; else if (I_NOCR(tty)) continue; else ; else if (c==10 && I_NLCR(tty)) c=13; if (I_UCLC(tty)) c=tolower(c); if (L_CANON(tty)) { if (c==ERASE_CHAR(tty)) { if (EMPTY(tty->secondary) || (c=LAST(tty->secondary))==10 || c==EOF_CHAR(tty)) continue; if (L_ECHO(tty)) { if (c<32) PUTCH(127,tty->write_q); PUTCH(127,tty->write_q); tty->write(tty); } DEC(tty->secondary.head); continue; } if (c==STOP_CHAR(tty)) { tty->stopped=1; continue; } if (c==START_CHAR(tty)) { tty->stopped=0; continue; } } if (!L_ISIG(tty)) { if (c==INTR_CHAR(tty)) { tty_intr(tty,SIGINT); continue; } } if (c==10 || c==EOF_CHAR(tty)) tty->secondary.data++; if (L_ECHO(tty)) { if (c==10) { PUTCH(10,tty->write_q); PUTCH(13,tty->write_q); } else if (c<32) { if (L_ECHOCTL(tty)) { PUTCH('^',tty->write_q); PUTCH(c+64,tty->write_q); } } else PUTCH(c,tty->write_q); tty->write(tty); } PUTCH(c,tty->secondary); } wake_up(&tty->secondary.proc_list); }
static void ISR_16550 (ComPort *p) { int count; byte source; byte b; disable(); while((source = inportb (p->uart + INTERRUPT_ID_REGISTER) & 0x07) != 1) { switch (source) { case IIR_RX_DATA_READY_INTERRUPT: do { b = inportb (p->uart + RECEIVE_BUFFER_REGISTER); if (!FULL(p->inputQueue)) { ENQUEUE (p->inputQueue, b); } else { p->lineStatus |= LSR_OVERRUN_ERROR; p->statusUpdated = true; } } while (inportb (p->uart + LINE_STATUS_REGISTER) & LSR_DATA_READY); break; case IIR_TX_HOLDING_REGISTER_INTERRUPT: count = 16; while ((! EMPTY(p->outputQueue)) && count--) { DEQUEUE (p->outputQueue, b); outportb (p->uart + TRANSMIT_HOLDING_REGISTER, b); } break; case IIR_MODEM_STATUS_INTERRUPT: p->modemStatus = (inportb (p->uart + MODEM_STATUS_REGISTER) & MODEM_STATUS_MASK) | p->modemStatusIgnore; p->statusUpdated = true; break; case IIR_LINE_STATUS_INTERRUPT: p->lineStatus = inportb (p->uart + LINE_STATUS_REGISTER); p->statusUpdated = true; break; } source = inportb (p->uart + INTERRUPT_ID_REGISTER) & 0x07; } // check for lost IIR_TX_HOLDING_REGISTER_INTERRUPT on 16550a! if (inportb (p->uart + LINE_STATUS_REGISTER ) & LSR_TRANSMITTER_EMPTY) { count = 16; while ((! EMPTY(p->outputQueue)) && count--) { DEQUEUE (p->outputQueue, b); outportb (p->uart + TRANSMIT_HOLDING_REGISTER, b); } } outportb (0x20, 0x20); }
void mm_check(char caller, void* caller_currblock, int caller_size) { int size; int alloc; char *currblock = prologue_block + DSIZE; int block_count = 1; int count_size; int count_list; int loc; int caller_loc = (char *)caller_currblock - currblock; int listcounter; char *scan_currblock; printf("\n[%d] %c %d %d: Checking heap...\n", line_count, caller, caller_size, caller_loc); while (1) { loc = currblock - prologue_block - DSIZE; size = GETSIZE(HEADER(currblock)); if (size == 0) break; alloc = FULL(HEADER(currblock)); printf("%d: Block at location %d has size %d and allocation %d\n", block_count, loc, size, alloc); if (RTAG(HEADER(currblock))) { printf("%d: Block at location %d is tagged\n", block_count, loc); } if (size != GETSIZE(FOOTER(currblock))) { printf("%d: Header size of %d does not match footer size of %d\n", block_count, size, GETSIZE(FOOTER(currblock))); } if (alloc != FULL(FOOTER(currblock))) { printf("%d: Header allocation of %d does not match footer allocation " "of %d\n", block_count, alloc, FULL(FOOTER(currblock))); } if (!alloc) { listcounter = 0; count_size = size; while ((listcounter < LISTS - 1) && (count_size > 1)) { count_size >>= 1; listcounter++; } scan_currblock = free_lists[listcounter]; while ((scan_currblock != NULL) && (scan_currblock != currblock)) { scan_currblock = PREVFREE(scan_currblock); } if (scan_currblock == NULL) { printf("%d: Free block of size %d is not in list index %d\n", block_count, size, listcounter); } } currblock = NEXT(currblock); block_count++; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { this->setFixedSize(this->size()); //setWindowFlags(windowFlags() ^ Qt::WindowMaximizeButtonHint); ui->setupUi(this); //initializam interfata //Pregatim imaginile //<<< //cap QPixmap head("C:/img/head.png"); ui->img1->setPixmap(head); //corp QPixmap body("C:/img/body.png"); ui->img1_2->setPixmap(body); //mana QPixmap lhand("C:/img/lhand.png"); ui->img1_3->setPixmap(lhand); //mana2 QPixmap rhand("C:/img/rhand.png"); ui->img1_4->setPixmap(rhand); //picior QPixmap rfeet("C:/img/rfeet.png"); ui->img1_5->setPixmap(rfeet); //complet QPixmap FULL("C:/img/FULL.png"); ui->img1_6->setPixmap(FULL); //logo QPixmap logo("C:/img/logo.png"); ui->img_logo->setPixmap(logo); //>>> //Main qDebug()<<categorii[0]; setWindowTitle("Spanzuratoarea"); //setam titlul //Setari interfata ui->lineEdit->setVisible(false); ui->pushButton_3->setVisible(false); ui->label_2->setVisible(false); ui->pushButton_4->setVisible(false); ui->butstatistici->setVisible(false); ui->buttop3->setVisible(false); ui->pushButton_8->setVisible(false); ui->stat1->setVisible(false); ui->stat1_2->setVisible(false); ui->statnume->setVisible(false); ui->statnume_2->setVisible(false); ui->statnume_3->setVisible(false); ui->statwins->setVisible(false); ui->statwins_2->setVisible(false); ui->statwins_3->setVisible(false); ui->butback->setVisible(false); ui->line_2->setVisible(false); ui->catanim->setVisible(false); ui->cataut->setVisible(false); ui->catfruct->setVisible(false); ui->catjud->setVisible(false); ui->catpict->setVisible(false); ui->catplant->setVisible(false); ui->cattari->setVisible(false); ui->lineEdit_3->setVisible(false); ui->label_3->setVisible(false); ui->label_4->setVisible(false); ui->img1->setVisible(false); ui->img1_2->setVisible(false); ui->img1_3->setVisible(false); ui->img1_4->setVisible(false); ui->img1_5->setVisible(false); ui->img1_6->setVisible(false); ui->groupBox->setVisible(false); ui->lineEdit_2->setVisible(false); ui->label_6->setVisible(false); ui->label_7->setVisible(false); ui->pushButton_9->setVisible(false); ui->pushButton_10->setVisible(false); ui->cataleat->setVisible(false); ui->butadmin->setVisible(false); ui->label->setVisible(false); //Conexiunea la baza de date utilizatori=QSqlDatabase::addDatabase("QSQLITE"); utilizatori.setDatabaseName("C:/sqlite/data.db"); if(utilizatori.open()) qDebug()<<"Baza de date e deschisa!"; else qDebug()<<"Baza de date nu e deschisa!"; }