Skip to content

Commit

Permalink
Add driver/nif for restart on resume from background support
Browse files Browse the repository at this point in the history
Change-Id: I2cf09765d238b241e8f7af339a5cd4c7f08dda89
Reviewed-on: http://review.couchbase.org/8811
Reviewed-by: Jens Alfke <jens@couchbase.com>
Tested-by: Aaron Miller <apage43@ninjawhale.com>
Reviewed-by: Chris Anderson <jchris@couchbase.com>
Tested-by: Chris Anderson <jchris@couchbase.com>
  • Loading branch information
apage43 committed Aug 11, 2011
1 parent 5122e97 commit e8b2243
Show file tree
Hide file tree
Showing 6 changed files with 385 additions and 205 deletions.
28 changes: 28 additions & 0 deletions iErl14.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@
D9ABA81513DFB5CC00D072BE /* snappy.cc in Sources */ = {isa = PBXBuildFile; fileRef = D9ABA80C13DFB5CC00D072BE /* snappy.cc */; };
D9ABA81613DFB5CC00D072BE /* snappy.h in Headers */ = {isa = PBXBuildFile; fileRef = D9ABA80D13DFB5CC00D072BE /* snappy.h */; };
D9ABA81713DFB5CC00D072BE /* snappy_nif.cc in Sources */ = {isa = PBXBuildFile; fileRef = D9ABA80E13DFB5CC00D072BE /* snappy_nif.cc */; };
D9F85BF113F191A700A73E46 /* ios_drv.m in Sources */ = {isa = PBXBuildFile; fileRef = D9F85BF013F191A700A73E46 /* ios_drv.m */; };
D9F85BF313F193FC00A73E46 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D9F85BF213F193FC00A73E46 /* CoreFoundation.framework */; };
D9F85BF513F1962C00A73E46 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D9F85BF413F1962C00A73E46 /* UIKit.framework */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -777,13 +780,18 @@
D9E24B561240275800AC152E /* couch_icu_driver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = couch_icu_driver.m; path = src/couch_icu_driver.m; sourceTree = SOURCE_ROOT; };
D9E24B571240275800AC152E /* crypto_drv.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = crypto_drv.c; path = src/crypto_drv.c; sourceTree = SOURCE_ROOT; };
D9E24C5B124031A700AC152E /* libicucore.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libicucore.dylib; path = usr/lib/libicucore.dylib; sourceTree = SDKROOT; };
D9F85BF013F191A700A73E46 /* ios_drv.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ios_drv.m; path = src/ios_drv.m; sourceTree = "<group>"; };
D9F85BF213F193FC00A73E46 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; };
D9F85BF413F1962C00A73E46 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
27167DCD13C4E1BF001CC5B6 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
D9F85BF513F1962C00A73E46 /* UIKit.framework in Frameworks */,
D9F85BF313F193FC00A73E46 /* CoreFoundation.framework in Frameworks */,
27167DCE13C4E1BF001CC5B6 /* Foundation.framework in Frameworks */,
27167DCF13C4E1BF001CC5B6 /* libicucore.dylib in Frameworks */,
);
Expand Down Expand Up @@ -840,6 +848,8 @@
0867D69AFE84028FC02AAC07 /* Frameworks */ = {
isa = PBXGroup;
children = (
D9F85BF413F1962C00A73E46 /* UIKit.framework */,
D9F85BF213F193FC00A73E46 /* CoreFoundation.framework */,
AACBBE490F95108600F1A2B1 /* Foundation.framework */,
);
name = Frameworks;
Expand All @@ -850,6 +860,7 @@
children = (
D9E24B561240275800AC152E /* couch_icu_driver.m */,
D9E24B571240275800AC152E /* crypto_drv.c */,
D9F85BF013F191A700A73E46 /* ios_drv.m */,
D9E24AA4124015FE00AC152E /* erl_memory_trace_parser.c */,
D9E24AA5124015FE00AC152E /* erl_misc_utils.c */,
D9E24AA6124015FE00AC152E /* erl_printf_format.c */,
Expand Down Expand Up @@ -1924,6 +1935,7 @@
D9ABA81313DFB5CC00D072BE /* snappy-stubs-internal.cc in Sources */,
D9ABA81513DFB5CC00D072BE /* snappy.cc in Sources */,
D9ABA81713DFB5CC00D072BE /* snappy_nif.cc in Sources */,
D9F85BF113F191A700A73E46 /* ios_drv.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1998,6 +2010,14 @@
GCC_OPTIMIZATION_LEVEL = s;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = iErl14_Prefix.pch;
GCC_PREPROCESSOR_DEFINITIONS = (
"ERTS_SMP=1",
"HAVE_CONFIG_H=1",
"_DARWIN_C_SOURCE=1",
"ERLANG_INTEGRATION=1",
"NO_RECURSE=1",
"USE_THREADS=1",
);
GCC_VERSION = 4.2;
INSTALL_PATH = /usr/local/lib;
LIBRARY_SEARCH_PATHS = (
Expand All @@ -2023,6 +2043,14 @@
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = iErl14_Prefix.pch;
GCC_PREPROCESSOR_DEFINITIONS = (
"ERTS_SMP=1",
"HAVE_CONFIG_H=1",
"_DARWIN_C_SOURCE=1",
"ERLANG_INTEGRATION=1",
"NO_RECURSE=1",
"USE_THREADS=1",
);
GCC_VERSION = 4.2;
INSTALL_PATH = /usr/local/lib;
LIBRARY_SEARCH_PATHS = (
Expand Down
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#define ERTS_HAVE_HYBRID_EMU 1

/* Define if the smp emulator is built */
/* #undef ERTS_HAVE_SMP_EMU */
#define ERTS_HAVE_SMP_EMU 1

/* Define if dlopen() needs to be called before first call to dlerror() */
/* #undef ERTS_NEED_DLOPEN_BEFORE_DLERROR */
Expand Down
6 changes: 4 additions & 2 deletions src/driver_tab.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extern ErlDrvEntry ram_file_driver_entry;
extern ErlDrvEntry ttsl_driver_entry;
extern ErlDrvEntry crypto_driver_entry;
extern ErlDrvEntry couch_driver_entry;
extern ErlDrvEntry ios_driver_entry;

ErlDrvEntry *driver_tab[DRIVER_TAB_SIZE] =
{
Expand All @@ -19,7 +20,8 @@ ErlDrvEntry *driver_tab[DRIVER_TAB_SIZE] =
&zlib_driver_entry,
&ram_file_driver_entry,
&ttsl_driver_entry,
&couch_driver_entry,
&crypto_driver_entry,
&couch_driver_entry,
&crypto_driver_entry,
&ios_driver_entry,
NULL
};
73 changes: 41 additions & 32 deletions src/emulator/sys/unix/erl_unix_sys_ddll.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,25 @@ void erl_sys_ddll_init(void) {
*/
int erts_sys_ddll_open2(char *full_name, void **handle, ErtsSysDdllError* err)
{
printf("Dynamic load attempt: %s\n", full_name);
if(strncmp("emonk", full_name, 5) == 0) {
*handle = (void*) 1;
return ERL_DE_NO_ERROR;
}
if(strncmp("ejson", full_name, 5) == 0) {
*handle = (void*) 2;
return ERL_DE_NO_ERROR;
}
if(strncmp("snappy", full_name, 6) == 0) {
*handle = (void*) 3;
return ERL_DE_NO_ERROR;
}
err->str = my_strdup_in(ERTS_ALC_T_DDLL_TMP_BUF,"Cannot load DLLs on iOS");
return ERL_DE_ERROR_NO_DDLL_FUNCTIONALITY;
fprintf(stderr, "Dynamic load attempt: %s\n", full_name);
if(strcmp("emonk", full_name) == 0) {
*handle = (void*) 1;
return ERL_DE_NO_ERROR;
}
if(strcmp("ejson", full_name) == 0) {
*handle = (void*) 2;
return ERL_DE_NO_ERROR;
}
if(strcmp("snappy", full_name) == 0) {
*handle = (void*) 3;
return ERL_DE_NO_ERROR;
}
if(strcmp("ios", full_name) == 0) {
*handle = (void*) 4;
return ERL_DE_NO_ERROR;
}
err->str = my_strdup_in(ERTS_ALC_T_DDLL_TMP_BUF,"Cannot load DLLs on iOS");
return ERL_DE_ERROR_NO_DDLL_FUNCTIONALITY;
}

int erts_sys_ddll_open_noext(char *dlname, void **handle, ErtsSysDdllError* err)
Expand Down Expand Up @@ -158,25 +162,30 @@ int erts_sys_ddll_load_driver_init(void *handle, void **function)
ErlNifEntry* emonk_init(void);
ErlNifEntry* ejson_init(void);
ErlNifEntry* snappy_init(void);
ErlNifEntry* couch_ios_init(void);
int erts_sys_ddll_load_nif_init(void *handle, void **function, ErtsSysDdllError* err)
{
printf("NIF Init #%d, ", (int) handle);
int res = ERL_DE_ERROR_NO_DDLL_FUNCTIONALITY;;
if((int)handle == 1) {
printf("emonk.\n");
*function = emonk_init;
res = ERL_DE_NO_ERROR;
}
if((int)handle == 2) {
printf("ejson.\n");
*function = ejson_init;
res = ERL_DE_NO_ERROR;
}
if((int)handle == 3) {
printf("snappy.\n");
*function = snappy_init;
res = ERL_DE_NO_ERROR;
}
int res = ERL_DE_ERROR_NO_DDLL_FUNCTIONALITY;;
if((size_t)handle == 1) {
fprintf(stderr, "Loaded NIF: emonk.\n");
*function = emonk_init;
res = ERL_DE_NO_ERROR;
}
if((size_t)handle == 2) {
fprintf(stderr, "Loaded NIF: ejson.\n");
*function = ejson_init;
res = ERL_DE_NO_ERROR;
}
if((size_t)handle == 3) {
fprintf(stderr, "Loaded NIF: snappy.\n");
*function = snappy_init;
res = ERL_DE_NO_ERROR;
}
if((size_t)handle == 4) {
fprintf(stderr, "Loaded NIF: ios.\n");
*function = couch_ios_init;
res = ERL_DE_NO_ERROR;
}
return res;
}

Expand Down
Loading

0 comments on commit e8b2243

Please sign in to comment.