Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
windows/util: move initialization code to uv__util_init
  • Loading branch information
piscisaureus committed Jun 2, 2012
1 parent cd1298c commit ec95a07
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/win/core.c
Expand Up @@ -55,6 +55,9 @@ static void uv_init(void) {

/* Initialize console */
uv_console_init();

/* Initialize utilities */
uv__util_init();
}


Expand Down
6 changes: 5 additions & 1 deletion src/win/internal.h
Expand Up @@ -349,7 +349,11 @@ void uv_fs_event_close(uv_loop_t* loop, uv_fs_event_t* handle);
void uv_fs_event_endgame(uv_loop_t* loop, uv_fs_event_t* handle);


/* Utils */
/*
* Utilities.
*/
void uv__util_init();

int uv_parent_pid();
void uv_filetime_to_time_t(FILETIME* file_time, time_t* stat_time);
void uv_fatal_error(const int errorno, const char* syscall);
Expand Down
22 changes: 14 additions & 8 deletions src/win/util.c
Expand Up @@ -47,10 +47,21 @@
*/
#define MAX_TITLE_LENGTH 8192


/* Cached copy of the process title, plus a mutex guarding it. */
static char *process_title;
static uv_once_t uv_process_title_init_guard_ = UV_ONCE_INIT;
static CRITICAL_SECTION process_title_lock;


/*
* One-time intialization code for functionality defined in util.c.
*/
void uv__util_init() {
/* Initialize process title access mutex. */
InitializeCriticalSection(&process_title_lock);
}


int uv_utf16_to_utf8(const wchar_t* utf16Buffer, size_t utf16Size,
char* utf8Buffer, size_t utf8Size) {
return WideCharToMultiByte(CP_UTF8,
Expand Down Expand Up @@ -265,17 +276,12 @@ char** uv_setup_args(int argc, char** argv) {
}


static void uv_process_title_init(void) {
InitializeCriticalSection(&process_title_lock);
}


uv_err_t uv_set_process_title(const char* title) {
uv_err_t err;
int length;
wchar_t* title_w = NULL;

uv_once(&uv_process_title_init_guard_, uv_process_title_init);
uv__once_init();

/* Find out how big the buffer for the wide-char title must be */
length = uv_utf8_to_utf16(title, NULL, 0);
Expand Down Expand Up @@ -350,7 +356,7 @@ static int uv__get_process_title() {


uv_err_t uv_get_process_title(char* buffer, size_t size) {
uv_once(&uv_process_title_init_guard_, uv_process_title_init);
uv__once_init();

EnterCriticalSection(&process_title_lock);
/*
Expand Down

0 comments on commit ec95a07

Please sign in to comment.