--- freem/src/locktab.c 2025/05/01 21:02:31 1.7
+++ freem/src/locktab.c 2025/05/15 02:49:11 1.9
@@ -1,5 +1,5 @@
/*
- * $Id: locktab.c,v 1.7 2025/05/01 21:02:31 snw Exp $
+ * $Id: locktab.c,v 1.9 2025/05/15 02:49:11 snw Exp $
* lock table implementation
*
*
@@ -24,6 +24,12 @@
* along with FreeM. If not, see .
*
* $Log: locktab.c,v $
+ * Revision 1.9 2025/05/15 02:49:11 snw
+ * Fix linker error on errno symbol in locktab.c
+ *
+ * Revision 1.8 2025/05/14 15:28:55 snw
+ * Get basic job table and lock table functionality working with new shared memory architecture
+ *
* Revision 1.7 2025/05/01 21:02:31 snw
* Documentation updates
*
@@ -46,6 +52,7 @@
#include
#include
#include
+#include
#include "mpsdef.h"
#include "locktab.h"
@@ -79,14 +86,12 @@ void locktab_init(void)
semid_locktab = semget (lt_sk, 1, 0666 | IPC_CREAT);
if (semid_locktab == -1) {
- fprintf (stderr, "locktab_init: failed to create lock table semaphore\r\n");
- exit (1);
+ logprintf (FM_LOG_FATAL, "locktab_init: failed to create lock table semaphore");
}
arg.val = 1;
if (semctl (semid_locktab, 0, SETVAL, arg) == -1) {
- fprintf (stderr, "locktab_init: failed to initialize lock table semaphore\r\n");
- exit (1);
+ logprintf (FM_LOG_FATAL, "locktab_init: failed to initialize lock table semaphore");
}
}
@@ -94,8 +99,7 @@ void locktab_init(void)
semid_locktab = semget (lt_sk, 1, 0);
if (semid_locktab == -1) {
- fprintf (stderr, "locktab_init: could not attach to lock table semaphore\r\n");
- exit (1);
+ logprintf (FM_LOG_FATAL, "locktab_init: could not attach to lock table semaphore");
}
}
@@ -109,15 +113,20 @@ short locktab_get_sem(void)
int tries;
struct sembuf s = {0, -1, 0};
+ logprintf (FM_LOG_DEBUG, "locktab_get_sem: attempting to acquire lock table semaphore");
+
for (tries = 0; tries < 5; tries++) {
if (semop (semid_locktab, &s, 1) != -1) {
+ logprintf (FM_LOG_DEBUG, "locktab_get_sem: acquired semaphore by virtue of calling semop on it");
return TRUE;
}
- printf ("jibjaw\r\n");
+
+ logprintf (FM_LOG_INFO, "locktab_get_sem: sleeping for retry [tries = %d; errno = %d; error = %s]", tries, errno, strerror (errno));
sleep (1);
}
+ logprintf (FM_LOG_ERROR, "locktab_get_sem: failed to acquire job table semaphore");
return FALSE;
}
@@ -126,7 +135,13 @@ void locktab_release_sem(void)
{
struct sembuf s = {0, 1, 0};
- semop (semid_locktab, &s, 1);
+ logprintf (FM_LOG_DEBUG, "locktab_release_sem: trying to release lock table semaphore");
+ if(semop (semid_locktab, &s, 1) != - 1) {
+ logprintf (FM_LOG_DEBUG, "locktab_release_sem: released lock table semaphore by means of semop");
+ }
+ else {
+ logprintf (FM_LOG_FATAL, "locktab_release_sem: failed to release lock table semaphore (error code %d [%s])", errno, strerror (errno));
+ }
}
@@ -441,7 +456,7 @@ void locktab_unlock_all_by_pid(const pid
}
- for (lck = shm_config->hdr->locktab_head; lck != NULL; lck = lck->next) {
+ for (lck = SOA(shm_config->hdr->locktab_head); lck != NULL; lck = SOA(lck->next)) {
if (lck->owner_job == target_pid) {
remove_ct++;
@@ -481,7 +496,7 @@ locktab_ent_t *locktab_find(char *key)
snprintf (chk_ns, sizeof (chk_ns) - 1, "%s", nsname);
}
- for (lck = shm_config->hdr->locktab_head; lck != NULL; lck = lck->next) {
+ for (lck = SOA(shm_config->hdr->locktab_head); lck != NULL; lck = SOA(lck->next)) {
if ((stcmp (lck->nref, key) == 0) && (strcmp (lck->namespace, chk_ns) == 0)) {
@@ -525,7 +540,7 @@ locktab_ent_t *locktab_insert(char *key)
snprintf (chk_ns, sizeof (chk_ns) - 1, "%s", nsname);
}
- for (l = shm_config->hdr->locktab_head; l != NULL; l = l->next) {
+ for (l = SOA(shm_config->hdr->locktab_head); l != NULL; l = SOA(l->next)) {
ok = mref_init (ok, MREF_RT_GLOBAL, "");
ok = internal_to_mref (ok, l->nref);
@@ -579,8 +594,8 @@ new_insert:
l->owner_job = pid;
l->ct = 1;
- l->next = shm_config->hdr->locktab_head;
- shm_config->hdr->locktab_head = l;
+ l->next = SBM(SOA(shm_config->hdr->locktab_head));
+ shm_config->hdr->locktab_head = SBM(l);
ssvn_lock_add (l->nref, l->owner_job, l->ct);
@@ -596,7 +611,7 @@ int locktab_count(char *key)
locktab_ent_t *l;
int ct = 0;
- for (l = shm_config->hdr->locktab_head; l != NULL; l = l->next) {
+ for (l = SOA(shm_config->hdr->locktab_head); l != NULL; l = SOA(l->next)) {
if (stcmp (l->nref, key) == 0) ct++;
}
@@ -623,7 +638,7 @@ unsigned long locktab_pages(void)
unsigned long pages = 0;
float extra;
- for (l = shm_config->hdr->locktab_head; l != NULL; l = l->next) {
+ for (l = SOA(shm_config->hdr->locktab_head); l != NULL; l = SOA(l->next)) {
bytes += sizeof (locktab_ent_t);
}
@@ -645,7 +660,7 @@ unsigned long locktab_bytes(void)
unsigned int ct = 0;
unsigned long bytes = 0;
- for (l = shm_config->hdr->locktab_head; l != NULL; l = l->next) {
+ for (l = SOA(shm_config->hdr->locktab_head); l != NULL; l = SOA(l->next)) {
ct++;
bytes += sizeof (locktab_ent_t);
}
@@ -672,14 +687,14 @@ void locktab_dump(void)
printf ("%-20s%-20s%-20s%s\r\n", "NAMESPACE", "PID", "COUNT", "KEY");
printf ("%-20s%-20s%-20s%s\r\n", "---------", "---", "-----", "---");
- if (shm_config->hdr->locktab_head == NULL) {
+ if (SOA(shm_config->hdr->locktab_head) == NULL) {
printf ("\r\n*** lock table empty ***\r\n");
free (r);
return;
}
- for (l = shm_config->hdr->locktab_head; l != NULL; l = l->next) {
+ for (l = SOA(shm_config->hdr->locktab_head); l != NULL; l = SOA(l->next)) {
mref_init (r, MREF_RT_GLOBAL, "");
internal_to_mref (r, l->nref);