mirror of
https://github.com/VincentWei/MiniGUI.git
synced 2026-09-26 03:23:46 +08:00
tune code to use __mg_lookfor_unused_slot and __mg_slot_clear_use; make these functions inline
This commit is contained in:
+15
-2
@@ -108,8 +108,21 @@ BOOL mg_InitSystemRes (void);
|
||||
void mg_TerminateSystemRes (void);
|
||||
|
||||
int __mg_lookfor_unused_slot (unsigned char* bitmap, int len_bmp, int set);
|
||||
void __mg_slot_set_use (unsigned char* bitmap, int index);
|
||||
int __mg_slot_clear_use (unsigned char* bitmap, int index);
|
||||
static inline
|
||||
void __mg_slot_set_use (unsigned char* bitmap, int index) {
|
||||
bitmap += index >> 3;
|
||||
*bitmap &= (~(0x80 >> (index % 8)));
|
||||
}
|
||||
|
||||
static inline
|
||||
int __mg_slot_clear_use (unsigned char* bitmap, int index) {
|
||||
bitmap += index >> 3;
|
||||
if (*bitmap & (0x80 >> (index % 8)))
|
||||
return 0;
|
||||
|
||||
*bitmap |= (0x80 >> (index % 8));
|
||||
return 1;
|
||||
}
|
||||
|
||||
BOOL __mg_is_abs_path (const char* path);
|
||||
int __mg_path_joint (char* dst, int dst_size, const char* abs_path,
|
||||
|
||||
@@ -71,6 +71,7 @@
|
||||
#include "gal.h"
|
||||
#include "internals.h"
|
||||
#include "ourhdr.h"
|
||||
#include "misc.h"
|
||||
|
||||
static struct _manager {
|
||||
int semid;
|
||||
@@ -136,25 +137,13 @@ void mg_TerminateSemManager (void)
|
||||
|
||||
int __mg_alloc_mutual_sem (int *semid)
|
||||
{
|
||||
int n = -1, i, j;
|
||||
BYTE* bitmap = manager.use_bmp;
|
||||
int n;
|
||||
|
||||
#ifndef _MGRM_STANDALONE
|
||||
pthread_mutex_lock (&manager.lock);
|
||||
#endif
|
||||
|
||||
for (i = 0; i < manager.len_use_bmp; i++) {
|
||||
for (j = 0; j < 8; j++) {
|
||||
if (*bitmap & (0x80 >> j)) {
|
||||
*bitmap &= (~(0x80 >> j));
|
||||
n = i * 8 + j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bitmap++;
|
||||
}
|
||||
|
||||
n = __mg_lookfor_unused_slot (manager.use_bmp, manager.len_use_bmp, 1);
|
||||
if (n >= manager.nr_sems) {
|
||||
n = -1;
|
||||
}
|
||||
@@ -173,8 +162,6 @@ int __mg_alloc_mutual_sem (int *semid)
|
||||
|
||||
void __mg_free_mutual_sem (int sem_num)
|
||||
{
|
||||
BYTE* bitmap = manager.use_bmp;
|
||||
|
||||
if (sem_num < 0 || sem_num >= manager.nr_sems) {
|
||||
_DBG_PRINTF("Bad semaphore number: %d\n", sem_num);
|
||||
return;
|
||||
@@ -184,15 +171,9 @@ void __mg_free_mutual_sem (int sem_num)
|
||||
pthread_mutex_lock (&manager.lock);
|
||||
#endif
|
||||
|
||||
bitmap = bitmap + (sem_num >> 3);
|
||||
|
||||
#ifdef _DEBUG
|
||||
if (*bitmap & (0x80 >> (sem_num % 8))) {
|
||||
if (!__mg_slot_clear_use (manager.use_bmp, sem_num)) {
|
||||
_WRN_PRINTF("The semaphore is not marked as used: %d\n", sem_num);
|
||||
}
|
||||
#endif
|
||||
|
||||
*bitmap |= (0x80 >> (sem_num % 8));
|
||||
|
||||
#ifndef _MGRM_STANDALONE
|
||||
pthread_mutex_unlock (&manager.lock);
|
||||
|
||||
@@ -72,6 +72,7 @@ int __mg_lookfor_unused_slot (unsigned char* bitmap, int len_bmp, int set)
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if 0 // inline since 4.2.0
|
||||
void __mg_slot_set_use (unsigned char* bitmap, int index)
|
||||
{
|
||||
bitmap += index >> 3;
|
||||
@@ -87,4 +88,5 @@ int __mg_slot_clear_use (unsigned char* bitmap, int index)
|
||||
*bitmap |= (0x80 >> (index % 8));
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user