Beispiel #1
0
void rewind(FILE* stream) {

	g_atomic_lock(&stream->lock);
	__fseeko_unlocked(stream, 0, SEEK_SET);
	__clearerr_unlocked(stream);
	stream->lock = 0;
}
Beispiel #2
0
int putc(int c, FILE* stream) {

	g_atomic_lock(&stream->lock);
	int res = __fputc_unlocked(c, stream);
	stream->lock = 0;
	return res;
}
Beispiel #3
0
size_t fwrite(const void* ptr, size_t size, size_t nmemb, FILE* stream) {

	g_atomic_lock(&stream->lock);
	size_t len = __fwrite_unlocked(ptr, size, nmemb, stream);
	stream->lock = 0;
	return len;
}
Beispiel #4
0
int fgetc(FILE* stream) {

	g_atomic_lock(&stream->lock);
	int res = __fgetc_unlocked(stream);
	stream->lock = 0;
	return res;
}
Beispiel #5
0
void RequestHandler::send(g_fd out, g_ui_transaction_id transaction, uint8_t* data, uint32_t length) {

	// lock
	g_atomic_lock(&sending_locked);

	// write transaction id
	uint32_t idlen = sizeof(g_ui_transaction_id);
	uint8_t idbytes[idlen];
	*((g_ui_transaction_id*) idbytes) = transaction;
	g_write(out, idbytes, idlen);

	// write length
	uint32_t lenlen = sizeof(uint32_t);
	uint8_t lenbytes[lenlen];
	*((uint32_t*) lenbytes) = length;
	g_write(out, lenbytes, lenlen);

	// write data
	uint32_t written = 0;
	while (written < length) {
		written += g_write(out, &data[written], length - written);
	}

	// unlock
	sending_locked = false;
}
Beispiel #6
0
void RequestHandler::remove_process(g_pid process) {

	g_atomic_lock(&process_map_lock);

	processMap.erase(process);

	process_map_lock = false;
}
Beispiel #7
0
void RequestHandler::event_dispatch_thread() {

	// register a name
	std::stringstream namestr;
	namestr << "windowserver:event-dispatcher";
	g_task_register_id(namestr.str().c_str());

	while (true) {
		// wait for events
		g_atomic_block(&event_dispatch_events_empty);

		// lock
		g_atomic_lock(&sending_locked);

		// call listener
		UIEventDispatchData ldata = event_dispatch_queue.back();
		event_dispatch_queue.pop_back();

		// write transaction id
		uint32_t idlen = sizeof(g_ui_transaction_id);
		uint8_t idbytes[idlen];
		*((g_ui_transaction_id*) idbytes) = 0;
		g_write(ldata.output, idbytes, idlen);

		// write length
		uint32_t lenlen = sizeof(uint32_t);
		uint8_t lenbytes[lenlen];
		*((uint32_t*) lenbytes) = ldata.length + 4;
		g_write(ldata.output, lenbytes, lenlen);

		// write listener id
		uint32_t lidlen = sizeof(uint32_t);
		uint8_t lidbytes[lidlen];
		*((uint32_t*) lidbytes) = ldata.listener;
		g_write(ldata.output, lidbytes, lidlen);

		// write data
		uint32_t written = 0;
		while (written < ldata.length) {
			written += g_write(ldata.output, &ldata.data[written], ldata.length - written);
		}

		// delete the data
		delete ldata.data;

		// check if empty
		if (event_dispatch_queue.empty()) {
			event_dispatch_events_empty = true;
		}

		// unlock
		sending_locked = false;
	}
}
Beispiel #8
0
void RequestHandler::add_process(g_pid process, g_fd output, g_fd input) {

	g_atomic_lock(&process_map_lock);

	UIRegisteredProcessData data;
	data.pid = process;
	data.output = output;
	data.input = input;
	processMap.insert(std::make_pair(process, data));

	process_map_lock = false;
}
Beispiel #9
0
/**
 * Sends a message (thread-safe) to the window manager.
 */
g_ui_transaction_id g_ui::send(uint8_t* data, uint32_t length) {

	// check if ready
	if (!g_ui_ready) {
		return -1;
	}

	static uint8_t sending_locked = false;

	// lock
	g_atomic_lock(&sending_locked);

	// create transaction
	g_ui_transaction_id transaction = next_transaction++;

	// create data for response
	g_ui_transaction_data* response_data = new g_ui_transaction_data;
	response_data->data = 0;
	response_data->length = 0;
	response_data->waiting = true;

	// insert to map
	if (transaction_map == 0) {
		transaction_map = new std::map<g_ui_transaction_id, g_ui_transaction_data*>();
	}
	transaction_map->insert(std::make_pair(transaction, response_data));

	// write transaction id
	uint32_t idlen = sizeof(g_ui_transaction_id);
	uint8_t idbytes[idlen];
	*((g_ui_transaction_id*) idbytes) = transaction;
	g_write(g_ui_channel_out, idbytes, idlen);

	// write length
	uint32_t lenlen = sizeof(uint32_t);
	uint8_t lenbytes[lenlen];
	*((uint32_t*) lenbytes) = length;
	g_write(g_ui_channel_out, lenbytes, lenlen);

	// write data
	int32_t written = 0;
	while (written < length) {
		written += g_write(g_ui_channel_out, &data[written], length - written);
	}

	// unlock
	sending_locked = false;

	return transaction;
}
Beispiel #10
0
uint32_t RequestHandler::nextListenerId() {

	static uint8_t locked = false;
	static uint32_t next_id = 0;

	// lock
	g_atomic_lock(&locked);

	uint32_t id = next_id++;

	// unlock
	locked = false;

	return id;
}
Beispiel #11
0
void RequestHandler::send_event(g_pid process, uint32_t listener_id, uint8_t* data, uint32_t length) {

	// lock
	g_atomic_lock(&process_map_lock);

	if (processMap.count(process) > 0) {
		UIRegisteredProcessData& procdat = processMap.at(process);

		// add event data to dispatcher queue
		UIEventDispatchData event_data;
		event_data.output = procdat.output;
		event_data.listener = listener_id;
		event_data.data = data;
		event_data.length = length;
		event_dispatch_queue_add(event_data);
	}

	// unlock
	process_map_lock = false;
}
void command_message_responder_thread_t::run() {

	event_processor_t* eventProcessor = windowserver_t::instance()->event_processor;
	while (true) {

		// wait until messages are added
		g_atomic_lock(&buffer_empty);

		// process all
		while (buffer.size() > 0) {

			// get reference to response from the queue
			command_message_response_t& response = buffer.back();
			g_send_message_t(response.target, response.message, response.length, response.transaction);

			// delete message buffer
			delete (g_message_header*) response.message;

			// remove response from queue
			buffer.pop_back();
		}
	}
}
Beispiel #13
0
void g_ui::event_dispatch_thread() {

	while (true) {
		// wait for events
		g_atomic_block(&event_dispatch_events_empty);

		// lock
		g_atomic_lock(&event_dispatch_locked);

		// call listener
		g_ui_event_dispatch_data& e = event_dispatch_queue.back();
		event_dispatch_queue.pop_back();
		e.listener->event_received(e.data, e.length);

		// check if empty
		if (event_dispatch_queue.empty()) {
			event_dispatch_events_empty = true;
		}

		// unlock
		event_dispatch_locked = false;
	}
}
Beispiel #14
0
g_message_transaction g_get_message_tx_id() {
	g_atomic_lock((uint8_t*) &__next_transaction_lock);
	g_message_transaction next_topic = __next_transaction++;
	__next_transaction_lock = false;
	return next_topic;
}