DWORD WINAPI RunThread(void *ptr) { DWORD ret = 0; #else void * RunThread(void *ptr) { long int ret = 0; #endif GF_Thread *t = (GF_Thread *)ptr; /* Signal the caller */ if (! t->_signal) goto exit; #ifdef GPAC_ANDROID if (pthread_once(¤tThreadInfoKey_once, ¤tThreadInfoKey_alloc) || pthread_setspecific(currentThreadInfoKey, t)) GF_LOG(GF_LOG_ERROR, GF_LOG_MUTEX, ("[Mutex] Couldn't run thread %s, ID 0x%08x\n", t->log_name, t->id)); #endif /* GPAC_ANDROID */ t->status = GF_THREAD_STATUS_RUN; gf_sema_notify(t->_signal, 1); #ifndef GPAC_DISABLE_LOG t->id = gf_th_id(); GF_LOG(GF_LOG_INFO, GF_LOG_MUTEX, ("[Thread %s] At %d Entering thread proc - thread ID 0x%08x\n", t->log_name, gf_sys_clock(), t->id)); #endif /* Each thread has its own seed */ gf_rand_init(0); /* Run our thread */ ret = t->Run(t->args); exit: #ifndef GPAC_DISABLE_LOG GF_LOG(GF_LOG_INFO, GF_LOG_MUTEX, ("[Thread %s] At %d Exiting thread proc\n", t->log_name, gf_sys_clock())); #endif t->status = GF_THREAD_STATUS_DEAD; t->Run = NULL; #ifdef WIN32 if (!CloseHandle(t->threadH)) { DWORD err = GetLastError(); GF_LOG(GF_LOG_ERROR, GF_LOG_MUTEX, ("[Thread %s] Couldn't close handle when exiting thread proc, error code: %d\n", t->log_name, err)); } t->threadH = NULL; return ret; #else #ifdef GPAC_ANDROID #ifndef GPAC_DISABLE_LOG GF_LOG(GF_LOG_INFO, GF_LOG_MUTEX, ("[Thread %s] RunBeforeExit=%p\n", t->log_name, t->RunBeforeExit)); #endif if (t->RunBeforeExit) t->RunBeforeExit(t->args); #endif /* GPAC_ANDROID */ pthread_exit((void *)0); return (void *)ret; #endif }
GF_EXPORT FILE *gf_temp_file_new(char ** const fileName) { FILE *res = NULL; #if defined(_WIN32_WCE) TCHAR pPath[MAX_PATH+1]; TCHAR pTemp[MAX_PATH+1]; if (!GetTempPath(MAX_PATH, pPath)) { pPath[0] = '.'; pPath[1] = '.'; } if (GetTempFileName(pPath, TEXT("git"), 0, pTemp)) res = _wfopen(pTemp, TEXT("w+b")); #elif defined(WIN32) res = tmpfile(); if (!res) { wchar_t tmp[MAX_PATH]; GF_LOG(GF_LOG_INFO, GF_LOG_CORE, ("[Win32] system failure for tmpfile(): 0x%08x\n", GetLastError())); /*tmpfile() may fail under vista ...*/ if (GetEnvironmentVariableW(L"TEMP", tmp, MAX_PATH)) { wchar_t tmp2[MAX_PATH], *t_file; char* mbs_t_file; gf_rand_init(GF_FALSE); swprintf(tmp2, MAX_PATH, L"gpac_%d_%08x_", _getpid(), gf_rand()); t_file = _wtempnam(tmp, tmp2); mbs_t_file = wcs_to_utf8(t_file); if (!mbs_t_file) return 0; res = gf_fopen(mbs_t_file, "w+b"); if (res) { gpac_file_handles--; if (fileName) { *fileName = gf_strdup(mbs_t_file); } else { GF_LOG(GF_LOG_WARNING, GF_LOG_CORE, ("[Win32] temporary file %s won't be deleted - contact the GPAC team\n", mbs_t_file)); } } gf_free(mbs_t_file); free(t_file); } } #else res = tmpfile(); #endif if (res) { gpac_file_handles++; } return res; }
void Playlist::OnRandomize() { GF_List *new_entries = gf_list_new(); gf_rand_init(GF_FALSE); while (gf_list_count(m_entries)>1) { u32 pos = gf_rand() % (gf_list_count(m_entries)-1); PLEntry *ple = (PLEntry *)gf_list_get(m_entries, pos); gf_list_rem(m_entries, pos); gf_list_add(new_entries, ple); } PLEntry *ple = (PLEntry *)gf_list_get(m_entries, 0); gf_list_rem(m_entries, 0); gf_list_add(new_entries, ple); gf_list_del(m_entries); m_entries = new_entries; m_cur_entry = -1; RefreshList(); }
void wxPlaylist::OnRandomize(wxCommandEvent &WXUNUSED(event) ) { GF_List *new_entries = gf_list_new(); gf_rand_init(0); while (gf_list_count(m_entries)>1) { u32 pos = gf_rand() % (gf_list_count(m_entries)-1); PLEntry *ple = (PLEntry *)gf_list_get(m_entries, pos); gf_list_rem(m_entries, pos); gf_list_add(new_entries, ple); } PLEntry *ple = (PLEntry *)gf_list_get(m_entries, 0); gf_list_rem(m_entries, 0); gf_list_add(new_entries, ple); gf_list_del(m_entries); m_entries = new_entries; m_cur_entry = -1; RefreshList(); }
GF_EXPORT FILE *gf_temp_file_new() { FILE *res=NULL; #if defined(_WIN32_WCE) TCHAR pPath[MAX_PATH+1]; TCHAR pTemp[MAX_PATH+1]; if (!GetTempPath(MAX_PATH, pPath)) { pPath[0] = '.'; pPath[1] = '.'; } if (GetTempFileName(pPath, TEXT("git"), 0, pTemp)) res = _wfopen(pTemp, TEXT("w+b")); #elif defined(WIN32) char tmp[MAX_PATH]; res = tmpfile(); if (!res) { GF_LOG(GF_LOG_WARNING, GF_LOG_CORE, ("[Win32] system failure for tmpfile(): 0x%08x\n", GetLastError())); /*tmpfile() may fail under vista ...*/ if (GetEnvironmentVariable("TEMP",tmp,MAX_PATH)) { char tmp2[MAX_PATH], *t_file; gf_rand_init(GF_FALSE); sprintf(tmp2, "gpac_%08x_", gf_rand()); t_file = tempnam(tmp, tmp2); res = gf_fopen(t_file, "w+b"); free(t_file); } } #else res = tmpfile(); #endif if (res) { gpac_file_handles++; } return res; }