[DEBUG] correct synchronization of Context

This commit is contained in:
Edouard DUPIN 2021-05-29 00:47:41 +02:00
parent de79013881
commit 31dae9d4e3

View File

@ -44,11 +44,13 @@ public class ResourceManager {
* This is to inform the resources manager that we have no more openGl context ... * This is to inform the resources manager that we have no more openGl context ...
*/ */
public synchronized void contextHasBeenDestroyed() { public synchronized void contextHasBeenDestroyed() {
synchronized (this.resourceList) {
for (final Resource it : this.resourceList) { for (final Resource it : this.resourceList) {
if (it.getCount() > 0) { if (it.getCount() > 0) {
it.removeContextToLate(); it.removeContextToLate();
} }
} }
}
// no context preent ... // no context preent ...
this.contextHasBeenRemoved = true; this.contextHasBeenRemoved = true;
} }
@ -59,19 +61,25 @@ public class ResourceManager {
public synchronized void display() { public synchronized void display() {
Log.info("Resources loaded : "); Log.info("Resources loaded : ");
// remove all resources ... // remove all resources ...
synchronized (this.resourceList) {
for (final Resource it : this.resourceList) { for (final Resource it : this.resourceList) {
Log.info(" [" + it.getId() + "]" + it.getClass().getCanonicalName() + "='" + it.getName() + "' " + it.getCount() + " elements"); Log.info(" [" + it.getId() + "]" + it.getClass().getCanonicalName() + "='" + it.getName() + "' " + it.getCount() + " elements");
} }
}
Log.info("Resources ---"); Log.info("Resources ---");
} }
public synchronized void localAdd(final Resource object) { public synchronized void localAdd(final Resource object) {
// add at the end if no slot is free // add at the end if no slot is free
synchronized (this.resourceList) {
this.resourceList.add(object); this.resourceList.add(object);
} }
}
// internal API to extent eResources in extern Soft // internal API to extent eResources in extern Soft
public synchronized Resource localKeep(final String filename) { public synchronized Resource localKeep(final String filename) {
synchronized (this.resourceList) {
Log.verbose("KEEP (DEFAULT) : file : '" + filename + "' in " + this.resourceList.size() + " resources"); Log.verbose("KEEP (DEFAULT) : file : '" + filename + "' in " + this.resourceList.size() + " resources");
for (final Resource it : this.resourceList) { for (final Resource it : this.resourceList) {
if (it == null) { if (it == null) {
@ -88,6 +96,7 @@ public class ResourceManager {
return it; return it;
} }
} }
}
return null; return null;
} }
@ -103,8 +112,9 @@ public class ResourceManager {
public synchronized void reLoadResources() { public synchronized void reLoadResources() {
Log.info("------------- Resources re-loaded -------------"); Log.info("------------- Resources re-loaded -------------");
// remove all resources ... // remove all resources ...
for (long jjj = 0; jjj < MAX_RESOURCE_LEVEL; jjj++) { for (long jjj = 0; jjj < ResourceManager.MAX_RESOURCE_LEVEL; jjj++) {
Log.info(" Reload level : " + jjj + "/" + (MAX_RESOURCE_LEVEL - 1)); Log.info(" Reload level : " + jjj + "/" + (ResourceManager.MAX_RESOURCE_LEVEL - 1));
synchronized (this.resourceList) {
for (final Resource it : this.resourceList) { for (final Resource it : this.resourceList) {
if (jjj == it.getResourceLevel()) { if (jjj == it.getResourceLevel()) {
if (it.getCount() > 0) { if (it.getCount() > 0) {
@ -114,6 +124,7 @@ public class ResourceManager {
} }
} }
} }
}
// TODO UNderstand why it is set here ... // TODO UNderstand why it is set here ...
//gale::requestUpdateSize(); //gale::requestUpdateSize();
Log.info("------------- Resources -------------"); Log.info("------------- Resources -------------");
@ -131,11 +142,13 @@ public class ResourceManager {
display(); display();
this.resourceListToUpdate.clear(); this.resourceListToUpdate.clear();
// remove all resources ... // remove all resources ...
synchronized (this.resourceList) {
for (final Resource it : this.resourceList) { for (final Resource it : this.resourceList) {
Log.warning("Find a resource that is not removed : [" + it.getId() + "]" + "='" + it.getName() + "' " + it.getCount() + " elements"); Log.warning("Find a resource that is not removed : [" + it.getId() + "]" + "='" + it.getName() + "' " + it.getCount() + " elements");
} }
this.resourceList.clear(); this.resourceList.clear();
} }
}
/** /**
* Call by the system to send all the needed data on the graphic card chen they change ... * Call by the system to send all the needed data on the graphic card chen they change ...
@ -172,8 +185,8 @@ public class ResourceManager {
} }
synchronized (this.resourceList) { synchronized (this.resourceList) {
if (this.resourceList.size() != 0) { if (this.resourceList.size() != 0) {
for (long jjj = 0; jjj < MAX_RESOURCE_LEVEL; jjj++) { for (long jjj = 0; jjj < ResourceManager.MAX_RESOURCE_LEVEL; jjj++) {
Log.verbose(" updateContext level (D) : " + jjj + "/" + (MAX_RESOURCE_LEVEL - 1)); Log.verbose(" updateContext level (D) : " + jjj + "/" + (ResourceManager.MAX_RESOURCE_LEVEL - 1));
for (final Resource it : this.resourceList) { for (final Resource it : this.resourceList) {
if (jjj == it.getResourceLevel()) { if (jjj == it.getResourceLevel()) {
//Log.debug("Update context named : " + lresourceList[iii].getName()); //Log.debug("Update context named : " + lresourceList[iii].getName());
@ -195,8 +208,8 @@ public class ResourceManager {
this.resourceListToUpdate = new ArrayList<>(); this.resourceListToUpdate = new ArrayList<>();
} }
if (resourceListToUpdate.size() != 0) { if (resourceListToUpdate.size() != 0) {
for (long jjj = 0; jjj < MAX_RESOURCE_LEVEL; jjj++) { for (long jjj = 0; jjj < ResourceManager.MAX_RESOURCE_LEVEL; jjj++) {
Log.verbose(" updateContext level (U) : " + jjj + "/" + (MAX_RESOURCE_LEVEL - 1)); Log.verbose(" updateContext level (U) : " + jjj + "/" + (ResourceManager.MAX_RESOURCE_LEVEL - 1));
for (final Resource it : resourceListToUpdate) { for (final Resource it : resourceListToUpdate) {
if (jjj == it.getResourceLevel()) { if (jjj == it.getResourceLevel()) {
if (!it.updateContext()) { if (!it.updateContext()) {