feat:replace boost library with C++11 std library

This commit is contained in:
Livox-SDK
2020-04-01 20:53:55 +08:00
parent 6d06233944
commit d3258bbd97
1936 changed files with 241862 additions and 60153 deletions
+267
View File
@@ -0,0 +1,267 @@
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
#include "apr_general.h"
#include "apr_lib.h"
#include "apr_strings.h"
#include "apr_portable.h"
#include "apr_arch_proc_mutex.h"
#include "apr_arch_file_io.h"
#include <string.h>
#include <stddef.h>
#define CurrentTid (*_threadid)
static char *fixed_name(const char *fname, apr_pool_t *pool)
{
char *semname;
if (fname == NULL)
semname = NULL;
else {
/* Semaphores don't live in the file system, fix up the name */
while (*fname == '/' || *fname == '\\') {
fname++;
}
semname = apr_pstrcat(pool, "/SEM32/", fname, NULL);
if (semname[8] == ':') {
semname[8] = '$';
}
}
return semname;
}
APR_DECLARE(apr_status_t) apr_proc_mutex_cleanup(void *vmutex)
{
apr_proc_mutex_t *mutex = vmutex;
return apr_proc_mutex_destroy(mutex);
}
APR_DECLARE(const char *) apr_proc_mutex_lockfile(apr_proc_mutex_t *mutex)
{
return NULL;
}
APR_DECLARE(apr_lockmech_e) apr_proc_mutex_mech(apr_proc_mutex_t *mutex)
{
return APR_LOCK_DEFAULT;
}
APR_DECLARE(const char *) apr_proc_mutex_name(apr_proc_mutex_t *mutex)
{
return "os2sem";
}
APR_DECLARE(const char *) apr_proc_mutex_defname(void)
{
return "os2sem";
}
APR_DECLARE(apr_status_t) apr_proc_mutex_create(apr_proc_mutex_t **mutex,
const char *fname,
apr_lockmech_e mech,
apr_pool_t *pool)
{
apr_proc_mutex_t *new;
ULONG rc;
char *semname;
if (mech != APR_LOCK_DEFAULT) {
return APR_ENOTIMPL;
}
new = (apr_proc_mutex_t *)apr_palloc(pool, sizeof(apr_proc_mutex_t));
new->pool = pool;
new->owner = 0;
new->lock_count = 0;
*mutex = new;
semname = fixed_name(fname, pool);
rc = DosCreateMutexSem(semname, &(new->hMutex), DC_SEM_SHARED, FALSE);
if (!rc) {
apr_pool_cleanup_register(pool, new, apr_proc_mutex_cleanup, apr_pool_cleanup_null);
}
return APR_FROM_OS_ERROR(rc);
}
APR_DECLARE(apr_status_t) apr_proc_mutex_child_init(apr_proc_mutex_t **mutex,
const char *fname,
apr_pool_t *pool)
{
apr_proc_mutex_t *new;
ULONG rc;
char *semname;
new = (apr_proc_mutex_t *)apr_palloc(pool, sizeof(apr_proc_mutex_t));
new->pool = pool;
new->owner = 0;
new->lock_count = 0;
semname = fixed_name(fname, pool);
rc = DosOpenMutexSem(semname, &(new->hMutex));
*mutex = new;
if (!rc) {
apr_pool_cleanup_register(pool, new, apr_proc_mutex_cleanup, apr_pool_cleanup_null);
}
return APR_FROM_OS_ERROR(rc);
}
APR_DECLARE(apr_status_t) apr_proc_mutex_lock(apr_proc_mutex_t *mutex)
{
ULONG rc = DosRequestMutexSem(mutex->hMutex, SEM_INDEFINITE_WAIT);
if (rc == 0) {
mutex->owner = CurrentTid;
mutex->lock_count++;
}
return APR_FROM_OS_ERROR(rc);
}
APR_DECLARE(apr_status_t) apr_proc_mutex_trylock(apr_proc_mutex_t *mutex)
{
ULONG rc = DosRequestMutexSem(mutex->hMutex, SEM_IMMEDIATE_RETURN);
if (rc == 0) {
mutex->owner = CurrentTid;
mutex->lock_count++;
}
return APR_FROM_OS_ERROR(rc);
}
APR_DECLARE(apr_status_t) apr_proc_mutex_unlock(apr_proc_mutex_t *mutex)
{
ULONG rc;
if (mutex->owner == CurrentTid && mutex->lock_count > 0) {
mutex->lock_count--;
rc = DosReleaseMutexSem(mutex->hMutex);
return APR_FROM_OS_ERROR(rc);
}
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_proc_mutex_destroy(apr_proc_mutex_t *mutex)
{
ULONG rc;
apr_status_t status = APR_SUCCESS;
if (mutex->owner == CurrentTid) {
while (mutex->lock_count > 0 && status == APR_SUCCESS) {
status = apr_proc_mutex_unlock(mutex);
}
}
if (status != APR_SUCCESS) {
return status;
}
if (mutex->hMutex == 0) {
return APR_SUCCESS;
}
rc = DosCloseMutexSem(mutex->hMutex);
if (!rc) {
mutex->hMutex = 0;
}
return APR_FROM_OS_ERROR(rc);
}
APR_PERMS_SET_ENOTIMPL(proc_mutex)
APR_POOL_IMPLEMENT_ACCESSOR(proc_mutex)
/* Implement OS-specific accessors defined in apr_portable.h */
APR_DECLARE(apr_status_t) apr_os_proc_mutex_get_ex(apr_os_proc_mutex_t *ospmutex,
apr_proc_mutex_t *pmutex,
apr_lockmech_e *mech)
{
*ospmutex = pmutex->hMutex;
if (mech) {
*mech = APR_LOCK_DEFAULT;
}
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex,
apr_proc_mutex_t *pmutex)
{
return apr_os_proc_mutex_get_ex(ospmutex, pmutex, NULL);
}
APR_DECLARE(apr_status_t) apr_os_proc_mutex_put_ex(apr_proc_mutex_t **pmutex,
apr_os_proc_mutex_t *ospmutex,
apr_lockmech_e mech,
int register_cleanup,
apr_pool_t *pool)
{
apr_proc_mutex_t *new;
if (pool == NULL) {
return APR_ENOPOOL;
}
if (mech != APR_LOCK_DEFAULT) {
return APR_ENOTIMPL;
}
new = (apr_proc_mutex_t *)apr_palloc(pool, sizeof(apr_proc_mutex_t));
new->pool = pool;
new->owner = 0;
new->lock_count = 0;
new->hMutex = *ospmutex;
*pmutex = new;
if (register_cleanup) {
apr_pool_cleanup_register(pool, *pmutex, apr_proc_mutex_cleanup,
apr_pool_cleanup_null);
}
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex,
apr_os_proc_mutex_t *ospmutex,
apr_pool_t *pool)
{
return apr_os_proc_mutex_put_ex(pmutex, ospmutex, APR_LOCK_DEFAULT,
0, pool);
}
+60
View File
@@ -0,0 +1,60 @@
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
#include "apr_general.h"
#include "apr_lib.h"
#include "apr_strings.h"
#include "apr_portable.h"
#include "apr_arch_thread_mutex.h"
#include "apr_arch_thread_cond.h"
#include "apr_arch_file_io.h"
#include <string.h>
APR_DECLARE(apr_status_t) apr_thread_cond_create(apr_thread_cond_t **cond,
apr_pool_t *pool)
{
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_cond_wait(apr_thread_cond_t *cond,
apr_thread_mutex_t *mutex)
{
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_cond_timedwait(apr_thread_cond_t *cond,
apr_thread_mutex_t *mutex,
apr_interval_time_t timeout){
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_cond_signal(apr_thread_cond_t *cond)
{
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_cond_broadcast(apr_thread_cond_t *cond)
{
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_cond_destroy(apr_thread_cond_t *cond)
{
return APR_ENOTIMPL;
}
APR_POOL_IMPLEMENT_ACCESSOR(thread_cond)
+102
View File
@@ -0,0 +1,102 @@
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
#include "apr_general.h"
#include "apr_lib.h"
#include "apr_strings.h"
#include "apr_portable.h"
#include "apr_arch_thread_mutex.h"
#include "apr_arch_file_io.h"
#include <string.h>
#include <stddef.h>
static apr_status_t thread_mutex_cleanup(void *themutex)
{
apr_thread_mutex_t *mutex = themutex;
return apr_thread_mutex_destroy(mutex);
}
/* XXX: Need to respect APR_THREAD_MUTEX_[UN]NESTED flags argument
* or return APR_ENOTIMPL!!!
*/
APR_DECLARE(apr_status_t) apr_thread_mutex_create(apr_thread_mutex_t **mutex,
unsigned int flags,
apr_pool_t *pool)
{
apr_thread_mutex_t *new_mutex;
ULONG rc;
new_mutex = (apr_thread_mutex_t *)apr_palloc(pool, sizeof(apr_thread_mutex_t));
new_mutex->pool = pool;
rc = DosCreateMutexSem(NULL, &(new_mutex->hMutex), 0, FALSE);
*mutex = new_mutex;
if (!rc)
apr_pool_cleanup_register(pool, new_mutex, thread_mutex_cleanup, apr_pool_cleanup_null);
return APR_OS2_STATUS(rc);
}
APR_DECLARE(apr_status_t) apr_thread_mutex_lock(apr_thread_mutex_t *mutex)
{
ULONG rc = DosRequestMutexSem(mutex->hMutex, SEM_INDEFINITE_WAIT);
return APR_OS2_STATUS(rc);
}
APR_DECLARE(apr_status_t) apr_thread_mutex_trylock(apr_thread_mutex_t *mutex)
{
ULONG rc = DosRequestMutexSem(mutex->hMutex, SEM_IMMEDIATE_RETURN);
return APR_OS2_STATUS(rc);
}
APR_DECLARE(apr_status_t) apr_thread_mutex_unlock(apr_thread_mutex_t *mutex)
{
ULONG rc = DosReleaseMutexSem(mutex->hMutex);
return APR_OS2_STATUS(rc);
}
APR_DECLARE(apr_status_t) apr_thread_mutex_destroy(apr_thread_mutex_t *mutex)
{
ULONG rc;
if (mutex->hMutex == 0)
return APR_SUCCESS;
while (DosReleaseMutexSem(mutex->hMutex) == 0);
rc = DosCloseMutexSem(mutex->hMutex);
if (!rc) {
mutex->hMutex = 0;
return APR_SUCCESS;
}
return APR_FROM_OS_ERROR(rc);
}
APR_POOL_IMPLEMENT_ACCESSOR(thread_mutex)
+200
View File
@@ -0,0 +1,200 @@
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
#include "apr_general.h"
#include "apr_lib.h"
#include "apr_strings.h"
#include "apr_portable.h"
#include "apr_arch_thread_rwlock.h"
#include "apr_arch_file_io.h"
#include <string.h>
static apr_status_t thread_rwlock_cleanup(void *therwlock)
{
apr_thread_rwlock_t *rwlock = therwlock;
return apr_thread_rwlock_destroy(rwlock);
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_create(apr_thread_rwlock_t **rwlock,
apr_pool_t *pool)
{
apr_thread_rwlock_t *new_rwlock;
ULONG rc;
new_rwlock = (apr_thread_rwlock_t *)apr_palloc(pool, sizeof(apr_thread_rwlock_t));
new_rwlock->pool = pool;
new_rwlock->readers = 0;
rc = DosCreateMutexSem(NULL, &(new_rwlock->write_lock), 0, FALSE);
if (rc)
return APR_FROM_OS_ERROR(rc);
rc = DosCreateEventSem(NULL, &(new_rwlock->read_done), 0, FALSE);
if (rc)
return APR_FROM_OS_ERROR(rc);
*rwlock = new_rwlock;
if (!rc)
apr_pool_cleanup_register(pool, new_rwlock, thread_rwlock_cleanup,
apr_pool_cleanup_null);
return APR_FROM_OS_ERROR(rc);
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_rdlock(apr_thread_rwlock_t *rwlock)
{
ULONG rc, posts;
rc = DosRequestMutexSem(rwlock->write_lock, SEM_INDEFINITE_WAIT);
if (rc)
return APR_FROM_OS_ERROR(rc);
/* We've successfully acquired the writer mutex so we can't be locked
* for write which means it's ok to add a reader lock. The writer mutex
* doubles as race condition protection for the readers counter.
*/
rwlock->readers++;
DosResetEventSem(rwlock->read_done, &posts);
rc = DosReleaseMutexSem(rwlock->write_lock);
return APR_FROM_OS_ERROR(rc);
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_tryrdlock(apr_thread_rwlock_t *rwlock)
{
/* As above but with different wait time */
ULONG rc, posts;
rc = DosRequestMutexSem(rwlock->write_lock, SEM_IMMEDIATE_RETURN);
if (rc)
return APR_FROM_OS_ERROR(rc);
rwlock->readers++;
DosResetEventSem(rwlock->read_done, &posts);
rc = DosReleaseMutexSem(rwlock->write_lock);
return APR_FROM_OS_ERROR(rc);
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_wrlock(apr_thread_rwlock_t *rwlock)
{
ULONG rc;
rc = DosRequestMutexSem(rwlock->write_lock, SEM_INDEFINITE_WAIT);
if (rc)
return APR_FROM_OS_ERROR(rc);
/* We've got the writer lock but we have to wait for all readers to
* unlock before it's ok to use it
*/
if (rwlock->readers) {
rc = DosWaitEventSem(rwlock->read_done, SEM_INDEFINITE_WAIT);
if (rc)
DosReleaseMutexSem(rwlock->write_lock);
}
return APR_FROM_OS_ERROR(rc);
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_trywrlock(apr_thread_rwlock_t *rwlock)
{
ULONG rc;
rc = DosRequestMutexSem(rwlock->write_lock, SEM_IMMEDIATE_RETURN);
if (rc)
return APR_FROM_OS_ERROR(rc);
/* We've got the writer lock but we have to wait for all readers to
* unlock before it's ok to use it
*/
if (rwlock->readers) {
/* There are readers active, give up */
DosReleaseMutexSem(rwlock->write_lock);
rc = ERROR_TIMEOUT;
}
return APR_FROM_OS_ERROR(rc);
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_unlock(apr_thread_rwlock_t *rwlock)
{
ULONG rc;
/* First, guess that we're unlocking a writer */
rc = DosReleaseMutexSem(rwlock->write_lock);
if (rc == ERROR_NOT_OWNER) {
/* Nope, we must have a read lock */
if (rwlock->readers) {
DosEnterCritSec();
rwlock->readers--;
if (rwlock->readers == 0) {
DosPostEventSem(rwlock->read_done);
}
DosExitCritSec();
rc = 0;
}
}
return APR_FROM_OS_ERROR(rc);
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_destroy(apr_thread_rwlock_t *rwlock)
{
ULONG rc;
if (rwlock->write_lock == 0)
return APR_SUCCESS;
while (DosReleaseMutexSem(rwlock->write_lock) == 0);
rc = DosCloseMutexSem(rwlock->write_lock);
if (!rc) {
rwlock->write_lock = 0;
DosCloseEventSem(rwlock->read_done);
return APR_SUCCESS;
}
return APR_FROM_OS_ERROR(rc);
}
APR_POOL_IMPLEMENT_ACCESSOR(thread_rwlock)