/* * Flush all TTY queues. * Called at spltty, tty already locked. * Calls device STOP routine; must already be on master if * device needs to run on master. */ void tty_flush( register struct tty *tp, int rw) { if (rw & D_READ) { cb_clear(&tp->t_inq); tty_queue_completion(&tp->t_delayed_read); } if (rw & D_WRITE) { tp->t_state &= ~TS_TTSTOP; (*tp->t_stop)(tp, rw); cb_clear(&tp->t_outq); tty_queue_completion(&tp->t_delayed_write); } }
static int remove_oldest_chunk(struct chunk_buffer *cb, int id, uint64_t ts) { int i, min, pos_min; if (cb->buffer[0].id == id) { return E_CB_DUPLICATE; } min = cb->buffer[0].id; pos_min = 0; for (i = 1; i < cb->num_chunks; i++) { if (cb->buffer[i].id == id) { return E_CB_DUPLICATE; } if (cb->buffer[i].id < min) { min = cb->buffer[i].id; pos_min = i; } } if (min < id) { chunk_free(&cb->buffer[pos_min]); cb->num_chunks--; return pos_min; } // check for ID looparound and other anomalies if (cb->buffer[pos_min].timestamp < ts) { cb_clear(cb); return 0; } return E_CB_OLD; }
wi_status wi_parse_plist(wi_t self, const char *from_buf, size_t length, plist_t *to_rpc_dict, bool *to_is_partial) { wi_private_t my = self->private_state; *to_is_partial = false; *to_rpc_dict = NULL; if (my->is_sim) { plist_from_bin(from_buf, length, to_rpc_dict); } else { plist_t wi_dict = NULL; plist_from_bin(from_buf, length, &wi_dict); if (!wi_dict) { return WI_ERROR; } plist_t wi_rpc = plist_dict_get_item(wi_dict, "WIRFinalMessageKey"); if (!wi_rpc) { wi_rpc = plist_dict_get_item(wi_dict, "WIRPartialMessageKey"); if (!wi_rpc) { return WI_ERROR; } *to_is_partial = true; } uint64_t rpc_len = 0; char *rpc_bin = NULL; plist_get_data_val(wi_rpc, &rpc_bin, &rpc_len); plist_free(wi_dict); // also frees wi_rpc if (!rpc_bin) { return WI_ERROR; } // assert rpc_len < MAX_RPC_LEN? size_t p_length = my->partial->tail - my->partial->head; if (*to_is_partial || p_length) { if (cb_ensure_capacity(my->partial, rpc_len)) { return self->on_error(self, "Out of memory"); } memcpy(my->partial->tail, rpc_bin, rpc_len); my->partial->tail += rpc_len; p_length += rpc_len; free(rpc_bin); if (*to_is_partial) { return WI_SUCCESS; } } if (p_length) { plist_from_bin(my->partial->head, (uint32_t)p_length, to_rpc_dict); cb_clear(my->partial); } else { plist_from_bin(rpc_bin, (uint32_t)rpc_len, to_rpc_dict); free(rpc_bin); } } return (*to_rpc_dict ? WI_SUCCESS : WI_ERROR); }
CircularBuffer* cb_create(size_t singleEntrySize, uint8_t bufferSize) { CircularBuffer* circularBuffer = (CircularBuffer*) malloc(sizeof(CircularBuffer)); circularBuffer->data = malloc(singleEntrySize * bufferSize); circularBuffer->loaded = malloc(sizeof(bool) * bufferSize); circularBuffer->singleEntrySize = singleEntrySize; circularBuffer->bufferSize = bufferSize; circularBuffer->bufferCenterPos = 0; circularBuffer->centerIndex = 0; cb_clear(circularBuffer); return circularBuffer; }
void free_shiptypes(void) { cb_clear(&cb_shiptypes); selist_foreach(shiptypes, free_shiptype); selist_free(shiptypes); shiptypes = 0; }
static void free_functions(void) { cb_clear(&functions); functions.root = 0; }
void cb_destroy(struct chunk_buffer *cb) { cb_clear(cb); free(cb->buffer); free(cb); }
void free_attribs(void) { cb_clear(&cb_deprecated); }
void stats_close(void) { cb_clear(&stats); }