[erlang-questions] Where is enif_keep_binary?

Max Lapshin max.lapshin@REDACTED
Mon Aug 22 08:10:15 CEST 2011


I start enif_thread_create and pass binary to there:


static ERL_NIF_TERM yuv_x264(ErlNifEnv* env, int argc, const
ERL_NIF_TERM argv[]) {
   ....
   enif_mutex_lock(x264->lock);
   enif_inspect_binary(env, argv[1], &x264->yuv);
   x264->has_yuv = 1;
   enif_cond_signal(x264->cond);
   enif_mutex_unlock(x264->lock);
   return enif_make_atom(env, "wait");
}

and in thread I make:


while(1) {
  while(!x264->has_yuv) {
    enif_cond_wait(x264->cond, x264->lock);
  }

  handle(x264->yuv);
}

Problem is that binary get expired. How should I add refcounter to binary?
Copy it to other env?



More information about the erlang-questions mailing list