static void queues2_execute(void) { unsigned i; size_t n; /* Initial empty state */ test_assert_lock(1, chOQIsEmptyI(&oq), "not empty"); /* Queue filling */ for (i = 0; i < TEST_QUEUES_SIZE; i++) chOQPut(&oq, 'A' + i); test_assert_lock(2, chOQIsFullI(&oq), "still has space"); /* Queue emptying */ for (i = 0; i < TEST_QUEUES_SIZE; i++) { char c; chSysLock(); c = chOQGetI(&oq); chSysUnlock(); test_emit_token(c); } test_assert_lock(3, chOQIsEmptyI(&oq), "still full"); test_assert_sequence(4, "ABCD"); test_assert_lock(5, chOQGetI(&oq) == Q_EMPTY, "failed to report Q_EMPTY"); /* Writing the whole thing */ n = chOQWriteTimeout(&oq, wa[1], TEST_QUEUES_SIZE * 2, TIME_IMMEDIATE); test_assert(6, n == TEST_QUEUES_SIZE, "wrong returned size"); test_assert_lock(7, chOQIsFullI(&oq), "not full"); threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()+1, thread2, NULL); test_assert_lock(8, chOQGetFullI(&oq) == TEST_QUEUES_SIZE, "not empty"); test_wait_threads(); /* Testing reset */ chSysLock(); chOQResetI(&oq); chSysUnlock(); test_assert_lock(9, chOQGetFullI(&oq) == 0, "still full"); /* Partial writes */ n = chOQWriteTimeout(&oq, wa[1], TEST_QUEUES_SIZE / 2, TIME_IMMEDIATE); test_assert(10, n == TEST_QUEUES_SIZE / 2, "wrong returned size"); n = chOQWriteTimeout(&oq, wa[1], TEST_QUEUES_SIZE / 2, TIME_IMMEDIATE); test_assert(11, n == TEST_QUEUES_SIZE / 2, "wrong returned size"); test_assert_lock(12, chOQIsFullI(&oq), "not full"); /* Timeout */ test_assert(13, chOQPutTimeout(&oq, 0, 10) == Q_TIMEOUT, "wrong timeout return"); }
size_t debugPut(const uint8_t *block, size_t n) /* truncate any block > 255 bytes returns # of characters actually output (including the trailing newline) */ { if (n) { chMtxLock(&debugOutLock); size_t space = chOQGetEmptyI(&debugOutQ); if (space) { if (n >= space) n = space - 1; if (n) { if (n > 255) n = 255; chOQPutTimeout( &debugOutQ, n, TIME_IMMEDIATE); chOQWriteTimeout( &debugOutQ, block, n, TIME_IMMEDIATE); resumeReader(); n++; } }else n = 0; chMtxUnlock(); }else if (debugPutc('\n') >= 0) n = 1; return n; }
static size_t qwrites(void *ip, const uint8_t *bp, size_t n) { qStream *qsp = ip; if (n > qsp->space) n = qsp->space; qsp->space -= n; chOQWriteTimeout( &debugOutQ, bp, n, TIME_IMMEDIATE); return n; }
static size_t writet(void *ip, const uint8_t *bp, size_t n, systime_t time) { return chOQWriteTimeout(&((BulkUSBDriver *)ip)->oqueue, bp, n, time); }
static size_t write(void *ip, const uint8_t *bp, size_t n) { return chOQWriteTimeout(&((BulkUSBDriver *)ip)->oqueue, bp, n, TIME_INFINITE); }
size_t OutQueue::writeTimeout(const uint8_t *bp, size_t n, systime_t time) { return chOQWriteTimeout(&oq, bp, n, time); }