A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/bytedeco/javacpp/commit/e8aacb2057a3ac0d4d4f319059d878149c983508 below:

* Use thread local in `Generator` to detach automatically native thr… · bytedeco/javacpp@e8aacb2 · GitHub

File tree Expand file treeCollapse file tree 3 files changed

+27

-7

lines changed

Filter options

Expand file treeCollapse file tree 3 files changed

+27

-7

lines changed Original file line number Diff line number Diff line change

@@ -1,4 +1,5 @@

1 1 2 +

* Use thread local in `Generator` to detach automatically native threads on exit for Windows as well ([pull #562](https://github.com/bytedeco/javacpp/pull/562))

2 3

* Add compiler options for C++14 and C++17 to platform properties files for Visual Studio

3 4

* Fix `Parser` incorrectly shortening type names for nested class template instances

4 5

* Make `Parser` output `boolean has_value()` methods for basic containers like `std::optional`

Original file line number Diff line number Diff line change

@@ -523,7 +523,16 @@ boolean classes(boolean handleExceptions, boolean defineAdapters, boolean conver

523 523

out.println(" va_end(ap);");

524 524

out.println("}");

525 525

out.println();

526 -

out.println("#if !defined(NO_JNI_DETACH_THREAD) && (defined(__linux__) || defined(__APPLE__))");

526 +

out.println("#if !defined(NO_JNI_DETACH_THREAD) && defined(_WIN32)");

527 +

out.println(" static __declspec(thread) struct JavaCPP_thread_local {");

528 +

out.println(" JNIEnv* env = NULL;");

529 +

out.println(" ~JavaCPP_thread_local() {");

530 +

out.println(" if (env && JavaCPP_vm) {");

531 +

out.println(" JavaCPP_vm->DetachCurrentThread();");

532 +

out.println(" }");

533 +

out.println(" }");

534 +

out.println(" } JavaCPP_thread_local; ");

535 +

out.println("#elif !defined(NO_JNI_DETACH_THREAD) && (defined(__linux__) || defined(__APPLE__))");

527 536

out.println(" static pthread_key_t JavaCPP_current_env;");

528 537

out.println(" static JavaCPP_noinline void JavaCPP_detach_env(void *data) {");

529 538

out.println(" if (JavaCPP_vm) {");

@@ -1431,7 +1440,7 @@ boolean classes(boolean handleExceptions, boolean defineAdapters, boolean conver

1431 1440

out.println("#endif");

1432 1441

out.println();

1433 1442

out.println("static JavaCPP_noinline void JavaCPP_detach(bool detach) {");

1434 -

out.println("#if !defined(NO_JNI_DETACH_THREAD) && !defined(__linux__) && !defined(__APPLE__)");

1443 +

out.println("#if !defined(NO_JNI_DETACH_THREAD) && !defined(__linux__) && !defined(__APPLE__) && !defined(_WIN32)");

1435 1444

out.println(" if (detach && JavaCPP_vm->DetachCurrentThread() != JNI_OK) {");

1436 1445

out.println(" JavaCPP_log(\"Could not detach the JavaVM from the current thread.\");");

1437 1446

out.println(" }");

@@ -1462,7 +1471,12 @@ boolean classes(boolean handleExceptions, boolean defineAdapters, boolean conver

1462 1471

out.println("#endif");

1463 1472

}

1464 1473

out.println(" }");

1465 -

out.println("#if !defined(NO_JNI_DETACH_THREAD) && (defined(__linux__) || defined(__APPLE__))");

1474 +

out.println("#if !defined(NO_JNI_DETACH_THREAD) && defined(_WIN32)");

1475 +

out.println(" if ((*env = JavaCPP_thread_local.env) != NULL) {");

1476 +

out.println(" attached = true;");

1477 +

out.println(" goto done;");

1478 +

out.println(" }");

1479 +

out.println("#elif !defined(NO_JNI_DETACH_THREAD) && (defined(__linux__) || defined(__APPLE__))");

1466 1480

out.println(" pthread_once(&JavaCPP_once, JavaCPP_create_pthread_key);");

1467 1481

out.println(" if ((*env = (JNIEnv *)pthread_getspecific(JavaCPP_current_env)) != NULL) {");

1468 1482

out.println(" attached = true;");

@@ -1492,7 +1506,9 @@ boolean classes(boolean handleExceptions, boolean defineAdapters, boolean conver

1492 1506

out.println(" *env = NULL;");

1493 1507

out.println(" goto done;");

1494 1508

out.println(" }");

1495 -

out.println("#if !defined(NO_JNI_DETACH_THREAD) && (defined(__linux__) || defined(__APPLE__))");

1509 +

out.println("#if !defined(NO_JNI_DETACH_THREAD) && defined(_WIN32)");

1510 +

out.println(" JavaCPP_thread_local.env = *env;");

1511 +

out.println("#elif !defined(NO_JNI_DETACH_THREAD) && (defined(__linux__) || defined(__APPLE__))");

1496 1512

out.println(" pthread_setspecific(JavaCPP_current_env, *env);");

1497 1513

out.println("#endif");

1498 1514

out.println(" attached = true;");

Original file line number Diff line number Diff line change

@@ -25,7 +25,7 @@

25 25

* @author Dan Avila

26 26

*

27 27

*/

28 -

@Platform(compiler = "cpp11", define = "NO_JNI_DETACH_THREAD", include = "ThreadTest.h")

28 +

@Platform(compiler = "cpp11", include = "ThreadTest.h")

29 29

public class ThreadTest {

30 30

public static class Callback extends Pointer {

31 31

/** Default native constructor. */

@@ -76,8 +76,8 @@ public static class Callback extends Pointer {

76 76 77 77

run(callback, count);

78 78 79 -

assertTrue(callbackValueRefs.size() == count);

80 -

assertTrue(threadRefs.size() == count);

79 +

assertEquals(callbackValueRefs.size(), count);

80 +

assertEquals(threadRefs.size(), count);

81 81 82 82

for (int i = 0; i < count; i++) {

83 83

int value = callbackValueRefs.get(i);

@@ -95,5 +95,8 @@ public static class Callback extends Pointer {

95 95 96 96

assertEquals(cbThread1, cbThread2);

97 97

}

98 + 99 +

// thread should be automatically detached upon completion

100 +

assertFalse(threadRefs.get(0).isAlive());

98 101

}

99 102

}

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4