Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Contextのコンストラクタが呼ばれるごとにライブラリの初期化を確認するよう

にした。
  • Loading branch information...
commit dac4ce4a21275031878984f6327a67d3adfe284c 1 parent c028184
@mashiro authored
Showing with 33 additions and 10 deletions.
  1. +33 −10 Context.cs
View
43 Context.cs
@@ -30,18 +30,39 @@ public GroongaException(GroongaResultCode result, String message, Exception inne
public class GroongaContext : IDisposable
{
- private static Initializer _initializer = null;
- private class Initializer
+ private static readonly Library _library = new Library();
+ private class Library
{
- public void Init() { GroongaApi.grn_init(); }
- public void Fin() { GroongaApi.grn_fin(); }
- ~Initializer() { Fin(); }
- }
+ private Boolean _initialized = false;
- static GroongaContext()
- {
- _initializer = new Initializer();
- _initializer.Init();
+ ~Library()
+ {
+ Uninitialize();
+ }
+
+ public void Initialize()
+ {
+ lock (this)
+ {
+ if (!_initialized)
+ {
+ GroongaApi.grn_init();
+ _initialized = true;
+ }
+ }
+ }
+
+ public void Uninitialize()
+ {
+ lock (this)
+ {
+ if (_initialized)
+ {
+ GroongaApi.grn_fin();
+ _initialized = false;
+ }
+ }
+ }
}
private GroongaApi.grn_ctx _context;
@@ -54,6 +75,8 @@ public GroongaContext()
public GroongaContext(GroongaContextFlags flags)
{
+ _library.Initialize();
+
GroongaResultCode result = GroongaApi.grn_ctx_init(out _context, flags);
if (result != GroongaResultCode.Success)
throw new GroongaException(result, "failed: grn_ctx_init");
Please sign in to comment.
Something went wrong with that request. Please try again.