Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce korlibs-concurrent (Lock + NativeThread) + add logger, datastructure and platform to K/N desktop targets #2132

Merged
merged 6 commits into from Jan 16, 2024

Conversation

soywiz
Copy link
Member

@soywiz soywiz commented Jan 16, 2024

@soywiz soywiz changed the title Introduce korlibs-concurrent (Lock + NativeThread) + later potential atomic stuff Introduce korlibs-concurrent (Lock + NativeThread) + add logger, datastructure and platform to K/N desktop targets Jan 16, 2024
private external val process: dynamic
private external val Deno: dynamic

private val isDenoJs: Boolean by lazy { js("(typeof Deno === 'object' && Deno.statSync)").unsafeCast<Boolean>() }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you duplicate platform code in logger? Why is it a problem to depend on platform?

Copy link
Member Author

@soywiz soywiz Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because just for two lines, I don't see adding an extra dependency in this case, like the JS ecosystem would do.

Copy link
Member Author

@soywiz soywiz Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully in Kotlin 2 we will have the ability to differentiate runtimes integrated in the stdlib at some point, so this will be removed ad the korlibs-platform will be reduced and eventually deleted.


private fun getEnvs(): Map<String, String> {
val out = LinkedHashMap<String, String>()
val env = platform.posix.__environ
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid so short variable names. It really makes the code hard to read.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could control env local variable, but not __environ since that comes from the operating system


internal actual val miniEnvironmentVariables: Map<String, String> by lazy { getEnvs() }

private fun readStringsz(ptr: CPointer<WCHARVar>?): List<String> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the z in the function name on purpose?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The stringz is typically from C-languags world. It is a string that ends with a '\0' byte. Typically in C strings strings work like that instead of having the size attached, they just end by '\0'

import korlibs.concurrent.lock.wait as waitConcurrent

@Deprecated("Use korlibs.concurrent.lock package")
typealias BaseLock = korlibs.concurrent.lock.BaseLock
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this so you do not brake others? Could we use this to move the events to a new package?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes for both questions. The thing is that we want to keep at least source-code compatibility for at least a few versions.

//fun unlock()
}

//typealias Lock = BaseLock
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not leave in comment code in PR. YAGNI: You aren't gonna need it. If you do, you can readd it from earlier commit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is old code that was like that, I'm okay with removing those lines. So feel free to do so.


package korlibs.concurrent.lock

import korlibs.concurrent.thread.*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • imports are not adviced since they make it hard to determine which classes are from which imports.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rationale behind the star imports:

KorGE uses star imports because it relies a lot on extension members. It was a pain in the ass adding all those members manually for people starting. Users typically don't care where classes come from as long as the code works.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it makes it pain in the ass to refactor. For our current task forexample it is important to see which methods are used from which packages, when we want to reduce the dependency towards a package.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it is a pain in the ass? Doesn't @Deprecated has a parameter to specify replacement to do it automatically inside the IDE?

@soywiz soywiz enabled auto-merge (squash) January 16, 2024 11:43
@soywiz soywiz merged commit 3fe7a19 into main Jan 16, 2024
9 checks passed
@soywiz soywiz deleted the feature/introduce.korlibs-concurrent branch January 16, 2024 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants