Download build/src/platform.h from camenduru/ncnn: direct link, hf CLI and curl.
- Browser
- Download file 7.25 kB
-
https://huggingface.co/camenduru/ncnn/resolve/main/build/src/platform.h
- Command line
-
hf download hf://camenduru/ncnn/build/src/platform.h
-
curl -L -o platform.h https://huggingface.co/camenduru/ncnn/resolve/main/build/src/platform.h
7.25 kB
| // Tencent is pleased to support the open source community by making ncnn available. | |
| // | |
| // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. | |
| // | |
| // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except | |
| // in compliance with the License. You may obtain a copy of the License at | |
| // | |
| // https://opensource.org/licenses/BSD-3-Clause | |
| // | |
| // Unless required by applicable law or agreed to in writing, software distributed | |
| // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| // CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| // specific language governing permissions and limitations under the License. | |
| namespace ncnn { | |
| class NCNN_EXPORT Mutex | |
| { | |
| public: | |
| Mutex() { InitializeSRWLock(&srwlock); } | |
| ~Mutex() {} | |
| void lock() { AcquireSRWLockExclusive(&srwlock); } | |
| void unlock() { ReleaseSRWLockExclusive(&srwlock); } | |
| private: | |
| friend class ConditionVariable; | |
| // NOTE SRWLock is available from windows vista | |
| SRWLOCK srwlock; | |
| }; | |
| class NCNN_EXPORT ConditionVariable | |
| { | |
| public: | |
| ConditionVariable() { InitializeConditionVariable(&condvar); } | |
| ~ConditionVariable() {} | |
| void wait(Mutex& mutex) { SleepConditionVariableSRW(&condvar, &mutex.srwlock, INFINITE, 0); } | |
| void broadcast() { WakeAllConditionVariable(&condvar); } | |
| void signal() { WakeConditionVariable(&condvar); } | |
| private: | |
| CONDITION_VARIABLE condvar; | |
| }; | |
| static unsigned __stdcall start_wrapper(void* args); | |
| class NCNN_EXPORT Thread | |
| { | |
| public: | |
| Thread(void* (*start)(void*), void* args = 0) { _start = start; _args = args; handle = (HANDLE)_beginthreadex(0, 0, start_wrapper, this, 0, 0); } | |
| ~Thread() {} | |
| void join() { WaitForSingleObject(handle, INFINITE); CloseHandle(handle); } | |
| private: | |
| friend unsigned __stdcall start_wrapper(void* args) | |
| { | |
| Thread* t = (Thread*)args; | |
| t->_start(t->_args); | |
| return 0; | |
| } | |
| HANDLE handle; | |
| void* (*_start)(void*); | |
| void* _args; | |
| }; | |
| class NCNN_EXPORT ThreadLocalStorage | |
| { | |
| public: | |
| ThreadLocalStorage() { key = TlsAlloc(); } | |
| ~ThreadLocalStorage() { TlsFree(key); } | |
| void set(void* value) { TlsSetValue(key, (LPVOID)value); } | |
| void* get() { return (void*)TlsGetValue(key); } | |
| private: | |
| DWORD key; | |
| }; | |
| class NCNN_EXPORT Mutex | |
| { | |
| public: | |
| Mutex() { pthread_mutex_init(&mutex, 0); } | |
| ~Mutex() { pthread_mutex_destroy(&mutex); } | |
| void lock() { pthread_mutex_lock(&mutex); } | |
| void unlock() { pthread_mutex_unlock(&mutex); } | |
| private: | |
| friend class ConditionVariable; | |
| pthread_mutex_t mutex; | |
| }; | |
| class NCNN_EXPORT ConditionVariable | |
| { | |
| public: | |
| ConditionVariable() { pthread_cond_init(&cond, 0); } | |
| ~ConditionVariable() { pthread_cond_destroy(&cond); } | |
| void wait(Mutex& mutex) { pthread_cond_wait(&cond, &mutex.mutex); } | |
| void broadcast() { pthread_cond_broadcast(&cond); } | |
| void signal() { pthread_cond_signal(&cond); } | |
| private: | |
| pthread_cond_t cond; | |
| }; | |
| class NCNN_EXPORT Thread | |
| { | |
| public: | |
| Thread(void* (*start)(void*), void* args = 0) { pthread_create(&t, 0, start, args); } | |
| ~Thread() {} | |
| void join() { pthread_join(t, 0); } | |
| private: | |
| pthread_t t; | |
| }; | |
| class NCNN_EXPORT ThreadLocalStorage | |
| { | |
| public: | |
| ThreadLocalStorage() { pthread_key_create(&key, 0); } | |
| ~ThreadLocalStorage() { pthread_key_delete(key); } | |
| void set(void* value) { pthread_setspecific(key, value); } | |
| void* get() { return pthread_getspecific(key); } | |
| private: | |
| pthread_key_t key; | |
| }; | |
| class NCNN_EXPORT Mutex | |
| { | |
| public: | |
| Mutex() {} | |
| ~Mutex() {} | |
| void lock() {} | |
| void unlock() {} | |
| }; | |
| class NCNN_EXPORT ConditionVariable | |
| { | |
| public: | |
| ConditionVariable() {} | |
| ~ConditionVariable() {} | |
| void wait(Mutex& /*mutex*/) {} | |
| void broadcast() {} | |
| void signal() {} | |
| }; | |
| class NCNN_EXPORT Thread | |
| { | |
| public: | |
| Thread(void* (*/*start*/)(void*), void* /*args*/ = 0) {} | |
| ~Thread() {} | |
| void join() {} | |
| }; | |
| class NCNN_EXPORT ThreadLocalStorage | |
| { | |
| public: | |
| ThreadLocalStorage() { data = 0; } | |
| ~ThreadLocalStorage() {} | |
| void set(void* value) { data = value; } | |
| void* get() { return data; } | |
| private: | |
| void* data; | |
| }; | |
| class NCNN_EXPORT MutexLockGuard | |
| { | |
| public: | |
| MutexLockGuard(Mutex& _mutex) : mutex(_mutex) { mutex.lock(); } | |
| ~MutexLockGuard() { mutex.unlock(); } | |
| private: | |
| Mutex& mutex; | |
| }; | |
| } // namespace ncnn | |