+int async_global_init(void)
+{
+ asyncwinpool = TlsAlloc();
+ asyncwinctx = TlsAlloc();
+ asyncwindispatch = TlsAlloc();
+ if (asyncwinpool == TLS_OUT_OF_INDEXES || asyncwinctx == TLS_OUT_OF_INDEXES
+ || asyncwindispatch == TLS_OUT_OF_INDEXES) {
+ if (asyncwinpool != TLS_OUT_OF_INDEXES) {
+ TlsFree(asyncwinpool);
+ }
+ if (asyncwinctx != TLS_OUT_OF_INDEXES) {
+ TlsFree(asyncwinctx);
+ }
+ if (asyncwindispatch != TLS_OUT_OF_INDEXES) {
+ TlsFree(asyncwindispatch);
+ }
+ return 0;
+ }
+ return 1;
+}
+
+int async_local_init(void)
+{
+ return (TlsSetValue(asyncwinpool, NULL) != 0)
+ && (TlsSetValue(asyncwinctx, NULL) != 0)
+ && (TlsSetValue(asyncwindispatch, NULL) != 0);
+}
+
+void async_local_cleanup(void)
+{
+ async_ctx *ctx = async_get_ctx();
+ if (ctx != NULL) {
+ async_fibre *fibre = &ctx->dispatcher;
+ if(fibre != NULL && fibre->fibre != NULL && fibre->converted) {
+ ConvertFiberToThread();
+ fibre->fibre = NULL;
+ }
+ }
+}
+
+void async_global_cleanup(void)
+{
+ TlsFree(asyncwinpool);
+ TlsFree(asyncwinctx);
+ TlsFree(asyncwindispatch);
+ asyncwinpool = 0;
+ asyncwinctx = 0;
+ asyncwindispatch = 0;
+}
+