|
@@ -88,9 +88,7 @@ void FileAccessNetworkClient::_thread_func() {
|
|
while (!quit) {
|
|
while (!quit) {
|
|
|
|
|
|
DEBUG_PRINT("SEM WAIT - " + itos(sem->get()));
|
|
DEBUG_PRINT("SEM WAIT - " + itos(sem->get()));
|
|
- Error err = sem->wait();
|
|
|
|
- if (err != OK)
|
|
|
|
- ERR_PRINT("sem->wait() failed");
|
|
|
|
|
|
+ sem.wait();
|
|
DEBUG_TIME("sem_unlock");
|
|
DEBUG_TIME("sem_unlock");
|
|
//DEBUG_PRINT("semwait returned "+itos(werr));
|
|
//DEBUG_PRINT("semwait returned "+itos(werr));
|
|
DEBUG_PRINT("MUTEX LOCK " + itos(lockcount));
|
|
DEBUG_PRINT("MUTEX LOCK " + itos(lockcount));
|
|
@@ -140,7 +138,7 @@ void FileAccessNetworkClient::_thread_func() {
|
|
fa->_respond(len, Error(status));
|
|
fa->_respond(len, Error(status));
|
|
}
|
|
}
|
|
|
|
|
|
- fa->sem->post();
|
|
|
|
|
|
+ fa->sem.post();
|
|
|
|
|
|
} break;
|
|
} break;
|
|
case FileAccessNetwork::RESPONSE_DATA: {
|
|
case FileAccessNetwork::RESPONSE_DATA: {
|
|
@@ -160,14 +158,14 @@ void FileAccessNetworkClient::_thread_func() {
|
|
|
|
|
|
int status = get_32();
|
|
int status = get_32();
|
|
fa->exists_modtime = status != 0;
|
|
fa->exists_modtime = status != 0;
|
|
- fa->sem->post();
|
|
|
|
|
|
+ fa->sem.post();
|
|
|
|
|
|
} break;
|
|
} break;
|
|
case FileAccessNetwork::RESPONSE_GET_MODTIME: {
|
|
case FileAccessNetwork::RESPONSE_GET_MODTIME: {
|
|
|
|
|
|
uint64_t status = get_64();
|
|
uint64_t status = get_64();
|
|
fa->exists_modtime = status;
|
|
fa->exists_modtime = status;
|
|
- fa->sem->post();
|
|
|
|
|
|
+ fa->sem.post();
|
|
|
|
|
|
} break;
|
|
} break;
|
|
}
|
|
}
|
|
@@ -229,7 +227,6 @@ FileAccessNetworkClient::FileAccessNetworkClient() {
|
|
singleton = this;
|
|
singleton = this;
|
|
last_id = 0;
|
|
last_id = 0;
|
|
client.instance();
|
|
client.instance();
|
|
- sem = Semaphore::create();
|
|
|
|
lockcount = 0;
|
|
lockcount = 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -237,12 +234,10 @@ FileAccessNetworkClient::~FileAccessNetworkClient() {
|
|
|
|
|
|
if (thread) {
|
|
if (thread) {
|
|
quit = true;
|
|
quit = true;
|
|
- sem->post();
|
|
|
|
|
|
+ sem.post();
|
|
Thread::wait_to_finish(thread);
|
|
Thread::wait_to_finish(thread);
|
|
memdelete(thread);
|
|
memdelete(thread);
|
|
}
|
|
}
|
|
-
|
|
|
|
- memdelete(sem);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void FileAccessNetwork::_set_block(int p_offset, const Vector<uint8_t> &p_block) {
|
|
void FileAccessNetwork::_set_block(int p_offset, const Vector<uint8_t> &p_block) {
|
|
@@ -262,7 +257,7 @@ void FileAccessNetwork::_set_block(int p_offset, const Vector<uint8_t> &p_block)
|
|
|
|
|
|
if (waiting_on_page == page) {
|
|
if (waiting_on_page == page) {
|
|
waiting_on_page = -1;
|
|
waiting_on_page = -1;
|
|
- page_sem->post();
|
|
|
|
|
|
+ page_sem.post();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -304,9 +299,9 @@ Error FileAccessNetwork::_open(const String &p_path, int p_mode_flags) {
|
|
nc->unlock_mutex();
|
|
nc->unlock_mutex();
|
|
DEBUG_PRINT("OPEN POST");
|
|
DEBUG_PRINT("OPEN POST");
|
|
DEBUG_TIME("open_post");
|
|
DEBUG_TIME("open_post");
|
|
- nc->sem->post(); //awaiting answer
|
|
|
|
|
|
+ nc->sem.post(); //awaiting answer
|
|
DEBUG_PRINT("WAIT...");
|
|
DEBUG_PRINT("WAIT...");
|
|
- sem->wait();
|
|
|
|
|
|
+ sem.wait();
|
|
DEBUG_TIME("open_end");
|
|
DEBUG_TIME("open_end");
|
|
DEBUG_PRINT("WAIT ENDED...");
|
|
DEBUG_PRINT("WAIT ENDED...");
|
|
|
|
|
|
@@ -390,7 +385,7 @@ void FileAccessNetwork::_queue_page(int p_page) const {
|
|
pages.write[p_page].queued = true;
|
|
pages.write[p_page].queued = true;
|
|
nc->blockrequest_mutex.unlock();
|
|
nc->blockrequest_mutex.unlock();
|
|
DEBUG_PRINT("QUEUE PAGE POST");
|
|
DEBUG_PRINT("QUEUE PAGE POST");
|
|
- nc->sem->post();
|
|
|
|
|
|
+ nc->sem.post();
|
|
DEBUG_PRINT("queued " + itos(p_page));
|
|
DEBUG_PRINT("queued " + itos(p_page));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -423,7 +418,7 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {
|
|
}
|
|
}
|
|
buffer_mutex.unlock();
|
|
buffer_mutex.unlock();
|
|
DEBUG_PRINT("wait");
|
|
DEBUG_PRINT("wait");
|
|
- page_sem->wait();
|
|
|
|
|
|
+ page_sem.wait();
|
|
DEBUG_PRINT("done");
|
|
DEBUG_PRINT("done");
|
|
} else {
|
|
} else {
|
|
|
|
|
|
@@ -472,8 +467,8 @@ bool FileAccessNetwork::file_exists(const String &p_path) {
|
|
nc->client->put_data((const uint8_t *)cs.ptr(), cs.length());
|
|
nc->client->put_data((const uint8_t *)cs.ptr(), cs.length());
|
|
nc->unlock_mutex();
|
|
nc->unlock_mutex();
|
|
DEBUG_PRINT("FILE EXISTS POST");
|
|
DEBUG_PRINT("FILE EXISTS POST");
|
|
- nc->sem->post();
|
|
|
|
- sem->wait();
|
|
|
|
|
|
+ nc->sem.post();
|
|
|
|
+ sem.wait();
|
|
|
|
|
|
return exists_modtime != 0;
|
|
return exists_modtime != 0;
|
|
}
|
|
}
|
|
@@ -489,8 +484,8 @@ uint64_t FileAccessNetwork::_get_modified_time(const String &p_file) {
|
|
nc->client->put_data((const uint8_t *)cs.ptr(), cs.length());
|
|
nc->client->put_data((const uint8_t *)cs.ptr(), cs.length());
|
|
nc->unlock_mutex();
|
|
nc->unlock_mutex();
|
|
DEBUG_PRINT("MODTIME POST");
|
|
DEBUG_PRINT("MODTIME POST");
|
|
- nc->sem->post();
|
|
|
|
- sem->wait();
|
|
|
|
|
|
+ nc->sem.post();
|
|
|
|
+ sem.wait();
|
|
|
|
|
|
return exists_modtime;
|
|
return exists_modtime;
|
|
}
|
|
}
|
|
@@ -518,8 +513,6 @@ FileAccessNetwork::FileAccessNetwork() {
|
|
eof_flag = false;
|
|
eof_flag = false;
|
|
opened = false;
|
|
opened = false;
|
|
pos = 0;
|
|
pos = 0;
|
|
- sem = Semaphore::create();
|
|
|
|
- page_sem = Semaphore::create();
|
|
|
|
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
|
|
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
|
|
nc->lock_mutex();
|
|
nc->lock_mutex();
|
|
id = nc->last_id++;
|
|
id = nc->last_id++;
|
|
@@ -535,8 +528,6 @@ FileAccessNetwork::FileAccessNetwork() {
|
|
FileAccessNetwork::~FileAccessNetwork() {
|
|
FileAccessNetwork::~FileAccessNetwork() {
|
|
|
|
|
|
close();
|
|
close();
|
|
- memdelete(sem);
|
|
|
|
- memdelete(page_sem);
|
|
|
|
|
|
|
|
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
|
|
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
|
|
nc->lock_mutex();
|
|
nc->lock_mutex();
|