semaphore between C and PHP
| From: | Geocrawler.com | Date: | Tue, 21 Sep 1999 02:33:45 +0000 |
| Subject: | semaphore between C and PHP | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-11123@lists.php.net to get a copy of this message | ||
This message was sent from Geocrawler.com by "Hong Eunsil" <marsis@shinbiro.com>
Be sure to reply to that address.
Hello..
I am making some program.
I want my C program to share some data with "PHP" using semaphore & shared memory.
I want next ...
1. PHP have some database query.
2. PHP transfer this query to C program.
3. C program transfer query to MySQL then C program obtain MySQL result.
4. C program manage MySQL result then return the last result to PHP
Now.. the shared memory between C and PHP was made.
PHP have specific rule to make share memory... so i keep the rule in C program.
But I can't apply this way to make semaphore.
PHP have all semaphore's list and manage the list using specific list id.
PHP get sysvsem_sem structure by id. the structure can access semaphore.
PHP's internal fuction _php3_sysvsem_semop() use the structure to change semaphore value.
But.. _php3_sysvsem_semop() hadle not only semaphore value
but also count variable in sysvsem_sem structure.
<<<<---- I have terrible problem here.
My C program can't access PHP's semaphore list so I can't change sysvsem_sem's
count value.
My C program change only semaphore value. --;
My semaphore don't operate like PHP semaphore.
What shall i do?
Please help me.
_php3_sysvsem_semop() in sysvsem.c in PHP source is like that.
PHP make semaphore using that file.
static void _php3_sysvsem_semop(INTERNAL_FUNCTION_PARAMETERS, int acquire)
{
pval *arg_id;
int id, type;
sysvsem_sem *sem_ptr;
struct sembuf sop;
switch(ARG_COUNT(ht)) {
case 1:
if (getParameters(ht, 1, &arg_id)==FAILURE) {
RETURN_FALSE;
}
convert_to_long(arg_id);
id = (int)arg_id->value.lval;
break;
default:
WRONG_PARAM_COUNT;
break;
}
sem_ptr = (sysvsem_sem *) php3_list_find(id, &type); // <<<<-- get sysvsem_sem
structure from semaphore list
if (type!=php3_sysvsem_module.le_sem) {
php3_error(E_WARNING, "%d is not a SysV semaphore index", id);
RETURN_FALSE;
}
if (!acquire && sem_ptr->count == 0) { // <<<<<<<<<-----
Here, sem_ptr->count was checked.
php3_error(E_WARNING, "SysV semaphore index %d (key 0x%x) is not currently acquired",
id, sem_ptr->key);
RETURN_FALSE;
}
sop.sem_num = SYSVSEM_SEM;
sop.sem_op = acquire ? -1 : 1;
sop.sem_flg = SEM_UNDO;
while (semop(sem_ptr->semid, &sop, 1) == -1) {
if (errno != EINTR) {
php3_error(E_WARNING, "semop(%s) failed for key 0x%x: %s",
acquire ? "acquire" : "release", sem_ptr->key, strerror(errno));
RETURN_FALSE;
}
}
sem_ptr->count -= acquire ? -1 : 1; // <<<<<<----- Here sem_ptr->count was
changed..
RETURN_TRUE;
}
Geocrawler.com - The Knowledge Archive
If you experience spam, please contact Geocrawler immediately.