-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
279 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Copyright 2024 AQ author, All Rights Reserved. | ||
# This program is licensed under the AQ License. You can find the AQ license in | ||
# the root directory. | ||
|
||
cmake_minimum_required(VERSION 3.10) | ||
|
||
include_directories(${PROJECT_SOURCE_DIR}) | ||
|
||
set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/read_write_lock.c) | ||
|
||
add_library(AqvmBaseFileReadWriteLock STATIC ${SOURCES}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright 2024 AQ author, All Rights Reserved. | ||
// This program is licensed under the AQ License. You can find the AQ license in | ||
// the root directory. | ||
|
||
#include "aqvm/base/file/read_write_lock/read_write_lock.h" | ||
|
||
int AqvmBaseFileReadWriteLock_InitializeReadWriteLock( | ||
struct AqvmBaseFileReadWriteLock_ReadWriteLock* read_write_lock) { | ||
if (read_write_lock == NULL) { | ||
// TODO | ||
return -1; | ||
} | ||
|
||
if (AqvmBaseThreadingMutex_InitializeMutex(&read_write_lock->mutex) != 0) { | ||
// TODO | ||
return -2; | ||
} | ||
read_write_lock->read_count = 0; | ||
return 0; | ||
} | ||
|
||
int AqvmBaseFileReadWriteLock_CloseReadWriteLock( | ||
struct AqvmBaseFileReadWriteLock_ReadWriteLock* read_write_lock) { | ||
if (read_write_lock == NULL) { | ||
// TODO | ||
return -1; | ||
} | ||
|
||
if (AqvmBaseThreadingMutex_CloseMutex(&read_write_lock->mutex) != 0) { | ||
// TODO | ||
return -2; | ||
} | ||
return 0; | ||
} | ||
|
||
int AqvmBaseFileReadWriteLock_LockReadLock( | ||
struct AqvmBaseFileReadWriteLock_ReadWriteLock* read_write_lock) { | ||
if (read_write_lock == NULL) { | ||
// TODO | ||
return -1; | ||
} | ||
|
||
if (AqvmBaseThreadingMutex_LockMutex(&read_write_lock->mutex) != 0) { | ||
// TODO | ||
return -2; | ||
} | ||
++read_write_lock->read_count; | ||
return 0; | ||
} | ||
|
||
int AqvmBaseFileReadWriteLock_LockWriteLock( | ||
struct AqvmBaseFileReadWriteLock_ReadWriteLock* read_write_lock) { | ||
if (read_write_lock == NULL) { | ||
// TODO | ||
return -1; | ||
} | ||
|
||
if (AqvmBaseThreadingMutex_LockMutex(&read_write_lock->mutex) != 0) { | ||
// TODO | ||
return -2; | ||
} | ||
return 0; | ||
} | ||
|
||
int AqvmBaseFileReadWriteLock_UnlockLock( | ||
struct AqvmBaseFileReadWriteLock_ReadWriteLock* read_write_lock) { | ||
if (read_write_lock == NULL) { | ||
// TODO | ||
return -1; | ||
} | ||
|
||
if (read_write_lock->read_count == 0 && | ||
AqvmBaseThreadingMutex_UnlockMutex(&read_write_lock->mutex) != 0) { | ||
// TODO | ||
return -2; | ||
} else { | ||
--read_write_lock->read_count; | ||
if (read_write_lock->read_count == 0 && | ||
AqvmBaseThreadingMutex_UnlockMutex(&read_write_lock->mutex) != 0) { | ||
// TODO | ||
return -3; | ||
} | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2024 AQ author, All Rights Reserved. | ||
// This program is licensed under the AQ License. You can find the AQ license in | ||
// the root directory. | ||
|
||
#ifndef AQ_AQVM_BASE_FILE_READ_WRITE_LOCK_READ_WRITE_LOCK_H_ | ||
#define AQ_AQVM_BASE_FILE_READ_WRITE_LOCK_READ_WRITE_LOCK_H_ | ||
|
||
#include "aqvm/base/threading/mutex/mutex.h" | ||
|
||
struct AqvmBaseFileReadWriteLock_ReadWriteLock { | ||
AqvmBaseThreadingMutex_Mutex mutex; | ||
int read_count; | ||
}; | ||
|
||
int AqvmBaseFileReadWriteLock_InitializeReadWriteLock( | ||
struct AqvmBaseFileReadWriteLock_ReadWriteLock* read_write_lock); | ||
|
||
int AqvmBaseFileReadWriteLock_CloseReadWriteLock( | ||
struct AqvmBaseFileReadWriteLock_ReadWriteLock* read_write_lock); | ||
|
||
int AqvmBaseFileReadWriteLock_LockReadLock( | ||
struct AqvmBaseFileReadWriteLock_ReadWriteLock* read_write_lock); | ||
|
||
int AqvmBaseFileReadWriteLock_LockWriteLock( | ||
struct AqvmBaseFileReadWriteLock_ReadWriteLock* read_write_lock); | ||
|
||
int AqvmBaseFileReadWriteLock_UnlockLock( | ||
struct AqvmBaseFileReadWriteLock_ReadWriteLock* read_write_lock); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.